From ace1bb7f9da4e1ec08f41fd3086f4ac424bd61cf Mon Sep 17 00:00:00 2001 From: steven choi Date: Fri, 13 Oct 2023 16:45:04 +1100 Subject: [PATCH] #657 Error when deleting comments on first go, ok after that --- .../controllers/CommentController.js | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/grails-app/assets/javascripts/profileEditor/controllers/CommentController.js b/grails-app/assets/javascripts/profileEditor/controllers/CommentController.js index f1fd17ab..6a7c15b1 100644 --- a/grails-app/assets/javascripts/profileEditor/controllers/CommentController.js +++ b/grails-app/assets/javascripts/profileEditor/controllers/CommentController.js @@ -5,6 +5,7 @@ profileEditor.controller('CommentController', function (profileService, util, co var self = this; self.comments = []; + self.savedComments = []; self.currentComment = null; self.opusId = util.getEntityId("opus"); self.profileId = util.getEntityId("profile"); @@ -19,6 +20,7 @@ profileEditor.controller('CommentController', function (profileService, util, co var promise = profileService.getComments(self.opusId, self.profileId); promise.then(function(data) { self.comments = orderBy(data, 'dateCreated'); + self.savedComments = orderBy(data, 'dateCreated'); }) }; @@ -78,8 +80,10 @@ profileEditor.controller('CommentController', function (profileService, util, co } else { if (!Array.isArray(self.comments)) { self.comments = []; + self.savedComments = [] } self.comments.push(data); + self.savedComments.push(data); } self.currentComment = null; @@ -89,9 +93,13 @@ profileEditor.controller('CommentController', function (profileService, util, co }; function find(path) { - var array = self.comments; + // var array = self.comments; + var array = self.savedComments; var comment = null; angular.forEach(path, function(index) { + if (index > array.length-1) { + index = array.length-1 + } comment = array[index]; if (comment.children) { array = orderBy(comment.children, 'dateCreated'); @@ -117,7 +125,16 @@ profileEditor.controller('CommentController', function (profileService, util, co comment.children.splice(lastIndex, 1); } else { - self.comments.splice(path[0], 1); + let selectedComment = self.savedComments[path[0]] + let filterdComments = self.comments.filter(i => i !== selectedComment) + self.comments = filterdComments; + // if (self.comments.length === 1) { + // self.comments.splice(0,1); + // } else if (self.comments.length < path[0]){ + // self.comments.splice(path[0]-1, 1); + // } else { + // self.comments.splice(path[0], 1); + // } } } });