Commit c251ce88 authored by ibuler's avatar ibuler

[Update] 回滚版本

parent b5e354b6
...@@ -33,25 +33,25 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges { ...@@ -33,25 +33,25 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
}, },
callback: { callback: {
onClick: this.onCzTreeOnClick.bind(this), onClick: this.onCzTreeOnClick.bind(this),
onRightClick: this.onRightClick.bind(this), onRightClick: this.onRightClick.bind(this)
onAsyncSuccess: this.onzTreeAsyncSuccess.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'}; pos = {left: '100px', top: '200px'};
hiddenNodes: any; hiddenNodes: any;
expandNodes: any; expandNodes: any;
zTree: any; zTree: any;
searching = false;
isShowRMenu = false; isShowRMenu = false;
rightClickSelectNode: any; 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, constructor(private _appService: AppService,
public _dialog: MatDialog, public _dialog: MatDialog,
public _logger: LogService) { public _logger: LogService) {
...@@ -67,7 +67,7 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges { ...@@ -67,7 +67,7 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
.debounceTime(300) .debounceTime(300)
.distinctUntilChanged() .distinctUntilChanged()
.subscribe((n) => { .subscribe((n) => {
this.searchNode(); this.filter();
}); });
} }
...@@ -80,53 +80,58 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges { ...@@ -80,53 +80,58 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
} }
} }
nodeFilter(treeId, parentNode, childNodes) { draw() {
$.each(childNodes, function (index, value) { const nodes = {};
value['node_id'] = value['id']; const assets = {};
value['id'] = value['tree_id']; this.Data.forEach(node => {
if (value['tree_id'] !== value['tree_parent']) { if (!nodes[node['id']]) {
value['pId'] = value['tree_parent']; nodes[node['id']] = true;
} else { this.nodes.push({
value['isParent'] = true; 'id': node['id'],
} 'key': node['key'],
value['name'] = value['value']; 'name': node['name'],
if (!value['is_node']) { 'title': node['name'],
const platform = value['asset']['platform'].toLowerCase().indexOf('win') === 0 ? 'windows' : 'linux'; 'value': node['value'],
value['title'] = value['asset']['ip'] || value['name']; 'pId': node['parent'],
value['iconSkin'] = platform; 'ip': '',
'assets_amount': node['assets_amount'],
'isParent': true,
'open': node['key'] === '0'
});
} }
value['isParent'] = value['is_node'];
});
return childNodes;
}
onzTreeAsyncSuccess(event, treeId, treeNode, msg) { node['assets_granted'].forEach(asset => {
// 代表第一次加载 if (!assets[asset['id']]) {
if (!treeNode) { const platform = asset['platform'].toLowerCase().indexOf('win') === 0 ? 'windows' : 'linux';
this.zTree = $.fn.zTree.getZTreeObj(treeId); this.nodes.push({
if (this.searching) { 'id': asset['id'],
this.zTree.expandAll(true); '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 { } else {
const root = this.zTree.getNodes()[0]; return node1.name < node2.name ? -1 : 1;
this.zTree.expandNode(root, true);
} }
} });
}
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); $.fn.zTree.init($('#ztree'), this.setting, this.nodes);
// this.zTree = $.fn.zTree.getZTreeObj('ztree'); this.zTree = $.fn.zTree.getZTreeObj('ztree');
// const root = this.zTree.getNodes()[0]; const root = this.zTree.getNodes()[0];
// this.zTree.expandNode(root, true); this.zTree.expandNode(root, true);
} }
showRMenu(left, top) { showRMenu(left, top) {
...@@ -140,7 +145,7 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges { ...@@ -140,7 +145,7 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
} }
onRightClick(event, treeId, treeNode) { onRightClick(event, treeId, treeNode) {
if (!treeNode || treeNode.isParent || treeNode.asset.platform.toLowerCase() === 'windows') { if (!treeNode || treeNode.isParent || treeNode.platform.toLowerCase() === 'windows') {
return null; return null;
} }
if (!treeNode && event.target.tagName.toLowerCase() !== 'button' && $(event.target).parents('a').length === 0) { if (!treeNode && event.target.tagName.toLowerCase() !== 'button' && $(event.target).parents('a').length === 0) {
...@@ -187,10 +192,10 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges { ...@@ -187,10 +192,10 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
} }
connectFileManager() { connectFileManager() {
const host = this.rightClickSelectNode.asset; const host = this.rightClickSelectNode;
const id = NavList.List.length - 1; const id = NavList.List.length - 1;
if (host) { if (host) {
NavList.List[id].nick = '[FILE]' + host.hostname; NavList.List[id].nick = '[FILE]' + host.name;
NavList.List[id].connected = true; NavList.List[id].connected = true;
NavList.List[id].edit = false; NavList.List[id].edit = false;
NavList.List[id].closed = false; NavList.List[id].closed = false;
...@@ -209,8 +214,10 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges { ...@@ -209,8 +214,10 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
login(host, user) { login(host, user) {
const id = NavList.List.length - 1; const id = NavList.List.length - 1;
this._logger.debug(NavList);
this._logger.debug(host);
if (user) { if (user) {
NavList.List[id].nick = host.hostname; NavList.List[id].nick = host.name;
NavList.List[id].connected = true; NavList.List[id].connected = true;
NavList.List[id].edit = false; NavList.List[id].edit = false;
NavList.List[id].closed = false; NavList.List[id].closed = false;
...@@ -241,25 +248,73 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges { ...@@ -241,25 +248,73 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
return user; 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'); const zTreeObj = $.fn.zTree.getZTreeObj('ztree');
if (!zTreeObj) { if (!zTreeObj) {
return null; return null;
} }
const _keywords = this.query; const _keywords = this.query;
const nodes = zTreeObj.transformToArray(zTreeObj.getNodes());
if (!_keywords) { if (!_keywords) {
// 第一次刷新 if (this.hiddenNodes) {
if (!this.searching) { zTreeObj.showNodes(this.hiddenNodes);
return null; this.hiddenNodes = null;
} }
// 以后搜索后回来 if (this.expandNodes) {
this.searching = false; this.expandNodes.forEach((node) => {
zTreeObj.setting.async.url = '/api/perms/v1/user/nodes/children/'; if (node.id !== nodes[0].id) {
} else { zTreeObj.expandNode(node, false);
this.searching = true; }
zTreeObj.setting.async.url = `/api/perms/v1/user/nodes/children/?search=${_keywords}`; });
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);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment