]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7931 Show hierarchy of profiles in rule activation
authorStas Vilchik <vilchiks@gmail.com>
Wed, 25 Jan 2017 15:06:26 +0000 (16:06 +0100)
committerStas Vilchik <vilchiks@gmail.com>
Thu, 26 Jan 2017 11:31:01 +0000 (12:31 +0100)
server/sonar-web/src/main/js/apps/coding-rules/rule/profile-activation-view.js
server/sonar-web/src/main/js/apps/coding-rules/templates/rule/coding-rules-profile-activation.hbs
server/sonar-web/src/main/js/apps/quality-profiles/utils.js

index 5c4e92d10c9d2763a1febfc181770bab749d53d7..70fe0cd6a4dc9ac15ffb37ecf918263acedfc5a1 100644 (file)
@@ -22,6 +22,7 @@ import Backbone from 'backbone';
 import ModalForm from '../../../components/common/modal-form';
 import Template from '../templates/rule/coding-rules-profile-activation.hbs';
 import { csvEscape } from '../../../helpers/csv';
+import { sortProfiles } from '../../quality-profiles/utils';
 
 export default ModalForm.extend({
   template: Template,
@@ -144,12 +145,18 @@ export default ModalForm.extend({
     const availableProfiles = this.getAvailableQualityProfiles(this.options.rule.get('lang'));
     const contextProfile = this.options.app.state.get('query').qprofile;
 
+    // decrease depth by 1, so the top level starts at 0
+    const profilesWithDepth = sortProfiles(availableProfiles).map(profile => ({
+      ...profile,
+      depth: profile.depth - 1
+    }));
+
     return {
       ...ModalForm.prototype.serializeData.apply(this, arguments),
       params,
       contextProfile,
       change: this.model && this.model.has('severity'),
-      qualityProfiles: availableProfiles,
+      qualityProfiles: profilesWithDepth,
       severities: ['BLOCKER', 'CRITICAL', 'MAJOR', 'MINOR', 'INFO'],
       saveEnabled: availableProfiles.length > 0 || (this.model && this.model.get('qProfile')),
       isCustomRule: (this.model && this.model.has('templateKey')) || this.options.rule.has('templateKey')
index 7a7a2d9a3a8dedc3fb09a1385c2ad63aa1009a59..e7b30dbbf09e91e66c4a6b3eec8ec545b9276842 100644 (file)
@@ -23,7 +23,9 @@
       {{else}}
         <select id="coding-rules-quality-profile-activation-select">
           {{#each qualityProfiles}}
-            <option value="{{key}}" {{#eq key ../contextProfile}}selected{{/eq}}>{{name}}</option>
+            <option value="{{key}}" {{#eq key ../contextProfile}}selected{{/eq}}>
+              {{#repeat depth}}&nbsp;&nbsp;&nbsp;{{/repeat}}{{name}}
+            </option>
           {{/each}}
         </select>
       {{/any}}
@@ -37,8 +39,9 @@
       </select>
     </div>
     {{#if isCustomRule}}
-    <div class="modal-field">
-      <p class="note">{{t 'coding_rules.custom_rule.activation_notice'}}</p>
+      <div class="modal-field">
+        <p class="note">{{t 'coding_rules.custom_rule.activation_notice'}}</p>
+      </div>
     {{else}}
       {{#each params}}
         <div class="modal-field">
     {{/if}}
   </div>
 
-    <div class="modal-foot">
-      <button id="coding-rules-quality-profile-activation-activate"
-              {{#unless saveEnabled}}disabled="disabled"{{/unless}}>
-        {{#if change}}{{t 'save'}}{{else}}{{t 'coding_rules.activate'}}{{/if}}
-      </button>
-      <a id="coding-rules-quality-profile-activation-cancel" class="js-modal-close">{{t 'cancel'}}</a>
-    </div>
+  <div class="modal-foot">
+    <button id="coding-rules-quality-profile-activation-activate"
+            {{#unless saveEnabled}}disabled="disabled"{{/unless}}>
+      {{#if change}}{{t 'save'}}{{else}}{{t 'coding_rules.activate'}}{{/if}}
+    </button>
+    <a id="coding-rules-quality-profile-activation-cancel" class="js-modal-close">{{t 'cancel'}}</a>
+  </div>
 </form>
index 0bc023fdd4375ddac62b5a284279248967c584cb..8e10d8553f72f2091a9c3f1d1d8b2e415493437b 100644 (file)
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
+// @flow
 import sortBy from 'lodash/sortBy';
 import moment from 'moment';
 
-export function sortProfiles (profiles) {
+type Profiles = Array<{
+  key: string,
+  name: string,
+  parentKey?: string
+}>;
+
+export function sortProfiles (profiles: Profiles) {
   const result = [];
   const sorted = sortBy(profiles, 'name');
 
@@ -46,7 +53,7 @@ export function sortProfiles (profiles) {
   return result;
 }
 
-export function createFakeProfile (overrides) {
+export function createFakeProfile (overrides: {}) {
   return {
     key: 'key',
     name: 'name',
@@ -61,6 +68,6 @@ export function createFakeProfile (overrides) {
   };
 }
 
-export function isStagnant (profile) {
+export function isStagnant (profile: { userUpdatedAt: string }) {
   return moment().diff(moment(profile.userUpdatedAt), 'years') >= 1;
 }