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