]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5007 Add inheritance and available since criteria
authorStas Vilchik <vilchiks@gmail.com>
Wed, 12 Mar 2014 11:56:08 +0000 (17:56 +0600)
committerStas Vilchik <vilchiks@gmail.com>
Wed, 12 Mar 2014 11:56:21 +0000 (17:56 +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/filters/inheritance-filter-view.coffee
sonar-server/src/main/webapp/javascripts/coding-rules/views/filters/inheritance-filter-view.js [new file with mode: 0644]
sonar-server/src/main/webapp/javascripts/coding-rules/views/filters/quality-profile-filter-view.coffee
sonar-server/src/main/webapp/javascripts/coding-rules/views/filters/quality-profile-filter-view.js
sonar-server/src/main/webapp/javascripts/navigator/filters/base-filters.js
sonar-server/src/main/webapp/javascripts/navigator/filters/date-filter-view.coffee [new file with mode: 0644]
sonar-server/src/main/webapp/javascripts/navigator/filters/date-filter-view.js [new file with mode: 0644]

index 20400fb62ede0f0f12c57fd0e6b4a7313fb8a31e..0c57cc7fc9027e712667bcaa70a0be07b1ef93f2 100644 (file)
@@ -33,6 +33,7 @@ requirejs [
   'navigator/filters/base-filters',
   'navigator/filters/choice-filters',
   'navigator/filters/string-filters',
+  'navigator/filters/date-filter-view',
   'coding-rules/views/filters/quality-profile-filter-view',
   'coding-rules/views/filters/inheritance-filter-view',
 
@@ -53,6 +54,7 @@ requirejs [
   BaseFilters,
   ChoiceFilters,
   StringFilterView,
+  DateFilterView,
   QualityProfileFilterView,
   InheritanceFilterView
 ) ->
@@ -174,45 +176,17 @@ requirejs [
       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: @repositories
-
     @filters.add new BaseFilters.Filter
       name: t 'coding_rules.filters.severity'
       property: 'severities'
       type: ChoiceFilters.ChoiceFilterView
-      enabled: true
-      optional: false
       choices:
         'BLOCKER': t 'severity.BLOCKER'
         'CRITICAL': t 'severity.CRITICAL'
@@ -226,20 +200,10 @@ requirejs [
         'MINOR': 'severity-minor'
         'INFO': 'severity-info'
 
-    @filters.add new BaseFilters.Filter
-      name: t 'coding_rules.filters.status'
-      property: 'statuses'
-      type: ChoiceFilters.ChoiceFilterView
-      enabled: true
-      optional: false
-      choices: @statuses
-
     @filters.add new BaseFilters.Filter
       name: t 'coding_rules.filters.tag'
       property: 'tags'
       type: ChoiceFilters.ChoiceFilterView
-      enabled: true
-      optional: false
       choices: @tags
 
     @activeInFilter = new BaseFilters.Filter
@@ -247,29 +211,68 @@ requirejs [
       property: 'in_quality_profile'
       type: QualityProfileFilterView
       multiple: false
-      enabled: true
-      optional: false
     @filters.add @activeInFilter
 
+
+    @filters.add new BaseFilters.Filter
+      name: t 'coding_rules.filters.key'
+      property: 'key'
+      type: StringFilterView
+      enabled: false
+      optional: true
+
+    @filters.add new BaseFilters.Filter
+      name: t 'coding_rules.filters.description'
+      property: 'description'
+      type: StringFilterView
+      enabled: false
+      optional: true
+
+    @filters.add new BaseFilters.Filter
+      name: t 'coding_rules.filters.repository'
+      property: 'repositories'
+      type: ChoiceFilters.ChoiceFilterView
+      enabled: false
+      optional: true
+      choices: @repositories
+
+    @filters.add new BaseFilters.Filter
+      name: t 'coding_rules.filters.status'
+      property: 'statuses'
+      type: ChoiceFilters.ChoiceFilterView
+      enabled: false
+      optional: true
+      choices: @statuses
+
+    @filters.add new BaseFilters.Filter
+      name: t 'coding_rules.filters.availableSince'
+      property: 'availableSince'
+      type: DateFilterView
+      enabled: false
+      optional: true
+
     @inactiveInFilter = new BaseFilters.Filter
       name: t 'coding_rules.filters.out_of_quality_profile'
       property: 'out_of_quality_profile'
       type: QualityProfileFilterView
       multiple: false
-      enabled: true
-      optional: false
+      enabled: false
+      optional: true
     @filters.add @inactiveInFilter
 
     @filters.add new BaseFilters.Filter
       name: t 'coding_rules.filters.inheritance'
       property: 'inheritance'
       type: InheritanceFilterView
-      enabled: true
-      optional: false
+      enabled: false
+      optional: true
+      multiple: false
       qualityProfileFilter: @activeInFilter
       choices:
-        'option1': 'Option 1'
-        'option2': 'Option 2'
+        'any': t 'coding_rules.filters.inheritance.any'
+        'not_inhertited': t 'coding_rules.filters.inheritance.not_inherited'
+        'inhertited': t 'coding_rules.filters.inheritance.inherited'
+        'overriden': t 'coding_rules.filters.inheritance.overriden'
 
     @filterBarView = new CodingRulesFilterBarView
       app: @
index 88547929dd1e2b2407659150f998a12c34c8ea9d..d24f093b7166bf14e6d130f7f1727f4a08f557d4 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/views/filters/inheritance-filter-view', 'coding-rules/mockjax'], function(Backbone, Marionette, CodingRulesLayout, CodingRulesRouter, CodingRulesHeaderView, CodingRulesActionsView, CodingRulesFilterBarView, CodingRulesListView, BaseFilters, ChoiceFilters, StringFilterView, QualityProfileFilterView, InheritanceFilterView) {
+  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', 'navigator/filters/date-filter-view', '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, DateFilterView, QualityProfileFilterView, InheritanceFilterView) {
     var App, appXHR;
     jQuery.ajaxSetup({
       error: function(jqXHR) {
       this.filters.add(new BaseFilters.Filter({
         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
+        type: StringFilterView
       }));
       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: this.repositories
-      }));
       this.filters.add(new BaseFilters.Filter({
         name: t('coding_rules.filters.severity'),
         property: 'severities',
         type: ChoiceFilters.ChoiceFilterView,
-        enabled: true,
-        optional: false,
         choices: {
           'BLOCKER': t('severity.BLOCKER'),
           'CRITICAL': t('severity.CRITICAL'),
           'INFO': 'severity-info'
         }
       }));
-      this.filters.add(new BaseFilters.Filter({
-        name: t('coding_rules.filters.status'),
-        property: 'statuses',
-        type: ChoiceFilters.ChoiceFilterView,
-        enabled: true,
-        optional: false,
-        choices: this.statuses
-      }));
       this.filters.add(new BaseFilters.Filter({
         name: t('coding_rules.filters.tag'),
         property: 'tags',
         type: ChoiceFilters.ChoiceFilterView,
-        enabled: true,
-        optional: false,
         choices: this.tags
       }));
       this.activeInFilter = new BaseFilters.Filter({
         name: t('coding_rules.filters.in_quality_profile'),
         property: 'in_quality_profile',
         type: QualityProfileFilterView,
-        multiple: false,
-        enabled: true,
-        optional: false
+        multiple: false
       });
       this.filters.add(this.activeInFilter);
+      this.filters.add(new BaseFilters.Filter({
+        name: t('coding_rules.filters.key'),
+        property: 'key',
+        type: StringFilterView,
+        enabled: false,
+        optional: true
+      }));
+      this.filters.add(new BaseFilters.Filter({
+        name: t('coding_rules.filters.description'),
+        property: 'description',
+        type: StringFilterView,
+        enabled: false,
+        optional: true
+      }));
+      this.filters.add(new BaseFilters.Filter({
+        name: t('coding_rules.filters.repository'),
+        property: 'repositories',
+        type: ChoiceFilters.ChoiceFilterView,
+        enabled: false,
+        optional: true,
+        choices: this.repositories
+      }));
+      this.filters.add(new BaseFilters.Filter({
+        name: t('coding_rules.filters.status'),
+        property: 'statuses',
+        type: ChoiceFilters.ChoiceFilterView,
+        enabled: false,
+        optional: true,
+        choices: this.statuses
+      }));
+      this.filters.add(new BaseFilters.Filter({
+        name: t('coding_rules.filters.availableSince'),
+        property: 'availableSince',
+        type: DateFilterView,
+        enabled: false,
+        optional: true
+      }));
       this.inactiveInFilter = new BaseFilters.Filter({
         name: t('coding_rules.filters.out_of_quality_profile'),
         property: 'out_of_quality_profile',
         type: QualityProfileFilterView,
         multiple: false,
-        enabled: true,
-        optional: false
+        enabled: false,
+        optional: true
       });
       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,
+        enabled: false,
+        optional: true,
+        multiple: false,
         qualityProfileFilter: this.activeInFilter,
         choices: {
-          'option1': 'Option 1',
-          'option2': 'Option 2'
+          'any': t('coding_rules.filters.inheritance.any'),
+          'not_inhertited': t('coding_rules.filters.inheritance.not_inherited'),
+          'inhertited': t('coding_rules.filters.inheritance.inherited'),
+          'overriden': t('coding_rules.filters.inheritance.overriden')
         }
       }));
       this.filterBarView = new CodingRulesFilterBarView({
index d4b84723bff15e30b01698ce67f20a60fab5834d..7f1533dc29ce60288b24fe2cfc05ea98affc8620 100644 (file)
@@ -63,10 +63,15 @@ define ['jquery.mockjax'], ->
         'coding_rules.activate_quality_profile': 'Activate Quality Profile'
         'coding_rules.deactivate_quality_profile': 'Deactivate'
 
+        'coding_rules.filters.availableSince': 'Available Since'
         '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.inheritance.inactive': 'Inheritance criteria is available when an inherited quality profile is selected'
+        'coding_rules.filters.inheritance.any': 'Any'
+        'coding_rules.filters.inheritance.not_inherited': 'Not Inherited'
+        'coding_rules.filters.inheritance.inherited': 'Inherited'
+        'coding_rules.filters.inheritance.overriden': 'Overriden'
         'coding_rules.filters.key': 'Key'
         'coding_rules.filters.language': 'Language'
         'coding_rules.filters.name': 'Name'
@@ -174,9 +179,9 @@ define ['jquery.mockjax'], ->
     responseText: JSON.stringify
       more: false
       results: [
-        { id: 'sonarway', text: 'Sonar Way' },
-        { id: 'qp1', text: 'Quality Profile 1' },
-        { id: 'qp2', text: 'Quality Profile 2' },
-        { id: 'qp3', text: 'Quality Profile 3' },
+        { id: 'sonarway', text: 'Sonar Way', parent: null },
+        { id: 'qp1', text: 'Quality Profile 1', parent: 'sonarway' },
+        { id: 'qp2', text: 'Quality Profile 2', parent: 'sonarway' },
+        { id: 'qp3', text: 'Quality Profile 3', parent: null },
       ]
 
index 0c3bdddef30e854f8da4e6437727671704452e43..c0b195ad61c36554fbae135abc72eb70e425d695 100644 (file)
           'coding_rules.quality_profiles': 'Quality Profiles',
           'coding_rules.activate_quality_profile': 'Activate Quality Profile',
           'coding_rules.deactivate_quality_profile': 'Deactivate',
+          'coding_rules.filters.availableSince': 'Available Since',
           '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.inheritance.inactive': 'Inheritance criteria is available when an inherited quality profile is selected',
+          'coding_rules.filters.inheritance.any': 'Any',
+          'coding_rules.filters.inheritance.not_inherited': 'Not Inherited',
+          'coding_rules.filters.inheritance.inherited': 'Inherited',
+          'coding_rules.filters.inheritance.overriden': 'Overriden',
           'coding_rules.filters.key': 'Key',
           'coding_rules.filters.language': 'Language',
           'coding_rules.filters.name': 'Name',
         results: [
           {
             id: 'sonarway',
-            text: 'Sonar Way'
+            text: 'Sonar Way',
+            parent: null
           }, {
             id: 'qp1',
-            text: 'Quality Profile 1'
+            text: 'Quality Profile 1',
+            parent: 'sonarway'
           }, {
             id: 'qp2',
-            text: 'Quality Profile 2'
+            text: 'Quality Profile 2',
+            parent: 'sonarway'
           }, {
             id: 'qp3',
-            text: 'Quality Profile 3'
+            text: 'Quality Profile 3',
+            parent: null
           }
         ]
       })
index 20dbbc9155a33f6643287bac141d9b50d4e542f3..ef4bb6454d061d3390d1813266e0df8d02f695e0 100644 (file)
@@ -15,7 +15,8 @@ define [
 
     onChangeQualityProfile: ->
       qualityProfile = @qualityProfileFilter.get 'value'
-      if _.isArray(qualityProfile) && qualityProfile.length == 1
+      parentQualityProfile = @qualityProfileFilter.get 'parentQualityProfile'
+      if _.isArray(qualityProfile) && qualityProfile.length == 1 && parentQualityProfile
         @makeActive()
       else
         @makeInactive()
diff --git a/sonar-server/src/main/webapp/javascripts/coding-rules/views/filters/inheritance-filter-view.js b/sonar-server/src/main/webapp/javascripts/coding-rules/views/filters/inheritance-filter-view.js
new file mode 100644 (file)
index 0000000..d780ef3
--- /dev/null
@@ -0,0 +1,83 @@
+// Generated by CoffeeScript 1.6.3
+(function() {
+  var __hasProp = {}.hasOwnProperty,
+    __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
+
+  define(['navigator/filters/choice-filters'], function(ChoiceFilters) {
+    var InheritanceFilterView, _ref;
+    return InheritanceFilterView = (function(_super) {
+      __extends(InheritanceFilterView, _super);
+
+      function InheritanceFilterView() {
+        _ref = InheritanceFilterView.__super__.constructor.apply(this, arguments);
+        return _ref;
+      }
+
+      InheritanceFilterView.prototype.initialize = function() {
+        InheritanceFilterView.__super__.initialize.apply(this, arguments);
+        this.qualityProfileFilter = this.model.get('qualityProfileFilter');
+        this.listenTo(this.qualityProfileFilter, 'change:value', this.onChangeQualityProfile);
+        return this.onChangeQualityProfile();
+      };
+
+      InheritanceFilterView.prototype.onChangeQualityProfile = function() {
+        var parentQualityProfile, qualityProfile;
+        qualityProfile = this.qualityProfileFilter.get('value');
+        parentQualityProfile = this.qualityProfileFilter.get('parentQualityProfile');
+        if (_.isArray(qualityProfile) && qualityProfile.length === 1 && parentQualityProfile) {
+          return this.makeActive();
+        } else {
+          return this.makeInactive();
+        }
+      };
+
+      InheritanceFilterView.prototype.makeActive = function() {
+        this.model.set({
+          inactive: false,
+          title: ''
+        });
+        this.model.trigger('change:enabled');
+        return this.$el.removeClass('navigator-filter-inactive').prop('title', '');
+      };
+
+      InheritanceFilterView.prototype.makeInactive = function() {
+        this.model.set({
+          inactive: true,
+          title: t('coding_rules.filters.inheritance.inactive')
+        });
+        this.model.trigger('change:enabled');
+        this.choices.each(function(model) {
+          return model.set('checked', false);
+        });
+        this.detailsView.updateLists();
+        this.detailsView.updateValue();
+        return this.$el.addClass('navigator-filter-inactive').prop('title', t('coding_rules.filters.inheritance.inactive'));
+      };
+
+      InheritanceFilterView.prototype.showDetails = function() {
+        if (!this.$el.is('.navigator-filter-inactive')) {
+          return InheritanceFilterView.__super__.showDetails.apply(this, arguments);
+        }
+      };
+
+      InheritanceFilterView.prototype.restore = function(value) {
+        if (_.isString(value)) {
+          value = value.split(',');
+        }
+        if (this.choices && value.length > 0) {
+          this.model.set({
+            value: value,
+            enabled: true
+          });
+          return this.onChangeQualityProfile;
+        } else {
+          return this.clear();
+        }
+      };
+
+      return InheritanceFilterView;
+
+    })(ChoiceFilters.ChoiceFilterView);
+  });
+
+}).call(this);
index 3561ff936ce6002e18115d7db1ddbfbea8041126..3e0503ff788dc60c9a1288a5374593d1e9623e12 100644 (file)
@@ -16,4 +16,13 @@ define [
     initialize: ->
       super
       @choices = new QualityProfileSuggestions
+      @listenTo @model, 'change:value', @updateParentQualityProfile
+
+
+    updateParentQualityProfile: ->
+      selected = @getSelected()
+      if selected.length == 1
+        @model.set 'parentQualityProfile', selected[0].get('parent')
+      else
+        @model.unset 'parentQualityProfile'
 
index a8ce1a54ef2c18371ce2e392a2c5f8f6613815bd..65d5574d9d96d618b0e0be92835168d43938fb35 100644 (file)
 
       QualityProfileFilterView.prototype.initialize = function() {
         QualityProfileFilterView.__super__.initialize.apply(this, arguments);
-        return this.choices = new QualityProfileSuggestions;
+        this.choices = new QualityProfileSuggestions;
+        return this.listenTo(this.model, 'change:value', this.updateParentQualityProfile);
+      };
+
+      QualityProfileFilterView.prototype.updateParentQualityProfile = function() {
+        var selected;
+        selected = this.getSelected();
+        if (selected.length === 1) {
+          return this.model.set('parentQualityProfile', selected[0].get('parent'));
+        } else {
+          return this.model.unset('parentQualityProfile');
+        }
       };
 
       return QualityProfileFilterView;
index 92e440d82b950828760d477a71e393fc03b11d97..e07a3517bfe6cc94cfe158e26e4f8fa9127e7c17 100644 (file)
@@ -3,6 +3,8 @@ define(['backbone', 'backbone.marionette', 'common/handlebars-extensions'], func
   var Filter = Backbone.Model.extend({
 
     defaults: {
+      enabled: true,
+      optional: false,
       multiple: true,
       placeholder: ''
     }
diff --git a/sonar-server/src/main/webapp/javascripts/navigator/filters/date-filter-view.coffee b/sonar-server/src/main/webapp/javascripts/navigator/filters/date-filter-view.coffee
new file mode 100644 (file)
index 0000000..da9fc81
--- /dev/null
@@ -0,0 +1,11 @@
+define [
+  'navigator/filters/string-filters'
+], (
+  StringFilterView
+) ->
+
+  class DateFilterView extends StringFilterView
+
+    render: ->
+      super
+      @detailsView.$('input').prop 'placeholder', '1970-01-31'
diff --git a/sonar-server/src/main/webapp/javascripts/navigator/filters/date-filter-view.js b/sonar-server/src/main/webapp/javascripts/navigator/filters/date-filter-view.js
new file mode 100644 (file)
index 0000000..83a7eff
--- /dev/null
@@ -0,0 +1,26 @@
+// Generated by CoffeeScript 1.6.3
+(function() {
+  var __hasProp = {}.hasOwnProperty,
+    __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
+
+  define(['navigator/filters/string-filters'], function(StringFilterView) {
+    var DateFilterView, _ref;
+    return DateFilterView = (function(_super) {
+      __extends(DateFilterView, _super);
+
+      function DateFilterView() {
+        _ref = DateFilterView.__super__.constructor.apply(this, arguments);
+        return _ref;
+      }
+
+      DateFilterView.prototype.render = function() {
+        DateFilterView.__super__.render.apply(this, arguments);
+        return this.detailsView.$('input').prop('placeholder', '1970-01-31');
+      };
+
+      return DateFilterView;
+
+    })(StringFilterView);
+  });
+
+}).call(this);