From 4b5fad1f58747fc904b025bfd856738beac863bb Mon Sep 17 00:00:00 2001 From: David Gageot Date: Thu, 3 May 2012 15:34:35 +0200 Subject: [PATCH] SONAR-1927 Dashboard and Detached controller and views are now almost the same --- .../WEB-INF/app/helpers/dashboard_helper.rb | 84 ++++++++++--------- .../WEB-INF/app/helpers/detached_helper.rb | 24 ++++++ .../app/views/dashboard/_header.html.erb | 6 +- .../app/views/dashboard/_widget.html.erb | 4 +- .../dashboard/_widget_definition.html.erb | 8 +- .../app/views/dashboard/configure.html.erb | 2 +- .../app/views/dashboard/edit_layout.html.erb | 30 +++---- .../views/detached/_configure_widget.html.erb | 32 +++---- .../app/views/detached/_header.html.erb | 22 ++--- .../app/views/detached/_widget.html.erb | 2 +- .../detached/_widget_definition.html.erb | 8 +- .../detached/_widget_definitions.html.erb | 12 +-- .../detached/_widget_properties.html.erb | 46 +++++----- .../app/views/detached/configure.html.erb | 2 +- .../app/views/detached/edit_layout.html.erb | 30 +++---- .../app/views/detached/no_dashboard.html.erb | 28 +++++++ 16 files changed, 190 insertions(+), 150 deletions(-) create mode 100644 sonar-server/src/main/webapp/WEB-INF/app/helpers/detached_helper.rb create mode 100644 sonar-server/src/main/webapp/WEB-INF/app/views/detached/no_dashboard.html.erb diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/dashboard_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/dashboard_helper.rb index a5082f7087c..0688adfd643 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/dashboard_helper.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/dashboard_helper.rb @@ -21,59 +21,63 @@ module DashboardHelper include WidgetPropertiesHelper include MetricsHelper + def dashboard_action(action_name, opts={}) + { :action => action_name, :did => @dashboard.id, :id => @resource.id }.merge!(opts) + end + def formatted_value(measure, default='') - measure ? measure.formatted_value : default + measure ? measure.formatted_value : default end def measure(metric_key) - @snapshot.measure(metric_key) + @snapshot.measure(metric_key) end def period_select_options(snapshot, index) - label=period_label(snapshot, index) - if label - selected=(params[:period]==index.to_s ? 'selected' : '') - "" - else - nil - end + label=period_label(snapshot, index) + if label + selected=(params[:period]==index.to_s ? 'selected' : '') + "" + else + nil + end end def violation_period_select_options(snapshot, index) - return nil if snapshot.nil? || snapshot.project_snapshot.nil? - mode=snapshot.project_snapshot.send "period#{index}_mode" - mode_param=snapshot.project_snapshot.send "period#{index}_param" - date=snapshot.project_snapshot.send "period#{index}_date" + return nil if snapshot.nil? || snapshot.project_snapshot.nil? + mode=snapshot.project_snapshot.send "period#{index}_mode" + mode_param=snapshot.project_snapshot.send "period#{index}_param" + date=snapshot.project_snapshot.send "period#{index}_date" - if mode - if mode=='days' - label = message('added_over_x_days', :params => mode_param.to_s) - elsif mode=='version' - label = message('added_since_version', :params => mode_param.to_s) - elsif mode=='previous_analysis' - if !date.nil? - label = message('added_since_previous_analysis_detailed', :params => date.strftime("%Y %b. %d").to_s) - else - label = message('added_since_previous_analysis') - end - elsif mode=='date' - label = message('added_since', :params => date.strftime("%Y %b %d").to_s) - end - if label - selected=(params[:period]==index.to_s ? 'selected' : '') - "" - end - else - nil - end + if mode + if mode=='days' + label = message('added_over_x_days', :params => mode_param.to_s) + elsif mode=='version' + label = message('added_since_version', :params => mode_param.to_s) + elsif mode=='previous_analysis' + if !date.nil? + label = message('added_since_previous_analysis_detailed', :params => date.strftime("%Y %b. %d").to_s) + else + label = message('added_since_previous_analysis') + end + elsif mode=='date' + label = message('added_since', :params => date.strftime("%Y %b %d").to_s) + end + if label + selected=(params[:period]==index.to_s ? 'selected' : '') + "" + end + else + nil + end end def measure_or_variation_value(measure) - if measure - @period_index ? measure.variation(@period_index) : measure.value - else - nil - end + if measure + @period_index ? measure.variation(@period_index) : measure.value + else + nil + end end -end \ No newline at end of file +end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/detached_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/detached_helper.rb new file mode 100644 index 00000000000..0dbdb7335e8 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/detached_helper.rb @@ -0,0 +1,24 @@ +# +# Sonar, entreprise quality control tool. +# Copyright (C) 2008-2012 SonarSource +# mailto:contact AT sonarsource DOT com +# +# Sonar is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 3 of the License, or (at your option) any later version. +# +# Sonar is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with Sonar; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 +# +module DetachedHelper + def dashboard_action(action_name, opts={}) + { :action => action_name, :id => @dashboard.id }.merge!(opts) + end +end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/dashboard/_header.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/dashboard/_header.html.erb index 2d45e7756bb..4b380a85f58 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/dashboard/_header.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/dashboard/_header.html.erb @@ -2,11 +2,11 @@ <% if logged_in? %> <%= image_tag 'loading.gif', :style=>'vertical-align: top;display: none', :id => 'filter-widgets-loading' -%>

<% @widget_definitions.each_with_index do |definition, index| %> - <% if index%4==0 %><% end %> - <%= render :partial => 'widget_definition', :locals => {:definition => definition, :dashboard_id => dashboard_id, :category => category} %> - <% if index%4==3 %><% end %> + <% if index%4==0 %><% end %> + <%= render :partial => 'widget_definition', :locals => {:definition => definition, :dashboard_id => dashboard_id, :category => category} %> + <% if index%4==3 %><% end %> <% end %> <% for i in 0..(4-(@widget_definitions.size%4)) %> - + <% end %> <% if @widget_definitions.size%4<3 %> - + <% end %>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/detached/_widget_properties.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/detached/_widget_properties.html.erb index d4fa2588773..abcd69ca28d 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/detached/_widget_properties.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/detached/_widget_properties.html.erb @@ -2,29 +2,29 @@ :method => :post, :update => {:failure => "error#{widget.id}"}, :failure => "$('error#{widget.id}').show()" do -%> - - - - <% widget.java_definition.getWidgetProperties().sort {|w1, w2| natural_comparison(w1.key, w2.key) }.each do |property_def| %> - - - - - <% end %> + +
<%= property_def.key() -%><%= "*" unless property_def.optional()==true -%> - <%= property_value_field(property_def, widget.property_text_value(property_def.key())) -%> -
- <%= message("widget." + widget.key + ".param." + property_def.key(), :default => property_def.description()) -%> -
-
+ + <% widget.java_definition.getWidgetProperties().sort {|w1, w2| natural_comparison(w1.key, w2.key) }.each do |property_def| %> - + - -
- <%= submit_tag message('save') %> - <% if widget.configured %> - <%= message('cancel') -%> - <% end %> + <%= property_def.key() -%><%= "*" unless property_def.optional()==true -%> + <%= property_value_field(property_def, widget.property_text_value(property_def.key())) -%> +
+ <%= message("widget." + widget.key + ".param." + property_def.key(), :default => property_def.description()) -%> +
- <%= hidden_field_tag "widgetid", "", :class => "widgetid" %> -<% end -%> + <% end %> + + + <%= submit_tag message('save') %> + <% if widget.configured %> + <%= message('cancel') -%> + <% end %> + + + + + <%= hidden_field_tag "widgetid", "", :class => "widgetid" %> +<% end -%> \ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/detached/configure.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/detached/configure.html.erb index 037c71d66b8..a1dbbc595ed 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/detached/configure.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/detached/configure.html.erb @@ -14,7 +14,7 @@ highlight_duration:2, highlight_startcolor:'#cae3f2', highlight_endcolor:'#ffffff', - saveurl:'<%= url_for :action => 'set_dashboard', :id => @dashboard.id -%>' + saveurl:'<%= url_for dashboard_action(:set_dashboard) -%>' }; var portal; function init_dashboard() { diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/detached/edit_layout.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/detached/edit_layout.html.erb index 3023388e47d..cd3f8269ce5 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/detached/edit_layout.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/detached/edit_layout.html.erb @@ -2,27 +2,19 @@ <%= render :partial => 'header', :locals => {:back => true} %>
-

<%= message('dashboard.click_to_choose_layout') -%>:


+

<%= message('dashboard.click_to_choose_layout') -%>:


-
- <%= link_to image_tag('layout100.png'), {:action => 'set_layout', :id => @dashboard.id, :layout => "100%"}, :method => :post %> + <% {'100%', 'layout100.png', + '50%-50%', 'layout5050.png', + '30%-70%', 'layout3070.png', + '70%-30%', 'layout7030.png', + '33%-33%-33%', 'layout333333.png' + }.each_pair do |layout, picto| %> +
+ <%= link_to image_tag(picto), dashboard_action(:set_layout, :layout => layout), :method => :post %>
+ <% end %> -
" style="text-align:center;width: 20%;"> - <%= link_to image_tag('layout5050.png'), {:action => 'set_layout', :id => @dashboard.id, :layout => "50%-50%"}, :method => :post %> -
- -
" style="text-align:center;width: 20%;"> - <%= link_to image_tag('layout3070.png'), {:action => 'set_layout', :id => @dashboard.id, :layout => "30%-70%"}, :method => :post %> -
- -
" style="text-align:center;width: 20%;"> - <%= link_to image_tag('layout7030.png'), {:action => 'set_layout', :id => @dashboard.id, :layout => "70%-30%"}, :method => :post %> -
- -
" style="text-align:center;width: 19%;"> - <%= link_to image_tag('layout333333.png'), {:action => 'set_layout', :id => @dashboard.id, :layout => "33%-33%-33%"}, :method => :post %> -
-
+
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/detached/no_dashboard.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/detached/no_dashboard.html.erb new file mode 100644 index 00000000000..4043a26546b --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/detached/no_dashboard.html.erb @@ -0,0 +1,28 @@ +<%= render :partial => 'gwt/base', :locals => {:resource => nil, :popup => false, :metric => nil} -%> +<%= render :partial => 'gwt/resource_viewers' -%> + + +
+ + \ No newline at end of file -- 2.39.5