]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5007 Rework bulk change
authorStas Vilchik <vilchiks@gmail.com>
Fri, 21 Mar 2014 09:36:50 +0000 (15:36 +0600)
committerStas Vilchik <vilchiks@gmail.com>
Fri, 21 Mar 2014 09:37:00 +0000 (15:37 +0600)
sonar-server/src/main/webapp/coffee/coding-rules/app.coffee
sonar-server/src/main/webapp/coffee/coding-rules/mockjax.coffee
sonar-server/src/main/webapp/coffee/coding-rules/views/actions-view.coffee
sonar-server/src/main/webapp/coffee/coding-rules/views/coding-rules-bulk-change-dropdown-view.coffee [new file with mode: 0644]
sonar-server/src/main/webapp/coffee/coding-rules/views/coding-rules-bulk-change-view.coffee
sonar-server/src/main/webapp/less/coding-rules.less
sonar-server/src/main/webapp/templates/coding-rules/coding-rules-bulk-change-dropdown.hbs [new file with mode: 0644]
sonar-server/src/main/webapp/templates/coding-rules/coding-rules-bulk-change.hbs
sonar-server/src/main/webapp/templates/coding-rules/coding-rules-detail.hbs

index a290059e0b0656ba17112e8a27576b51ccab868b..5c68e21642954c490925809d3ae1efd7db041d02 100644 (file)
@@ -30,6 +30,7 @@ requirejs [
   'coding-rules/views/coding-rules-list-view',
   'coding-rules/views/coding-rules-bulk-change-view',
   'coding-rules/views/coding-rules-quality-profile-activation-view',
+  'coding-rules/views/coding-rules-bulk-change-dropdown-view'
 
   # filters
   'navigator/filters/base-filters',
@@ -54,6 +55,7 @@ requirejs [
   CodingRulesListView,
   CodingRulesBulkChangeView,
   CodingRulesQualityProfileActivationView,
+  CodingRulesBulkChangeDropdownView
 
   # filters
   BaseFilters,
@@ -179,9 +181,10 @@ requirejs [
     @layout.actionsRegion.show @codingRulesActionsView
 
 
-  # Construct bulk change view
+  # Construct bulk change views
   App.addInitializer ->
     @codingRulesBulkChangeView = new CodingRulesBulkChangeView app: @
+    @codingRulesBulkChangeDropdownView = new CodingRulesBulkChangeDropdownView app: @
 
 
   # Construct quality profile activation view
index a42a3afe4867258e84b1b3f0f7ad5ce7183be6a8..c36b02d58ba25e8afe5945cf696e9a5a3a4dcd16 100644 (file)
@@ -68,12 +68,17 @@ define ['jquery.mockjax'], ->
         'severity.INFO': 'Info'
 
         'coding_rules.activate': 'Activate'
-        'coding_rules.activate_in_quality_profile': 'Activate in Quality Profile'
+        'coding_rules.activate_in': 'Activate In'
+        'coding_rules.activate_in_quality_profile': 'Activate In Quality Profile'
         'coding_rules.add_note': 'Add Note'
         'coding_rules.available_since': 'Available Since'
         'coding_rules.bulk_change': 'Bulk Change'
+        'coding_rules.change_severity': 'Change Severity'
+        'coding_rules.change_severity_in': 'Change Severity In'
         'coding_rules.extend_description': 'Extend Description'
+        'coding_rules.deactivate_in': 'Deactivate In'
         'coding_rules.deactivate_quality_profile': 'Deactivate'
+        'coding_rules.deactivate_in_quality_profile': 'Deactivate In Quality Profile'
         'coding_rules.found': 'Found'
         'coding_rules._inherits': 'inherits'
         'coding_rules.key': 'Key:'
@@ -89,7 +94,7 @@ define ['jquery.mockjax'], ->
         'coding_rules.quality_profile': 'Quality Profile'
         'coding_rules.repository': 'Repository:'
         'coding_rules.revert_to_parent_definition': 'Revert to Parent Definition'
-        'coding_rules._rules': 'rule(s)'
+        'coding_rules._rules': 'rules'
         'coding_rules.select_tag': 'Select Tag'
 
         'coding_rules.filters.availableSince': 'Available Since'
index c3d69eb334bb17e6719d18dbbfd487c49ec12ec0..96e306ed8e883972923e1cfd64f14c7d723085c0 100644 (file)
@@ -1,8 +1,8 @@
 define [
-  'backbone.marionette',
+  'backbone.marionette'
   'templates/coding-rules'
 ], (
-  Marionette,
+  Marionette
   Templates
 ) ->
 
@@ -16,12 +16,13 @@ define [
 
     ui:
       orderChoices: '.navigator-actions-order-choices'
+      bulkChange: '.navigator-actions-bulk'
 
 
     events:
       'click .navigator-actions-order': 'toggleOrderChoices'
       'click @ui.orderChoices': 'sort'
-      'click .navigator-actions-bulk': 'bulkChange'
+      'click @ui.bulkChange': 'bulkChange'
 
 
     onRender: ->
@@ -50,8 +51,9 @@ define [
         @options.app.fetchFirstPage()
 
 
-    bulkChange: ->
-      @options.app.codingRulesBulkChangeView.show()
+    bulkChange: (e) ->
+      e.stopPropagation()
+      @options.app.codingRulesBulkChangeDropdownView.toggle()
 
 
     serializeData: ->
diff --git a/sonar-server/src/main/webapp/coffee/coding-rules/views/coding-rules-bulk-change-dropdown-view.coffee b/sonar-server/src/main/webapp/coffee/coding-rules/views/coding-rules-bulk-change-dropdown-view.coffee
new file mode 100644 (file)
index 0000000..c359d26
--- /dev/null
@@ -0,0 +1,53 @@
+define [
+  'backbone.marionette',
+  'templates/coding-rules'
+], (
+  Marionette,
+  Templates
+) ->
+
+  class CodingRulesBulkChangeDropdownView extends Marionette.ItemView
+    className: 'coding-rules-bulk-change-dropdown'
+    template: Templates['coding-rules-bulk-change-dropdown']
+
+
+    events:
+      'click .coding-rules-bulk-change-dropdown-link': 'doAction'
+
+
+    doAction: (e) ->
+      action = jQuery(e.target).data 'action'
+      param = jQuery(e.target).data 'param'
+      unless param
+        @options.app.codingRulesBulkChangeView.show action
+      else
+        query = @options.app.getQuery()
+        switch action
+          when 'activate' then _.extend query, bulk_activate: [param]
+          when 'deactivate' then _.extend query, bulk_deactivate: [param]
+        @options.app.codingRulesBulkChangeView.bulkChange query
+
+
+    onRender: ->
+      jQuery('body').append @el
+      jQuery('body').off('click.bulk-change').on 'click.bulk-change', => @hide()
+
+
+    toggle: ->
+      if @$el.is(':visible') then @hide() else @show()
+
+
+    show: ->
+      @render()
+      @$el.show()
+
+
+    hide: ->
+      @$el.hide()
+
+
+    serializeData: ->
+      activeQualityProfile: @options.app.getActiveQualityProfile()
+      activeQualityProfileName: @options.app.activeInFilter.view.renderValue()
+      inactiveQualityProfile: @options.app.getInactiveQualityProfile()
+      inactiveQualityProfileName: @options.app.inactiveInFilter.view.renderValue()
\ No newline at end of file
index f0919610617b8633d327369b25f237dd0c9038c9..2d1ed767a542066ec06bb3ed7e93003af4470bb5 100644 (file)
@@ -44,7 +44,8 @@ define [
         escapeMarkup: (m) -> m
 
 
-    show: ->
+    show: (action) ->
+      @action = action
       @render()
       @$el.dialog 'open'
 
@@ -55,40 +56,23 @@ define [
 
     prepareQuery: ->
       query = @options.app.getQuery()
-      activateIn = []
-      deactivateIn = []
-      severity = null
-      if @$('#coding-rules-bulk-change-activate-qp').is(':checked')
-        activateIn.push @options.app.getInactiveQualityProfile()
-      if @$('#coding-rules-bulk-change-activate').is(':checked')
-        activateIn.push @$('#coding-rules-bulk-change-activate-on').val()
-      if @$('#coding-rules-bulk-change-deactivate-qp').is(':checked')
-        deactivateIn.push @options.app.getActiveQualityProfile()
-      if @$('#coding-rules-bulk-change-deactivate').is(':checked')
-        deactivateIn.push @$('#coding-rules-bulk-change-deactivate-on').val()
-      if @$('#coding-rules-bulk-change-set-severity').is(':checked')
-        severity = @$('#coding-rules-bulk-change-severity').val()
-      actions = []
-      if activateIn.length > 0
-        actions.push 'bulk_activate'
-        _.extend query, bulk_activate_in: activateIn.join(',')
-      if deactivateIn.length > 0
-        actions.push 'bulk_deactivate'
-        _.extend query, bulk_deactivate_in: deactivateIn.join(',')
-      if severity
-        actions.push 'bulk_set_severity'
-        _.extend query, bulk_severity: severity
-      _.extend query, bulk_actions: actions
+      switch @action
+        when 'activate' then _.extend query, bulk_activate: @$('#coding-rules-bulk-change-activate-on').val()
+        when 'deactivate' then _.extend query, bulk_deactivate: @$('#coding-rules-bulk-change-deactivate-on').val()
+        when 'change-severity' then _.extend query, bulk_change_severity: @$('#coding-rules-bulk-change-severity').val()
 
-    onSubmit: (e) ->
-      e.preventDefault()
+
+    bulkChange: (query) ->
       jQuery.ajax
         type: 'POST'
         url: "#{baseUrl}/api/codingrules/bulk_change"
-        data: @prepareQuery()
+        data: query
       .done =>
         @options.app.fetchFirstPage()
-        @hide()
+
+    onSubmit: (e) ->
+      e.preventDefault()
+      @bulkChange(@prepareQuery()).done => @hide()
 
 
 
@@ -97,6 +81,8 @@ define [
 
 
     serializeData: ->
+      action: @action
+
       paging: @options.app.codingRules.paging
       qualityProfiles: @options.app.qualityProfiles
 
index 389d28309ca9b84e28e927b79a4b7d925542c673..19f49511568c632e4b99a9ac6acd4eb428e19a2b 100644 (file)
   margin-top: -3px;
   margin-left: @navigatorPadding;
 }
+
+
+// Bulk Change
+.coding-rules-bulk-change-dropdown {
+  position: fixed;
+  z-index: 10;
+  top: @navigatorTopOffset + @navigatorHeaderHeight + @navigatorFiltersHeight + @navigatorStatusHeight - 1px;
+  left: @navigatorResultsWidth - 200px;
+  width: 200px;
+  border: 1px solid @navigatorBorderLightColor;
+  .box-sizing(border-box);
+  background-color: #fff;
+}
+
+.coding-rules-bulk-change-dropdown-link {
+  display: block;
+  height: 30px;
+  line-height: 30px;
+  padding: 0 @navigatorPadding;
+  font-size: @smallFontSize;
+  .trans;
+
+  &:hover { background-color: @navigatorBarBackground; }
+
+  strong { font-weight: bold; }
+}
\ No newline at end of file
diff --git a/sonar-server/src/main/webapp/templates/coding-rules/coding-rules-bulk-change-dropdown.hbs b/sonar-server/src/main/webapp/templates/coding-rules/coding-rules-bulk-change-dropdown.hbs
new file mode 100644 (file)
index 0000000..a6f5436
--- /dev/null
@@ -0,0 +1,17 @@
+<a class="coding-rules-bulk-change-dropdown-link" data-action="activate"
+   {{#if inactiveQualityProfile}}data-param="{{inactiveQualityProfile}}"{{/if}}>
+  {{t 'coding_rules.activate_in'}}
+  {{#if inactiveQualityProfile}}<strong>{{inactiveQualityProfileName}}</strong>{{/if}}
+</a>
+
+<a class="coding-rules-bulk-change-dropdown-link" data-action="deactivate"
+   {{#if activeQualityProfile}}data-param="{{activeQualityProfile}}"{{/if}}>
+  {{t 'coding_rules.deactivate_in'}}
+  {{#if activeQualityProfile}}<strong>{{activeQualityProfileName}}</strong>{{/if}}
+</a>
+
+{{#if activeQualityProfile}}
+  <a class="coding-rules-bulk-change-dropdown-link" data-action="change-severity">
+    {{t 'coding_rules.change_severity_in'}} <strong>{{activeQualityProfileName}}</strong>
+  </a>
+{{/if}}
\ No newline at end of file
index f7f1010eeba185fd235b4eb101fd6e811a9819b2..c8ecaab182106f0b985107f1e00d46264c37e1ab 100644 (file)
@@ -1,58 +1,53 @@
 <form>
   <div class="modal-head">
-    <h2>{{t 'coding_rules.bulk_change'}} {{paging.fTotal}} {{t 'coding_rules._rules'}}</h2>
+    {{#eq action 'activate'}}
+      <h2>{{t 'coding_rules.activate_in_quality_profile'}} ({{paging.fTotal}} {{t 'coding_rules._rules'}})</h2>
+    {{/eq}}
+    {{#eq action 'deactivate'}}
+      <h2>{{t 'coding_rules.deactivate_in_quality_profile'}} ({{paging.fTotal}} {{t 'coding_rules._rules'}})</h2>
+    {{/eq}}
+    {{#eq action 'change-severity'}}
+      <h2>{{t 'coding_rules.change_severity'}} ({{paging.fTotal}} {{t 'coding_rules._rules'}})</h2>
+    {{/eq}}
   </div>
 
   <div class="modal-body">
     <div class="modal-error"></div>
 
-    {{#if inactiveQualityProfile}}
+    {{#eq action 'activate'}}
       <div class="modal-field">
-        <label for="coding-rules-bulk-change-activate-on-qp">Activate on</label>
-        <input id="coding-rules-bulk-change-activate-qp" type="checkbox">
-        <span class="text">{{inactiveQualityProfileName}}</span>
-      </div>
-    {{/if}}
-
-    <div class="modal-field">
-      <label for="coding-rules-bulk-change-activate-on">{{#unless inactiveQualityProfile}}Activate on{{/unless}}</label>
-      <input id="coding-rules-bulk-change-activate" type="checkbox">
-      <select id="coding-rules-bulk-change-activate-on" multiple>
-        {{#each activateOnQualityProfiles}}
-          <option value="{{key}}">{{name}}</option>
-        {{/each}}
-      </select>
-    </div>
-
-    {{#if activeQualityProfile}}
-      <div class="modal-field">
-        <label for="coding-rules-bulk-change-deactivate-on-qp">Deactivate on</label>
-        <input id="coding-rules-bulk-change-deactivate-qp" type="checkbox">
-        <span class="text">{{activeQualityProfileName}}</span>
+        <label for="coding-rules-bulk-change-activate-on">{{t 'coding_rules.activate_in'}}</label>
+        <select id="coding-rules-bulk-change-activate-on" multiple>
+          {{#each activateOnQualityProfiles}}
+            <option value="{{key}}">{{name}}</option>
+          {{/each}}
+        </select>
       </div>
-    {{/if}}
+    {{/eq}}
 
-    <div class="modal-field">
-      <label for="coding-rules-bulk-change-deactivate-on">{{#unless activeQualityProfile}}Deactivate on{{/unless}}</label>
-      <input id="coding-rules-bulk-change-deactivate" type="checkbox">
-      <select id="coding-rules-bulk-change-deactivate-on" multiple>
-        {{#each deactivateOnQualityProfiles}}
-          <option value="{{key}}">{{name}}</option>
-        {{/each}}
-      </select>
-    </div>
-
-    {{#if activeQualityProfile}}
+    {{#eq action 'deactivate'}}
       <div class="modal-field">
-        <label for="coding-rules-bulk-change-severity">Change Severity</label>
-        <input id="coding-rules-bulk-change-set-severity" type="checkbox">
-        <select id="coding-rules-bulk-change-severity">
-          {{#each severities}}
-            <option value="{{this}}">{{t 'severity' this}}</option>
+        <label for="coding-rules-bulk-change-deactivate-on">{{t 'coding_rules.deactivate_in'}}</label>
+        <select id="coding-rules-bulk-change-deactivate-on" multiple>
+          {{#each deactivateOnQualityProfiles}}
+            <option value="{{key}}">{{name}}</option>
           {{/each}}
         </select>
       </div>
-    {{/if}}
+    {{/eq}}
+
+    {{#eq action 'change-severity'}}
+      {{#if activeQualityProfile}}
+        <div class="modal-field">
+          <label for="coding-rules-bulk-change-severity">{{t 'coding_rules.change_severity'}}</label>
+          <select id="coding-rules-bulk-change-severity">
+            {{#each severities}}
+              <option value="{{this}}">{{t 'severity' this}}</option>
+            {{/each}}
+          </select>
+        </div>
+      {{/if}}
+    {{/eq}}
   </div>
 
   <div class="modal-foot">
index 4c424f1bd05aa9a6492e1c680a171653f628544a..7234ab5a16cf4750e08c1e91c942a73a6092a344 100644 (file)
@@ -83,6 +83,6 @@
 
 <h3 class="coding-rules-detail-title">{{t 'coding_rules.quality_profiles'}}</h3>
 <div class="button-group coding-rules-detail-quality-profiles-activation">
-  <button id="coding-rules-quality-profile-activate">{{t 'coding_rules.activate_quality_profile'}}</button>
+  <button id="coding-rules-quality-profile-activate">{{t 'coding_rules.activate_in_quality_profile'}}</button>
 </div>
 <div id="coding-rules-detail-quality-profiles"></div>
\ No newline at end of file