Newer
Older
import {Component, OnInit, ViewChild} from '@angular/core';
import {BasicEditComponent} from '../../modal/basic-edit/basic-edit.component';
import {CreateGroupComponent} from '../../modal/create-group/create-group.component';
import {OverAllService} from '../overAll.service';
import {NzMessageService, NzModalService} from 'ng-zorro-antd';
import {AlarmModalComponent} from '../../modal/alarm-modal/alarm-modal.component';
import {BasiCheckComponent} from '../../modal/basi-check/basi-check.component';
import {JhiMainComponent} from '../../layouts';
import {FormBuilder} from '@angular/forms';
import {color} from '../../app.constants';
import {PauseComponent} from '../../modal/pause/pause.component';
import {TreeNodeInterface} from '../basic/basic.component';
import {Router} from '@angular/router';
import {DiscoveryComponent} from '../../modal/discovery/discovery.component';
import {StrategyComponent} from '../../modal/strategy/strategy.component';
import {WorkService} from '../../work/work.service';
import {CommonService} from '../../shared/common/common.service';
import {UploadComponent} from '../../work/modal/upload/upload.component';
selector: 'smart-template',
templateUrl: './template.component.html',
styles: []
})
export class TemplateComponent implements OnInit {
//组件
@ViewChild('basicEdit') basicEdit: BasicEditComponent;
@ViewChild('smartCheck') smartCheck: BasiCheckComponent;
@ViewChild('smartCreateGroup') smartCreateGroup: CreateGroupComponent;
@ViewChild('smartPause') smartPause: PauseComponent;
@ViewChild('smartAlarmModal') smartAlarmModal: AlarmModalComponent;
@ViewChild('smartDiscovery') smartDiscovery: DiscoveryComponent;
@ViewChild('smartStrategy') smartStrategy: StrategyComponent;
frontPagination = true;
selectedValue;
isCheck = false;
allChecked = false;
hostId;
isKey = false;
keyList: any[];
keyType = '1';
//批量删除list
batchDelList = [];
//设备状态
red;
yellow;
green;
gray;
//搜索
searchStatus = false;
searchName;
searchData;
constructor(private fb: FormBuilder, private overAllSer: OverAllService, private router: Router,private workSer:WorkService,
private modalService: NzModalService, private message: NzMessageService, private main: JhiMainComponent,
private commonSer:CommonService) {
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
}
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.host === d.host);
target.expand = false;
this.collapse(array, target, false);
});
} else {
return;
}
}
}
showInFullScreen() {
this.main.fullScreen();
}
convertTreeToList(root: any, groupId: string, index): 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});
}
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 {
if (!hashMap[node.host]) {
hashMap[node.host] = true;
array.push(node);
}
}
ngOnInit(): void {
(res) => {
this.dataSet = res.data;
this.isLoading = false;
for (let i = 0; i < this.dataSet.length; i++) {
this.dataSet[i].host = i;
this.dataSet[i].checked = false;
}
this.toTree(null);
}
this.searchStatus = true;
const data = {
search: {
name: this.searchName
}
};
(res) => {
if (res.errCode == 10000) {
this.searchData = res.data;
}
}
);
}
//backList
backList() {
this.searchStatus = false;
}
showDiscoveryAddModal(item) {
this.smartDiscovery.showAddModal(item.templateid, '添加自动发现');
this.router.navigate(['app/main/discoveryList'], {
queryParams: {
this.router.navigate(['app/main/itemList'], {
queryParams: {
templateid: item.templateid,
name: item.name,
hostName: item.host
}
});
}
//goto阈值列表
this.router.navigate(['app/main/triList'], {
queryParams: {
templateid: item.templateid,
name: item.name,
hostName: item.host
}
});
}
toTree(index) {
this.dataSet.forEach(item => {
this.expandDataCache[item.host] = this.convertTreeToList(item, item.id, index);
});
}
//添加分组
showGroupModal() {
}
//编辑分组
updateGroup(item) {
this.smartCreateGroup.showEditModal('修改分组', item);
}
//删除分组
showDeleteGroupConfirm(item) {
this.modalService.confirm({
nzTitle: '删除',
nzContent: '<b style="color: red;">确认删除该分组吗?</b>',
nzOkText: '确定',
nzOkType: 'danger',
nzOnOk: () => {
const data = {groupid: []};
data.groupid.push(item.groupid);
this.overAllSer.deleteGroup(data).subscribe(
(res) => {
if (res.errCode == 10000) {
}
}
);
},
nzCancelText: '取消',
nzOnCancel: () => console.log('Cancel')
});
}
//添加告警
showAlarm() {
}
//获取下级list
getChildren(item) {
if (item.list) {
if (item.expand) {
item.expand = false;
} else {
item.expand = true;
}
return false;
}
(res) => {
if (res.data) {
this.dataSet[item.host].list = res.data;
this.toTree(item.host);
} else {
this.message.info('该分组下无资源');
}
}
);
}
//根据设备类型查询主机资源
getChildrenType(item) {
if (item.list) {
if (item.expand) {
item.expand = false;
} else {
item.expand = true;
}
return false;
}
const data = {
type: item.equipmentTypeId
};
this.overAllSer.findHostByType(data).subscribe(
(res) => {
if (res.data) {
this.dataSet[item.host].list = res.data;
this.toTree(item.host);
} else {
this.message.info('该分组下无资源');
}
}
);
}
//临时暂停
showTempStop(item) {
this.smartPause.showModal(item.hostid, '基础资源');
}
//选择
selectChecked(event, item) {
if (event) {
if (item.templateid) {
this.batchDelList.push(item.templateid);
if (item.templateid) {
const index = this.batchDelList.indexOf(item.templateid);
//批量删除资源
batchDeleteConfirm() {
if (this.batchDelList.length == 0) {
this.message.info('请选择需要删除的设备');
return false;
}
this.commonSer.confirmThing('删除','确认要删除所选模版吗?',()=>{
const data = {
templateids: this.batchDelList
};
this.overAllSer.deleteTemplates(data).subscribe(
(res) => {
if (res.errCode == 10000) {
this.message.success('删除成功');
this.batchDelList = [];
this.getTemplateGroup();
} else {
this.message.error(res.errMsg);
this.commonSer.confirmThing('删除','确认删除该模版吗?',()=>{
const data = {
templateids: []
};
data.templateids.push(item.templateid);
this.overAllSer.deleteTemplates(data).subscribe(
(res) => {
if (res.errCode == 10000) {
this.message.info('删除成功');
this.getTemplateGroup();
} else {
this.message.info(res.errMsg);
this.commonSer.confirmThing('克隆','确认克隆该模版吗?',()=>{
this.isClone = true;
const data = {
templateid: Number(item.templateid)
};
this.overAllSer.cloneTemplates(data).subscribe(
(res) => {
if (res.errCode == 10000) {
this.message.info('克隆成功');
this.getTemplateGroup();
} else {
this.message.info(res.errMsg);
//导入资产
showUploadModal(){
this.smartUpload.showModal("上传XML模版");
}
//下载模版
download(){
this.isDownload = true;
const data = {
ids:this.batchDelList
};
this.overAllSer.exportTemplates(data).subscribe(
(res)=>{
if(res.errCode == 10000){
this.workSer.downloadTemplate('templateExport',res.data).subscribe(
(data)=>{
this.isDownload = false;
}
)
}else{
this.isDownload = false;
this.message.error(res.errMsg);
}
}
)
}