Newer
Older
import {Component, EventEmitter, OnInit, Output, ViewChild} from '@angular/core';
import {BasicKeyComponent} from '../basic-key/basic-key.component';
import {NzMessageService} from 'ng-zorro-antd';
import {NewTypeComponent} from '../new-type/new-type.component';
selector: 'smart-basi-check',
templateUrl: './basi-check.component.html',
styles: [
`.tag-button[disabled],
.tag-button {
width: 80%;
height: 30px;
color: rgba(0, 0, 0, 0.65);
background-color: #fff;
border-color: #d9d9d9;
}
:host ::ng-deep .ant-tabs-nav .ant-tabs-tab-disabled{
color: rgba(0,0,0,.65);
}
`
@ViewChild('basicKey') basicKey: BasicKeyComponent;
@ViewChild('newType') newType: NewTypeComponent;
tabNum:number;
triggerObj = {
condition:'',
faultCondition:'',
itemName:''
};
constructor(private overAllSer: OverAllService, private fb: FormBuilder,
private message: NzMessageService) {
}
ngOnInit() {
name:[null,[Validators.required]],
interfaceid:[null,[Validators.required]],
key_:[null,[Validators.required]],
value_type:[null,[Validators.required]],
type:[null,[Validators.required]],
data_type:[null,[Validators.required]],
units:[null],
formula:[null,[Validators.required]],
trends:[null],
valuemapid:[null],
delay:[null,[Validators.required]],
snmp_oid:[null],
snmp_community:[null],
delta:[null],
applicationids:[null],
});
this.triggerObj = {
condition:'',
faultCondition:'',
itemName:''
};
this.title = '添加监测点';
this.isCheck = true;
this.hostId = hostId;
//主机接口
this.overAllSer.findDetailed(this.hostId).subscribe(
(res) => {
this.interfaceList = res.data[0].interfaces;
}
);
this.getItemType();
}
//编辑
showEditModal(hostId,id){
this.title = "编辑监测点";
this.hostId = hostId;
this.isCheck = true;
const data = res.data[0];
data.type += '';
data.interfaceid += "";
data.value_type += "";
data.data_type += "";
this.validateForm.patchValue(data);
this.overAllSer.findDetailed(this.hostId).subscribe(
(res) => {
this.interfaceList = res.data[0].interfaces;
handleCheckOk() {
for(let i in this.validateForm.controls) {
this.validateForm.controls[ i ].markAsDirty();
this.validateForm.controls[ i ].updateValueAndValidity();
if(this.validateForm.invalid){
return false;
}
this.validateForm.value.applicationids = [this.validateForm.value.applicationids];
create(){
this.overAllSer.create(this.validateForm.value).subscribe(
}
},
(err) => {
this.message.info('系统错误');
}
);
}
//修改监控项
update(){
this.validateForm.addControl('itemid',new FormControl(this.itemId));
(res) => {
if (res.errCode == 10000) {
this.isCheck = false;
const data = {
condition:'',
faultCondition:''
};
if (this.conditionType == 'commonly') { //常规
this.conditionList.forEach(res => {
data.condition += '{' + this.hostName + ':' + this.validateForm.value.key_ + '.last()}' + res.equal + '' + res.value ;
data.faultCondition += '{' + this.hostName + ':' + this.validateForm.value.key_ + '.last()}' + res.equal + '' + res.value;
data.condition = this.triggerObj.condition;
data.faultCondition = this.triggerObj.faultCondition;
}
if(this.title == "添加监测点"){
this.createTrigger(data);
}
if(this.title == "编辑监测点"){
this.updateTrigger(data);
}
}
//1.创建阈值
createTrigger(data){
const res = {
itemName:this.validateForm.value.name,
faultCondition:data.faultCondition,
condition:data.condition
};
this.overAllSer.createTrigger(res).subscribe(
(response)=>{
if(response.errCode == 10000){
this.message.success("创建阈值成功");
}
//2.修改阈值
updateTrigger(data){
const res = {
triggerid:'',
itemName:this.validateForm.value.name,
faultCondition:data.faultCondition,
condition:data.condition
};
this.overAllSer.updateTrigger(data).subscribe(res=>{
if(res.errCode == 10000){
this.message.success("修改阈值成功");
this.done.emit();
this.initForm();
this.isCheck = false;
}else{
this.message.error(res.errMsg);
}