Commit cd12feb0 authored by ibuler's avatar ibuler

[Update] 修改asset tree支持搜索ip和显示ip作为tittle

parent 516e9bf2
......@@ -25,6 +25,9 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
data: {
simpleData: {
enable: true
},
key: {
title: 'title'
}
},
callback: {
......@@ -81,8 +84,10 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
'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'
......@@ -91,16 +96,18 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
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'],
'comment': asset['comment'],
'ip': asset['ip'],
'title': asset['ip'],
'isParent': false,
'pId': node['id'],
'iconSkin': asset['platform'].toLowerCase()
'iconSkin': platform
});
assets[asset['id'] + '@' + node['id']] = true;
}
......@@ -116,6 +123,9 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
}
});
$.fn.zTree.init($('#ztree'), this.setting, this.nodes);
const zTree = $.fn.zTree.getZTreeObj('ztree');
const root = zTree.getNodes()[0];
zTree.expandNode(root);
}
Connect(host) {
......@@ -237,12 +247,13 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
return null;
}
let shouldShow = [];
nodes.forEach((node) => {
if (shouldShow.indexOf(node) === -1 && node.name.indexOf(_keywords) !== -1) {
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;
......
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