Repository: metron Updated Branches: refs/heads/master 097ce9503 -> 93276f87b
METRON-1635 Alerts UI status update doesn't immediately show up (merrimanr) closes apache/metron#1080 Project: http://git-wip-us.apache.org/repos/asf/metron/repo Commit: http://git-wip-us.apache.org/repos/asf/metron/commit/93276f87 Tree: http://git-wip-us.apache.org/repos/asf/metron/tree/93276f87 Diff: http://git-wip-us.apache.org/repos/asf/metron/diff/93276f87 Branch: refs/heads/master Commit: 93276f87b7dfb41b6fd1e6aa6d42895e422fe912 Parents: 097ce95 Author: merrimanr <[email protected]> Authored: Tue Jul 3 08:37:41 2018 -0500 Committer: rmerriman <[email protected]> Committed: Tue Jul 3 08:37:41 2018 -0500 ---------------------------------------------------------------------- .../alert-details/alert-details.component.ts | 68 +++++++++----------- 1 file changed, 30 insertions(+), 38 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/metron/blob/93276f87/metron-interface/metron-alerts/src/app/alerts/alert-details/alert-details.component.ts ---------------------------------------------------------------------- diff --git a/metron-interface/metron-alerts/src/app/alerts/alert-details/alert-details.component.ts b/metron-interface/metron-alerts/src/app/alerts/alert-details/alert-details.component.ts index e68a8e0..2af79a8 100644 --- a/metron-interface/metron-alerts/src/app/alerts/alert-details/alert-details.component.ts +++ b/metron-interface/metron-alerts/src/app/alerts/alert-details/alert-details.component.ts @@ -93,20 +93,20 @@ export class AlertDetailsComponent implements OnInit { return false; } - getData(fireToggleEditor = false) { + getData() { this.alertCommentStr = ''; this.searchService.getAlert(this.alertSourceType, this.alertId).subscribe(alertSource => { - this.alertSource = alertSource; - this.selectedAlertState = this.getAlertState(alertSource['alert_status']); - this.alertSources = (alertSource.metron_alert && alertSource.metron_alert.length > 0) ? alertSource.metron_alert : [alertSource]; + this.setAlert(alertSource); this.setComments(alertSource['comments'] || []); - - if (fireToggleEditor) { - this.toggleNameEditor(); - } }); } + setAlert(alertSource) { + this.alertSource = alertSource; + this.alertSources = (alertSource.metron_alert && alertSource.metron_alert.length > 0) ? alertSource.metron_alert : [alertSource]; + this.selectedAlertState = this.getAlertState(alertSource['alert_status']); + } + setComments(alertComments) { this.alertCommentsWrapper = alertComments.map(alertComment => new AlertCommentWrapper(alertComment, moment(new Date(alertComment.timestamp)).fromNow())); @@ -149,53 +149,39 @@ export class AlertDetailsComponent implements OnInit { } processOpen() { - let tAlert = new Alert(); - tAlert.source = this.alertSource; - - this.selectedAlertState = AlertState.OPEN; - this.updateService.updateAlertState([tAlert], 'OPEN').subscribe(results => { - this.getData(); - }); + this.updateAlertState('OPEN'); } processNew() { - let tAlert = new Alert(); - tAlert.source = this.alertSource; - - this.selectedAlertState = AlertState.NEW; - this.updateService.updateAlertState([tAlert], 'NEW').subscribe(results => { - this.getData(); - }); + this.updateAlertState('NEW'); } processEscalate() { + this.updateAlertState('ESCALATE'); + let tAlert = new Alert(); tAlert.source = this.alertSource; - - this.selectedAlertState = AlertState.ESCALATE; - this.updateService.updateAlertState([tAlert], 'ESCALATE').subscribe(results => { - this.getData(); - }); this.alertsService.escalate([tAlert]).subscribe(); } processDismiss() { - let tAlert = new Alert(); - tAlert.source = this.alertSource; - - this.selectedAlertState = AlertState.DISMISS; - this.updateService.updateAlertState([tAlert], 'DISMISS').subscribe(results => { - this.getData(); - }); + this.updateAlertState('DISMISS'); } processResolve() { + this.updateAlertState('RESOLVE'); + } + + updateAlertState(state: string) { let tAlert = new Alert(); tAlert.source = this.alertSource; - this.selectedAlertState = AlertState.RESOLVE; - this.updateService.updateAlertState([tAlert], 'RESOLVE').subscribe(results => { - this.getData(); + let previousAlertStatus = this.alertSource['alert_status']; + this.alertSource['alert_status'] = state; + this.setAlert(this.alertSource); + this.updateService.updateAlertState([tAlert], state).subscribe(() => {}, () => { + this.alertSource['alert_status'] = previousAlertStatus; + this.setAlert(this.alertSource); }); } @@ -213,8 +199,14 @@ export class AlertDetailsComponent implements OnInit { patchRequest.sensorType = 'metaalert'; patchRequest.patch = [new Patch('add', '/name', this.alertName)]; + let previousName = this.alertSource['name']; + this.alertSource['name'] = this.alertName; this.updateService.patch(patchRequest).subscribe(rep => { - this.getData(true); + this.toggleNameEditor(); + }, () => { + this.alertSource['name'] = previousName; + this.alertName = previousName; + this.toggleNameEditor(); }); } }
