]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5007 Put criteria in order
authorStas Vilchik <vilchiks@gmail.com>
Wed, 12 Mar 2014 06:53:44 +0000 (12:53 +0600)
committerStas Vilchik <vilchiks@gmail.com>
Wed, 12 Mar 2014 06:53:44 +0000 (12:53 +0600)
sonar-server/src/main/webapp/javascripts/coding-rules/app.coffee
sonar-server/src/main/webapp/javascripts/coding-rules/app.js
sonar-server/src/main/webapp/javascripts/coding-rules/mockjax.coffee
sonar-server/src/main/webapp/javascripts/coding-rules/mockjax.js
sonar-server/src/main/webapp/javascripts/coding-rules/views/filter-bar-view.coffee
sonar-server/src/main/webapp/javascripts/coding-rules/views/filter-bar-view.js
sonar-server/src/main/webapp/javascripts/coding-rules/views/filters/inheritance-filter-view.coffee [new file with mode: 0644]

index ec4caa0b769597b2b0ca84e1efe8ac700692c2ab..20400fb62ede0f0f12c57fd0e6b4a7313fb8a31e 100644 (file)
@@ -34,6 +34,7 @@ requirejs [
   'navigator/filters/choice-filters',
   'navigator/filters/string-filters',
   'coding-rules/views/filters/quality-profile-filter-view',
+  'coding-rules/views/filters/inheritance-filter-view',
 
   'coding-rules/mockjax'
 ], (
@@ -52,7 +53,8 @@ requirejs [
   BaseFilters,
   ChoiceFilters,
   StringFilterView,
-  QualityProfileFilterView
+  QualityProfileFilterView,
+  InheritanceFilterView
 ) ->
 
   # Create a generic error handler for ajax requests
@@ -106,7 +108,6 @@ requirejs [
     @storeQuery query, @codingRules.sorting
 
     @layout.showSpinner 'resultsRegion'
-    @layout.showSpinner 'facetsRegion'
     jQuery.ajax
       url: "#{baseUrl}/api/codingrules/search"
       data: fetchQuery
@@ -170,25 +171,41 @@ requirejs [
     @filters = new BaseFilters.Filters
 
     @filters.add new BaseFilters.Filter
-      name: t 'coding_rules.filters.name_key'
-      property: 'searchtext'
+      name: t 'coding_rules.filters.name'
+      property: 'name'
       type: StringFilterView
       enabled: true
       optional: false
 
+    @filters.add new BaseFilters.Filter
+      name: t 'coding_rules.filters.key'
+      property: 'key'
+      type: StringFilterView
+      enabled: true
+      optional: false
+
+    @filters.add new BaseFilters.Filter
+      name: t 'coding_rules.filters.description'
+      property: 'description'
+      type: StringFilterView
+      enabled: true
+      optional: false
+
+    @filters.add new BaseFilters.Filter
+      name: t 'coding_rules.filters.language'
+      property: 'languages'
+      type: ChoiceFilters.ChoiceFilterView
+      enabled: true
+      optional: false
+      choices: @languages
+
     @filters.add new BaseFilters.Filter
       name: t 'coding_rules.filters.repository'
       property: 'repositories'
       type: ChoiceFilters.ChoiceFilterView
       enabled: true
       optional: false
-      choices:
-        'checkstyle': 'Checkstyle'
-        'common-java': 'Common SonarQube'
-        'findbugs': 'FindBugs'
-        'pmd': 'PMD'
-        'pmd-unit-tests': 'PMD Unit Tests'
-        'squid': 'SonarQube'
+      choices: @repositories
 
     @filters.add new BaseFilters.Filter
       name: t 'coding_rules.filters.severity'
@@ -215,10 +232,7 @@ requirejs [
       type: ChoiceFilters.ChoiceFilterView
       enabled: true
       optional: false
-      choices:
-        'BETA': 'Beta'
-        'DEPRECATED': 'Deprecated'
-        'READY': 'Ready'
+      choices: @statuses
 
     @filters.add new BaseFilters.Filter
       name: t 'coding_rules.filters.tag'
@@ -226,40 +240,37 @@ requirejs [
       type: ChoiceFilters.ChoiceFilterView
       enabled: true
       optional: false
-      choices:
-        'brain-overload': 'brain-overload'
-        'bug': 'bug'
-        'comment': 'comment'
-        'convention': 'convention'
-        'error-handling': 'error-handling'
-        'formatting': 'formatting'
-        'java8': 'java8'
-        'multithreading': 'multithreading'
-        'naming': 'naming'
-        'pitfall': 'pitfall'
-        'security': 'security'
-        'size': 'size'
-        'unused': 'unused'
-        'unused-code': 'unused-code'
+      choices: @tags
 
     @activeInFilter = new BaseFilters.Filter
-      name: t 'coding_rules.filters.active_in'
-      property: 'active_in'
+      name: t 'coding_rules.filters.in_quality_profile'
+      property: 'in_quality_profile'
       type: QualityProfileFilterView
-      single: true
+      multiple: false
       enabled: true
       optional: false
     @filters.add @activeInFilter
 
     @inactiveInFilter = new BaseFilters.Filter
-      name: t 'coding_rules.filters.inactive_in'
-      property: 'inactive_in'
+      name: t 'coding_rules.filters.out_of_quality_profile'
+      property: 'out_of_quality_profile'
       type: QualityProfileFilterView
-      single: true
+      multiple: false
       enabled: true
       optional: false
     @filters.add @inactiveInFilter
 
+    @filters.add new BaseFilters.Filter
+      name: t 'coding_rules.filters.inheritance'
+      property: 'inheritance'
+      type: InheritanceFilterView
+      enabled: true
+      optional: false
+      qualityProfileFilter: @activeInFilter
+      choices:
+        'option1': 'Option 1'
+        'option2': 'Option 2'
+
     @filterBarView = new CodingRulesFilterBarView
       app: @
       collection: @filters,
@@ -282,6 +293,10 @@ requirejs [
       App.appState = new Backbone.Model
       App.state = new Backbone.Model
       App.qualityProfiles = r.qualityprofiles
+      App.languages = r.languages
+      App.repositories = r.repositories
+      App.statuses = r.statuses
+      App.tags = r.tags
       window.messages = r.messages
 
       # Remove the initial spinner
index bb0e902cf2bb21cbcbbe36028b5e7795f8a28939..88547929dd1e2b2407659150f998a12c34c8ea9d 100644 (file)
@@ -22,7 +22,7 @@
     }
   });
 
-  requirejs(['backbone', 'backbone.marionette', 'coding-rules/layout', 'coding-rules/router', 'coding-rules/views/header-view', 'coding-rules/views/actions-view', 'coding-rules/views/filter-bar-view', 'coding-rules/views/coding-rules-list-view', 'navigator/filters/base-filters', 'navigator/filters/choice-filters', 'navigator/filters/string-filters', 'coding-rules/views/filters/quality-profile-filter-view', 'coding-rules/mockjax'], function(Backbone, Marionette, CodingRulesLayout, CodingRulesRouter, CodingRulesHeaderView, CodingRulesActionsView, CodingRulesFilterBarView, CodingRulesListView, BaseFilters, ChoiceFilters, StringFilterView, QualityProfileFilterView) {
+  requirejs(['backbone', 'backbone.marionette', 'coding-rules/layout', 'coding-rules/router', 'coding-rules/views/header-view', 'coding-rules/views/actions-view', 'coding-rules/views/filter-bar-view', 'coding-rules/views/coding-rules-list-view', 'navigator/filters/base-filters', 'navigator/filters/choice-filters', 'navigator/filters/string-filters', 'coding-rules/views/filters/quality-profile-filter-view', 'coding-rules/views/filters/inheritance-filter-view', 'coding-rules/mockjax'], function(Backbone, Marionette, CodingRulesLayout, CodingRulesRouter, CodingRulesHeaderView, CodingRulesActionsView, CodingRulesFilterBarView, CodingRulesListView, BaseFilters, ChoiceFilters, StringFilterView, QualityProfileFilterView, InheritanceFilterView) {
     var App, appXHR;
     jQuery.ajaxSetup({
       error: function(jqXHR) {
@@ -75,7 +75,6 @@
       }
       this.storeQuery(query, this.codingRules.sorting);
       this.layout.showSpinner('resultsRegion');
-      this.layout.showSpinner('facetsRegion');
       return jQuery.ajax({
         url: "" + baseUrl + "/api/codingrules/search",
         data: fetchQuery
     App.addInitializer(function() {
       this.filters = new BaseFilters.Filters;
       this.filters.add(new BaseFilters.Filter({
-        name: t('coding_rules.filters.name_key'),
-        property: 'searchtext',
+        name: t('coding_rules.filters.name'),
+        property: 'name',
         type: StringFilterView,
         enabled: true,
         optional: false
       }));
+      this.filters.add(new BaseFilters.Filter({
+        name: t('coding_rules.filters.key'),
+        property: 'key',
+        type: StringFilterView,
+        enabled: true,
+        optional: false
+      }));
+      this.filters.add(new BaseFilters.Filter({
+        name: t('coding_rules.filters.description'),
+        property: 'description',
+        type: StringFilterView,
+        enabled: true,
+        optional: false
+      }));
+      this.filters.add(new BaseFilters.Filter({
+        name: t('coding_rules.filters.language'),
+        property: 'languages',
+        type: ChoiceFilters.ChoiceFilterView,
+        enabled: true,
+        optional: false,
+        choices: this.languages
+      }));
       this.filters.add(new BaseFilters.Filter({
         name: t('coding_rules.filters.repository'),
         property: 'repositories',
         type: ChoiceFilters.ChoiceFilterView,
         enabled: true,
         optional: false,
-        choices: {
-          'checkstyle': 'Checkstyle',
-          'common-java': 'Common SonarQube',
-          'findbugs': 'FindBugs',
-          'pmd': 'PMD',
-          'pmd-unit-tests': 'PMD Unit Tests',
-          'squid': 'SonarQube'
-        }
+        choices: this.repositories
       }));
       this.filters.add(new BaseFilters.Filter({
         name: t('coding_rules.filters.severity'),
         type: ChoiceFilters.ChoiceFilterView,
         enabled: true,
         optional: false,
-        choices: {
-          'BETA': 'Beta',
-          'DEPRECATED': 'Deprecated',
-          'READY': 'Ready'
-        }
+        choices: this.statuses
       }));
       this.filters.add(new BaseFilters.Filter({
         name: t('coding_rules.filters.tag'),
         type: ChoiceFilters.ChoiceFilterView,
         enabled: true,
         optional: false,
-        choices: {
-          'brain-overload': 'brain-overload',
-          'bug': 'bug',
-          'comment': 'comment',
-          'convention': 'convention',
-          'error-handling': 'error-handling',
-          'formatting': 'formatting',
-          'java8': 'java8',
-          'multithreading': 'multithreading',
-          'naming': 'naming',
-          'pitfall': 'pitfall',
-          'security': 'security',
-          'size': 'size',
-          'unused': 'unused',
-          'unused-code': 'unused-code'
-        }
+        choices: this.tags
       }));
       this.activeInFilter = new BaseFilters.Filter({
-        name: t('coding_rules.filters.active_in'),
-        property: 'active_in',
+        name: t('coding_rules.filters.in_quality_profile'),
+        property: 'in_quality_profile',
         type: QualityProfileFilterView,
-        single: true,
+        multiple: false,
         enabled: true,
         optional: false
       });
       this.filters.add(this.activeInFilter);
       this.inactiveInFilter = new BaseFilters.Filter({
-        name: t('coding_rules.filters.inactive_in'),
-        property: 'inactive_in',
+        name: t('coding_rules.filters.out_of_quality_profile'),
+        property: 'out_of_quality_profile',
         type: QualityProfileFilterView,
-        single: true,
+        multiple: false,
         enabled: true,
         optional: false
       });
       this.filters.add(this.inactiveInFilter);
+      this.filters.add(new BaseFilters.Filter({
+        name: t('coding_rules.filters.inheritance'),
+        property: 'inheritance',
+        type: InheritanceFilterView,
+        enabled: true,
+        optional: false,
+        qualityProfileFilter: this.activeInFilter,
+        choices: {
+          'option1': 'Option 1',
+          'option2': 'Option 2'
+        }
+      }));
       this.filterBarView = new CodingRulesFilterBarView({
         app: this,
         collection: this.filters,
       App.appState = new Backbone.Model;
       App.state = new Backbone.Model;
       App.qualityProfiles = r.qualityprofiles;
+      App.languages = r.languages;
+      App.repositories = r.repositories;
+      App.statuses = r.statuses;
+      App.tags = r.tags;
       window.messages = r.messages;
       jQuery('#coding-rules-page-loader').remove();
       return App.start();
index 1423e37bdb0f4485209b7b0570c442c4da2bf78e..d4b84723bff15e30b01698ce67f20a60fab5834d 100644 (file)
@@ -12,8 +12,38 @@ define ['jquery.mockjax'], ->
         { name: 'Sonar Way', lang: 'JavaScript' }
         { name: 'Quality Profile 1', lang: 'Java' }
       ]
+      languages:
+        java: 'Java'
+        javascript: 'JavaScript'
+      repositories:
+        'checkstyle': 'Checkstyle'
+        'common-java': 'Common SonarQube'
+        'findbugs': 'FindBugs'
+        'pmd': 'PMD'
+        'pmd-unit-tests': 'PMD Unit Tests'
+        'squid': 'SonarQube'
+      statuses:
+        'BETA': 'Beta'
+        'DEPRECATED': 'Deprecated'
+        'READY': 'Ready'
+      tags:
+        'brain-overload': 'brain-overload'
+        'bug': 'bug'
+        'comment': 'comment'
+        'convention': 'convention'
+        'error-handling': 'error-handling'
+        'formatting': 'formatting'
+        'java8': 'java8'
+        'multithreading': 'multithreading'
+        'naming': 'naming'
+        'pitfall': 'pitfall'
+        'security': 'security'
+        'size': 'size'
+        'unused': 'unused'
+        'unused-code': 'unused-code'
       messages:
         'all': 'All'
+        'any': 'Any'
         'bulk_change': 'Bulk Change'
         'moreCriteria': '+ More Criteria'
         'search_verb': 'Search'
@@ -33,9 +63,14 @@ define ['jquery.mockjax'], ->
         'coding_rules.activate_quality_profile': 'Activate Quality Profile'
         'coding_rules.deactivate_quality_profile': 'Deactivate'
 
-        'coding_rules.filters.active_in': 'Active In'
-        'coding_rules.filters.inactive_in': 'Inactive In'
-        'coding_rules.filters.name_key': 'Name/Key'
+        'coding_rules.filters.description': 'Description'
+        'coding_rules.filters.in_quality_profile': 'In Quality Profile'
+        'coding_rules.filters.inheritance': 'Inheritance'
+        'coding_rules.filters.inheritance.inactive': 'Inheritance criteria is available when a quality profile is selected'
+        'coding_rules.filters.key': 'Key'
+        'coding_rules.filters.language': 'Language'
+        'coding_rules.filters.name': 'Name'
+        'coding_rules.filters.out_of_quality_profile': 'Out of Quality Profile'
         'coding_rules.filters.repository': 'Repository'
         'coding_rules.filters.severity': 'Severity'
         'coding_rules.filters.status': 'Status'
index ad63ef15be6cc40e62a76de8fae774d7379ff1e3..0c3bdddef30e854f8da4e6437727671704452e43 100644 (file)
             lang: 'Java'
           }
         ],
+        languages: {
+          java: 'Java',
+          javascript: 'JavaScript'
+        },
+        repositories: {
+          'checkstyle': 'Checkstyle',
+          'common-java': 'Common SonarQube',
+          'findbugs': 'FindBugs',
+          'pmd': 'PMD',
+          'pmd-unit-tests': 'PMD Unit Tests',
+          'squid': 'SonarQube'
+        },
+        statuses: {
+          'BETA': 'Beta',
+          'DEPRECATED': 'Deprecated',
+          'READY': 'Ready'
+        },
+        tags: {
+          'brain-overload': 'brain-overload',
+          'bug': 'bug',
+          'comment': 'comment',
+          'convention': 'convention',
+          'error-handling': 'error-handling',
+          'formatting': 'formatting',
+          'java8': 'java8',
+          'multithreading': 'multithreading',
+          'naming': 'naming',
+          'pitfall': 'pitfall',
+          'security': 'security',
+          'size': 'size',
+          'unused': 'unused',
+          'unused-code': 'unused-code'
+        },
         messages: {
           'all': 'All',
+          'any': 'Any',
           'bulk_change': 'Bulk Change',
           'moreCriteria': '+ More Criteria',
           'search_verb': 'Search',
           'coding_rules.quality_profiles': 'Quality Profiles',
           'coding_rules.activate_quality_profile': 'Activate Quality Profile',
           'coding_rules.deactivate_quality_profile': 'Deactivate',
-          'coding_rules.filters.active_in': 'Active In',
-          'coding_rules.filters.inactive_in': 'Inactive In',
-          'coding_rules.filters.name_key': 'Name/Key',
+          'coding_rules.filters.description': 'Description',
+          'coding_rules.filters.in_quality_profile': 'In Quality Profile',
+          'coding_rules.filters.inheritance': 'Inheritance',
+          'coding_rules.filters.inheritance.inactive': 'Inheritance criteria is available when a quality profile is selected',
+          'coding_rules.filters.key': 'Key',
+          'coding_rules.filters.language': 'Language',
+          'coding_rules.filters.name': 'Name',
+          'coding_rules.filters.out_of_quality_profile': 'Out of Quality Profile',
           'coding_rules.filters.repository': 'Repository',
           'coding_rules.filters.severity': 'Severity',
           'coding_rules.filters.status': 'Status',
index f6b7cf4b745cc607fb64e89b1b33c68e634cffd0..8b662446a99dc4406157179811fbb09437932cba 100644 (file)
@@ -44,16 +44,17 @@ define [
 
 
     changeEnabled: ->
-      disabledFilters = _.reject @collection.where(enabled: false), (filter) ->
-        filter.get('type') == MoreCriteriaFilters.MoreCriteriaFilterView
+      if @moreCriteriaFilter?
+        disabledFilters = _.reject @collection.where(enabled: false), (filter) ->
+          filter.get('type') == MoreCriteriaFilters.MoreCriteriaFilterView
 
-      if disabledFilters.length == 0
-        @moreCriteriaFilter.set { enabled: false }, { silent: true }
-      else
-        @moreCriteriaFilter.set { enabled: true }, { silent: true }
+        if disabledFilters.length == 0
+          @moreCriteriaFilter.set { enabled: false }, { silent: true }
+        else
+          @moreCriteriaFilter.set { enabled: true }, { silent: true }
 
-      @moreCriteriaFilter.set { filters: disabledFilters }, { silent: true }
-      @moreCriteriaFilter.trigger 'change:filters'
+        @moreCriteriaFilter.set { filters: disabledFilters }, { silent: true }
+        @moreCriteriaFilter.trigger 'change:filters'
 
 
     search: ->
index 475ac88981f9ed02eeb0292a86e0df6ea423547f..0fda961f1fc7801176956c5e0253064398de8245 100644 (file)
 
       CodingRulesFilterBarView.prototype.changeEnabled = function() {
         var disabledFilters;
-        disabledFilters = _.reject(this.collection.where({
-          enabled: false
-        }), function(filter) {
-          return filter.get('type') === MoreCriteriaFilters.MoreCriteriaFilterView;
-        });
-        if (disabledFilters.length === 0) {
-          this.moreCriteriaFilter.set({
+        if (this.moreCriteriaFilter != null) {
+          disabledFilters = _.reject(this.collection.where({
             enabled: false
-          }, {
-            silent: true
+          }), function(filter) {
+            return filter.get('type') === MoreCriteriaFilters.MoreCriteriaFilterView;
           });
-        } else {
+          if (disabledFilters.length === 0) {
+            this.moreCriteriaFilter.set({
+              enabled: false
+            }, {
+              silent: true
+            });
+          } else {
+            this.moreCriteriaFilter.set({
+              enabled: true
+            }, {
+              silent: true
+            });
+          }
           this.moreCriteriaFilter.set({
-            enabled: true
+            filters: disabledFilters
           }, {
             silent: true
           });
+          return this.moreCriteriaFilter.trigger('change:filters');
         }
-        this.moreCriteriaFilter.set({
-          filters: disabledFilters
-        }, {
-          silent: true
-        });
-        return this.moreCriteriaFilter.trigger('change:filters');
       };
 
       CodingRulesFilterBarView.prototype.search = function() {
diff --git a/sonar-server/src/main/webapp/javascripts/coding-rules/views/filters/inheritance-filter-view.coffee b/sonar-server/src/main/webapp/javascripts/coding-rules/views/filters/inheritance-filter-view.coffee
new file mode 100644 (file)
index 0000000..20dbbc9
--- /dev/null
@@ -0,0 +1,49 @@
+define [
+  'navigator/filters/choice-filters'
+], (
+  ChoiceFilters
+) ->
+
+  class InheritanceFilterView extends ChoiceFilters.ChoiceFilterView
+
+    initialize: ->
+      super
+      @qualityProfileFilter = @model.get 'qualityProfileFilter'
+      @listenTo @qualityProfileFilter, 'change:value', @onChangeQualityProfile
+      @onChangeQualityProfile()
+
+
+    onChangeQualityProfile: ->
+      qualityProfile = @qualityProfileFilter.get 'value'
+      if _.isArray(qualityProfile) && qualityProfile.length == 1
+        @makeActive()
+      else
+        @makeInactive()
+
+
+    makeActive: ->
+      @model.set inactive: false, title: ''
+      @model.trigger 'change:enabled'
+      @$el.removeClass('navigator-filter-inactive').prop 'title', ''
+
+
+    makeInactive: ->
+      @model.set inactive: true, title: t 'coding_rules.filters.inheritance.inactive'
+      @model.trigger 'change:enabled'
+      @choices.each (model) -> model.set 'checked', false
+      @detailsView.updateLists()
+      @detailsView.updateValue()
+      @$el.addClass('navigator-filter-inactive').prop 'title', t 'coding_rules.filters.inheritance.inactive'
+
+
+    showDetails: ->
+      super unless @$el.is '.navigator-filter-inactive'
+
+
+    restore: (value) ->
+      value = value.split(',') if _.isString(value)
+      if @choices && value.length > 0
+        @model.set value: value, enabled: true
+        @onChangeQualityProfile
+      else
+        @clear()