]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4761 Use modal windows in Manual Metrics pages
authorstephenbroyer <stephen.broyer@sonarsource.com>
Thu, 24 Oct 2013 15:43:59 +0000 (17:43 +0200)
committerstephenbroyer <stephen.broyer@sonarsource.com>
Wed, 30 Oct 2013 15:09:59 +0000 (16:09 +0100)
sonar-server/src/main/webapp/WEB-INF/app/controllers/metrics_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/views/metrics/_create_form.html.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/metrics/_edit_form.html.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/metrics/_reactivate_form.html.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/metrics/index.html.erb

index 88329e02ab00a2eb49c089ce637e964868c98fb5..3583ed33f4513082f66de0c00b3771a32b2f6f95 100644 (file)
@@ -35,6 +35,31 @@ class MetricsController < ApplicationController
     render :action => 'index'
   end
 
+ def create_form
+    prepare_metrics_and_domains
+
+    if params['id']
+      @metric=Metric.find(params['id'].to_i)
+      params['domain']=@metric.domain(false)
+    else
+      @metric=Metric.new
+    end
+    render :partial => 'metrics/create_form'
+  end
+
+  def edit_form
+    prepare_metrics_and_domains
+
+    @metric=Metric.find(params['id'].to_i)
+    params['domain']=@metric.domain(false)
+
+    render :partial => 'metrics/edit_form'
+  end
+
+  def reactivate_form
+    render :partial => 'metrics/reactivate_form'
+  end
+
   def save_from_web
     short_name = params[:metric][:short_name]
     metric_name = short_name.downcase.gsub(/\s/, '_')[0..59]
@@ -74,12 +99,17 @@ class MetricsController < ApplicationController
         end
       end
     rescue
-      flash[:error] = metric.errors.full_messages.join("<br/>\n")
+      @errors = []
+      @errors << metric.errors.full_messages.join("<br/>\n")
     end
     
     if @reactivate_metric
       prepare_metrics_and_domains
-      render :action => 'index'
+      render :partial => 'metrics/reactivate_form', :status => 400
+    elsif @errors
+      @metric = metric
+      @domains = metric.domain
+      render :partial => 'metrics/create_form', :status => 400
     else
       redirect_to :action => 'index', :domain => metric.domain(false)
     end
@@ -98,12 +128,15 @@ class MetricsController < ApplicationController
     redirect_to :action => 'index', :domain => metric.domain(false)
   end
 
+
   def delete_from_web
     metric = Metric.by_id(params[:id].to_i) if params[:id] && params[:id].size > 0
     if metric
       Metric.delete_with_manual_measures(params[:id].to_i)
       flash[:notice] = 'Successfully deleted.'
       Metric.clear_cache
+    else
+      flash[:error] = 'Sorry there was a problem with deleting'
     end
     redirect_to :action => 'index'
   end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/metrics/_create_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/metrics/_create_form.html.erb
new file mode 100644 (file)
index 0000000..9343c7a
--- /dev/null
@@ -0,0 +1,35 @@
+<% form_for :metric, @metric, :url => { :action => 'save_from_web', :id => @metric.id }, :html => { :id =>'metric_create_form', :method => 'post'} do |f| %>
+  <fieldset>
+    <div class="modal-head">
+      <h2>Create Manual Metric</h2>
+    </div>
+    <div class="modal-body">
+      <% if @errors %>
+        <p class="error"><%= @errors -%></p>
+      <% end %>
+
+      <div class="modal-field">
+        <label for="user[login]">Name <em class="mandatory">*</em></label><%= f.text_field :short_name %><br/>
+      </div>
+      <div class="modal-field">
+        <label for="user[login]"> Description</label><%= f.text_area :description, :size => 40, :cols => 25, :rows => 2 %><br/>
+      </div>
+      <div class="modal-field">
+        <label for="user[login]">Domain</label><%= f.select( :domain, @domains, :include_blank => true) %>
+        <span class="desc">or</span> <input id="newdomain" name="newdomain" size="15" type="text"><br/><br/>
+      </div>
+      <div class="modal-field">
+        <label for="user[login]">Type</label><%= f.select( :val_type, Metric.value_type_names.invert) %><br/>
+      </div>
+    </div>
+
+    <div class="modal-foot">
+      <%= submit_tag 'create'%>
+      <%= link_to message('cancel'), { :controller => 'metrics', :action => 'index', :id => nil}, { :class => 'action' } %>
+    </div>
+  </fieldset>
+<% end %>
+
+<script>
+  $j("#metric_create_form").modalForm();
+</script>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/metrics/_edit_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/metrics/_edit_form.html.erb
new file mode 100644 (file)
index 0000000..5bb510b
--- /dev/null
@@ -0,0 +1,35 @@
+<% form_for :metric, @metric, :url => { :action => 'save_from_web', :id => @metric.id }, :html => { :id =>'metric_edit_form', :method => 'post'} do |f| %>
+  <fieldset>
+      <div class="modal-head">
+          <h2>Edit Manual Metric: <%= @metric.key -%></h2>
+      </div>
+      <div class="modal-body">
+          <% if @errors %>
+            <p class="error"><%= @errors -%></p>
+          <% end %>
+
+          <div class="modal-field">
+              <label for="user[login]">Name <em class="mandatory">*</em></label><%= f.text_field :short_name %><br/>
+          </div>
+          <div class="modal-field">
+              <label for="user[login]"> Description</label><%= f.text_area :description, :size => 40, :cols => 25, :rows => 2 %><br/>
+          </div>
+          <div class="modal-field">
+              <label for="user[login]">Domain</label><%= f.select( :domain, @domains, :include_blank => true) %>
+              <span class="desc">or</span> <input id="newdomain" name="newdomain" size="15" type="text"><br/><br/>
+          </div>
+          <div class="modal-field">
+              <label for="user[login]">Type</label><%= f.select( :val_type, Metric.value_type_names.invert) %><br/>
+          </div>
+      </div>
+
+      <div class="modal-foot">
+          <%= submit_tag 'Save' %>
+          <%= link_to message('cancel'), { :controller => 'metrics', :action => 'index', :id => nil}, { :class => 'action' } %>
+      </div>
+  </fieldset>
+<% end %>
+
+<script>
+  $j("#metric_edit_form").modalForm();
+</script>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/metrics/_reactivate_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/metrics/_reactivate_form.html.erb
new file mode 100644 (file)
index 0000000..ff413c2
--- /dev/null
@@ -0,0 +1,22 @@
+<% form_for :metric, @reactivate_metric, :url => { :action => 'reactivate', :id => @reactivate_metric.id }, :html => { :id =>'metric_reactivate_form', :method => 'post'} do |f| %>
+  <fieldset>
+      <div class="modal-head">
+          <h2>Reactivate Manual Metric: <%= @reactivate_metric.key -%></h2>
+      </div>
+      <div class="modal-body">
+          <p class="error">
+              A metric named "<%= @reactivate_metric.short_name(false) -%>" already exists in the database but is deactivated.<br/>
+              <br/>
+              Do you really want to reactivate this metric?
+          </p>
+      </div>
+      <div class="modal-foot">
+          <%= submit_tag 'Reactivate' %>
+          <%= link_to message('cancel'), { :controller => 'metrics', :action => 'index', :id => nil}, { :class => 'action' } %>
+      </div>
+  </fieldset>
+<% end %>
+
+<script>
+  $j("#metric_reactivate_form").modalForm();
+</script>
index bf574c503f36e548728c34bb61146c9db1b5eb45..b94bdf07c8efdde5f13179ecffee40f279e13023 100644 (file)
@@ -1,7 +1,17 @@
+<div class="line-block">
+    <% if profiles_administrator? %>
+      <ul style="float: right" class="horizontal">
+          <li class="marginleft10 add">
+              <a id="create-link-metric" href="<%=ApplicationController.root_context-%>/metrics/create_form" id="create-link-metric" class="open-modal link-action">Add new metric</a>
+          </li>
+      </ul>
+    <% end %>
+    <h1 class="marginbottom10"><%= message('manual_metrics.page') -%></h1>
+</div>
+
 <table width="100%">
   <tr>
     <td valign="top">
-      <h1 class="marginbottom10"><%= message('manual_metrics.page') -%></h1>
       <table class="sortable data width100" id="metrics">
         <thead>
           <tr>
           </tr>
         </thead>
         <tbody>
-      <% @metrics.each do |metric| %>
-        <tr>
-          <td class="left" nowrap id="metric_key_<%= metric.key -%>"><span class="note"><%= metric.key -%></span></td>
-          <td class="left" nowrap id="metric_name_<%= metric.key -%>"><%= h metric.short_name -%></td>
-          <td class="left" id="metric_desc_<%= metric.key -%>"><%= h metric.description -%></td>
-          <td class="left" id="metric_domain_<%= metric.key -%>"><%= metric.domain -%></td>
-          <td class="left" id="metric_type_name<%= metric.key -%>"><%= metric.value_type_name -%></td>
-          <td class="right thin nowrap">
-          <% if is_admin? %>
-            <%= link_to 'Edit', {:action => 'index', :id => metric.id}, {:class => 'link-action', :id => "edit_#{h(metric.short_name)}", :method => 'get'} %>
-            &nbsp;
-            <%= link_to 'Delete', {:action => 'delete_from_web', :id => metric.id}, {:confirm => "Warning : all the measures will be deleted.", :class => 'link-action link-red', :id => "delete_#{h(metric.short_name)}"} %>
-          <% end %>
-          </td>
-        </tr>
-      <% end %>
-      </tbody>
-    </table>
-    <script>TableKit.Sortable.init('metrics');</script>
-  </td>
-<% if is_admin? %>
-  <td class="sep"> </td>
-  <td valign="top" align="right" width="210">
-    <table class="admintable"  width="100%">
-    <% if @reactivate_metric %>
-      <% form_for :metric, @reactivate_metric, :url => { :action => 'reactivate', :id => @reactivate_metric.id } do |f| %>
-      <tbody>
-        <tr>
-          <td>
-            <p class="error">
-              A metric named "<%= @reactivate_metric.short_name(false) -%>" already exists in the database but is deactivated.<br/>
-              <br/>
-              Do you really want to reactivate this metric?
-            </p>
-          </td>
-        <tr>
-        <tr>
-          <td class="left" valign="top">
-            <input type="hidden" name="reactivate" value="true"/>
-            <%= submit_tag 'Reactivate metric' %>
-            <%= link_to 'Cancel', { :controller => 'metrics', :action => 'index'}, { :class => 'action' } %><br/>
-          </td>
-        </tr>
-      </tbody>
-      <% end %>
-    <% else %>
-      <% form_for :metric, @metric, :url => { :action => 'save_from_web', :id => @metric.id } do |f| %>
-      <tbody>
-        <tr>
-          <td class="left"><h1 class="marginbottom10"><%= @metric && @metric.id.nil? ? 'Create Manual Metric' : 'Edit Manual Metric' -%></h1></td>
-        </tr>
-        <tr>
-          <td class="left" valign="top">
-            Name:<br/><%= f.text_field :short_name %><br/>
-            <span class="desc">Ex. : Configuration management</span>
-          </td>
-        </tr>
-        <tr>
-          <td class="left" valign="top">
-            Description:<br/>
-            <%= f.text_area :description, :size => 40, :cols => 25, :rows => 2 %><br/>
-            <span class="desc">Ex. : Respect level of the configuration management procedure (branch, label, ...), from 0% (worst) to 100% (best).</span>
-          </td>
-        </tr>
-        <tr>
-          <td class="left" valign="top">
-            Domain:<br/>
-            <%= f.select( :domain, @domains, :include_blank => true) %>
-            <span class="desc">or</span> <input id="newdomain" name="newdomain" size="15" type="text">
-          </td>
-        </tr>
-        <tr>
-          <td class="left" valign="top">
-            Type:<br/>
-            <%= f.select( :val_type, Metric.value_type_names.invert) %>
-          </td>
-        </tr>
-        <tr>
-          <td class="left" valign="top">
-            <%= submit_tag @metric.id.nil? ? message('create') : message('edit') %>
-            <%= link_to message('cancel'), { :controller => 'metrics', :action => 'index', :id => nil}, { :class => 'action' } %>
-          </td>
-        </tr>
-      </tbody>
-      <% end %>
-    <% end %>
-    </table>
-  </td>
-<% end %>
+        <% @metrics.each do |metric| %>
+          <tr>
+            <td class="left" nowrap id="metric_key_<%= metric.key -%>"><span class="note"><%= metric.key -%></span></td>
+            <td class="left" nowrap id="metric_name_<%= metric.key -%>"><%= h metric.short_name -%></td>
+            <td class="left" id="metric_desc_<%= metric.key -%>"><%= h metric.description -%></td>
+            <td class="left" id="metric_domain_<%= metric.key -%>"><%= metric.domain -%></td>
+            <td class="left" id="metric_type_name<%= metric.key -%>"><%= metric.value_type_name -%></td>
+            <td class="right thin nowrap">
+            <% if is_admin? %>
+             <a id="create-link-metric" href="<%=ApplicationController.root_context-%>/metrics/edit_form/<%= metric.id -%>" id="edit_<%= h(metric.short_name)-%>" class="open-modal link-action">Edit</a>
+              &nbsp;
+              <%= link_to_action message('delete'), "#{ApplicationController.root_context}/metrics/delete_from_web/#{metric.id}",
+                                 :class => 'link-action link-red',
+                                 :id => "delete_#{h(metric.short_name)}",
+                                 :confirm_button => message('delete'),
+                                 :confirm_title => 'Delete manual metric: '+ metric.key,
+                                 :confirm_msg => 'Warning : all the measures will be deleted.',
+                                 :confirm_msg_params => [metric.id]
+              -%>
+            <% end %>
+            </td>
+          </tr>
+        <% end %>
+        </tbody>
+      </table>
+      <script>TableKit.Sortable.init('metrics');</script>
+    </td>
   </tr>
 </table>