]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3529 Improve property sets
authorDavid Gageot <david@gageot.net>
Thu, 4 Oct 2012 14:25:18 +0000 (16:25 +0200)
committerDavid Gageot <david@gageot.net>
Thu, 4 Oct 2012 14:33:24 +0000 (16:33 +0200)
16 files changed:
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java
sonar-plugin-api/src/main/java/org/sonar/api/PropertyField.java
sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyFieldDefinition.java
sonar-plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionTest.java
sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/controllers/settings_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/helpers/settings_helper.rb
sonar-server/src/main/webapp/WEB-INF/app/views/settings/_set_instance.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_FLOAT.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_INTEGER.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_PASSWORD.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_PROPERTY_SET_DEFINITION.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_REGULAR_EXPRESSION.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_STRING.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_TEXT.html.erb
sonar-server/src/main/webapp/stylesheets/style.css

index 00e99053d241532f4b5c10f910943dd9152522cf..e1c7f2eab749613bd733980289165c7d944eb057 100644 (file)
@@ -130,19 +130,67 @@ import java.util.List;
   @Property(
     key = "sonar.test.jira.servers",
     name = "Jira Servers",
+    description = "List of jira server definitions",
     global = true,
     project = true,
     category = "DEV",
     fields = {
+      @PropertyField(
+        key = "key",
+        name = "Key",
+        type = PropertyType.STRING,
+        indicativeSize = 10),
       @PropertyField(
         key = "url",
         name = "Url",
         description = "l'url du serveur jira",
-        type = PropertyType.STRING),
+        type = PropertyType.STRING,
+        indicativeSize = 20),
       @PropertyField(
         key = "port",
         name = "Port",
-        type = PropertyType.INTEGER)}),
+        type = PropertyType.INTEGER,
+        indicativeSize = 5)}),
+  @Property(
+    key = "sonar.demo",
+    name = "Demo",
+    global = true,
+    project = true,
+    category = "DEV",
+    fields = {
+      @PropertyField(
+        key = "text",
+        name = "text",
+        type = PropertyType.TEXT),
+      @PropertyField(
+        key = "boolean",
+        name = "boolean",
+        type = PropertyType.BOOLEAN),
+      @PropertyField(
+        key = "float",
+        name = "float",
+        type = PropertyType.FLOAT),
+      @PropertyField(
+        key = "license",
+        name = "license",
+        type = PropertyType.LICENSE),
+      @PropertyField(
+        key = "metric",
+        name = "metric",
+        type = PropertyType.METRIC),
+      @PropertyField(
+        key = "password",
+        name = "password",
+        type = PropertyType.PASSWORD),
+      @PropertyField(
+        key = "regexp",
+        name = "regexp",
+        type = PropertyType.REGULAR_EXPRESSION),
+      @PropertyField(
+        key = "list",
+        name = "list",
+        type = PropertyType.SINGLE_SELECT_LIST,
+        options = {"AAA", "BBB"})}),
   @Property(
     key = "sonar.test.jira",
     name = "Jira",
index eb50526b67b98e5b3d9f5c7c20193d49b9a0447b..d0ca927ac2554fffb2f3f14a47c9fe563bb00914 100644 (file)
@@ -57,6 +57,12 @@ public @interface PropertyField {
    */
   String description() default "";
 
+  /**
+   * Indicative size of the field value in characters. This size is not validated, it is merely used by the GUI
+   * to size the different input fields of a property set.
+   */
+  int indicativeSize() default 20;
+
   PropertyType type() default PropertyType.STRING;
 
   /**
index 2a941b7a71cf588f01527d3db062bc5ad9bd5e5b..cc73824eb879106e4183c126859bc47f6c6649a6 100644 (file)
  */
 package org.sonar.api.config;
 
+import com.google.common.collect.Lists;
 import org.sonar.api.PropertyField;
 import org.sonar.api.PropertyType;
 
 import javax.annotation.Nullable;
 
+import java.util.List;
+
 /**
  * @since 3.3
  */
 public final class PropertyFieldDefinition {
-  private String key;
-  private String defaultValue;
-  private String name;
-  private PropertyType type = PropertyType.STRING;
-  private String[] options;
-  private String description;
+  private final String key;
+  private final String defaultValue;
+  private final String name;
+  private final String description;
+  private final int indicativeSize;
+  private final PropertyType type;
+  private final String[] options;
 
   private PropertyFieldDefinition(PropertyField annotation) {
     this.key = annotation.key();
-    this.name = annotation.name();
     this.defaultValue = annotation.defaultValue();
+    this.name = annotation.name();
     this.description = annotation.description();
+    this.indicativeSize = annotation.indicativeSize();
     this.type = annotation.type();
     this.options = annotation.options();
   }
 
-  public static PropertyFieldDefinition create(PropertyField annotation) {
-    return new PropertyFieldDefinition(annotation);
-  }
-
   public static PropertyFieldDefinition[] create(PropertyField[] fields) {
-    PropertyFieldDefinition[] definitions = new PropertyFieldDefinition[fields.length];
-
-    for (int i = 0; i < fields.length; i++) {
-      definitions[i] = create(fields[i]);
+    List<PropertyFieldDefinition> definitions = Lists.newArrayList();
+    for (PropertyField field : fields) {
+      definitions.add(new PropertyFieldDefinition(field));
     }
-
-    return definitions;
+    return definitions.toArray(new PropertyFieldDefinition[definitions.size()]);
   }
 
   public String getKey() {
@@ -70,6 +69,14 @@ public final class PropertyFieldDefinition {
     return name;
   }
 
+  public String getDescription() {
+    return description;
+  }
+
+  public int getIndicativeSize() {
+    return indicativeSize;
+  }
+
   public PropertyType getType() {
     return type;
   }
@@ -78,10 +85,6 @@ public final class PropertyFieldDefinition {
     return options.clone();
   }
 
-  public String getDescription() {
-    return description;
-  }
-
   public PropertyDefinition.Result validate(@Nullable String value) {
     return PropertyDefinition.validate(type, value, options);
   }
index 3a4fcbea15635815c7f8d4d593cc0b02bac5c0b7..bc76fcd7507fd7b63d3c50b3e12e7523112ef07e 100644 (file)
@@ -82,7 +82,7 @@ public class PropertyDefinitionTest {
 
   @Properties(@Property(key = "hello", name = "Hello", fields = {
     @PropertyField(key = "first", name = "First", description = "Description", options = {"A", "B"}),
-    @PropertyField(key = "second", name = "Second", type = PropertyType.INTEGER)}))
+    @PropertyField(key = "second", name = "Second", type = PropertyType.INTEGER, indicativeSize = 5)}))
   static class WithPropertySet {
   }
 
@@ -99,10 +99,12 @@ public class PropertyDefinitionTest {
     assertThat(def.getFields()[0].getDescription()).isEqualTo("Description");
     assertThat(def.getFields()[0].getType()).isEqualTo(PropertyType.STRING);
     assertThat(def.getFields()[0].getOptions()).containsOnly("A", "B");
+    assertThat(def.getFields()[0].getIndicativeSize()).isEqualTo(20);
     assertThat(def.getFields()[1].getKey()).isEqualTo("second");
     assertThat(def.getFields()[1].getName()).isEqualTo("Second");
     assertThat(def.getFields()[1].getType()).isEqualTo(PropertyType.INTEGER);
     assertThat(def.getFields()[1].getOptions()).isEmpty();
+    assertThat(def.getFields()[1].getIndicativeSize()).isEqualTo(5);
   }
 
   @Properties(@Property(key = "hello", name = "Hello"))
index 1b49f23e2e171046f6ccea3c89fea18d77eb5a6b..11b71dc084c23e7d84de1035387709c4d77bb492 100644 (file)
@@ -45,7 +45,6 @@ class ResourceController < ApplicationController
         if @extension.getId()=='violations'
           render_violations()
         elsif (@extension.getId()=='coverage')
-          puts '-------------------------------------------'
           render_coverage()
         elsif (@extension.getId()=='source')
           render_source()
index 8125a3036799ace7743e795e13083bb4321aa191..c64c1f025a21d704d3f873b5370fc5035e2a3c28 100644 (file)
@@ -56,13 +56,22 @@ class SettingsController < ApplicationController
 
   def update_property_sets(resource_id)
     (params[:property_sets] || []).each do |key, set_keys|
-      Property.with_key_prefix(key + '.').with_resource(resource_id).delete_all
-      update_property(key, set_keys, resource_id)
+      Property.transaction do
+        # clear
+        Property.with_key_prefix(key + '.').with_resource(resource_id).delete_all
+
+        # set keys
+        update_property(key, set_keys, resource_id)
+        set_keys.each do |set_key|
+          update_property("#{key}.#{set_key}.key", set_key, resource_id)
+        end
 
-      params[key].each do |field_key, field_values|
-        field_values.zip(set_keys).each do |field_value, set_key|
-          if set_key
-            update_property("#{key}.#{set_key}.#{field_key}", field_value, resource_id)
+        # set fields
+        params[key].each do |field_key, field_values|
+          field_values.zip(set_keys).each do |field_value, set_key|
+            if set_key
+              update_property("#{key}.#{set_key}.#{field_key}", field_value, resource_id)
+            end
           end
         end
       end
index 6e3500af73d2e1a3b5f1319afe14d51765a99251..13603e2af3547b3d4f54db2b9796d66d8c4f5de5 100644 (file)
@@ -38,6 +38,10 @@ module SettingsHelper
     message("field.#{property.key}.#{field.key}.description", :default => field.description)
   end
 
+  def key_field(property)
+    property.fields.find { |f| f.key == 'key' }
+  end
+
   def option_name(property, field, option)
     if field
       message("option.#{property.key}.#{field.key}.#{option}.name", :default => option)
index a510f678c4747b6cadc2b755fd45a45948c7f450..25f871da34464eb0faecda2cdbb14fa003d0dd85 100644 (file)
@@ -1,13 +1,18 @@
 <% errors = [] -%>
+<% key_field = key_field(property) -%>
 
-<tr class="multi_value <%= 'template' unless set_key -%>" style="<%= 'display:none' unless set_key -%>">
-  <td><%= text_field_tag "property_sets[#{property.key}][]", set_key, :size => 50 -%></td>
+<tr class="top multi_value <%= 'template' unless set_key -%>" style="<%= 'display:none' unless set_key -%>">
+  <% if key_field -%>
+    <td><%= render "settings/type_#{key_field.type}", :property => key_field, :field => key_field, :value => set_key, :name => "property_sets[#{property.key}][]", :id => "input_#{h key_field.key}", :size => key_field.indicativeSize -%></td>
+  <% else -%>
+    <%= hidden_field_tag "property_sets[#{property.key}][]", set_key -%>
+  <% end -%>
 
-  <% property.fields.each do |field| -%>
+  <% property.fields.reject { |field| field.key == 'key' }.each do |field| -%>
     <% key = "#{property.key}.#{set_key}.#{field.key}" if set_key -%>
     <% value = Property.value(key, resource_id) if set_key -%>
 
-    <td><%= render "settings/type_#{field.type}", :property => field, :field => field, :value => value, :name => "#{property.key}[#{field.key}][]", :id => "input_#{h field.key}" -%></td>
+    <td><%= render "settings/type_#{field.type}", :property => field, :field => field, :value => value, :name => "#{property.key}[#{field.key}][]", :id => "input_#{h field.key}", :size => field.indicativeSize -%></td>
 
     <% errors << (render "settings/error", :key => key) if set_key -%>
   <% end -%>
 
 <% unless errors.all?(&:blank?) -%>
   <tr>
-    <td></td>
+    <% if key_field -%>
+      <td></td>
+    <% end -%>
+
     <% errors.each do |error| -%>
       <td><%= error -%></td>
     <% end -%>
+
     <td></td>
   </tr>
 <% end -%>
index 5f8b11660da6cbad9d62a433c9557d588942ab14..80bad33688044b74e560c0d9cb00c73d773be41d 100644 (file)
@@ -1 +1 @@
-<input type="text" name="<%= name -%>" value="<%= h value if value -%>" size="50" id="<%= id -%>"/>
\ No newline at end of file
+<input type="text" name="<%= name -%>" value="<%= h value if value -%>" size="<%= (defined? size) ? size : 50 -%>" id="<%= id -%>"/>
\ No newline at end of file
index fa2b44e9788ea51e0bb3023b67d6235e01940c6a..ea7d4d7d8e774b8f9d10a4978148fdd8dee59539 100644 (file)
@@ -1 +1 @@
-<input type="text" name="<%= name -%>" value="<%= h value if value -%>" size="50" id="<%= id-%>"/>
\ No newline at end of file
+<input type="text" name="<%= name -%>" value="<%= h value if value -%>" size="<%= (defined? size) ? size : 50 -%>" id="<%= id-%>"/>
\ No newline at end of file
index bb7e70b07212499fe8d2a6643b056c59377571fe..919ff05bd61dba78528d400425c7b037c19e8fbe 100644 (file)
@@ -1 +1 @@
-<input type="password" name="<%= name -%>" value="<%= h value if value -%>" size="50" id="<%= id -%>"/>
\ No newline at end of file
+<input type="password" name="<%= name -%>" value="<%= h value if value -%>" size="<%= defined? size ? size : 50-%>" id="<%= id -%>"/>
\ No newline at end of file
index 243999d2137ab1e1da5e7095f3976b7670497d52..9a601b52a041e1e7e65ce83d5d66b9348bfbf4e2 100644 (file)
@@ -3,8 +3,10 @@
 <table class="data">
   <thead>
   <tr>
-    <th><%= message('key') -%></th>
-    <% property.fields.each do |field| -%>
+    <% if key_field(property) -%>
+      <th><%= message('key') -%></th>
+    <% end -%>
+    <% property.fields.reject { |field| field.key == 'key' }.each do |field| -%>
       <th>
         <%= field_name(property, field) -%>
         <% desc = field_description(property, field) -%>
     <%= render 'settings/set_instance', :property => property, :set_key => set_key, :resource_id => resource_id %>
   <% end -%>
   <%= render 'settings/set_instance', :property => property, :set_key => nil, :resource_id => resource_id %>
-
   </tbody>
 
   <tfoot>
   <tr>
-    <td>
+    <td colspan="<%= property.fields.size + 1 -%>">
       <button class="add_value"><%= message('settings.add') -%></button>
     </td>
   </tr>
index 5f8b11660da6cbad9d62a433c9557d588942ab14..80bad33688044b74e560c0d9cb00c73d773be41d 100644 (file)
@@ -1 +1 @@
-<input type="text" name="<%= name -%>" value="<%= h value if value -%>" size="50" id="<%= id -%>"/>
\ No newline at end of file
+<input type="text" name="<%= name -%>" value="<%= h value if value -%>" size="<%= (defined? size) ? size : 50 -%>" id="<%= id -%>"/>
\ No newline at end of file
index 5f8b11660da6cbad9d62a433c9557d588942ab14..80bad33688044b74e560c0d9cb00c73d773be41d 100644 (file)
@@ -1 +1 @@
-<input type="text" name="<%= name -%>" value="<%= h value if value -%>" size="50" id="<%= id -%>"/>
\ No newline at end of file
+<input type="text" name="<%= name -%>" value="<%= h value if value -%>" size="<%= (defined? size) ? size : 50 -%>" id="<%= id -%>"/>
\ No newline at end of file
index f552d9c804dfdb36b8a4542631ac7b1a42bdb703..d5722465b9398ef43655a08043beffe16f140025 100644 (file)
@@ -1 +1 @@
-<textarea rows="5" cols="80" class="width100" name="<%= name -%>" id="<%= id -%>"><%= h value if value -%></textarea>
\ No newline at end of file
+<textarea rows="5" cols="<%= (defined? size) ? size : 80 -%>" class="width100" name="<%= name -%>" id="<%= id -%>"><%= h value if value -%></textarea>
\ No newline at end of file
index 819ddc41a8d774fb66d87cd0e9c4d07193463dd7..7a86b6f5c64a9c50273998b2faeaf71283b419eb 100644 (file)
@@ -2431,3 +2431,12 @@ textarea.width100 {
 .coverage td.name {
   text-align: right;
 }
+
+.property table.data > tbody > tr > td {
+  vertical-align: top;
+}
+
+.property table.data {
+  width: auto;
+  min-width: 600px;
+}
\ No newline at end of file