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;
selectedValue;
isCheck = false;
allChecked = false;
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 {
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
toTree(index) {
this.dataSet.forEach(item => {
this.expandDataCache[item.host] = this.convertTreeToList(item, item.id, index);
});
}
//获取下级list
getChildren(item) {
if (item.list) {
if (item.expand) {
item.expand = false;
} else {
item.expand = true;
}
return false;
}
this.loading = true;
const data = {
'groupids': [item.groupid],
};
this.overAllSer.findHostNew(data).subscribe(
(res) => {
if (res.data) {
this.dataSet[item.host].list = res.data;
this.toTree(item.host);
} else {
this.message.info('该分组下无资源');
}
this.loading = false;
}
);
}
ngOnInit(): void {
this.selectedValue = 'group';
this.select();
this.status = status;
}
this.pageNum = 1;
this.search();
}
/*
//waringName:(值为:正常,禁用,告警,严重)
*/
this.loading = true;
this.searchStatus = true;
const data = {
pageNum: this.pageNum,
pageCount: this.pageCount,
obj: {
name: this.searchName,
waringName: this.status,
groupids: []
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);
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的
const data = {
hostids: []
};
data.hostids.push(item.hostid);
this.overAllSer.deleteHostPost(data).subscribe(
(res) => {
if (res.errCode == 10000) {
this.message.info('删除成功');
this.select();
} else {
this.message.info(res.errMsg);
const data = {
hostids: this.batchDelList
};
this.overAllSer.deleteHostPost(data).subscribe(
(res) => {
if (res.errCode == 10000) {
this.message.info('删除成功');
this.batchDelList = [];
this.select();
} else {
this.message.error(res.errMsg);
updateGroup(item) {
this.smartCreateGroup.showEditModal('修改分组', item);
nzTitle: '删除',
nzContent: '<b style="color: red;">确认删除该分组吗?</b>',
nzOkText: '确定',
nzOkType: 'danger',
nzOnOk: () => {
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) {
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
}
});
if (item.equipmentType == '数据库') {
type = 'database';
} else if (item.equipmentType == '交换机') {
type = 'switch';
} else {
type = 'server';