]> source.dussan.org Git - sonarqube.git/commitdiff
revert SONAR-6742 Stop displaying plugin actions for issues
authorStas Vilchik <vilchiks@gmail.com>
Fri, 9 Oct 2015 07:50:40 +0000 (09:50 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 9 Oct 2015 14:48:24 +0000 (16:48 +0200)
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/templates/issue-more-actions.hbs [new file with mode: 0644]
server/sonar-web/src/main/js/components/issue/templates/issue.hbs
server/sonar-web/src/main/js/components/issue/views/more-actions-view.js
server/sonar-web/src/main/js/libs/handlebars-extensions.js

index 5c91f18d23d33dc7bcaee31fd41b1945e17dd6fe..12ff93c00ba7ae3e5749d991a1140e0040781b53 100644 (file)
@@ -10,6 +10,7 @@ import AssignFormView from './views/assign-form-view';
 import CommentFormView from './views/comment-form-view';
 import PlanFormView from './views/plan-form-view';
 import SetSeverityFormView from './views/set-severity-form-view';
+import MoreActionsView from './views/more-actions-view';
 import TagsFormView from './views/tags-form-view';
 import Workspace from 'components/workspace/main';
 import './templates';
@@ -34,6 +35,7 @@ export default Marionette.ItemView.extend({
       'click .js-issue-assign-to-me': 'assignToMe',
       'click .js-issue-plan': 'plan',
       'click .js-issue-show-changelog': 'showChangeLog',
+      'click .js-issue-more': 'showMoreActions',
       'click .js-issue-rule': 'showRule',
       'click .js-issue-edit-tags': 'editTags',
       'click .js-issue-locations': 'showLocations'
@@ -208,6 +210,30 @@ export default Marionette.ItemView.extend({
     RealWorkspace.openRule({ key: ruleKey });
   },
 
+  showMoreActions: function (e) {
+    e.stopPropagation();
+    $('body').click();
+    this.popup = new MoreActionsView({
+      triggerEl: $(e.currentTarget),
+      bottomRight: true,
+      model: this.model,
+      detailView: this
+    });
+    this.popup.render();
+  },
+
+  action: function (action) {
+    var that = this;
+    this.disableControls();
+    return this.model.customAction(action)
+        .done(function () {
+          that.updateAfterAction(true);
+        })
+        .fail(function () {
+          that.enableControls();
+        });
+  },
+
   editTags: function (e) {
     e.stopPropagation();
     $('body').click();
index c619361c39901f9ddf8e132520b150613366d0f4..5d509e77acb94ba7db8fb4d07ea61d5defd44b51 100644 (file)
@@ -214,6 +214,21 @@ export default Backbone.Model.extend({
     });
   },
 
+
+  /**
+   * Do a custom (plugin) action
+   * @param {String} actionKey Action Key
+   * @param {Object|null} options Options for jQuery ajax
+   * @returns {jqXHR}
+   */
+  customAction: function (actionKey, options) {
+    var opts = _.extend({
+      url: this.urlRoot() + '/do_action',
+      data: { issue: this.id, actionKey: actionKey }
+    }, options);
+    return this._action(opts);
+  },
+
   getLinearLocations: function () {
     var textRange = this.get('textRange');
     if (!textRange) {
diff --git a/server/sonar-web/src/main/js/components/issue/templates/issue-more-actions.hbs b/server/sonar-web/src/main/js/components/issue/templates/issue-more-actions.hbs
new file mode 100644 (file)
index 0000000..f4e8422
--- /dev/null
@@ -0,0 +1,9 @@
+<ul class="menu">
+  {{#pluginActions actions}}
+    <li>
+      <a class="issue-action js-issue-action" href="#" data-action="{{this}}">{{t "issue.action" this "formlink"}}</a>
+    </li>
+  {{/pluginActions}}
+</ul>
+
+<div class="bubble-popup-arrow"></div>
index 61a03ecb248a057c314f001f640be0371110382c..33ca4c1f18e854e5f3c0989ed12d1986572b0c45 100644 (file)
                   class="issue-meta-label">{{t 'issue.comment.formlink' }}</span></button>
             </li>
           {{/inArray}}
+
+          {{#ifHasExtraActions actions}}
+            <li class="issue-meta">
+              <button class="button-link issue-action issue-action-with-options js-issue-more">
+                <span class="issue-meta-label">{{t 'more'}}</span>&nbsp;<i class="icon-dropdown"></i>
+              </button>
+            </li>
+          {{/ifHasExtraActions}}
         </ul>
 
         {{#inArray actions "assign_to_me"}}
index 4fa157c153363b09871fe533eddd0102bcba3207..70db7c1b2e4898a80c76eb00f3107e842a7cae9e 100644 (file)
@@ -1,18 +1,17 @@
 import $ from 'jquery';
-import PopupView from 'components/common/popup';
+import ActionOptionsView from 'components/common/action-options-view';
 import '../templates';
 
-export default PopupView.extend({
+export default ActionOptionsView.extend({
   template: Templates['issue-more-actions'],
 
-  events: function () {
-    return {
-      'click .js-issue-action': 'action'
-    };
+  selectOption: function (e) {
+    var action = $(e.currentTarget).data('action');
+    this.submit(action);
+    return ActionOptionsView.prototype.selectOption.apply(this, arguments);
   },
 
-  action: function (e) {
-    var actionKey = $(e.currentTarget).data('action');
+  submit: function (actionKey) {
     return this.options.detailView.action(actionKey);
   }
 });
index 9ea3c5bc7f1bf6312e30060bc48f06f6937ed5ec..adac1db2b0aafb14278a71cd443be2dc91576da4 100644 (file)
@@ -1,4 +1,6 @@
 (function () {
+  var defaultActions = ['comment', 'assign', 'assign_to_me', 'plan', 'set_severity', 'set_tags'];
+
   Handlebars.registerHelper('log', function () {
     /* eslint no-console: 0 */
     var args = Array.prototype.slice.call(arguments, 0, -1);
     return numeral(number).format(format);
   });
 
+  Handlebars.registerHelper('pluginActions', function (actions, options) {
+    var pluginActions = _.difference(actions, defaultActions);
+    return pluginActions.reduce(function (prev, current) {
+      return prev + options.fn(current);
+    }, '');
+  });
+
+  Handlebars.registerHelper('ifHasExtraActions', function (actions, options) {
+    var actionsLeft = _.difference(actions, defaultActions);
+    if (actionsLeft.length > 0) {
+      return options.fn(this);
+    } else {
+      return options.inverse(this);
+    }
+  });
+
   Handlebars.registerHelper('withFirst', function (list, options) {
     if (list && list.length > 0) {
       return options.fn(list[0]);