]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8539 Avoid useless WS call when adding/editing/deleting a comment to refresh...
authorStas Vilchik <vilchiks@gmail.com>
Wed, 25 Jan 2017 14:47:42 +0000 (15:47 +0100)
committerStas Vilchik <vilchiks@gmail.com>
Thu, 26 Jan 2017 11:31:01 +0000 (12:31 +0100)
server/sonar-web/src/main/js/components/issue/issue-view.js
server/sonar-web/src/main/js/components/issue/models/issue.js
server/sonar-web/src/main/js/components/issue/views/comment-form-view.js

index 0d133a2e4527edec1ce6923ec05b5266e4b8270e..325a153dff63e62aa1f2d3323e754aa75dd11650 100644 (file)
@@ -100,12 +100,12 @@ export default Marionette.ItemView.extend({
     });
   },
 
-  updateAfterAction (fetch) {
+  updateAfterAction (response) {
     if (this.popup) {
       this.popup.destroy();
     }
-    if (fetch) {
-      this.resetIssue();
+    if (response) {
+      this.model.set(this.model.parse(response));
     }
   },
 
@@ -155,7 +155,7 @@ export default Marionette.ItemView.extend({
         $.ajax({
           type: 'POST',
           url: window.baseUrl + '/api/issues/delete_comment?key=' + commentKey
-        }).done(() => this.updateAfterAction(true));
+        }).done(r => this.updateAfterAction(r));
       }
     });
     this.popup.render();
@@ -222,15 +222,10 @@ export default Marionette.ItemView.extend({
   },
 
   action (action) {
-    const that = this;
     this.disableControls();
     return this.model.customAction(action)
-        .done(() => {
-          that.updateAfterAction(true);
-        })
-        .fail(() => {
-          that.enableControls();
-        });
+        .done(r => this.updateAfterAction(r))
+        .fail(() => this.enableControls());
   },
 
   editTags (e) {
index a115c93129a03cbb14b84b207b27b26c7aff00ae..46f31dbcc86261cbd817d872c2f1c16f2a1ddf70 100644 (file)
@@ -69,14 +69,13 @@ export default Backbone.Model.extend({
 
   _injectCommentsRelational (issue, users) {
     if (issue.comments) {
-      const that = this;
       const newComments = issue.comments.map(comment => {
         let newComment = { ...comment, author: comment.login };
         delete newComment.login;
-        newComment = that._injectRelational(newComment, users, 'author', 'login');
+        newComment = this._injectRelational(newComment, users, 'author', 'login');
         return newComment;
       });
-      issue = { ...issue, comments: newComments };
+      return { ...issue, comments: newComments };
     }
     return issue;
   },
index eec1250de3c2830f0f180e247bed0ea1c8fbfbff..b80d0b5603d53898a670ada4222f224c559cb65e 100644 (file)
@@ -65,7 +65,7 @@ export default PopupView.extend({
   },
 
   cancel () {
-    this.options.detailView.updateAfterAction(false);
+    this.options.detailView.updateAfterAction();
   },
 
   disableForm () {
@@ -77,7 +77,6 @@ export default PopupView.extend({
   },
 
   submit () {
-    const that = this;
     const text = this.ui.textarea.val();
 
     if (!text.length) {
@@ -96,11 +95,10 @@ export default PopupView.extend({
     this.disableForm();
     this.options.detailView.disableControls();
     return $.post(url, data)
-        .done(() => {
-          that.options.detailView.updateAfterAction(true);
-        }).fail(() => {
-          that.enableForm();
-          that.options.detailView.enableControls();
+        .done(r => this.options.detailView.updateAfterAction(r))
+        .fail(() => {
+          this.enableForm();
+          this.options.detailView.enableControls();
         });
   },