Skip to content

Commit

Permalink
Fixed failure of alert form validation (#2259)
Browse files Browse the repository at this point in the history
  • Loading branch information
kerwin612 authored Jul 10, 2024
1 parent 3e50b96 commit 8f91430
Showing 1 changed file with 12 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
* under the License.
*/

import { Component, Inject, OnInit } from '@angular/core';
import { Component, Inject, OnInit, ViewChild } from '@angular/core';
import { NgForm } from '@angular/forms';
import { I18NService } from '@core';
import { ALAIN_I18N_TOKEN } from '@delon/theme';
import { NzCascaderFilter } from 'ng-zorro-antd/cascader';
Expand All @@ -33,12 +34,9 @@ import { AlertDefine } from '../../../pojo/AlertDefine';
import { AlertDefineBind } from '../../../pojo/AlertDefineBind';
import { Message } from '../../../pojo/Message';
import { Monitor } from '../../../pojo/Monitor';
import { TagItem } from '../../../pojo/NoticeRule';
import { Tag } from '../../../pojo/Tag';
import { AlertDefineService } from '../../../service/alert-define.service';
import { AppDefineService } from '../../../service/app-define.service';
import { MonitorService } from '../../../service/monitor.service';
import { TagService } from '../../../service/tag.service';

const AVAILABILITY = 'availability';

Expand All @@ -54,9 +52,9 @@ export class AlertSettingComponent implements OnInit {
private appDefineSvc: AppDefineService,
private monitorSvc: MonitorService,
private alertDefineSvc: AlertDefineService,
private tagSvc: TagService,
@Inject(ALAIN_I18N_TOKEN) private i18nSvc: I18NService
) {}
@ViewChild('defineForm', { static: false }) defineForm: NgForm | undefined;
search!: string;
pageIndex: number = 1;
pageSize: number = 8;
Expand Down Expand Up @@ -150,21 +148,6 @@ export class AlertSettingComponent implements OnInit {
this.editAlertDefine(alertDefineId);
}

onEditAlertDefine() {
// 编辑时只能选中一个
if (this.checkedDefineIds == null || this.checkedDefineIds.size === 0) {
this.notifySvc.warning(this.i18nSvc.fanyi('common.notify.no-select-edit'), '');
return;
}
if (this.checkedDefineIds.size > 1) {
this.notifySvc.warning(this.i18nSvc.fanyi('common.notify.one-select-edit'), '');
return;
}
let alertDefineId = 0;
this.checkedDefineIds.forEach(item => (alertDefineId = item));
this.editAlertDefine(alertDefineId);
}

updateAlertDefine(alertDefine: AlertDefine) {
this.tableLoading = true;
const updateDefine$ = this.alertDefineSvc
Expand Down Expand Up @@ -543,6 +526,15 @@ export class AlertSettingComponent implements OnInit {
}

onManageModalOk() {
if (this.defineForm?.invalid) {
Object.values(this.defineForm.controls).forEach(control => {
if (control.invalid) {
control.markAsDirty();
control.updateValueAndValidity({ onlySelf: true });
}
});
return;
}
this.isManageModalOkLoading = true;
this.define.app = this.cascadeValues[0];
this.define.metric = this.cascadeValues[1];
Expand Down Expand Up @@ -607,7 +599,6 @@ export class AlertSettingComponent implements OnInit {
);
}
}

// end 新增修改告警定义model

// start 告警定义与监控关联model
Expand Down Expand Up @@ -714,29 +705,4 @@ export class AlertSettingComponent implements OnInit {
});
}
// end 告警定义与监控关联model
//查询告警阈值
onFilterSearchAlertDefinesByName() {
this.tableLoading = true;
let filter$ = this.alertDefineSvc.getAlertDefines(this.search, this.pageIndex - 1, this.pageSize).subscribe(
message => {
filter$.unsubscribe();
this.tableLoading = false;
this.checkedAll = false;
this.checkedDefineIds.clear();
if (message.code === 0) {
let page = message.data;
this.defines = page.content;
this.pageIndex = page.number + 1;
this.total = page.totalElements;
} else {
console.warn(message.msg);
}
},
error => {
this.tableLoading = false;
filter$.unsubscribe();
console.error(error.msg);
}
);
}
}

0 comments on commit 8f91430

Please sign in to comment.