From e768b554633b645eaac9301f4ad258e16a15b38d Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Fri, 21 Mar 2014 15:36:50 +0600 Subject: [PATCH] SONAR-5007 Rework bulk change --- .../webapp/coffee/coding-rules/app.coffee | 5 +- .../webapp/coffee/coding-rules/mockjax.coffee | 9 ++- .../coding-rules/views/actions-view.coffee | 12 +-- ...ing-rules-bulk-change-dropdown-view.coffee | 53 +++++++++++++ .../coding-rules-bulk-change-view.coffee | 44 ++++------- .../src/main/webapp/less/coding-rules.less | 26 +++++++ .../coding-rules-bulk-change-dropdown.hbs | 17 ++++ .../coding-rules/coding-rules-bulk-change.hbs | 77 +++++++++---------- .../coding-rules/coding-rules-detail.hbs | 2 +- 9 files changed, 166 insertions(+), 79 deletions(-) create mode 100644 sonar-server/src/main/webapp/coffee/coding-rules/views/coding-rules-bulk-change-dropdown-view.coffee create mode 100644 sonar-server/src/main/webapp/templates/coding-rules/coding-rules-bulk-change-dropdown.hbs diff --git a/sonar-server/src/main/webapp/coffee/coding-rules/app.coffee b/sonar-server/src/main/webapp/coffee/coding-rules/app.coffee index a290059e0b0..5c68e216429 100644 --- a/sonar-server/src/main/webapp/coffee/coding-rules/app.coffee +++ b/sonar-server/src/main/webapp/coffee/coding-rules/app.coffee @@ -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 diff --git a/sonar-server/src/main/webapp/coffee/coding-rules/mockjax.coffee b/sonar-server/src/main/webapp/coffee/coding-rules/mockjax.coffee index a42a3afe486..c36b02d58ba 100644 --- a/sonar-server/src/main/webapp/coffee/coding-rules/mockjax.coffee +++ b/sonar-server/src/main/webapp/coffee/coding-rules/mockjax.coffee @@ -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' diff --git a/sonar-server/src/main/webapp/coffee/coding-rules/views/actions-view.coffee b/sonar-server/src/main/webapp/coffee/coding-rules/views/actions-view.coffee index c3d69eb334b..96e306ed8e8 100644 --- a/sonar-server/src/main/webapp/coffee/coding-rules/views/actions-view.coffee +++ b/sonar-server/src/main/webapp/coffee/coding-rules/views/actions-view.coffee @@ -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 index 00000000000..c359d2697c6 --- /dev/null +++ b/sonar-server/src/main/webapp/coffee/coding-rules/views/coding-rules-bulk-change-dropdown-view.coffee @@ -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 diff --git a/sonar-server/src/main/webapp/coffee/coding-rules/views/coding-rules-bulk-change-view.coffee b/sonar-server/src/main/webapp/coffee/coding-rules/views/coding-rules-bulk-change-view.coffee index f0919610617..2d1ed767a54 100644 --- a/sonar-server/src/main/webapp/coffee/coding-rules/views/coding-rules-bulk-change-view.coffee +++ b/sonar-server/src/main/webapp/coffee/coding-rules/views/coding-rules-bulk-change-view.coffee @@ -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 diff --git a/sonar-server/src/main/webapp/less/coding-rules.less b/sonar-server/src/main/webapp/less/coding-rules.less index 389d28309ca..19f49511568 100644 --- a/sonar-server/src/main/webapp/less/coding-rules.less +++ b/sonar-server/src/main/webapp/less/coding-rules.less @@ -164,3 +164,29 @@ 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 index 00000000000..a6f543691f4 --- /dev/null +++ b/sonar-server/src/main/webapp/templates/coding-rules/coding-rules-bulk-change-dropdown.hbs @@ -0,0 +1,17 @@ + + {{t 'coding_rules.activate_in'}} + {{#if inactiveQualityProfile}}{{inactiveQualityProfileName}}{{/if}} + + + + {{t 'coding_rules.deactivate_in'}} + {{#if activeQualityProfile}}{{activeQualityProfileName}}{{/if}} + + +{{#if activeQualityProfile}} + + {{t 'coding_rules.change_severity_in'}} {{activeQualityProfileName}} + +{{/if}} \ No newline at end of file diff --git a/sonar-server/src/main/webapp/templates/coding-rules/coding-rules-bulk-change.hbs b/sonar-server/src/main/webapp/templates/coding-rules/coding-rules-bulk-change.hbs index f7f1010eeba..c8ecaab1821 100644 --- a/sonar-server/src/main/webapp/templates/coding-rules/coding-rules-bulk-change.hbs +++ b/sonar-server/src/main/webapp/templates/coding-rules/coding-rules-bulk-change.hbs @@ -1,58 +1,53 @@