diff options
author | David Gageot <david@gageot.net> | 2012-10-01 10:58:42 +0200 |
---|---|---|
committer | David Gageot <david@gageot.net> | 2012-10-01 15:03:10 +0200 |
commit | 57c87a64a0a545ad81f3859b57d4962260ef6ee3 (patch) | |
tree | 6c24b58f8cd7108d04b308f426256b879357219c | |
parent | d6cac6a13b02ae53896a359df85f7ee0e32b5ac1 (diff) | |
download | sonarqube-57c87a64a0a545ad81f3859b57d4962260ef6ee3.tar.gz sonarqube-57c87a64a0a545ad81f3859b57d4962260ef6ee3.zip |
SONAR-3529 Better look. Use field property type
23 files changed, 97 insertions, 49 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 10ab1cbb509..e10206e7952 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 @@ -133,6 +133,7 @@ import java.util.List; @PropertyField( key = "url", name = "Url", + description = "l'url du serveur jira", type = PropertyType.STRING), @PropertyField( key = "port", 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 4f2c9e18dce..c8114b724da 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 @@ -33,7 +33,7 @@ import java.lang.annotation.Target; @Target(ElementType.TYPE) public @interface PropertyField { /** - * Unique key within a property. + * Unique key within a property. It shouldn't be prefixed. */ String key(); @@ -42,8 +42,16 @@ public @interface PropertyField { */ String defaultValue() default ""; + /** + * This name will be displayed on the Settings page. This can be overridden/translated + * by adding a a value for: <code>field.{key of parent property}.{key of this field}.name</code> in the language bundle. + */ String name(); + /** + * If not empty, this description will be displayed on the Settings page. This can be overridden/translated + * by adding a a value for: <code>field.{key of parent property}.{key of this field}.description</code> in the language bundle. + */ String description() default ""; PropertyType type() default PropertyType.STRING; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java index 7e497b49aaa..6025d79bd44 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java @@ -114,6 +114,10 @@ public final class PropertyDefinition { } public Result validate(@Nullable String value) { + return validate(type, value, options); + } + + static Result validate(PropertyType type, @Nullable String value, String[] options) { if (StringUtils.isNotBlank(value)) { if (type == PropertyType.BOOLEAN) { if (!StringUtils.equalsIgnoreCase(value, "true") && !StringUtils.equalsIgnoreCase(value, "false")) { 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 51775b7fe4a..2a941b7a71c 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 @@ -22,6 +22,8 @@ package org.sonar.api.config; import org.sonar.api.PropertyField; import org.sonar.api.PropertyType; +import javax.annotation.Nullable; + /** * @since 3.3 */ @@ -56,7 +58,6 @@ public final class PropertyFieldDefinition { return definitions; } - public String getKey() { return key; } @@ -80,4 +81,8 @@ public final class PropertyFieldDefinition { public String getDescription() { return description; } + + public PropertyDefinition.Result validate(@Nullable String value) { + return PropertyDefinition.validate(type, value, options); + } } 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 d6eb4b4345a..3376c8807d2 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 @@ -23,15 +23,23 @@ module SettingsHelper end def property_name(property) - message("property.#{property.key()}.name", :default => property.name()) + message("property.#{property.key}.name", :default => property.name()) end def property_description(property) - message("property.#{property.key()}.description", :default => property.description()) + message("property.#{property.key}.description", :default => property.description) + end + + def field_name(property, field) + message("field.#{property.key}.#{field.key}.name", :default => field.name) + end + + def field_description(property, field) + message("field.#{property.key}.#{field.key}.description", :default => field.description) end def property_help(property) - message("property.#{property.key()}.help", :default => '') + message("property.#{property.key}.help", :default => '') end def property_value(property) @@ -60,6 +68,10 @@ module SettingsHelper end def input_name(property) - "settings[#{h property.key}]" + (property.multi_values ? '[]' : '') + name = "settings[#{h property.key}]" + if property.multi_values + name += '[]' + end + name end end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/property.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/property.rb index ec98d312c9a..e4bec485aaf 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/property.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/property.rb @@ -157,7 +157,7 @@ class Property < ActiveRecord::Base def validate if java_definition - validation_result=java_definition.validate(text_value) + validation_result = java_definition.validate(text_value) errors.add_to_base(validation_result.getErrorKey()) unless validation_result.isValid() end end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_properties.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_properties.html.erb index 8bc051e7339..5d2e340b5c3 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_properties.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_properties.html.erb @@ -28,7 +28,7 @@ <% value = property_value(property) -%> <% if property.multi_values -%> - <% value.each_with_index do |sub_value, index| -%> + <% value.each do |sub_value| -%> <%= render "settings/multi_value", :property => property, :value => sub_value, :delete_link => true -%> <% end -%> <div class="template" style="display:none;"> @@ -70,7 +70,7 @@ <script> $j('.delete').live('click', function () { - $j(this).parent('.multi_value').remove(); + $j(this).parents('.multi_value').remove(); return false; }); 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 new file mode 100644 index 00000000000..4cafb504ce0 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_set_instance.html.erb @@ -0,0 +1,22 @@ +<div class="multi_value"> + <div class="field"> + <label><%= message('key') %>:</label> + <%= text_field_tag "property_sets[#{property.key}][]", set_key, :size => 50 -%> + <a href="#" class="delete link-action"><%= message('delete') -%></a> + </div> + + <% property.fields.each do |field| -%> + <div class="field"> + <label><%= field_name(property, field) -%>: </label> + + <% value = Property.value("#{property.key}.#{set_key}.#{field.key}", resource_id) if set_key -%> + <%= render "settings/type_#{field.type}", :property => field, :value => value, :name => "#{property.key}[#{field.key}][]", :id => "input_#{h field.key}" -%> + + <% desc=field_description(property, field) -%> + <% unless desc.blank? %> + <p class="note"><%= desc -%></p> + <% end -%> + </div> + <% end -%> + <br/> +</div> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_settings.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_settings.html.erb index 347811ce841..db82d07cee7 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_settings.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_settings.html.erb @@ -1,5 +1,5 @@ <div id="plugins"> - <h1 class="marginbottom10"><%= message(@resource ? 'project_settings.page' : 'settings.page' ) -%></h1> + <h1 class="marginbottom10"><%= message(@resource ? 'project_settings.page' : 'settings.page') -%></h1> <table width="100%"> <tr> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_single_value.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_single_value.html.erb index 284a89f39cd..a08cc708b38 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_single_value.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_single_value.html.erb @@ -1 +1 @@ -<%= render "settings/type_#{property_type(property, value)}", :property => property, :value => value -%> +<%= render "settings/type_#{property_type(property, value)}", :property => property, :value => value, :name => input_name(property), :id => "input_#{h property.key}" -%> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_BOOLEAN.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_BOOLEAN.html.erb index b1643852f5c..117cf3b9127 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_BOOLEAN.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_BOOLEAN.html.erb @@ -1,4 +1,4 @@ -<select name="<%= input_name(property) -%>" id="input_<%= h property.getKey() -%>"> +<select name="<%= name -%>" id="<%= id -%>"> <option value="" <%= 'selected' if value.blank? -%>><%= message('default') -%></option> <option value="true" <%= 'selected' if value=='true' -%>><%= message('true') -%></option> <option value="false" <%= 'selected' if value=='false' -%>><%= message('false') -%></option> 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 9694f05758e..5f8b11660da 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 @@ -<input type="text" name="<%= input_name(property) -%>" value="<%= h value if value -%>" size="50" id="input_<%= h property.getKey() -%>"/>
\ No newline at end of file +<input type="text" name="<%= name -%>" value="<%= h value if value -%>" size="50" id="<%= id -%>"/>
\ 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 767aa39ad63..fa2b44e9788 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 @@ -<input type="text" name="<%= input_name(property) -%>" value="<%= h value if value -%>" size="50" id="input_<%= h property.getKey()-%>"/>
\ No newline at end of file +<input type="text" name="<%= name -%>" value="<%= h value if value -%>" size="50" id="<%= id-%>"/>
\ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_LICENSE.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_LICENSE.html.erb index 5080da013d1..ea93d74dec8 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_LICENSE.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_LICENSE.html.erb @@ -1,12 +1,12 @@ <% if !value || value.blank? %> - <textarea rows="5" cols="80" class="width100" name="<%= input_name(property) -%>" id="input_<%= h property.getKey() -%>"></textarea> + <textarea rows="5" cols="80" class="width100" name="<%= name -%>" id="<%= id -%>"></textarea> <% else license = controller.java_facade.parseLicense(value) date = license.getExpirationDateAsString() %> <div class="width100"> - <textarea rows="6" name="<%= input_name(property) -%>" id="input_<%= h property.getKey() -%>" style="float: left;width: 390px"><%= h value -%></textarea> + <textarea rows="6" name="<%= name -%>" id="<%= id -%>" style="float: left;width: 390px"><%= h value -%></textarea> <div style="margin-left: 400px"> <table> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_METRIC.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_METRIC.html.erb index ac5d599482c..c4329684079 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_METRIC.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_METRIC.html.erb @@ -1,4 +1,4 @@ -<select name="<%= input_name(property) -%>" id="input_<%= h property.getKey() -%>"> +<select name="<%= name -%>" id="<%= id -%>"> <option value=""><%= message('default') -%></option> <% metrics_per_domain={} 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 5b3a604ca8d..bb7e70b0721 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 @@ -<input type="password" name="<%= input_name(property) -%>" value="<%= h value if value -%>" size="50" id="input_<%= h property.getKey() -%>"/>
\ No newline at end of file +<input type="password" name="<%= name -%>" value="<%= h value if value -%>" size="50" id="<%= id -%>"/>
\ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_PROPERTY_SET.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_PROPERTY_SET.html.erb index 5a5928c9730..d7ce63aa0e6 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_PROPERTY_SET.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_PROPERTY_SET.html.erb @@ -1,4 +1,4 @@ -<select name="<%= input_name(property) -%>" id="input_<%= h property.getKey() -%>"> +<select name="<%= name -%>" id="<%= id -%>"> <option value=""><%= message('default') -%></option> <% Property.values(property.propertySetKey).reject(&:blank?).each do |set_key| -%> 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 3ebfdfffdf7..d51e73fc377 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 @@ -1,35 +1,11 @@ <% resource_id = @resource.id if @resource -%> <% Property.values(property.key, resource_id).reject(&:blank?).each do |set_key| -%> - <div class="multi_value"> - <%= text_field_tag "property_sets[#{property.key}][]", set_key -%> - <br/> - - <% property.fields.each do |field| -%> - <label><%= field.key -%>: </label><br/> - <%= text_field_tag "#{property.key}[#{field.key}][]", Property.value("#{property.key}.#{set_key}.#{field.key}", resource_id) -%> - <br/> - <% end -%> - - <a href="#" class="delete link-action"><%= message('delete') -%></a> - <br/><br/> - </div> + <%= render 'settings/set_instance', :property => property, :set_key => set_key, :resource_id => resource_id %> <% end -%> <div class="template" style="display:none;"> - <div class="multi_value"> - <%= text_field_tag "property_sets[#{property.key}][]" %> - <br/> - - <% property.fields.each do |field| -%> - <label><%= field.key -%>: </label><br/> - <%= text_field_tag "#{property.key}[#{field.key}][]" -%> - <br/> - <% end -%> - - <a href="#" class="delete link-action"><%= message('delete') -%></a> - <br/><br/> - </div> + <%= render 'settings/set_instance', :property => property, :set_key => nil, :resource_id => resource_id %> </div> <button class="add_value"><%= message('settings.add') -%></button> 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 9694f05758e..5f8b11660da 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 @@ -<input type="text" name="<%= input_name(property) -%>" value="<%= h value if value -%>" size="50" id="input_<%= h property.getKey() -%>"/>
\ No newline at end of file +<input type="text" name="<%= name -%>" value="<%= h value if value -%>" size="50" id="<%= id -%>"/>
\ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_SINGLE_SELECT_LIST.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_SINGLE_SELECT_LIST.html.erb index 1e6839f1524..e2ffefee9ec 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_SINGLE_SELECT_LIST.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_SINGLE_SELECT_LIST.html.erb @@ -1,4 +1,4 @@ -<select name="<%= input_name(property) -%>" id="input_<%= h property.key-%>"> +<select name="<%= name -%>" id="<%= id -%>"> <option value=""><%= message('default') -%></option> <% property.options.each do |option| %> <option value="<%= h option -%>" <%= 'selected' if value && value==option -%>><%= h option -%></option> 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 e1951b5f5a2..5f8b11660da 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 @@ -<input type="text" name="<%= input_name(property) -%>" value="<%= h value if value -%>" size="50" id="input_<%= property.key.parameterize -%>"/>
\ No newline at end of file +<input type="text" name="<%= name -%>" value="<%= h value if value -%>" size="50" id="<%= id -%>"/>
\ 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 ce59e4a8a07..f552d9c804d 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 @@ -<textarea rows="5" cols="80" class="width100" name="<%= input_name(property) -%>" id="input_<%= h property.getKey() -%>"><%= h value if value -%></textarea>
\ No newline at end of file +<textarea rows="5" cols="80" class="width100" name="<%= name -%>" id="<%= id -%>"><%= h value if value -%></textarea>
\ 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 d899710cd5c..3eefcc481bc 100644 --- a/sonar-server/src/main/webapp/stylesheets/style.css +++ b/sonar-server/src/main/webapp/stylesheets/style.css @@ -2424,3 +2424,23 @@ textarea.width100 { box-sizing: border-box; /* Opera/IE 8+ */ } +.field { + margin-bottom: 5px; +} + +.field label { + text-align: right; + width: 80px; + display: block; + float: left; + line-height: 1; + word-wrap: break-word; + position: relative; + padding-top: 5px; + padding-right: 5px; +} + +.field .note { + margin-top: 3px; + margin-left: 90px; +} |