Commit 90972e43 authored by wangqinghua's avatar wangqinghua

directive

parent e1ff90e4
......@@ -43,35 +43,13 @@
</thead>
<tbody>
<ng-template ngFor let-data [ngForOf]="nzTable.data">
<ng-template ngFor let-item [ngForOf]="expandDataCache[data.host]">
<ng-template ngFor let-item [ngForOf]="expandDataCache[data.serviceid]">
<tr *ngIf="(item.parent&&item.parent.expand)||!(item.parent)">
<td [nzIndentSize]="item.level*20" nzShowExpand [nzExpand]='item.expand' (nzExpandChange)="getChildren(item)">
<span (click)="showEditModal(item)" class="main-color cursor">{{item.name}}</span>
</td>
<td class="round-tag tag-form">
<ng-container *ngIf="item.status == 0">
<nz-tag class="tag-green" [nzColor]="color.green"></nz-tag>
</ng-container>
<ng-container *ngIf="item.status == 2 || item.status == 3">
<nz-tag class="tag-yellow" [nzColor]="color.yellow"></nz-tag>
</ng-container>
<ng-container *ngIf="item.status == 4 || item.status == 5">
<nz-tag class="tag-red" [nzColor]="color.red"></nz-tag>
</ng-container>
</td>
<td class="cursor">
<span (click)="goTOInventory(item?.inventory?.id)">{{item?.inventory?.name}}</span>
</td>
<td class="handle main-color">
<span (click)="showBasicEditModal(item)">添加子节点</span>
<ng-container *ngIf="!item.level">
<span (click)="showBasicEditModal(item)">配置告警推送</span>
</ng-container>
<ng-container *ngIf="item.level">
<span (click)="editBasicModal(item)">编辑</span>
<span (click)="showDeleteConfirm(item)">移除</span>
</ng-container>
<td [nzIndentSize]="item.level*20" [nzShowExpand]="!!item.children" [(nzExpand)]="item.expand" (nzExpandChange)="getChildren(item)">
{{item.name}}
</td>
<td>{{item.age}}</td>
<td>{{item.address}}</td>
</tr>
</ng-template>
</ng-template>
......
......@@ -18,46 +18,59 @@ export class BConfigComponent implements OnInit {
allChecked = false;
isLoading = false; //加载中
dataSet; //数据list
expandDataCache = {};
constructor(private busineSer:BusinessService,private message:NzMessageService) {
}
convertTreeToList(root: any, serviceid: string, index): TreeNodeInterface[] {
dataSet: any[];
expandDataCache = {};
collapse(array: TreeNodeInterface[], data: TreeNodeInterface, $event: boolean): void {
if ($event === false) {
if (data.children) {
data.children.forEach(d => {
const target = array.find(a => a.serviceid === d.serviceid);
target.expand = false;
this.collapse(array, target, false);
});
} else {
return;
}
}
}
convertTreeToList(root: object): TreeNodeInterface[] {
const stack = [];
const array = [];
const hashMap = {};
if (root.host == index) {
stack.push({...root, level: 0, expand: true});
} else {
stack.push({...root, level: 0, expand: false});
}
stack.push({ ...root, level: 0, expand: true });
while (stack.length !== 0) {
const node = stack.pop();
this.visitNode(node, hashMap, array);
if (node.list) {
for (let i = node.list.length - 1; i >= 0; i--) {
stack.push({...node.list[i], level: node.level + 1, expand: true,serviceid: serviceid, parent: node, checked: false});
if (node.children) {
for (let i = node.children.length - 1; i >= 0; i--) {
stack.push({ ...node.children[ i ], level: node.level + 1, expand: false, parent: node });
}
}
}
// console.log(array);
return array;
}
visitNode(node: TreeNodeInterface, hashMap: object, array: TreeNodeInterface[]): void {
if (!hashMap[node.host]) {
hashMap[node.host] = true;
console.log(hashMap);
if (!hashMap[ node.serviceid ]) {
hashMap[ node.serviceid ] = true;
array.push(node);
}
}
toTree(index) {
this.dataSet.forEach(item => {
this.expandDataCache[item.host] = this.convertTreeToList(item, item.serviceid, index);
this.dataSet.forEach((item,i) => {
this.expandDataCache[item.serviceid] = this.convertTreeToList(item);
});
console.log(this.expandDataCache);
}
ngOnInit() {
......@@ -76,9 +89,9 @@ export class BConfigComponent implements OnInit {
if(res.errCode == 10000){
this.dataSet = res.data;
this.dataSet.forEach((e,index)=>{
e.host = index;
e.checked = false;
})
e.children = [];
});
this.toTree(null);
}else{
this.message.error(res.errMsg);
......@@ -89,14 +102,6 @@ export class BConfigComponent implements OnInit {
//
getChildren(item){
if (item.list) {
if (item.expand) {
item.expand = false;
} else {
item.expand = true;
}
return false;
}
this.isLoading = true;
const data = {
"sid":item.serviceid,
......@@ -104,11 +109,13 @@ export class BConfigComponent implements OnInit {
this.busineSer.findChild(data).subscribe(
(res)=>{
if (res.data) {
this.dataSet[item.host].list = res.data;
this.toTree(item.host);
this.dataSet.forEach(e=>{
if(e.serviceid == item.serviceid){
e.children = res.data;
}
});
this.toTree(item.service);
} else {
this.dataSet[item.host].list = [];
this.toTree(item.host);
this.message.info('该分组下无资源');
}
this.isLoading = false;
......
......@@ -18,11 +18,10 @@ import {JhiMainComponent} from '../../layouts';
export interface TreeNodeInterface {
host: any;
serviceid: any;
name: string;
age: number;
level: number;
expand: boolean;
address: string;
children?: TreeNodeInterface[];
}
......@@ -120,7 +119,6 @@ export class BasicComponent implements OnInit {
}
}
}
return array;
}
......
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