]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5353 Display list of custom rules in the details of a template rule
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Thu, 12 Jun 2014 14:37:36 +0000 (16:37 +0200)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Thu, 12 Jun 2014 14:38:07 +0000 (16:38 +0200)
sonar-server/src/main/coffee/coding-rules/views/coding-rules-detail-custom-rule-view.coffee [new file with mode: 0644]
sonar-server/src/main/coffee/coding-rules/views/coding-rules-detail-custom-rules-view.coffee [new file with mode: 0644]
sonar-server/src/main/coffee/coding-rules/views/coding-rules-detail-view.coffee
sonar-server/src/main/hbs/coding-rules/coding-rules-detail-custom-rule.hbs [new file with mode: 0644]

diff --git a/sonar-server/src/main/coffee/coding-rules/views/coding-rules-detail-custom-rule-view.coffee b/sonar-server/src/main/coffee/coding-rules/views/coding-rules-detail-custom-rule-view.coffee
new file mode 100644 (file)
index 0000000..033dffe
--- /dev/null
@@ -0,0 +1,26 @@
+define [
+  'backbone.marionette'
+  'templates/coding-rules'
+], (
+  Marionette
+  Templates
+) ->
+
+  class CodingRulesDetailCustomRuleView extends Marionette.ItemView
+    className: 'coding-rules-detail-custom-rule'
+    template: Templates['coding-rules-detail-custom-rule']
+
+    ui:
+      delete: '.coding-rules-detail-custom-rule-delete'
+
+    events:
+      'click @ui.delete': 'delete'
+
+    delete: ->
+      confirm('Are you sure ?')
+
+
+    serializeData: ->
+      _.extend super,
+        templateRule: @options.templateRule
+        canWrite: @options.app.canWrite
diff --git a/sonar-server/src/main/coffee/coding-rules/views/coding-rules-detail-custom-rules-view.coffee b/sonar-server/src/main/coffee/coding-rules/views/coding-rules-detail-custom-rules-view.coffee
new file mode 100644 (file)
index 0000000..258bd9e
--- /dev/null
@@ -0,0 +1,14 @@
+define [
+  'backbone.marionette'
+  'coding-rules/views/coding-rules-detail-custom-rule-view'
+], (
+  Marionette
+  CodingRulesDetailCustomRuleView
+) ->
+
+  class CodingRulesDetailCustomRulesView extends Marionette.CollectionView
+    itemView: CodingRulesDetailCustomRuleView
+
+    itemViewOptions: ->
+      app: @options.app
+      templateRule: @options.templateRule
index 9ab21979bd327106e2255b56222c26fe80fc543c..54b69efdf97c96eb303acbb7c52249e9b0ccdb07 100644 (file)
@@ -3,12 +3,14 @@ define [
   'backbone.marionette'
   'coding-rules/views/coding-rules-detail-quality-profiles-view'
   'coding-rules/views/coding-rules-detail-quality-profile-view'
+  'coding-rules/views/coding-rules-detail-custom-rules-view'
   'templates/coding-rules'
 ], (
   Backbone
   Marionette
   CodingRulesDetailQualityProfilesView
   CodingRulesDetailQualityProfileView
+  CodingRulesDetailCustomRulesView
   Templates
 ) ->
 
@@ -18,7 +20,8 @@ define [
 
     regions:
       qualityProfilesRegion: '#coding-rules-detail-quality-profiles'
-      customRulesRegion: '#coding-rules-detail-custom-rules'
+      customRulesRegion: '.coding-rules-detail-custom-rules-section'
+      customRulesListRegion: '#coding-rules-detail-custom-rules'
       contextRegion: '.coding-rules-detail-context'
 
 
@@ -63,20 +66,7 @@ define [
       if @model.get 'params'
         @model.set 'params', _.sortBy(@model.get('params'), 'key')
 
-      if @model.get 'isTemplate'
-        customRules = new Backbone.Collection()
-        jQuery.ajax
-          url: "#{baseUrl}/api/rules/search"
-          data:
-            template_key: @model.get 'key'
-            f: 'name'
-        .done (r) =>
-          customRules.add r.rules
-        #@customRulesView = new CodingrulesDetailCustomRulesView
-        #  app: @options.app
-        #  collection: customRules
-        #  rule: @model
-      else
+      unless @model.get 'isTemplate'
         _.map options.actives, (active) =>
           _.extend active, options.app.getQualityProfileByKey active.qProfile
         qualityProfiles = new Backbone.Collection options.actives,
@@ -106,8 +96,35 @@ define [
 
       if @model.get 'isTemplate'
         @$(@contextRegion.el).hide()
-        # @customRulesRegion.show @customRulesView
+        @$(@qualityProfilesRegion.el).hide()
+        @$(@customRulesRegion.el).show()
+
+        customRulesOriginal = @$(@customRulesRegion.el).html()
+
+        @$(@customRulesRegion.el).html '<i class="spinner"></i>'
+
+        customRules = new Backbone.Collection()
+        jQuery.ajax
+          url: "#{baseUrl}/api/rules/search"
+          data:
+            template_key: @model.get 'key'
+            f: 'name,severity,params'
+        .done (r) =>
+          customRules.add r.rules
+
+          if customRules.isEmpty() and not @options.app.canWrite
+            @$(@customRulesRegion.el).hide()
+          else
+            @customRulesView = new CodingRulesDetailCustomRulesView
+              app: @options.app
+              collection: customRules
+              templateRule: @model
+            @$(@customRulesRegion.el).html customRulesOriginal
+            @customRulesListRegion.show @customRulesView
+
       else
+        @$(@customRulesRegion.el).hide()
+        @$(@qualityProfilesRegion.el).show()
         @qualityProfilesRegion.show @qualityProfilesView
 
         if @options.app.getQualityProfile()
@@ -206,8 +223,8 @@ define [
       @options.app.codingRulesQualityProfileActivationView.show()
 
     createCustomRule: ->
-      #@options.app.codingRulesCustomRuleView.model = @model
-      #@options.app.codingRulesCustomRuleView.show()
+      #@options.app.codingRulesCreateCustomRuleView.template = @model
+      #@options.app.codingRulesCreateCustomRuleView.show()
 
 
     serializeData: ->
diff --git a/sonar-server/src/main/hbs/coding-rules/coding-rules-detail-custom-rule.hbs b/sonar-server/src/main/hbs/coding-rules/coding-rules-detail-custom-rule.hbs
new file mode 100644 (file)
index 0000000..eaedc7f
--- /dev/null
@@ -0,0 +1,32 @@
+<table class="width100">
+  <tbody>
+  <tr>
+    <td class="coding-rules-detail-custom-rule-name">
+      <a class="nolink" href="#rule_key={{key}}">{{name}}</a>
+    </td>
+
+    <td class="coding-rules-detail-custom-rule-severity">
+      {{severityIcon severity}} {{t "severity" severity}}
+    </td>
+
+    <td class="coding-rules-detail-custom-rule-parameters">
+      {{#each parameters}}
+        <div class="coding-rules-detail-custom-rule-parameter">
+          <span class="key">{{key}}</span><span class="sep">:&nbsp;</span><span class="value" title="{{value}}">{{value}}</span>
+        </div>
+      {{/each}}
+      &nbsp;
+    </td>
+
+    {{#if canWrite}}
+    <td class="coding-rules-detail-custom-rule-actions">
+      <div class="button-group">
+        <button class="coding-rules-detail-custom-rule-delete button-red">
+          {{t 'delete'}}
+        </button>
+      </div>
+    </td>
+    {{/if}}
+  </tr>
+  </tbody>
+</table>