Commit 76e97f41 authored by ibuler's avatar ibuler

[Update] 修改tree search 带上组织

parent ff8c1436
...@@ -4,6 +4,7 @@ import {BehaviorSubject, Subject} from 'rxjs'; ...@@ -4,6 +4,7 @@ import {BehaviorSubject, Subject} from 'rxjs';
import {takeUntil} from 'rxjs/operators'; import {takeUntil} from 'rxjs/operators';
import {ActivatedRoute} from '@angular/router'; import {ActivatedRoute} from '@angular/router';
import {groupBy} from '@app/utils/common';
import {AppService, HttpService, LogService, NavService, SettingService, TreeFilterService} from '@app/services'; import {AppService, HttpService, LogService, NavService, SettingService, TreeFilterService} from '@app/services';
import {connectEvt, translate} from '@app/globals'; import {connectEvt, translate} from '@app/globals';
import {TreeNode, ConnectEvt} from '@app/model'; import {TreeNode, ConnectEvt} from '@app/model';
...@@ -323,7 +324,7 @@ export class ElementAssetTreeComponent implements OnInit, OnDestroy { ...@@ -323,7 +324,7 @@ export class ElementAssetTreeComponent implements OnInit, OnDestroy {
if (!this.assetsTree) { if (!this.assetsTree) {
return; return;
} }
const searchNode = this.assetsTree.getNodesByFilter((node) => node.id === 'search'); let searchNode = this.assetsTree.getNodesByFilter((node) => node.id === 'search');
if (searchNode) { if (searchNode) {
this.assetsTree.removeChildNodes(searchNode[0]); this.assetsTree.removeChildNodes(searchNode[0]);
this.assetsTree.removeNode(searchNode[0]); this.assetsTree.removeNode(searchNode[0]);
...@@ -348,10 +349,19 @@ export class ElementAssetTreeComponent implements OnInit, OnDestroy { ...@@ -348,10 +349,19 @@ export class ElementAssetTreeComponent implements OnInit, OnDestroy {
const assetsAmount = nodes.length; const assetsAmount = nodes.length;
name = `${name} (${assetsAmount})`; name = `${name} (${assetsAmount})`;
const newNode = {id: 'search', name: name, isParent: true, open: true, zAsync: true}; const newNode = {id: 'search', name: name, isParent: true, open: true, zAsync: true};
const parentNode = this.assetsTree.addNodes(null, newNode)[0]; searchNode = this.assetsTree.addNodes(null, newNode)[0];
parentNode.zAsync = true; searchNode.zAsync = true;
this.assetsTree.addNodes(parentNode, nodes); const nodesGroupByOrg = groupBy(nodes, (node) => {
parentNode.open = true; return node.meta.asset.org_name;
});
nodesGroupByOrg.forEach((item) => {
const orgName = item[0].meta.asset.org_name;
const orgNodeData = {id: orgName, name: orgName, isParent: true, open: true, zAsync: true};
const orgNode = this.assetsTree.addNodes(searchNode, orgNodeData)[0];
orgNode.zAsync = true;
this.assetsTree.addNodes(orgNode, item);
});
searchNode.open = true;
}); });
return; return;
} }
......
export function groupBy(array, f) {
const groups = {};
array.forEach( function( o ) {
const group = JSON.stringify( f(o) );
groups[group] = groups[group] || [];
groups[group].push( o );
});
return Object.keys(groups).map( function( group ) {
return groups[group];
});
}
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