From 92f19cac9cd14ef8301112e560867f624a8af740 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Thu, 4 Oct 2012 16:25:18 +0200 Subject: [PATCH] SONAR-3529 Improve property sets --- .../org/sonar/plugins/core/CorePlugin.java | 52 ++++++++++++++++++- .../java/org/sonar/api/PropertyField.java | 6 +++ .../api/config/PropertyFieldDefinition.java | 45 ++++++++-------- .../api/config/PropertyDefinitionTest.java | 4 +- .../app/controllers/resource_controller.rb | 1 - .../app/controllers/settings_controller.rb | 21 +++++--- .../WEB-INF/app/helpers/settings_helper.rb | 4 ++ .../app/views/settings/_set_instance.html.erb | 19 +++++-- .../app/views/settings/_type_FLOAT.html.erb | 2 +- .../app/views/settings/_type_INTEGER.html.erb | 2 +- .../views/settings/_type_PASSWORD.html.erb | 2 +- .../_type_PROPERTY_SET_DEFINITION.html.erb | 9 ++-- .../_type_REGULAR_EXPRESSION.html.erb | 2 +- .../app/views/settings/_type_STRING.html.erb | 2 +- .../app/views/settings/_type_TEXT.html.erb | 2 +- .../src/main/webapp/stylesheets/style.css | 9 ++++ 16 files changed, 136 insertions(+), 46 deletions(-) diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java index 00e99053d24..e1c7f2eab74 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java @@ -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", diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/PropertyField.java b/sonar-plugin-api/src/main/java/org/sonar/api/PropertyField.java index eb50526b67b..d0ca927ac25 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/PropertyField.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/PropertyField.java @@ -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; /** diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyFieldDefinition.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyFieldDefinition.java index 2a941b7a71c..cc73824eb87 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyFieldDefinition.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyFieldDefinition.java @@ -19,43 +19,42 @@ */ 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 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); } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionTest.java index 3a4fcbea156..bc76fcd7507 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionTest.java @@ -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")) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb index 1b49f23e2e1..11b71dc084c 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb @@ -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() diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/settings_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/settings_controller.rb index 8125a303679..c64c1f025a2 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/settings_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/settings_controller.rb @@ -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 diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/settings_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/settings_helper.rb index 6e3500af73d..13603e2af35 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/settings_helper.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/settings_helper.rb @@ -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) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_set_instance.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_set_instance.html.erb index a510f678c47..25f871da344 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_set_instance.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_set_instance.html.erb @@ -1,13 +1,18 @@ <% errors = [] -%> +<% key_field = key_field(property) -%> - - <%= text_field_tag "property_sets[#{property.key}][]", set_key, :size => 50 -%> + + <% if key_field -%> + <%= 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 -%> + <% 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 -%> - <%= render "settings/type_#{field.type}", :property => field, :field => field, :value => value, :name => "#{property.key}[#{field.key}][]", :id => "input_#{h field.key}" -%> + <%= render "settings/type_#{field.type}", :property => field, :field => field, :value => value, :name => "#{property.key}[#{field.key}][]", :id => "input_#{h field.key}", :size => field.indicativeSize -%> <% errors << (render "settings/error", :key => key) if set_key -%> <% end -%> @@ -17,10 +22,14 @@ <% unless errors.all?(&:blank?) -%> - + <% if key_field -%> + + <% end -%> + <% errors.each do |error| -%> <%= error -%> <% end -%> + <% end -%> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_FLOAT.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_FLOAT.html.erb index 5f8b11660da..80bad336880 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_FLOAT.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_FLOAT.html.erb @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_INTEGER.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_INTEGER.html.erb index fa2b44e9788..ea7d4d7d8e7 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_INTEGER.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_INTEGER.html.erb @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_PASSWORD.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_PASSWORD.html.erb index bb7e70b0721..919ff05bd61 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_PASSWORD.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_PASSWORD.html.erb @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_PROPERTY_SET_DEFINITION.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_PROPERTY_SET_DEFINITION.html.erb index 243999d2137..9a601b52a04 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_PROPERTY_SET_DEFINITION.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_PROPERTY_SET_DEFINITION.html.erb @@ -3,8 +3,10 @@ - - <% property.fields.each do |field| -%> + <% if key_field(property) -%> + + <% end -%> + <% property.fields.reject { |field| field.key == 'key' }.each do |field| -%> - diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_REGULAR_EXPRESSION.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_REGULAR_EXPRESSION.html.erb index 5f8b11660da..80bad336880 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_REGULAR_EXPRESSION.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_REGULAR_EXPRESSION.html.erb @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_STRING.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_STRING.html.erb index 5f8b11660da..80bad336880 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_STRING.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_STRING.html.erb @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_TEXT.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_TEXT.html.erb index f552d9c804d..d5722465b93 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_TEXT.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_TEXT.html.erb @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/sonar-server/src/main/webapp/stylesheets/style.css b/sonar-server/src/main/webapp/stylesheets/style.css index 819ddc41a8d..7a86b6f5c64 100644 --- a/sonar-server/src/main/webapp/stylesheets/style.css +++ b/sonar-server/src/main/webapp/stylesheets/style.css @@ -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 -- 2.39.5
<%= message('key') -%><%= message('key') -%> <%= field_name(property, field) -%> <% desc = field_description(property, field) -%> @@ -22,12 +24,11 @@ <%= 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 %> -
+