Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
L
luna
Project
Project
Details
Activity
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
luna
Commits
c251ce88
Commit
c251ce88
authored
Nov 23, 2018
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 回滚版本
parent
b5e354b6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
123 additions
and
68 deletions
+123
-68
asset-tree.component.ts
src/app/elements/asset-tree/asset-tree.component.ts
+123
-68
No files found.
src/app/elements/asset-tree/asset-tree.component.ts
View file @
c251ce88
...
...
@@ -33,25 +33,25 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
},
callback
:
{
onClick
:
this
.
onCzTreeOnClick
.
bind
(
this
),
onRightClick
:
this
.
onRightClick
.
bind
(
this
),
onAsyncSuccess
:
this
.
onzTreeAsyncSuccess
.
bind
(
this
)
onRightClick
:
this
.
onRightClick
.
bind
(
this
)
},
async
:
{
enable
:
true
,
url
:
'/api/perms/v1/user/nodes/children/'
,
autoParam
:
[
'node_id=id'
,
'name=n'
,
'level=lv'
],
type
:
'get'
,
dataFilter
:
this
.
nodeFilter
}
};
pos
=
{
left
:
'100px'
,
top
:
'200px'
};
hiddenNodes
:
any
;
expandNodes
:
any
;
zTree
:
any
;
searching
=
false
;
isShowRMenu
=
false
;
rightClickSelectNode
:
any
;
onCzTreeOnClick
(
event
,
treeId
,
treeNode
,
clickFlag
)
{
if
(
treeNode
.
isParent
)
{
const
zTreeObj
=
$
.
fn
.
zTree
.
getZTreeObj
(
'ztree'
);
zTreeObj
.
expandNode
(
treeNode
);
}
else
{
this
.
Connect
(
treeNode
);
}
}
constructor
(
private
_appService
:
AppService
,
public
_dialog
:
MatDialog
,
public
_logger
:
LogService
)
{
...
...
@@ -67,7 +67,7 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
.
debounceTime
(
300
)
.
distinctUntilChanged
()
.
subscribe
((
n
)
=>
{
this
.
searchNode
();
this
.
filter
();
});
}
...
...
@@ -80,53 +80,58 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
}
}
nodeFilter
(
treeId
,
parentNode
,
childNodes
)
{
$
.
each
(
childNodes
,
function
(
index
,
value
)
{
value
[
'node_id'
]
=
value
[
'id'
];
value
[
'id'
]
=
value
[
'tree_id'
];
if
(
value
[
'tree_id'
]
!==
value
[
'tree_parent'
])
{
value
[
'pId'
]
=
value
[
'tree_parent'
];
}
else
{
value
[
'isParent'
]
=
true
;
}
value
[
'name'
]
=
value
[
'value'
];
if
(
!
value
[
'is_node'
])
{
const
platform
=
value
[
'asset'
][
'platform'
].
toLowerCase
().
indexOf
(
'win'
)
===
0
?
'windows'
:
'linux'
;
value
[
'title'
]
=
value
[
'asset'
][
'ip'
]
||
value
[
'name'
];
value
[
'iconSkin'
]
=
platform
;
draw
()
{
const
nodes
=
{};
const
assets
=
{};
this
.
Data
.
forEach
(
node
=>
{
if
(
!
nodes
[
node
[
'id'
]])
{
nodes
[
node
[
'id'
]]
=
true
;
this
.
nodes
.
push
({
'id'
:
node
[
'id'
],
'key'
:
node
[
'key'
],
'name'
:
node
[
'name'
],
'title'
:
node
[
'name'
],
'value'
:
node
[
'value'
],
'pId'
:
node
[
'parent'
],
'ip'
:
''
,
'assets_amount'
:
node
[
'assets_amount'
],
'isParent'
:
true
,
'open'
:
node
[
'key'
]
===
'0'
});
}
value
[
'isParent'
]
=
value
[
'is_node'
];
});
return
childNodes
;
}
onzTreeAsyncSuccess
(
event
,
treeId
,
treeNode
,
msg
)
{
// 代表第一次加载
if
(
!
treeNode
)
{
this
.
zTree
=
$
.
fn
.
zTree
.
getZTreeObj
(
treeId
);
if
(
this
.
searching
)
{
this
.
zTree
.
expandAll
(
true
);
node
[
'assets_granted'
].
forEach
(
asset
=>
{
if
(
!
assets
[
asset
[
'id'
]])
{
const
platform
=
asset
[
'platform'
].
toLowerCase
().
indexOf
(
'win'
)
===
0
?
'windows'
:
'linux'
;
this
.
nodes
.
push
({
'id'
:
asset
[
'id'
],
'name'
:
asset
[
'hostname'
],
'value'
:
asset
[
'hostname'
],
'system_users_granted'
:
asset
[
'system_users_granted'
],
'platform'
:
asset
[
'platform'
],
'ip'
:
asset
[
'ip'
],
'title'
:
asset
[
'ip'
],
'isParent'
:
false
,
'pId'
:
node
[
'id'
],
'iconSkin'
:
platform
});
assets
[
asset
[
'id'
]
+
'@'
+
node
[
'id'
]]
=
true
;
}
});
});
this
.
nodes
.
sort
(
function
(
node1
,
node2
)
{
if
(
node1
.
isParent
&&
!
node2
.
isParent
)
{
return
-
1
;
}
else
if
(
!
node1
.
isParent
&&
node2
.
isParent
)
{
return
1
;
}
else
{
const
root
=
this
.
zTree
.
getNodes
()[
0
];
this
.
zTree
.
expandNode
(
root
,
true
);
return
node1
.
name
<
node2
.
name
?
-
1
:
1
;
}
}
}
onCzTreeOnClick
(
event
,
treeId
,
treeNode
,
clickFlag
)
{
if
(
treeNode
.
isParent
)
{
const
zTreeObj
=
$
.
fn
.
zTree
.
getZTreeObj
(
'ztree'
);
zTreeObj
.
expandNode
(
treeNode
);
}
else
{
this
.
Connect
(
treeNode
.
asset
);
}
}
draw
()
{
});
$
.
fn
.
zTree
.
init
(
$
(
'#ztree'
),
this
.
setting
,
this
.
nodes
);
//
this.zTree = $.fn.zTree.getZTreeObj('ztree');
//
const root = this.zTree.getNodes()[0];
//
this.zTree.expandNode(root, true);
this
.
zTree
=
$
.
fn
.
zTree
.
getZTreeObj
(
'ztree'
);
const
root
=
this
.
zTree
.
getNodes
()[
0
];
this
.
zTree
.
expandNode
(
root
,
true
);
}
showRMenu
(
left
,
top
)
{
...
...
@@ -140,7 +145,7 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
}
onRightClick
(
event
,
treeId
,
treeNode
)
{
if
(
!
treeNode
||
treeNode
.
isParent
||
treeNode
.
asset
.
platform
.
toLowerCase
()
===
'windows'
)
{
if
(
!
treeNode
||
treeNode
.
isParent
||
treeNode
.
platform
.
toLowerCase
()
===
'windows'
)
{
return
null
;
}
if
(
!
treeNode
&&
event
.
target
.
tagName
.
toLowerCase
()
!==
'button'
&&
$
(
event
.
target
).
parents
(
'a'
).
length
===
0
)
{
...
...
@@ -187,10 +192,10 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
}
connectFileManager
()
{
const
host
=
this
.
rightClickSelectNode
.
asset
;
const
host
=
this
.
rightClickSelectNode
;
const
id
=
NavList
.
List
.
length
-
1
;
if
(
host
)
{
NavList
.
List
[
id
].
nick
=
'[FILE]'
+
host
.
host
name
;
NavList
.
List
[
id
].
nick
=
'[FILE]'
+
host
.
name
;
NavList
.
List
[
id
].
connected
=
true
;
NavList
.
List
[
id
].
edit
=
false
;
NavList
.
List
[
id
].
closed
=
false
;
...
...
@@ -209,8 +214,10 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
login
(
host
,
user
)
{
const
id
=
NavList
.
List
.
length
-
1
;
this
.
_logger
.
debug
(
NavList
);
this
.
_logger
.
debug
(
host
);
if
(
user
)
{
NavList
.
List
[
id
].
nick
=
host
.
host
name
;
NavList
.
List
[
id
].
nick
=
host
.
name
;
NavList
.
List
[
id
].
connected
=
true
;
NavList
.
List
[
id
].
edit
=
false
;
NavList
.
List
[
id
].
closed
=
false
;
...
...
@@ -241,25 +248,73 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
return
user
;
}
searchNode
()
{
recurseParent
(
node
)
{
const
parentNode
=
node
.
getParentNode
();
if
(
parentNode
&&
parentNode
.
pId
)
{
return
[
parentNode
,
...
this
.
recurseParent
(
parentNode
)];
}
else
if
(
parentNode
)
{
return
[
parentNode
];
}
else
{
return
[];
}
}
recurseChildren
(
node
)
{
if
(
!
node
.
isParent
)
{
return
[];
}
const
children
=
node
.
children
;
if
(
!
children
)
{
return
[];
}
let
all_children
=
[];
children
.
forEach
((
n
)
=>
{
all_children
=
[...
children
,
...
this
.
recurseChildren
(
n
)];
});
return
all_children
;
}
filter
()
{
const
zTreeObj
=
$
.
fn
.
zTree
.
getZTreeObj
(
'ztree'
);
if
(
!
zTreeObj
)
{
return
null
;
}
const
_keywords
=
this
.
query
;
const
nodes
=
zTreeObj
.
transformToArray
(
zTreeObj
.
getNodes
());
if
(
!
_keywords
)
{
// 第一次刷新
if
(
!
this
.
searching
)
{
return
null
;
if
(
this
.
hiddenNodes
)
{
zTreeObj
.
showNodes
(
this
.
hiddenNodes
);
this
.
hiddenNodes
=
null
;
}
// 以后搜索后回来
this
.
searching
=
false
;
zTreeObj
.
setting
.
async
.
url
=
'/api/perms/v1/user/nodes/children/'
;
}
else
{
this
.
searching
=
true
;
zTreeObj
.
setting
.
async
.
url
=
`/api/perms/v1/user/nodes/children/?search=
${
_keywords
}
`
;
if
(
this
.
expandNodes
)
{
this
.
expandNodes
.
forEach
((
node
)
=>
{
if
(
node
.
id
!==
nodes
[
0
].
id
)
{
zTreeObj
.
expandNode
(
node
,
false
);
}
});
this
.
expandNodes
=
null
;
}
return
null
;
}
zTreeObj
.
reAsyncChildNodes
(
null
,
'refresh'
);
let
shouldShow
=
[];
const
matchedNodes
=
zTreeObj
.
getNodesByFilter
(
function
(
node
){
return
node
.
name
.
indexOf
(
_keywords
)
!==
-
1
||
node
.
ip
.
indexOf
(
_keywords
)
!==
-
1
;
});
matchedNodes
.
forEach
((
node
)
=>
{
const
parents
=
this
.
recurseParent
(
node
);
const
children
=
this
.
recurseChildren
(
node
);
shouldShow
=
[...
shouldShow
,
...
parents
,
...
children
,
node
];
});
this
.
hiddenNodes
=
nodes
;
this
.
expandNodes
=
shouldShow
;
zTreeObj
.
hideNodes
(
nodes
);
zTreeObj
.
showNodes
(
shouldShow
);
shouldShow
.
forEach
((
node
)
=>
{
if
(
node
.
isParent
)
{
zTreeObj
.
expandNode
(
node
,
true
);
}
});
// zTreeObj.expandAll(true);
}
}
...
...
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