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';
name: string;
level: number;
expand: boolean;
children?: TreeNodeInterface[];
}
@ViewChild('basicEdit') basicEdit: BasicEditComponent;
@ViewChild('smartCheck') smartCheck: BasiCheckComponent;
@ViewChild('smartCreateGroup') smartCreateGroup: CreateGroupComponent;
@ViewChild('smartPause') smartPause: PauseComponent;
@ViewChild('smartAlarmModal') smartAlarmModal: AlarmModalComponent;
//表格信息
loading = false;
isCheck = false;
allChecked = false;
selectedValue = 'group';
groupList = []; //分组列表
groupid = null;
equipmentTypeid = null;
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 {
toTree(index) {
this.dataSet.forEach(item => {
this.expandDataCache[item.host] = this.convertTreeToList(item, item.id, index);
});
}
ngOnInit(): void {
this.findOpStatus();
this.select('group');
}
select(e) {
this.groupid = null;
this.equipmentTypeid = null;
if (e == 'group') {
this.getGroup();
} else {
this.getType();
//获取资源分组
getGroup() {
this.overAllSer.findGroup().subscribe(
if (res.errCode == 10000) {
this.groupList = res.data;
this.search();
//获取设备类型
getType() {
this.overAllSer.findType().subscribe(
(res) => {
this.loading = false;
if (res.errCode == 10000) {
this.groupList = res.data;
this.search();
}
}
);
this.status = status;
}
this.pageNum = 1;
this.search();
}
/*
//waringName:(值为:正常,禁用,告警,严重)
*/
this.pageNum = 1;
this.groupid = e;
this.equipmentTypeid = null;
this.searchRe();
}
this.loading = true;
this.pageNum = 1;
this.groupid = null;
this.equipmentTypeid = e;
this.searchRe();
}
searchRe() {
pageNum: this.pageNum,
pageCount: this.pageCount,
obj: {
name: this.searchName,
waringName: this.status,
if (this.groupid) {
data.obj.groupids.push(this.groupid);
} else {
this.loading = true;
this.pageNum = event;
this.searchRe();
this.green = res.data.normal;
this.gray = res.data.disable;
this.yellow = res.data.waring;
this.red = res.data.serious;
this.deviceNo = res.data.total;
editBasicModal(item) {
this.basicEdit.editModal(item.hostid, item.name, item.gId);
const data = {
hostids: []
};
data.hostids.push(item.hostid);
this.overAllSer.deleteHostPost(data).subscribe(
(res) => {
if (res.errCode == 10000) {
this.message.info('删除成功');
const data = {
hostids: this.batchDelList
};
this.overAllSer.deleteHostPost(data).subscribe(
(res) => {
if (res.errCode == 10000) {
this.message.info('删除成功');
this.batchDelList = [];
updateGroup() {
if (!this.groupid && !this.equipmentTypeid) {
this.message.info('请选择分组!');
return false;
}
let item;
if (this.groupid) {
this.groupList.forEach(e => {
if (e.groupid == this.groupid) {
item = e;
}
});
} else {
this.groupList.forEach(e => {
if (e.equipmentTypeId == this.equipmentTypeid) {
item = e;
}
});
}
showDeleteGroupConfirm() {
if (!this.groupid && !this.equipmentTypeid) {
this.message.info('请选择分组!');
return false;
}
this.commonSer.confirmThing('删除', '确认删除该分组吗?', () => {
this.loading = true;
const data = {groupid: []};
if (this.groupid) data.groupid.push(this.groupid);
if (this.equipmentTypeid) data.groupid.push(this.equipmentTypeid);
this.overAllSer.deleteGroup(data).subscribe(
(res) => {
if (res.errCode == 10000) {
this.message.info('删除成功');
this.searchRe();
} else {
this.message.info(res.errMsg);
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);
goDetail(item) {
this.router.navigate(['app/main/basic-detail'], {
queryParams: {
hostId: item.hostid,
showTempStop(item) {
this.smartPause.showModal(item.hostid, '基础资源');
selectChecked(event, item) {
if (event) {
if (item.hostid) {
(res) => {
if (res.errCode == 10000) {
this.message.info('修改成功');
} 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: '监控',
this.overAllSer.batchStopOrOpen(data).subscribe(
(res) => {
if (res.errCode == 10000) {
this.message.info('修改成功');
this.batchDelList = [];
} else {
this.message.info(res.errMsg);
}
}
);
},
nzOnCancel: () => console.log('Cancel')
});
goTOInventory(id) {
this.router.navigate(['app/main/assetsDetail'], {
queryParams: {
invertoryId: id
}
});
if (item.equipmentType == '数据库' || item.equipmentType == '业务软件') {
type = 'database';
} else if (item.equipmentType == '交换机') {
type = 'switch';
} else {
type = 'server';
}
this.router.navigate(['app/main/' + type], {
queryParams: {
hostId: item.hostid,
equipmentType: item.equipmentType
}
});
}