Github user justinleet commented on a diff in the pull request: https://github.com/apache/metron/pull/788#discussion_r143198763 --- Diff: metron-interface/metron-alerts/src/app/alerts/alert-details/alert-details.component.ts --- @@ -133,6 +173,40 @@ 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); + tAlertComments.unshift(alertComment); + this.patchAlert(new Patch('add', '/comments', tAlertComments)); + } + + patchAlert(patch: Patch) { + 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(); + }); + } + + onDeleteComment(index: number) { + let commentText = 'Do you wish to delete the comment '; + if (this.alertCommentsWrapper[index].alertComment.comment.length > 25 ) { + commentText += ' \'' + this.alertCommentsWrapper[index].alertComment.comment.substr(0, 25) + '...\''; + } else { + commentText += ' \'' + this.alertCommentsWrapper[index].alertComment.comment + '\''; + } + + this.metronDialogBox.showConfirmationMessage(commentText).subscribe(response => { + if (response) { + this.alertCommentsWrapper.splice(index, 1); + this.patchAlert(new Patch('add', '/comments', this.alertCommentsWrapper.map(alertsWrapper => alertsWrapper.alertComment))); --- End diff -- Thinking through this a bit more, my major concern of making it nonsearchable is that if we ever want to make those comments searchable, we'd probably have to eat a reindex of every sensor. Existing mappings can't be changed, you have to create a new index and migrate the data. That sounds awful. And I definitely can see cases where you'd want to search those comments (give me every comment that person X made in the last month. Give me every comment by person X regarding sensor Y. and so on). If we make the field nested from the beginning, that does mean that the current patch calls need to be replace calls where the entire doc is constructed by the UI. Alternatively, we eat the backend work and make a comments endpoint that accepts a GUID and has add comment / delete comment and the backend constructs the new doc and ships it out.
---