]> 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>
Wed, 21 Jan 2015 16:45:22 +0000 (17:45 +0100)
committerStas Vilchik <vilchiks@gmail.com>
Wed, 21 Jan 2015 16:49:57 +0000 (17:49 +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/workspace-list-item-view.js
server/sonar-web/src/main/js/tests/e2e/tests/coding-rules/app.json
sonar-core/src/main/resources/org/sonar/l10n/core.properties

index d5641452773bebe78ec2088e03800709620056e1..92087c04044c87637d502acbb98a5e2e9fe4bd7c 100644 (file)
@@ -6,11 +6,11 @@
           {{severityIcon activeProfile.severity}}
           {{#eq activeProfile.inherit 'OVERRIDES'}}
             <i class="icon-inheritance"
-               title="{{tp 'coding_rules.overrides' activeProfile.name activeProfile.parent.name}}"></i>
+               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.parent.name}}"></i>
+               title="{{tp 'coding_rules.inherits' activeProfile.name activeProfile.parentProfile.name}}"></i>
           {{/eq}}
         </td>
       {{/if}}
         <td class="coding-rule-table-meta-cell coding-rule-activation-actions">
           <div class="button-group">
             {{#if activeProfile.severity}}
-              {{#unless activeProfile.isTemplate}}
-                <button class="coding-rules-detail-quality-profile-change">{{t 'change_verb'}}</button>
-              {{/unless}}
-              {{#if activeProfile.parent}}
-                {{#eq activeProfile.inherit 'OVERRIDES'}}
-                  <button class="coding-rules-detail-quality-profile-revert button-red">
-                    {{t 'coding_rules.revert_to_parent_definition'}}
-                  </button>
-                {{/eq}}
-              {{else}}
+              {{#eq activeProfile.inherit 'NONE'}}
                 <button class="coding-rules-detail-quality-profile-deactivate button-red">
                   {{t 'coding_rules.deactivate'}}
                 </button>
-              {{/if}}
+              {{/eq}}
             {{else}}
               <button class="coding-rules-detail-quality-profile-activate">
                 {{t 'coding_rules.activate'}}
index 8c9b6a91923083f2ce156170011e9c5a742cabfe..36f422a6710875ed88b8ef4483078655c355ab78 100644 (file)
   <div class="modal-body modal-body-select2">
     <div class="modal-error"></div>
 
-    {{#notEmpty qualityProfiles}}
-      <table>
-        <tr class="property">
-          <th><h3>{{t 'coding_rules.quality_profile'}}</h3></th>
-          <td>
-            {{#if key}}
-              {{name}}
-            {{else}}
-              <select id="coding-rules-quality-profile-activation-select">
-                {{#each qualityProfiles}}
-                  <option value="{{key}}">{{name}}</option>
-                {{/each}}
-              </select>
-            {{/if}}
-          </td>
-        </tr>
-        <tr class="property">
-          <th><h3>{{t 'severity'}}</h3></th>
-          <td>
-            <select id="coding-rules-quality-profile-activation-severity">
-              {{#each severities}}
-                <option value="{{this}}">{{t 'severity' this}}</option>
+    {{#empty qualityProfiles}}
+      {{#unless change}}
+        <div class="message-notice">{{t 'coding_rules.active_in_all_profiles'}}</div>
+      {{/unless}}
+    {{/empty}}
+
+    <table>
+      <tr class="property">
+        <th><h3>{{t 'coding_rules.quality_profile'}}</h3></th>
+        <td>
+          {{#if key}}
+            {{name}}
+          {{else}}
+            <select id="coding-rules-quality-profile-activation-select">
+              {{#each qualityProfiles}}
+                <option value="{{key}}">{{name}}</option>
               {{/each}}
             </select>
-          </td>
-        </tr>
-        {{#if isCustomRule}}
-        <tr class="property">
-          <td colspan="2" class="note">{{t 'coding_rules.custom_rule.activation_notice'}}</td>
-        {{else}}
+          {{/if}}
+        </td>
+      </tr>
+      <tr class="property">
+        <th><h3>{{t 'severity'}}</h3></th>
+        <td>
+          <select id="coding-rules-quality-profile-activation-severity">
+            {{#each severities}}
+              <option value="{{this}}">{{t 'severity' this}}</option>
+            {{/each}}
+          </select>
+        </td>
+      </tr>
+      {{#if isCustomRule}}
+      <tr class="property">
+        <td colspan="2" class="note">{{t 'coding_rules.custom_rule.activation_notice'}}</td>
+      {{else}}
         {{#each params}}
           <tr class="property">
             <th><h3>{{key}}</h3></th>
                 <textarea class="width100" rows="3" name="{{key}}" placeholder="{{defaultValue}}">{{value}}</textarea>
               {{else}}
                 {{#eq type 'BOOLEAN'}}
-                <select name="{{key}}" value="{{value}}">
-                  <option value="{{defaultValue}}">{{t 'default'}} ({{t defaultValue}})</option>
-                  <option value="true"{{#eq value 'true'}} selected="selected"{{/eq}}>{{t 'true'}}</option>
-                  <option value="false"{{#eq value 'false'}} selected="selected"{{/eq}}>{{t 'false'}}</option>
-                </select>
+                  <select name="{{key}}" value="{{value}}">
+                    <option value="{{defaultValue}}">{{t 'default'}} ({{t defaultValue}})</option>
+                    <option value="true"{{#eq value 'true'}} selected="selected"{{/eq}}>{{t 'true'}}</option>
+                    <option value="false"{{#eq value 'false'}} selected="selected"{{/eq}}>{{t 'false'}}</option>
+                  </select>
                 {{else}}
-                <input type="text" name="{{key}}" value="{{value}}" placeholder="{{defaultValue}}">
+                  <input type="text" name="{{key}}" value="{{value}}" placeholder="{{defaultValue}}">
                 {{/eq}}
               {{/eq}}
               <div class="note">{{{htmlDesc}}}</div>
             </td>
           </tr>
         {{/each}}
-        {{/if}}
-      </table>
-    {{else}}
-      <div class="message-notice">{{t 'coding_rules.active_in_all_profiles'}}</div>
-    {{/notEmpty}}
+      {{/if}}
+    </table>
   </div>
 
   <div class="modal-foot">
index 6a502e4a0e81babd791a3d142ce28e30ab8baaca..f00691c679d33907b8737606e1fa88b53df9c695 100644 (file)
@@ -19,6 +19,7 @@ define([
           profile = this.app.state.get('query').qprofile;
       if (profile != null) {
         fields.push('actives');
+        fields.push('params');
       }
       return {
         p: this.app.state.get('page'),
index e6d92e6135e84571b8f9cc00419fc6143b059a07..60bb4d7e48f3569736792533c381a187cef01d9c 100644 (file)
@@ -6,11 +6,19 @@ define([
     model: Rule,
 
     parseRules: function (r) {
-      var rules = r.rules;
+      var rules = r.rules,
+          profileBases = r.qProfiles || [];
+
       if (r.actives != null) {
         rules = rules.map(function (rule) {
-          var profiles = r.actives[rule.key];
-          return _.extend(rule, { activeProfiles: profiles });
+          var profiles = (r.actives[rule.key] || []).map(function (profile) {
+            _.extend(profile, profileBases[profile.qProfile]);
+            if (profile.parent != null) {
+              _.extend(profile, { parentProfile: profileBases[profile.parent] });
+            }
+            return profile;
+          });
+          return _.extend(rule, { activeProfile: profiles.length > 0 ? profiles[0] : null });
         });
       }
       return rules;
index a9c0bee72d09976455ef059fc9403e59a2d8b67d..f83b0341a9a7fa94056c7d219fce831b5bf534a3 100644 (file)
@@ -83,7 +83,11 @@ define([
           params: paramsHash
         }
       }).done(function () {
-        that.options.app.controller.showDetails(that.options.rule);
+        if (that.options.fromList) {
+          that.options.rule.set({ activeProfile: { qProfile: profileKey, inherit: 'NONE', severity: severity } });
+        } else {
+          that.options.app.controller.showDetails(that.options.rule);
+        }
         window.process.finishBackgroundProcess(p);
       }).fail(function () {
         that.options.app.controller.showDetails(that.options.rule);
@@ -92,7 +96,7 @@ define([
     },
 
     getAvailableQualityProfiles: function (lang) {
-      var activeQualityProfiles = this.collection,
+      var activeQualityProfiles = this.collection || new Backbone.Collection(),
           inactiveProfiles = _.reject(this.options.app.qualityProfiles, function (profile) {
             return activeQualityProfiles.findWhere({ key: profile.key });
           });
index 5625796913d5140dfb68f3dd13da78ae8b47e27a..37f1cbcdf535def5cd4f49a6400379c4c9f17d9d 100644 (file)
@@ -64,13 +64,10 @@ define([
 
     deactivate: function () {
       var that = this,
-          ruleKey = this.options.rule.get('key'),
-          myProfile = _.findWhere(this.options.app.qualityProfiles, {
-            key: this.model.get('qProfile')
-          });
+          ruleKey = this.options.rule.get('key');
       window.confirmDialog({
         title: t('coding_rules.deactivate'),
-        html: tp('coding_rules.deactivate.confirm', myProfile.name),
+        html: tp('coding_rules.deactivate.confirm'),
         yesHandler: function () {
           var p = window.process.addBackgroundProcess();
           return jQuery.ajax({
index 02627c69f243a70cc02031ef1bd07628247d93c5..8a8dc8e2c57043a4f9065f1c7da741fc09ffd48a 100644 (file)
@@ -1,7 +1,8 @@
 define([
   'components/navigator/workspace-list-item-view',
+  'coding-rules/rule/profile-activation-view',
   'templates/coding-rules'
-], function (WorkspaceListItemView) {
+], function (WorkspaceListItemView, ProfileActivationView) {
 
   return WorkspaceListItemView.extend({
     className: 'coding-rule',
@@ -13,7 +14,9 @@ define([
 
     events: {
       'click': 'selectCurrent',
-      'click .js-rule': 'openRule'
+      'click .js-rule': 'openRule',
+      'click .coding-rules-detail-quality-profile-activate': 'activate',
+      'click .coding-rules-detail-quality-profile-deactivate': 'deactivate'
     },
 
     selectCurrent: function () {
@@ -24,9 +27,51 @@ 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,
+          othersQualityProfiles = _.reject(this.options.app.qualityProfiles, function (profile) {
+            return profile.key === activeProfile;
+          });
+
+      new ProfileActivationView({
+        rule: this.model,
+        collection: new Backbone.Collection(othersQualityProfiles),
+        app: this.options.app,
+        fromList: true
+      }).render();
+    },
+
+    deactivate: function () {
+      var that = this,
+          ruleKey = this.model.get('key'),
+          myProfile = this.model.get('activeProfile');
+      window.confirmDialog({
+        title: t('coding_rules.deactivate'),
+        html: tp('coding_rules.deactivate.confirm'),
+        yesHandler: function () {
+          var p = window.process.addBackgroundProcess();
+          return jQuery.ajax({
+            type: 'POST',
+            url: baseUrl + '/api/qualityprofiles/deactivate_rule',
+            data: {
+              profile_key: myProfile.qProfile,
+              rule_key: ruleKey
+            }
+          }).done(function () {
+            window.process.finishBackgroundProcess(p);
+            var newProfile = _.extend({}, myProfile, { severity: undefined });
+            that.model.set({ activeProfile: newProfile });
+          });
+        }
+      });
+    },
+
     serializeData: function () {
-      var activeProfiles = this.model.get('activeProfiles'),
-          activeProfile = _.isArray(activeProfiles) && activeProfiles.length === 1 ? activeProfiles[0] : null,
+      var activeProfile = this.getActiveProfile(),
           selectedProfile = this.options.app.state.get('query').qprofile;
       if (selectedProfile != null && activeProfile == null) {
         activeProfile = selectedProfile;
index 4f3319c8707cf920513dc33f29d1d88a4f18398b..0eb43bc39f7a5a54c6e0851e930bce53194ca32d 100644 (file)
     "DEPRECATED": "Deprecated",
     "READY": "Ready"
   },
-  "characteristics": {
-    "UNDERSTANDABILITY": "Maintainability: Understandability",
-    "MAINTAINABILITY": "Maintainability",
-    "TIME_ZONE_RELATED_PORTABILITY": "Portability: Time zone related portability",
-    "READABILITY": "Maintainability: Readability",
-    "SECURITY_FEATURES": "Security: Security features",
-    "ARCHITECTURE_RELIABILITY": "Reliability: Architecture related reliability",
-    "OS_RELATED_PORTABILITY": "Portability: OS related portability",
-    "EXCEPTION_HANDLING": "Reliability: Exception handling",
-    "LOGIC_CHANGEABILITY": "Changeability: Logic related changeability",
-    "SOFTWARE_RELATED_PORTABILITY": "Portability: Software related portability",
-    "INPUT_VALIDATION_AND_REPRESENTATION": "Security: Input validation and representation",
-    "LANGUAGE_RELATED_PORTABILITY": "Portability: Language related portability",
-    "ERRORS": "Security: Errors",
-    "SECURITY": "Security",
-    "RELIABILITY": "Reliability",
-    "PORTABILITY": "Portability",
-    "HARDWARE_RELATED_PORTABILITY": "Portability: Hardware related portability",
-    "SYNCHRONIZATION_RELIABILITY": "Reliability: Synchronization related reliability",
-    "TRANSPORTABILITY": "Reusability: Transportability",
-    "COMPILER_RELATED_PORTABILITY": "Portability: Compiler related portability",
-    "RESOURCE_RELIABILITY": "Reliability: Resource",
-    "CPU_EFFICIENCY": "Efficiency: Processor use",
-    "EFFICIENCY": "Efficiency",
-    "CHANGEABILITY": "Changeability",
-    "DATA_CHANGEABILITY": "Changeability: Data related changeability",
-    "API_ABUSE": "Security: API abuse",
-    "ARCHITECTURE_CHANGEABILITY": "Changeability: Architecture related changeability",
-    "UNIT_TESTS": "Reliability: Unit tests",
-    "INSTRUCTION_RELIABILITY": "Reliability: Instruction related reliability",
-    "REUSABILITY": "Reusability",
-    "MODULARITY": "Reusability: Modularity",
-    "UNIT_TESTABILITY": "Testability: Unit level testability",
-    "TESTABILITY": "Testability",
-    "INTEGRATION_TESTABILITY": "Testability: Integration level testability",
-    "NETWORK_USE": "Efficiency: Network use",
-    "MEMORY_EFFICIENCY": "Efficiency: Memory use",
-    "DATA_RELIABILITY": "Reliability: Data related reliability",
-    "FAULT_TOLERANCE": "Reliability: Fault tolerance",
-    "LOGIC_RELIABILITY": "Reliability: Logic related reliability"
-  }
+  "characteristics": [
+    {
+      "key": "UNDERSTANDABILITY",
+      "name": "Understandability",
+      "parent": "MAINTAINABILITY"
+    },
+    {
+      "key": "MAINTAINABILITY",
+      "name": "Maintainability"
+    },
+    {
+      "key": "TIME_ZONE_RELATED_PORTABILITY",
+      "name": "Time zone related portability",
+      "parent": "PORTABILITY"
+    },
+    {
+      "key": "READABILITY",
+      "name": "Readability",
+      "parent": "MAINTAINABILITY"
+    },
+    {
+      "key": "SECURITY_FEATURES",
+      "name": "Security features",
+      "parent": "SECURITY"
+    },
+    {
+      "key": "ARCHITECTURE_RELIABILITY",
+      "name": "Architecture related reliability",
+      "parent": "RELIABILITY"
+    },
+    {
+      "key": "OS_RELATED_PORTABILITY",
+      "name": "OS related portability",
+      "parent": "PORTABILITY"
+    },
+    {
+      "key": "EXCEPTION_HANDLING",
+      "name": "Exception handling",
+      "parent": "RELIABILITY"
+    },
+    {
+      "key": "LOGIC_CHANGEABILITY",
+      "name": "Logic related changeability",
+      "parent": "CHANGEABILITY"
+    },
+    {
+      "key": "SOFTWARE_RELATED_PORTABILITY",
+      "name": "Software related portability",
+      "parent": "PORTABILITY"
+    },
+    {
+      "key": "INPUT_VALIDATION_AND_REPRESENTATION",
+      "name": "Input validation and representation",
+      "parent": "SECURITY"
+    },
+    {
+      "key": "LANGUAGE_RELATED_PORTABILITY",
+      "name": "Language related portability",
+      "parent": "PORTABILITY"
+    },
+    {
+      "key": "ERRORS",
+      "name": "Errors",
+      "parent": "SECURITY"
+    },
+    {
+      "key": "SECURITY",
+      "name": "Security"
+    },
+    {
+      "key": "RELIABILITY",
+      "name": "Reliability"
+    },
+    {
+      "key": "PORTABILITY",
+      "name": "Portability"
+    },
+    {
+      "key": "HARDWARE_RELATED_PORTABILITY",
+      "name": "Hardware related portability",
+      "parent": "PORTABILITY"
+    },
+    {
+      "key": "SYNCHRONIZATION_RELIABILITY",
+      "name": "Synchronization related reliability",
+      "parent": "RELIABILITY"
+    },
+    {
+      "key": "TRANSPORTABILITY",
+      "name": "Transportability",
+      "parent": "REUSABILITY"
+    },
+    {
+      "key": "COMPILER_RELATED_PORTABILITY",
+      "name": "Compiler related portability",
+      "parent": "PORTABILITY"
+    },
+    {
+      "key": "RESOURCE_RELIABILITY",
+      "name": "Resource",
+      "parent": "RELIABILITY"
+    },
+    {
+      "key": "CPU_EFFICIENCY",
+      "name": "Processor use",
+      "parent": "EFFICIENCY"
+    },
+    {
+      "key": "EFFICIENCY",
+      "name": "Efficiency"
+    },
+    {
+      "key": "CHANGEABILITY",
+      "name": "Changeability"
+    },
+    {
+      "key": "DATA_CHANGEABILITY",
+      "name": "Data related changeability",
+      "parent": "CHANGEABILITY"
+    },
+    {
+      "key": "API_ABUSE",
+      "name": "API abuse",
+      "parent": "SECURITY"
+    },
+    {
+      "key": "ARCHITECTURE_CHANGEABILITY",
+      "name": "Architecture related changeability",
+      "parent": "CHANGEABILITY"
+    },
+    {
+      "key": "UNIT_TESTS",
+      "name": "Unit tests",
+      "parent": "RELIABILITY"
+    },
+    {
+      "key": "INSTRUCTION_RELIABILITY",
+      "name": "Instruction related reliability",
+      "parent": "RELIABILITY"
+    },
+    {
+      "key": "REUSABILITY",
+      "name": "Reusability"
+    },
+    {
+      "key": "MODULARITY",
+      "name": "Modularity",
+      "parent": "REUSABILITY"
+    },
+    {
+      "key": "UNIT_TESTABILITY",
+      "name": "Unit level testability",
+      "parent": "TESTABILITY"
+    },
+    {
+      "key": "TESTABILITY",
+      "name": "Testability"
+    },
+    {
+      "key": "INTEGRATION_TESTABILITY",
+      "name": "Integration level testability",
+      "parent": "TESTABILITY"
+    },
+    {
+      "key": "NETWORK_USE",
+      "name": "Network use",
+      "parent": "EFFICIENCY"
+    },
+    {
+      "key": "MEMORY_EFFICIENCY",
+      "name": "Memory use",
+      "parent": "EFFICIENCY"
+    },
+    {
+      "key": "DATA_RELIABILITY",
+      "name": "Data related reliability",
+      "parent": "RELIABILITY"
+    },
+    {
+      "key": "FAULT_TOLERANCE",
+      "name": "Fault tolerance",
+      "parent": "RELIABILITY"
+    },
+    {
+      "key": "LOGIC_RELIABILITY",
+      "name": "Logic related reliability",
+      "parent": "RELIABILITY"
+    }
+  ]
 }
index 8e3508a85d4a201345a4304957fa0f1bbfd89ad8..573613916fa34e1ba6fe2582837190facec5c1f6 100644 (file)
@@ -1793,7 +1793,7 @@ coding_rules.delete.manual.confirm=Are you sure you want to delete manual rule "
 coding_rules.extend_description=Extend Description
 coding_rules.deactivate_in=Deactivate In
 coding_rules.deactivate=Deactivate
-coding_rules.deactivate.confirm=Are you sure you want to deactivate this rule in profile {0}?
+coding_rules.deactivate.confirm=Are you sure you want to deactivate this rule in the profile?
 coding_rules.deactivate_in_quality_profile=Deactivate In Quality Profile
 coding_rules.deactivate_in_all_quality_profiles=Deactivate In All {0} Profiles
 coding_rules.found=Found