Newer
Older
import {Component, EventEmitter, OnInit, Output} from '@angular/core';
import {FormBuilder} from '@angular/forms';
import {Router} from '@angular/router';
import {JhiMainComponent} from '../../layouts';
import {NzMessageService, NzModalService} from 'ng-zorro-antd';
import {OverAllService} from '../../overAll/overAll.service';
selector: 'smart-strategy',
templateUrl: './strategy.component.html',
styles: []
@Output() done = new EventEmitter<any>();
isVisible = false;
title;
tabNum = 0;
nzSize = 'large';
tempList; //模版
//宏
macroTYpe = 'macro'; //宏tabs
mainHost = 'hostType1'; //主机tabs
constructor(private fb: FormBuilder, private overAllSer: OverAllService, private router: Router,
private modalService: NzModalService, private message: NzMessageService, private main: JhiMainComponent) {
}
ngOnInit() {
this.getTemplateGroup();
this.getTemplate();
this.initForm();
}
initForm() {
this.templateList.forEach(e => {
e.checked = false;
});
this.macroList1 = [];
this.macroList2 = [];
this.validateForm = {
host: null,
name: null,
groups: [],
templates: [],
macros: [],
hosts: [],
};
}
//获取模版组
getTemplateGroup() {
this.templateList = [];
(res) => {
const list = res.data;
list.forEach(e => {
const gObj = {
label: e.name, value: e.groupid, checked: false
};
this.templateList.push(gObj);
});
}
);
}
//获取模版
getTemplate() {
this.tempList = [];
this.overAllSer.templates().subscribe(
(res) => {
this.tempList = res.data;
}
);
}
this.tabNum = e;
}
showAddModal(title): void {
this.isVisible = true;
this.title = title;
}
this.isVisible = true;
this.title = title;
this.tempId = id;
const data = {
const data = res.data[0];
this.validateForm.host = data.host;
this.validateForm.name = data.name;
this.templateList.forEach(e1 => {
data.groups.forEach(e2 => {
if (e1.value == e2.groupid) {
this.validateForm.templates = tempArr;
this.templatesResoure = tempArr;
if(data.macros){
//宏回显
let macroArr = [];
macroArr = data.macros.map(e=>{
const d = {
macro:e.macro,
value:e.value,
};
return d;
})
this.macroList1 = macroArr;
}
const han = /.*[\u4e00-\u9fa5]+.*$/;
if (han.test(this.validateForm.host)) {
if (this.macroTYpe == 'macroExpand') {
this.validateForm.macros = this.macroList2;
}
if (this.macroTYpe == 'macro') {
this.validateForm.macros = this.macroList1;
}
if (this.title == '添加模版') {
const data = {
host: this.validateForm.host,
name: this.validateForm.name,
groups: arr,
hosts: [],
};
this.overAllSer.createTemplates(data).subscribe(
(res) => {
if (res.errCode == 10000) {
this.message.success('添加模版成功');
this.initForm();
this.done.emit();
this.isVisible = false;
//比较监控模版是否发生变化
const clearArr = [];
this.templatesResoure.forEach(res => {
if (this.validateForm.templates.indexOf(res) == -1) {
const d = {
templateid:res
}
clearArr.push(d);
}
});
host: this.validateForm.host,
name: this.validateForm.name,
groups: arr,
(res) => {
if (res.errCode == 10000) {
this.message.success('修改模版成功');
this.initForm();
this.done.emit();
this.isVisible = false;
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
}
handleCancel(): void {
this.isVisible = false;
this.initForm();
}
//新增宏
addMacro1() {
const data = {
macro: '{$SNMP_COMMUNITY}',
value: 'public',
};
this.macroList1.push(data);
}
//移除宏
deleteMacro1(index) {
this.macroList1.splice(index, 1);
}
//新增主机宏
addMacro2() {
const data = {
macro: '{$SNMP_COMMUNITY}',
value: 'public',
};
this.macroList2.push(data);
}
//移除主机宏
deleteMacro2(index) {
this.macroList2.splice(index, 1);
}