Newer
Older
import {Component, OnInit, ViewChild} from '@angular/core';
import {OverAllService} from '../overAll.service';
import {NzModalService} from 'ng-zorro-antd';
import {NzMessageService} from 'ng-zorro-antd';
import {Router} from '@angular/router';
import {
FormBuilder,
FormGroup,
Validators
} from '@angular/forms';
import {BasicEditComponent} from '../../modal/basic-edit/basic-edit.component';
import {BasiCheckComponent} from '../../modal/basi-check/basi-check.component';
import {CreateGroupComponent} from '../../modal/create-group/create-group.component';
import {AlarmModalComponent} from '../../modal/alarm-modal/alarm-modal.component';
export interface TreeNodeInterface {
host: any;
name: string;
age: number;
level: number;
expand: boolean;
address: string;
children?: TreeNodeInterface[];
}
@ViewChild('basicEdit') basicEdit: BasicEditComponent;
@ViewChild('smartCheck') smartCheck: BasiCheckComponent;
@ViewChild('smartCreateGroup') smartCreateGroup: CreateGroupComponent;
@ViewChild('smartPause') smartPause: PauseComponent;
@ViewChild('smartAlarmModal') smartAlarmModal: AlarmModalComponent;
constructor(private fb: FormBuilder, private overAllSer: OverAllService, private router: Router,
private modalService: NzModalService, private message: NzMessageService, private main: JhiMainComponent) {
collapse(array: TreeNodeInterface[], data: TreeNodeInterface, $event: boolean): void {
if ($event === false) {
if (data.children) {
data.children.forEach(d => {
const target = array.find(a => a.host === d.host);
target.expand = false;
this.collapse(array, target, false);
});
} else {
return;
}
}
}
convertTreeToList(root: any, groupId: string, index): TreeNodeInterface[] {
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, parent: node, gId: groupId, checked: false});
}
}
}
return array;
}
visitNode(node: TreeNodeInterface, hashMap: object, array: TreeNodeInterface[]): void {
array.push(node);
}
}
ngOnInit(): void {
this.selectedValue = 'group';
this.select();
this.findSize();
this.loading = true;
this.searchStatus = true;
this.frontPagination = false;
const data = {
this.searchStatus = false;
this.frontPagination = true;
}
(res) => {
if (res.errCode == 10000) {
this.green = res.data.size;
} else {
editBasicModal(item) {
this.basicEdit.editModal(item.hostid, item.name, item.gId);
showBasicCheckModal(hostid, host) {
this.smartCheck.showAddModal(hostid, host);
this.dataSet = res.data;
// this.dataSet = this.dataSet.filter(d => d.list); //过滤无list的
for (let i = 0; i < this.dataSet.length; i++) {
this.dataSet[i].host = i;
this.dataSet[i].checked = false;
this.dataSet = res.data;
// this.dataSet = this.dataSet.filter(d => d.list); //过滤无list的
this.expandDataCache[item.host] = this.convertTreeToList(item, item.id, index);
nzTitle: '删除',
nzContent: '<b style="color: red;">确认删除该资源吗?</b>',
nzOkText: '确定',
nzOkType: 'danger',
nzOnOk: () => {
};
data.hostids.push(item.hostid);
this.overAllSer.deleteHostPost(data).subscribe(
this.message.info('请选择需要删除的设备');
return false;
}
this.modalService.confirm({
nzTitle: '删除',
nzContent: '<b style="color: red;">确认要删除所选设备吗?</b>',
nzOkText: '确定',
nzOkType: 'danger',
nzOnOk: () => {
const data = {
this.overAllSer.deleteHostPost(data).subscribe(
(res) => {
if (res.errCode == 10000) {
this.message.info('删除成功');
this.select();
} else {
this.message.info(res.errMsg);
}
}
);
},
nzCancelText: '取消',
nzOnCancel: () => console.log('Cancel')
});
}
updateGroup(item) {
this.smartCreateGroup.showEditModal('修改分组', item);
nzTitle: '删除',
nzContent: '<b style="color: red;">确认删除该分组吗?</b>',
nzOkText: '确定',
nzOkType: 'danger',
nzOnOk: () => {
'groupids': [item.groupid],
'hostExtend': {
'superiorHostid': null
getChildrenType(item) {
if (item.list) {
if (item.expand) {
item.expand = true;
}
return false;
}
this.loading = true;
this.dataSet[item.host].list = res.data;
this.toTree(item.host);
if (item.hostExtend) {
if (item.hostExtend.equipmentType == '交换机') {
this.router.navigate(['app/main/basic-detail'], {
queryParams: {
hostId: item.hostid,
type: type,
name: item.name,
hostName: item.host
showTempStop(item) {
this.smartPause.showModal(item.hostid, '基础资源');
selectChecked(event, item) {
if (event) {
if (item.hostid) {
nzOkText: '确定',
nzCancelText: '取消',
nzOnOk: () => {
let params1 = 0;
(res) => {
if (res.errCode == 10000) {
this.message.info('修改成功');
this.select();
} else {
this.message.info(res.errMsg);
}
}
);
},
nzOnCancel: () => console.log('Cancel')
});
}
openBatchHost(status, operation) {
if (this.batchDelList.length == 0) {
this.message.info('请选择需要' + operation + '的设备');
return false;
}
this.modalService.confirm({
nzTitle: '监控',
nzOkText: '确定',
nzCancelText: '取消',
nzOnOk: () => {
const data = {
this.overAllSer.batchStopOrOpen(data).subscribe(
(res) => {
if (res.errCode == 10000) {
this.message.info('修改成功');
this.batchDelList = [];
this.select();
} else {
this.message.info(res.errMsg);
}
}
);
},
nzOnCancel: () => console.log('Cancel')
});
goTOInventory(id) {
this.router.navigate(['app/main/assetsDetail'], {
queryParams: {
invertoryId: id
}
});