]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5820/SONAR-5987 Ability to filter rules that are active in a quality profile
authorStas Vilchik <vilchiks@gmail.com>
Thu, 22 Jan 2015 13:07:13 +0000 (14:07 +0100)
committerStas Vilchik <vilchiks@gmail.com>
Thu, 22 Jan 2015 13:07:20 +0000 (14:07 +0100)
server/sonar-web/src/main/hbs/coding-rules/coding-rules-workspace-list-item.hbs
server/sonar-web/src/main/hbs/coding-rules/rule/coding-rules-profile-activation.hbs
server/sonar-web/src/main/js/coding-rules/controller.js
server/sonar-web/src/main/js/coding-rules/models/rules.js
server/sonar-web/src/main/js/coding-rules/rule/profile-activation-view.js
server/sonar-web/src/main/js/coding-rules/rule/rule-profile-view.js
server/sonar-web/src/main/js/coding-rules/rule/rule-profiles-view.js
server/sonar-web/src/main/js/coding-rules/workspace-list-item-view.js

index 92087c04044c87637d502acbb98a5e2e9fe4bd7c..7db42af39193239f17cc1bab15177b544a13f3f8 100644 (file)
@@ -1,19 +1,17 @@
 <table class="coding-rule-table">
   <tr>
-    {{#if activeProfile}}
-      {{#if activeProfile.severity}}
-        <td class="coding-rule-table-meta-cell coding-rule-activation">
-          {{severityIcon activeProfile.severity}}
-          {{#eq activeProfile.inherit 'OVERRIDES'}}
-            <i class="icon-inheritance"
-               title="{{tp 'coding_rules.overrides' activeProfile.name activeProfile.parentProfile.name}}"></i>
-          {{/eq}}
-          {{#eq activeProfile.inherit 'INHERITED'}}
-            <i class="icon-inheritance"
-               title="{{tp 'coding_rules.inherits' activeProfile.name activeProfile.parentProfile.name}}"></i>
-          {{/eq}}
-        </td>
-      {{/if}}
+    {{#if activation}}
+      <td class="coding-rule-table-meta-cell coding-rule-activation">
+        {{severityIcon activation.severity}}
+        {{#eq activation.inherit 'OVERRIDES'}}
+          <i class="icon-inheritance"
+             title="{{tp 'coding_rules.overrides' activation.profile.name activation.parentProfile.name}}"></i>
+        {{/eq}}
+        {{#eq activation.inherit 'INHERITED'}}
+          <i class="icon-inheritance"
+             title="{{tp 'coding_rules.inherits' activation.profile.name activation.parentProfile.name}}"></i>
+        {{/eq}}
+      </td>
     {{/if}}
 
     <td>
       </div>
     </td>
 
-    {{#if activeProfile}}
+    {{#any activation selectedProfile}}
       {{#if canWrite}}
         <td class="coding-rule-table-meta-cell coding-rule-activation-actions">
           <div class="button-group">
-            {{#if activeProfile.severity}}
-              {{#eq activeProfile.inherit 'NONE'}}
+            {{#if activation}}
+              {{#eq activation.inherit 'NONE'}}
                 <button class="coding-rules-detail-quality-profile-deactivate button-red">
                   {{t 'coding_rules.deactivate'}}
                 </button>
               {{/eq}}
             {{else}}
-              <button class="coding-rules-detail-quality-profile-activate">
-                {{t 'coding_rules.activate'}}
-              </button>
+              {{#unless isTemplate}}
+                <button class="coding-rules-detail-quality-profile-activate">{{t 'coding_rules.activate'}}</button>
+              {{/unless}}
             {{/if}}
           </div>
         </td>
       {{/if}}
-    {{/if}}
+    {{/any}}
   </tr>
 </table>
index 36f422a6710875ed88b8ef4483078655c355ab78..a13691e57051e382571f6660e3bff762c08bc371 100644 (file)
@@ -1,3 +1,5 @@
+{{log this}}
+
 <form>
   <div class="modal-head">
     {{#if change}}
@@ -20,7 +22,7 @@
       <tr class="property">
         <th><h3>{{t 'coding_rules.quality_profile'}}</h3></th>
         <td>
-          {{#if key}}
+          {{#any key qProfile}}
             {{name}}
           {{else}}
             <select id="coding-rules-quality-profile-activation-select">
@@ -28,7 +30,7 @@
                 <option value="{{key}}">{{name}}</option>
               {{/each}}
             </select>
-          {{/if}}
+          {{/any}}
         </td>
       </tr>
       <tr class="property">
index f00691c679d33907b8737606e1fa88b53df9c695..4d512eaeef927aa2698fb6331cfe28b615f8921d 100644 (file)
@@ -20,6 +20,7 @@ define([
       if (profile != null) {
         fields.push('actives');
         fields.push('params');
+        fields.push('isTemplate');
       }
       return {
         p: this.app.state.get('page'),
index 60bb4d7e48f3569736792533c381a187cef01d9c..6c282ee0e4882d3ad82a4e319394dcc2ae42aa5d 100644 (file)
@@ -7,18 +7,21 @@ define([
 
     parseRules: function (r) {
       var rules = r.rules,
-          profileBases = r.qProfiles || [];
+          profiles = r.qProfiles || [];
 
       if (r.actives != null) {
         rules = rules.map(function (rule) {
-          var profiles = (r.actives[rule.key] || []).map(function (profile) {
-            _.extend(profile, profileBases[profile.qProfile]);
-            if (profile.parent != null) {
-              _.extend(profile, { parentProfile: profileBases[profile.parent] });
+          var activations = (r.actives[rule.key] || []).map(function (activation) {
+            var profile = profiles[activation.qProfile];
+            if (profile != null) {
+              _.extend(activation, { profile: profile });
+              if (profile.parent != null) {
+                _.extend(activation, { parentProfile: profiles[profile.parent] });
+              }
             }
-            return profile;
+            return activation;
           });
-          return _.extend(rule, { activeProfile: profiles.length > 0 ? profiles[0] : null });
+          return _.extend(rule, { activation: activations.length > 0 ? activations[0] : null });
         });
       }
       return rules;
index f83b0341a9a7fa94056c7d219fce831b5bf534a3..1edcf56028e7e1e4ecc984a8347a6914a469ef14 100644 (file)
@@ -83,14 +83,10 @@ define([
           params: paramsHash
         }
       }).done(function () {
-        if (that.options.fromList) {
-          that.options.rule.set({ activeProfile: { qProfile: profileKey, inherit: 'NONE', severity: severity } });
-        } else {
-          that.options.app.controller.showDetails(that.options.rule);
-        }
+        that.trigger('profileActivated', severity, params);
         window.process.finishBackgroundProcess(p);
       }).fail(function () {
-        that.options.app.controller.showDetails(that.options.rule);
+        that.trigger('profileActivationFailed');
         window.process.failBackgroundProcess(p);
       });
     },
index 37f1cbcdf535def5cd4f49a6400379c4c9f17d9d..4ce97d6a9270757754f261da531dcb73a5912885 100644 (file)
@@ -30,12 +30,17 @@ define([
     },
 
     change: function () {
-      new ProfileActivationView({
-        model: this.model,
-        collection: this.model.collection,
-        rule: this.options.rule,
-        app: this.options.app
-      }).render();
+      var that = this,
+          activationView = new ProfileActivationView({
+            model: this.model,
+            collection: this.model.collection,
+            rule: this.options.rule,
+            app: this.options.app
+          });
+      activationView.on('profileActivated', function () {
+        that.options.app.controller.showDetails(that.options.rule);
+      });
+      activationView.render();
     },
 
     revert: function () {
index bead27c9bedd158af1324bfa0617237c296b5b3d..b903b130ea4574a9b3205c09763c5d0857cb68a5 100644 (file)
@@ -41,11 +41,16 @@ define([
     },
 
     activate: function () {
-      new ProfileActivationView({
-        rule: this.model,
-        collection: this.collection,
-        app: this.options.app
-      }).render();
+      var that = this,
+          activationView = new ProfileActivationView({
+            rule: this.model,
+            collection: this.collection,
+            app: this.options.app
+          });
+      activationView.on('profileActivated', function () {
+        that.options.app.controller.showDetails(that.model);
+      });
+      activationView.render();
     },
 
     serializeData: function () {
index 8a8dc8e2c57043a4f9065f1c7da741fc09ffd48a..19810a6e5a5bf305af3addd81da019155b95904d 100644 (file)
@@ -16,6 +16,8 @@ define([
       'click': 'selectCurrent',
       'click .js-rule': 'openRule',
       'click .coding-rules-detail-quality-profile-activate': 'activate',
+      'click .coding-rules-detail-quality-profile-change': 'change',
+      'click .coding-rules-detail-quality-profile-revert': 'revert',
       'click .coding-rules-detail-quality-profile-deactivate': 'deactivate'
     },
 
@@ -27,28 +29,31 @@ define([
       this.options.app.controller.showDetails(this.model);
     },
 
-    getActiveProfile: function () {
-      return this.model.get('activeProfile');
-    },
-
     activate: function () {
-      var activeProfile = this.options.app.state.get('query').qprofile,
+      var that = this,
+          selectedProfile = this.options.app.state.get('query').qprofile,
           othersQualityProfiles = _.reject(this.options.app.qualityProfiles, function (profile) {
-            return profile.key === activeProfile;
+            return profile.key === selectedProfile;
+          }),
+          activationView = new ProfileActivationView({
+            rule: this.model,
+            collection: new Backbone.Collection(othersQualityProfiles),
+            app: this.options.app
           });
-
-      new ProfileActivationView({
-        rule: this.model,
-        collection: new Backbone.Collection(othersQualityProfiles),
-        app: this.options.app,
-        fromList: true
-      }).render();
+      activationView.on('profileActivated', function (severity) {
+        var activation = {
+          severity: severity,
+          inherit: 'NONE'
+        };
+        that.model.set({ activation: activation });
+      });
+      activationView.render();
     },
 
     deactivate: function () {
       var that = this,
           ruleKey = this.model.get('key'),
-          myProfile = this.model.get('activeProfile');
+          activation = this.model.get('activation');
       window.confirmDialog({
         title: t('coding_rules.deactivate'),
         html: tp('coding_rules.deactivate.confirm'),
@@ -58,28 +63,22 @@ define([
             type: 'POST',
             url: baseUrl + '/api/qualityprofiles/deactivate_rule',
             data: {
-              profile_key: myProfile.qProfile,
+              profile_key: activation.qProfile,
               rule_key: ruleKey
             }
           }).done(function () {
             window.process.finishBackgroundProcess(p);
-            var newProfile = _.extend({}, myProfile, { severity: undefined });
-            that.model.set({ activeProfile: newProfile });
+            that.model.unset('activation');
           });
         }
       });
     },
 
     serializeData: function () {
-      var activeProfile = this.getActiveProfile(),
-          selectedProfile = this.options.app.state.get('query').qprofile;
-      if (selectedProfile != null && activeProfile == null) {
-        activeProfile = selectedProfile;
-      }
       return _.extend(WorkspaceListItemView.prototype.serializeData.apply(this, arguments), {
         tags: _.union(this.model.get('sysTags'), this.model.get('tags')),
         canWrite: this.options.app.canWrite,
-        activeProfile: activeProfile
+        selectedProfile: this.options.app.state.get('query').qprofile
       });
     }
   });