From 3147c52f738fa46157a543f4173d2b60c448306b Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Lievremont Date: Mon, 9 Jun 2014 12:05:16 +0200 Subject: [PATCH] SONAR-5133 Fix behavior of quality profile dependent filters activation --- .../src/main/coffee/coding-rules/app.coffee | 5 +- .../filters/activation-filter-view.coffee | 63 +++++++++++-------- .../filters/inheritance-filter-view.coffee | 21 +++++-- .../views/filters/language-filter-view.coffee | 27 +++++++- .../filters/more-criteria-filters.js | 17 ++++- 5 files changed, 98 insertions(+), 35 deletions(-) diff --git a/sonar-server/src/main/coffee/coding-rules/app.coffee b/sonar-server/src/main/coffee/coding-rules/app.coffee index 8f1e5de0af4..4c4532417ec 100644 --- a/sonar-server/src/main/coffee/coding-rules/app.coffee +++ b/sonar-server/src/main/coffee/coding-rules/app.coffee @@ -223,6 +223,9 @@ requirejs [ App.getQualityProfilesForLanguage = (language_key) -> _.filter App.qualityProfiles, (p) => p.lang == language_key + App.getQualityProfileByKey = (profile_key) -> + _.findWhere App.qualityProfiles, key: profile_key + App.showRule = (ruleKey) -> App.layout.showSpinner 'detailsRegion' jQuery.ajax @@ -343,7 +346,7 @@ requirejs [ property: 'activation' type: ActivationFilterView enabled: false - optional: false + optional: true multiple: false qualityProfileFilter: @qualityProfileFilter choices: diff --git a/sonar-server/src/main/coffee/coding-rules/views/filters/activation-filter-view.coffee b/sonar-server/src/main/coffee/coding-rules/views/filters/activation-filter-view.coffee index fb51c3a03fc..68996355666 100644 --- a/sonar-server/src/main/coffee/coding-rules/views/filters/activation-filter-view.coffee +++ b/sonar-server/src/main/coffee/coding-rules/views/filters/activation-filter-view.coffee @@ -6,39 +6,52 @@ define [ InheritanceFilterView ) -> - class DetailsActivationFilterView extends ChoiceFilters.DetailsChoiceFilterView - - onCheck: (e) -> - id = jQuery(e.target).val() - selected = @options.filterView.choices.findWhere checked: true - unless id == selected - @options.filterView.choices.each (item) -> item.set 'checked', item.id == id - else - e.preventDefault() - @updateValue() - @updateLists() - - - - class ActivationFilterView extends InheritanceFilterView + class ActivationFilterView extends ChoiceFilters.ChoiceFilterView tooltip: 'coding_rules.filters.activation.help' - initialize: -> - super detailsView: DetailsActivationFilterView + super + @qualityProfileFilter = @model.get 'qualityProfileFilter' + @listenTo @qualityProfileFilter, 'change:value', @onChangeQualityProfile + @onChangeQualityProfile() onChangeQualityProfile: -> - qualityProfile = @qualityProfileFilter.get 'value' - if _.isArray(qualityProfile) && qualityProfile.length == 1 then @makeActive() else @makeInactive() + qualityProfileKey = @qualityProfileFilter.get 'value' + if _.isArray(qualityProfileKey) && qualityProfileKey.length == 1 + @makeActive() + else + @makeInactive() makeActive: -> - @restore('true') - super + @model.set inactive: false, title: '' + @model.trigger 'change:enabled' + unless @model.get 'value' + @choices.each (model) -> model.set 'checked', model.id == 'true' + @$el.removeClass('navigator-filter-inactive').prop 'title', '' + @options.filterBarView.moreCriteriaFilter.view.detailsView.enableByProperty(@detailsView.model.get 'property') + @hideDetails() + + + makeInactive: -> + @model.set inactive: true, title: t @tooltip + @model.trigger 'change:enabled' + @choices.each (model) -> model.set 'checked', false + @detailsView.updateLists() + @detailsView.updateValue() + @$el.addClass('navigator-filter-inactive').prop 'title', t @tooltip + + + showDetails: -> + super unless @$el.is '.navigator-filter-inactive' + restore: (value) -> - @choices.each (item) -> item.set 'checked', item.id == value - @detailsView.updateValue() - @detailsView.updateLists() - @render() + value = value.split(',') if _.isString(value) + if @choices && value.length > 0 + @choices.each (model) -> model.set 'checked', value.indexOf(model.id) >= 0 + @model.set value: value, enabled: true + @onChangeQualityProfile() + else + @clear() diff --git a/sonar-server/src/main/coffee/coding-rules/views/filters/inheritance-filter-view.coffee b/sonar-server/src/main/coffee/coding-rules/views/filters/inheritance-filter-view.coffee index c184e7c3a70..77768ece87d 100644 --- a/sonar-server/src/main/coffee/coding-rules/views/filters/inheritance-filter-view.coffee +++ b/sonar-server/src/main/coffee/coding-rules/views/filters/inheritance-filter-view.coffee @@ -18,11 +18,22 @@ define [ onChangeQualityProfile: -> qualityProfileKey = @qualityProfileFilter.get 'value' if _.isArray(qualityProfileKey) && qualityProfileKey.length == 1 - qualityProfile = @options.app.getQualityProfile qualityProfileKey - parentQualityProfile = @options.app.getQualityProfile qualityProfile.parent - if parentQualityProfile - @makeActive() + qualityProfile = @options.app.getQualityProfileByKey qualityProfileKey[0] + console.log qualityProfile + if qualityProfile.parent + console.log 'has parent ' + qualityProfile.parent + parentQualityProfile = @options.app.getQualityProfile qualityProfile.parent + if parentQualityProfile + console.log 'found parent' + @makeActive() + else + console.log 'parent not found' + @makeInactive() + else + console.log 'no parent' + @makeInactive() else + console.log 'no quality profile' @makeInactive() @@ -30,6 +41,8 @@ define [ @model.set inactive: false, title: '' @model.trigger 'change:enabled' @$el.removeClass('navigator-filter-inactive').prop 'title', '' + @options.filterBarView.moreCriteriaFilter.view.detailsView.enableByProperty(@detailsView.model.get 'property') + @hideDetails() makeInactive: -> diff --git a/sonar-server/src/main/coffee/coding-rules/views/filters/language-filter-view.coffee b/sonar-server/src/main/coffee/coding-rules/views/filters/language-filter-view.coffee index c8cbd445e6a..96a07561137 100644 --- a/sonar-server/src/main/coffee/coding-rules/views/filters/language-filter-view.coffee +++ b/sonar-server/src/main/coffee/coding-rules/views/filters/language-filter-view.coffee @@ -8,15 +8,36 @@ define [ class LanguageFilterView extends ChoiceFilters.ChoiceFilterView + modelEvents: + 'change:value': 'onChangeValue' + 'change:enabled': 'focus', + + initialize: -> super @app = @model.get 'app' @listenTo @app.qualityProfileFilter, 'change:value', @onChangeProfile + @selectedFromProfile = false onChangeProfile: -> profiles = @app.qualityProfileFilter.get 'value' if _.isArray(profiles) && profiles.length > 0 profile = _.findWhere @app.qualityProfiles, key: profiles[0] - @restore profile.lang - # force alignment of details list - @app.qualityProfileFilter.view.showDetails() + @options.filterBarView.moreCriteriaFilter.view.detailsView.enableByProperty(@detailsView.model.get 'property') + @choices.each (item) -> item.set 'checked', item.id == profile.lang + @refreshValues() + @selectedFromProfile = true + else if @selectedFromProfile + @choices.each (item) -> item.set 'checked', false + @refreshValues() + + onChangeValue: -> + @selectedFromProfile = false + @renderBase() + + + refreshValues: -> + @detailsView.updateValue() + @detailsView.updateLists() + @render() + @hideDetails() diff --git a/sonar-server/src/main/js/navigator/filters/more-criteria-filters.js b/sonar-server/src/main/js/navigator/filters/more-criteria-filters.js index 309f89ff047..438630a1a4b 100644 --- a/sonar-server/src/main/js/navigator/filters/more-criteria-filters.js +++ b/sonar-server/src/main/js/navigator/filters/more-criteria-filters.js @@ -13,10 +13,23 @@ define([ }, - enableFilter: function(e) { - var id = $j(e.target).data('id'); + enableById: function(id) { this.model.view.options.filterBarView.enableFilter(id); this.model.view.hideDetails(); + }, + + + enableByProperty: function(property) { + var filter = _.find(this.model.get('filters'), function(filter) { return filter.get('property') === property; }); + if (filter) { + this.enableById(filter.cid); + } + }, + + + enableFilter: function(e) { + var id = $j(e.target).data('id'); + this.enableById(id); this.updateCurrent(0); }, -- 2.39.5