Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kityminder-core
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
吴志俊
kityminder-core
Commits
ce1fca81
Commit
ce1fca81
authored
May 07, 2014
by
techird
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加策略函数
parent
a5fe311c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
66 additions
and
21 deletions
+66
-21
expand.js
src/module/expand.js
+66
-21
No files found.
src/module/expand.js
View file @
ce1fca81
...
@@ -3,6 +3,38 @@ KityMinder.registerModule( "Expand", function () {
...
@@ -3,6 +3,38 @@ KityMinder.registerModule( "Expand", function () {
STATE_EXPAND
=
'expand'
,
STATE_EXPAND
=
'expand'
,
STATE_COLLAPSE
=
'collapse'
;
STATE_COLLAPSE
=
'collapse'
;
/**
* 该函数返回一个策略,表示递归到节点指定的层数
*
* 返回的策略表示把操作(展开/收起)进行到指定的层数
* 也可以给出一个策略指定超过层数的节点如何操作,默认不进行任何操作
*
* @param {int} deep_level 指定的层数
* @param {Function} policy_after_level 超过的层数执行的策略
*/
function
generateDeepPolicy
(
deep_level
,
policy_after_level
)
{
return
function
(
node
,
state
,
policy
,
level
)
{
var
children
,
child
,
i
;
node
.
setData
(
EXPAND_STATE_DATA
,
state
);
level
=
level
||
1
;
children
=
node
.
getChildren
();
for
(
i
=
0
;
i
<
children
.
length
;
i
++
)
{
child
=
children
[
i
];
if
(
level
<=
deep_level
)
{
policy
(
child
,
state
,
policy
,
level
+
1
);
}
else
if
(
policy_after_level
)
{
policy_after_level
(
child
,
state
,
policy
,
level
+
1
);
}
}
};
}
/**
/**
* 节点展开和收缩的策略常量
* 节点展开和收缩的策略常量
*
*
...
@@ -13,45 +45,58 @@ KityMinder.registerModule( "Expand", function () {
...
@@ -13,45 +45,58 @@ KityMinder.registerModule( "Expand", function () {
* @param {Function} policy 提供当前策略的函数,方便递归调用
* @param {Function} policy 提供当前策略的函数,方便递归调用
*/
*/
MinderNode
.
EXAPND_POLICY
=
{
MinderNode
.
EXAPND_POLICY
=
{
/**
/**
* 策略 1:只修改当前节点的状态,不递归子节点的状态
* 策略 1:只修改当前节点的状态,不递归子节点的状态
*/
*/
KEEP_STATE
:
function
(
node
,
state
,
policy
)
{
KEEP_STATE
:
function
(
node
,
state
,
policy
)
{
node
.
setData
(
expandStateData
,
state
===
STATE_EXPAND
);
node
.
setData
(
EXPAND_STATE_DATA
,
state
);
},
},
generateDeepPolicy
:
generateDeepPolicy
,
/**
/**
* 策略 2:该函数返回一个策略,表示递归到节点指定的层数
* 策略 2:把操作进行到儿子
* 返回的策略表示把操作(展开/收起)进行到指定的层数
*
* @param {int} deep_level 指定的层数
*/
*/
DEEP_TO_LEVEL
:
function
(
deep_level
)
{
DEEP_TO_CHILD
:
generateDeepPolicy
(
1
),
return
function
(
node
,
state
,
policy
)
{
};
},
DEEP_TO_CHILD
:
function
()
{
},
/**
DEEP_TO_LEAVE
:
function
()
{
* 策略 3:把操作进行到叶子
*/
}
DEEP_TO_LEAF
:
generateDeepPolicy
(
Number
.
MAX_VALUE
)
};
};
// 将展开的操作和状态读取接口拓展到 MinderNode 上
kity
.
extendClass
(
MinderNode
,
{
kity
.
extendClass
(
MinderNode
,
{
/**
* 使用指定的策略展开节点
* @param {Policy} policy 展开的策略,默认为 KEEP_STATE
*/
expand
:
function
(
policy
)
{
expand
:
function
(
policy
)
{
node
.
setData
(
EXPAND_STATE_DATA
,
STATE_EXPAND
);
policy
=
policy
||
EXAPND_POLICY
.
KEEP_STATE
;
policy
(
this
,
STATE_EXPAND
,
policy
);
return
this
;
},
},
collapse
:
function
()
{
node
.
setData
(
EXPAND_STATE_DATA
,
STATE_COLLAPSE
);
/**
* 使用指定的策略收起节点
* @param {Policy} policy 展开的策略,默认为 KEEP_STATE
*/
collapse
:
function
(
policy
)
{
policy
=
policy
||
EXAPND_POLICY
.
KEEP_STATE
;
policy
(
this
,
STATE_EXPAND
,
policy
);
return
this
;
},
},
/**
* 判断节点当前的状态是否为展开
*/
isExpanded
:
function
()
{
isExpanded
:
function
()
{
return
node
.
getData
(
EXPAND_STATE_DATA
)
===
STATE_EXPAND
;
return
!!
node
.
getData
(
EXPAND_STATE_DATA
)
;
}
}
}
);
}
);
return
{
return
{
'commands'
:
{
'commands'
:
{}
}
};
};
}
);
}
);
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment