From 7cdb6f0363ce1b7b6e8273d2689abfe79b9c2927 Mon Sep 17 00:00:00 2001 From: merrimanr Date: Fri, 22 Jun 2018 13:07:17 -0500 Subject: [PATCH 1/5] initial commit --- .../alert-details/alert-details.component.ts | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) 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 c939f04849..51a92b1ec4 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 @@ -99,7 +99,7 @@ export class AlertDetailsComponent implements OnInit { 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.setComments(alertSource); + this.setComments(alertSource['comments'] ? alertSource['comments'] : []); if (fireToggleEditor) { this.toggleNameEditor(); @@ -107,8 +107,7 @@ export class AlertDetailsComponent implements OnInit { }); } - setComments(alert) { - let alertComments = alert['comments'] ? alert['comments'] : []; + setComments(alertComments) { this.alertCommentsWrapper = alertComments.map(alertComment => new AlertCommentWrapper(alertComment, moment(new Date(alertComment.timestamp)).fromNow())); } @@ -224,20 +223,22 @@ export class AlertDetailsComponent implements OnInit { onAddComment() { let alertComment = new AlertComment(this.alertCommentStr, this.authenticationService.getCurrentUserName(), new Date().getTime()); let tAlertComments = this.alertCommentsWrapper.map(alertsWrapper => alertsWrapper.alertComment); + let previousComments = tAlertComments.slice(); tAlertComments.unshift(alertComment); - this.patchAlert(new Patch('add', '/comments', tAlertComments)); + this.setComments(tAlertComments); + this.patchAlert(new Patch('add', '/comments', tAlertComments), () => { + this.setComments(previousComments); + }); } - patchAlert(patch: Patch) { + patchAlert(patch: Patch, onPatchError) { let patchRequest = new PatchRequest(); patchRequest.guid = this.alertSource.guid; patchRequest.index = this.alertIndex; patchRequest.patch = [patch]; patchRequest.sensorType = this.alertSourceType; - this.updateService.patch(patchRequest).subscribe(() => { - this.getData(); - }); + this.updateService.patch(patchRequest).subscribe(() => {}, onPatchError); } onDeleteComment(index: number) { @@ -250,8 +251,11 @@ export class AlertDetailsComponent implements OnInit { this.metronDialogBox.showConfirmationMessage(commentText).subscribe(response => { if (response) { + let previousCommentsWrapper = this.alertCommentsWrapper.slice(); this.alertCommentsWrapper.splice(index, 1); - this.patchAlert(new Patch('add', '/comments', this.alertCommentsWrapper.map(alertsWrapper => alertsWrapper.alertComment))); + this.patchAlert(new Patch('add', '/comments', this.alertCommentsWrapper.map(alertsWrapper => alertsWrapper.alertComment)), () => { + this.alertCommentsWrapper = previousCommentsWrapper; + }); } }); } From 48f7e0a8ea64b1236b7da309b4b5e8e698ab2677 Mon Sep 17 00:00:00 2001 From: merrimanr Date: Mon, 25 Jun 2018 08:33:09 -0500 Subject: [PATCH 2/5] pr feedback --- .../alerts/alert-details/alert-details.component.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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 51a92b1ec4..0876b889cb 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 @@ -99,7 +99,7 @@ export class AlertDetailsComponent implements OnInit { 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.setComments(alertSource['comments'] ? alertSource['comments'] : []); + this.setComments(alertSource['comments'] || []); if (fireToggleEditor) { this.toggleNameEditor(); @@ -222,11 +222,11 @@ export class AlertDetailsComponent implements OnInit { onAddComment() { let alertComment = new AlertComment(this.alertCommentStr, this.authenticationService.getCurrentUserName(), new Date().getTime()); - let tAlertComments = this.alertCommentsWrapper.map(alertsWrapper => alertsWrapper.alertComment); - let previousComments = tAlertComments.slice(); - tAlertComments.unshift(alertComment); - this.setComments(tAlertComments); - this.patchAlert(new Patch('add', '/comments', tAlertComments), () => { + let newComments = this.alertCommentsWrapper.map(alertsWrapper => alertsWrapper.alertComment); + let previousComments = newComments.slice(); + newComments.unshift(alertComment); + this.setComments(newComments); + this.patchAlert(new Patch('add', '/comments', newComments), () => { this.setComments(previousComments); }); } From 4c0e989d65d1df005afc5de8e39c42acf52874ce Mon Sep 17 00:00:00 2001 From: merrimanr Date: Mon, 25 Jun 2018 09:02:28 -0500 Subject: [PATCH 3/5] pr feedback --- .../alerts/alert-details/alert-details.component.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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 0876b889cb..65a96f0b7e 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 @@ -221,12 +221,12 @@ export class AlertDetailsComponent implements OnInit { } onAddComment() { - let alertComment = new AlertComment(this.alertCommentStr, this.authenticationService.getCurrentUserName(), new Date().getTime()); - let newComments = this.alertCommentsWrapper.map(alertsWrapper => alertsWrapper.alertComment); - let previousComments = newComments.slice(); - newComments.unshift(alertComment); - this.setComments(newComments); - this.patchAlert(new Patch('add', '/comments', newComments), () => { + let newComment = new AlertComment(this.alertCommentStr, this.authenticationService.getCurrentUserName(), new Date().getTime()); + let alertComments = this.alertCommentsWrapper.map(alertsWrapper => alertsWrapper.alertComment); + let previousComments = alertComments.slice(); + alertComments.unshift(newComment); + this.setComments(alertComments); + this.patchAlert(new Patch('add', '/comments', alertComments), () => { this.setComments(previousComments); }); } From a00bd6ac91249cf45f6faa7f2facd5f3212542f5 Mon Sep 17 00:00:00 2001 From: merrimanr Date: Mon, 25 Jun 2018 16:06:42 -0500 Subject: [PATCH 4/5] manually undo operation --- .../alerts/alert-details/alert-details.component.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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 65a96f0b7e..ee8ed277e7 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 @@ -32,6 +32,7 @@ import {AuthenticationService} from '../../service/authentication.service'; import {MetronDialogBox} from '../../shared/metron-dialog-box'; import {META_ALERTS_INDEX, META_ALERTS_SENSOR_TYPE} from '../../utils/constants'; import { GlobalConfigService } from '../../service/global-config.service'; +import {del} from "selenium-webdriver/http"; export enum AlertState { NEW, OPEN, ESCALATE, DISMISS, RESOLVE @@ -223,10 +224,11 @@ export class AlertDetailsComponent implements OnInit { onAddComment() { let newComment = new AlertComment(this.alertCommentStr, this.authenticationService.getCurrentUserName(), new Date().getTime()); let alertComments = this.alertCommentsWrapper.map(alertsWrapper => alertsWrapper.alertComment); - let previousComments = alertComments.slice(); alertComments.unshift(newComment); this.setComments(alertComments); this.patchAlert(new Patch('add', '/comments', alertComments), () => { + let previousComments = this.alertCommentsWrapper.map(alertsWrapper => alertsWrapper.alertComment) + .filter(alertComment => alertComment !== newComment); this.setComments(previousComments); }); } @@ -251,10 +253,11 @@ export class AlertDetailsComponent implements OnInit { this.metronDialogBox.showConfirmationMessage(commentText).subscribe(response => { if (response) { - let previousCommentsWrapper = this.alertCommentsWrapper.slice(); - this.alertCommentsWrapper.splice(index, 1); + let deletedCommentWrapper = this.alertCommentsWrapper.splice(index, 1)[0]; this.patchAlert(new Patch('add', '/comments', this.alertCommentsWrapper.map(alertsWrapper => alertsWrapper.alertComment)), () => { - this.alertCommentsWrapper = previousCommentsWrapper; + // add the deleted comment back + this.alertCommentsWrapper.unshift(deletedCommentWrapper); + this.alertCommentsWrapper.sort((a, b) => b.alertComment.timestamp - a.alertComment.timestamp); }); } }); From 17ae5ad31b481909e937fb20f6b9a906a74c1dbc Mon Sep 17 00:00:00 2001 From: merrimanr Date: Mon, 25 Jun 2018 16:10:24 -0500 Subject: [PATCH 5/5] undo import --- .../src/app/alerts/alert-details/alert-details.component.ts | 1 - 1 file changed, 1 deletion(-) 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 ee8ed277e7..efc7e84d1f 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 @@ -32,7 +32,6 @@ import {AuthenticationService} from '../../service/authentication.service'; import {MetronDialogBox} from '../../shared/metron-dialog-box'; import {META_ALERTS_INDEX, META_ALERTS_SENSOR_TYPE} from '../../utils/constants'; import { GlobalConfigService } from '../../service/global-config.service'; -import {del} from "selenium-webdriver/http"; export enum AlertState { NEW, OPEN, ESCALATE, DISMISS, RESOLVE