]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3529 Better look. Use field property type
authorDavid Gageot <david@gageot.net>
Mon, 1 Oct 2012 08:58:42 +0000 (10:58 +0200)
committerDavid Gageot <david@gageot.net>
Mon, 1 Oct 2012 13:03:10 +0000 (15:03 +0200)
23 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/PropertyDefinition.java
sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyFieldDefinition.java
sonar-server/src/main/webapp/WEB-INF/app/helpers/settings_helper.rb
sonar-server/src/main/webapp/WEB-INF/app/models/property.rb
sonar-server/src/main/webapp/WEB-INF/app/views/settings/_properties.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/settings/_set_instance.html.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/settings/_settings.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/settings/_single_value.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_BOOLEAN.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_LICENSE.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_METRIC.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.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_SINGLE_SELECT_LIST.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 10ab1cbb50930cdcfcf2e6df2b0a392c9f9bd0ac..e10206e7952b0648bc159cdeec7f10c8c988d302 100644 (file)
@@ -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",
index 4f2c9e18dcebc8281024a5d7219ffcc4eac24747..c8114b724da949e78fff75407f5fd16e7130e3bc 100644 (file)
@@ -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;
index 7e497b49aaa14799a61f403ed4904fc3c3eaee3c..6025d79bd449183284fed91de0af906ddfea410d 100644 (file)
@@ -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")) {
index 51775b7fe4a3477a43027c3fd8266f740c41af7d..2a941b7a71cf588f01527d3db062bc5ad9bd5e5b 100644 (file)
@@ -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);
+  }
 }
index d6eb4b4345adc9e87166cc0284907753cf25001a..3376c8807d2d5a3fe2f6f3b9e2537d60f2b63cac 100644 (file)
@@ -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
index ec98d312c9abeddffdd256c7d7b5d4de228adf2b..e4bec485aaf32a59404f95b88d99a78d1582e73b 100644 (file)
@@ -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
index 8bc051e73396dc9b2d410dca98d2d65dc547c6f4..5d2e340b5c380676e4fd6ae3ce0faf87e4ddd9a3 100644 (file)
@@ -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 (file)
index 0000000..4cafb50
--- /dev/null
@@ -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>
index 347811ce84128cf5e5338a956666f98d95413134..db82d07cee750d2af3d2fe8e3bc7316f2ac50f95 100644 (file)
@@ -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>
index 284a89f39cd1a2b504fa7c35fbd6968dae1e55ad..a08cc708b38415d4aef8f0cedd2727af68280569 100644 (file)
@@ -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}" -%>
index b1643852f5c85fe85660e825d590e1d124d19123..117cf3b912771c629819af3c53b2d20ad86e8580 100644 (file)
@@ -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>
index 9694f05758ecafb47785ceffab7a4003f1dadd84..5f8b11660da6cbad9d62a433c9557d588942ab14 100644 (file)
@@ -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
index 767aa39ad63fb5c56491b53a2fc1f76eb5829fb4..fa2b44e9788ea51e0bb3023b67d6235e01940c6a 100644 (file)
@@ -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
index 5080da013d1d263b6e3d73ddf80d4d28f4c51a11..ea93d74dec8298d507a6859807f856dc78ccc9bb 100644 (file)
@@ -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>
index ac5d599482cac9218c5fdd3d7b30778756f853cc..c4329684079c881a327566a4ee5e1d5cdeade378 100644 (file)
@@ -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={}
index 5b3a604ca8d4bf43a0935aba2ff94b16b89f487c..bb7e70b07212499fe8d2a6643b056c59377571fe 100644 (file)
@@ -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
index 5a5928c97306704b852ffc919f61fe317fca9e70..d7ce63aa0e602030a3d5c34b3dc8591abdc0c918 100644 (file)
@@ -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| -%>
index 3ebfdfffdf7fbd8e04e7643c97b362b914a8d720..d51e73fc37771df93dea03fc3a4b5b3f1ce41b7e 100644 (file)
@@ -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>
index 9694f05758ecafb47785ceffab7a4003f1dadd84..5f8b11660da6cbad9d62a433c9557d588942ab14 100644 (file)
@@ -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
index 1e6839f1524992987741fe2c4dfb5e7138871124..e2ffefee9eca045ed1092ae4ddcaa773bda07198 100644 (file)
@@ -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>
index e1951b5f5a2a9c2b11b5226d6573a7010a857a27..5f8b11660da6cbad9d62a433c9557d588942ab14 100644 (file)
@@ -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
index ce59e4a8a07873ca9a193a260d61b3d6b7172be2..f552d9c804dfdb36b8a4542631ac7b1a42bdb703 100644 (file)
@@ -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
index d899710cd5cc8e96d920c26463e758e30baf19bb..3eefcc481bc7fdaadca5c0dc70a7f0179e6e2ce4 100644 (file)
@@ -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;
+}