Skip to content

Commit

Permalink
[alert,webapp] support delete all alerts at once. (#273)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsun28 committed Sep 4, 2022
1 parent a844644 commit 1b5b6aa
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public ResponseEntity<Message<Page<Alert>>> getAlerts(

@DeleteMapping
@ApiOperation(value = "Delete alarms in batches", notes = "根据告警ID列表批量删除告警")
public ResponseEntity<Message<Void>> deleteAlertDefines(
public ResponseEntity<Message<Void>> deleteAlerts(
@ApiParam(value = "Alarm List ID | 告警IDs", example = "6565463543") @RequestParam(required = false) List<Long> ids) {
if (ids != null && !ids.isEmpty()) {
alertService.deleteAlerts(new HashSet<>(ids));
Expand All @@ -116,6 +116,14 @@ public ResponseEntity<Message<Void>> deleteAlertDefines(
return ResponseEntity.ok(message);
}

@DeleteMapping("/clear")
@ApiOperation(value = "Delete alarms in batches", notes = "清空所有告警信息")
public ResponseEntity<Message<Void>> clearAllAlerts() {
alertService.clearAlerts();
Message<Void> message = new Message<>();
return ResponseEntity.ok(message);
}

@PutMapping(path = "/status/{status}")
@ApiOperation(value = "Batch modify alarm status, set read and unread", notes = "批量修改告警状态,设置已读未读")
public ResponseEntity<Message<Void>> applyAlertDefinesStatus(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ public interface AlertService {
*/
void deleteAlerts(HashSet<Long> ids);

/**
* Clear all alerts
* 清空所有告警记录
*/
void clearAlerts();

/**
* Update the alarm status according to the alarm ID-status value
* 根据告警ID-状态值 更新告警状态
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ public void deleteAlerts(HashSet<Long> ids) {
alertDao.deleteAlertsByIdIn(ids);
}

@Override
public void clearAlerts() {
alertDao.deleteAll();
}

@Override
public void editAlertStatus(Byte status, List<Long> ids) {
alertDao.updateAlertsStatus(status, ids);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
<i nz-icon nzType="delete" nzTheme="outline"></i>
{{ 'alert.center.delete' | i18n }}
</button>
<button nz-button nzType="primary" nzDanger (click)="onClearAllAlerts()">
<i nz-icon nzType="clear" nzTheme="outline"></i>
{{ 'alert.center.clear' | i18n }}
</button>

<button style="margin-right: 25px; float: right" nz-button nzType="primary" (click)="loadAlertsTable()">
{{ 'common.search' | i18n }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,17 @@ export class AlertCenterComponent implements OnInit {
});
}

onClearAllAlerts() {
this.modal.confirm({
nzTitle: this.i18nSvc.fanyi('alert.center.confirm.clear-all'),
nzOkText: this.i18nSvc.fanyi('common.button.ok'),
nzCancelText: this.i18nSvc.fanyi('common.button.cancel'),
nzOkDanger: true,
nzOkType: 'primary',
nzOnOk: () => this.clearAllAlerts()
});
}

onMarkReadAlerts() {
if (this.checkedAlertIds == null || this.checkedAlertIds.size === 0) {
this.notifySvc.warning(this.i18nSvc.fanyi('alert.center.notify.no-mark'), '');
Expand Down Expand Up @@ -171,6 +182,27 @@ export class AlertCenterComponent implements OnInit {
);
}

clearAllAlerts() {
this.tableLoading = true;
const deleteAlerts$ = this.alertSvc.clearAlerts().subscribe(
message => {
deleteAlerts$.unsubscribe();
if (message.code === 0) {
this.notifySvc.success(this.i18nSvc.fanyi('common.notify.clear-success'), '');
this.loadAlertsTable();
} else {
this.tableLoading = false;
this.notifySvc.error(this.i18nSvc.fanyi('common.notify.clear-fail'), message.msg);
}
},
error => {
this.tableLoading = false;
deleteAlerts$.unsubscribe();
this.notifySvc.error(this.i18nSvc.fanyi('common.notify.clear-fail'), error.msg);
}
);
}

updateAlertsStatus(alertIds: Set<number>, status: number) {
this.tableLoading = true;
const markAlertsStatus$ = this.alertSvc.applyAlertsStatus(alertIds, status).subscribe(
Expand Down
5 changes: 5 additions & 0 deletions web-app/src/app/service/alert.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Message } from '../pojo/Message';
import { Page } from '../pojo/Page';

const alerts_uri = '/alerts';
const alerts_clear_uri = '/alerts/clear';
const alerts_summary_uri = '/alerts/summary';
const alerts_status_uri = '/alerts/status';

Expand Down Expand Up @@ -57,6 +58,10 @@ export class AlertService {
return this.http.delete<Message<any>>(alerts_uri, options);
}

public clearAlerts(): Observable<Message<any>> {
return this.http.delete<Message<any>>(alerts_clear_uri);
}

public applyAlertsStatus(alertIds: Set<number>, status: number): Observable<Message<any>> {
let httpParams = new HttpParams();
alertIds.forEach(alertId => {
Expand Down
3 changes: 3 additions & 0 deletions web-app/src/assets/i18n/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
"alert.setting.target.instance": "Instance of the row",
"alert.setting.operator": "Supported operator functions",
"alert.center.delete": "Delete Alerts",
"alert.center.clear": "Clear All",
"alert.center.deal": "Mark Processed",
"alert.center.no-deal": "Mark Pending",
"alert.center.search": "Search Alert Content",
Expand All @@ -142,6 +143,7 @@
"alert.center.notify.no-delete": "No items selected for deletion!",
"alert.center.confirm.delete": "Please confirm whether to delete!",
"alert.center.confirm.delete-batch": "Please confirm whether to delete in batch!",
"alert.center.confirm.clear-all": "Please confirm whether to clear all alerts!",
"alert.center.notify.no-mark": "No items selected for mark!",
"alert.center.confirm.mark-done-batch": "Please confirm whether to mark processed in batch!",
"alert.center.confirm.mark-done": "Please confirm whether to mark processed!",
Expand Down Expand Up @@ -277,6 +279,7 @@
"common.notify.enable-fail": "Enable Failed!",
"common.confirm.clear-cache": "Please confirm whether to clear cache!",
"common.notify.clear-success": "Clear Success!",
"common.notify.clear-fail": "Clear Failed!",
"common.notify.copy-success": "Copy Success!",
"common.button.ok": "OK",
"common.button.cancel": "Cancel",
Expand Down
3 changes: 3 additions & 0 deletions web-app/src/assets/i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
"alert.setting.target.instance": "所属行实例",
"alert.setting.operator": "支持操作符函数",
"alert.center.delete": "删除告警",
"alert.center.clear": "一键清空",
"alert.center.deal": "标记已处理",
"alert.center.no-deal": "标记未处理",
"alert.center.search": "搜索告警内容",
Expand All @@ -142,6 +143,7 @@
"alert.center.notify.no-delete": "未选中任何待删除项!",
"alert.center.confirm.delete": "请确认是否删除!",
"alert.center.confirm.delete-batch": "请确认是否批量删除!",
"alert.center.confirm.clear-all": "请确认是否清空所有告警记录!",
"alert.center.notify.no-mark": "未选中任何待标记项!",
"alert.center.confirm.mark-done-batch": "请确认是否批量标记已处理!",
"alert.center.confirm.mark-done": "请确认是否标记已处理!",
Expand Down Expand Up @@ -277,6 +279,7 @@
"common.notify.enable-fail": "启用监控失败!",
"common.confirm.clear-cache": "请确认是否清理缓存!",
"common.notify.clear-success": "清理成功!",
"common.notify.clear-fail": "清理失败!",
"common.notify.copy-success": "复制成功!",
"common.button.ok": "确定",
"common.button.detect": "测试",
Expand Down
3 changes: 3 additions & 0 deletions web-app/src/assets/i18n/zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
"alert.setting.target.instance": "所屬行實例",
"alert.setting.operator": "支持操作符函數",
"alert.center.delete": "刪除告警",
"alert.center.clear": "一鍵清空",
"alert.center.deal": "標記已處理",
"alert.center.no-deal": "標記未處理",
"alert.center.search": "搜索告警內容",
Expand All @@ -142,6 +143,7 @@
"alert.center.notify.no-delete": "未選中任何待刪除項!",
"alert.center.confirm.delete": "請確認是否刪除!",
"alert.center.confirm.delete-batch": "請確認是否批量刪除!",
"alert.center.confirm.clear-all": "請確認是否清空所有告警記錄!",
"alert.center.notify.no-mark": "未選中任何待標記項!",
"alert.center.confirm.mark-done-batch": "請確認是否批量標記已處理!",
"alert.center.confirm.mark-done": "請確認是否標記已處理!",
Expand Down Expand Up @@ -277,6 +279,7 @@
"common.notify.enable-fail": "啓用監控失敗!",
"common.confirm.clear-cache": "請確認是否清理緩存!",
"common.notify.clear-success": "清理成功!",
"common.notify.clear-fail": "清理失敗!",
"common.notify.copy-success": "複製成功!",
"common.button.ok": "確定",
"common.button.detect": "測試",
Expand Down

0 comments on commit 1b5b6aa

Please sign in to comment.