diff options
author | David Gageot <david@gageot.net> | 2012-05-09 15:35:55 +0200 |
---|---|---|
committer | David Gageot <david@gageot.net> | 2012-05-09 16:51:32 +0200 |
commit | c48688951a43985f3f96f42d6ed68aa61457ac86 (patch) | |
tree | 3eb1c3de19fe82a991853bae7c3b8e8d65290f92 /sonar-server | |
parent | 6d9c6c522a2760a85cf259924a83840e1b5d0e68 (diff) | |
download | sonarqube-c48688951a43985f3f96f42d6ed68aa61457ac86.tar.gz sonarqube-c48688951a43985f3f96f42d6ed68aa61457ac86.zip |
SONAR-1927 Add resource_id to widgets
Diffstat (limited to 'sonar-server')
9 files changed, 75 insertions, 47 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboard_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboard_controller.rb index 05758277929..464a7b35a3d 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboard_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboard_controller.rb @@ -128,6 +128,7 @@ class DashboardController < ApplicationController prop.save! end end + widget.resource_id=params[:resource_id] widget.configured=true widget.save! render :update do |page| @@ -186,7 +187,7 @@ class DashboardController < ApplicationController end def load_widget_definitions(dashboard, filter_on_category=nil) - @widget_definitions=java_facade.getWidgets().select { |w| w.isGlobal() == dashboard.global} + @widget_definitions=java_facade.getWidgets() @widget_categories=@widget_definitions.map(&:getWidgetCategories).flatten.uniq.sort unless filter_on_category.blank? 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 75f4442d3b3..2be2647d9f2 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 @@ -89,4 +89,28 @@ module DashboardHelper nil end end + + def switch_to_widget_resource(widget) + @backup_resource=@resource + @backup_project=@project + @backup_snapshot=@snapshot + @backup_dashboard_configuration=@dashboard_configuration + + if widget.resource_id + widget_resource = Project.find_by_id(widget.resource_id) + if widget_resource + @project = @resource = widget_resource + @snapshot=@resource.last_snapshot + @dashboard_configuration=Api::DashboardConfiguration.new(@dashboard, :period_index => params[:period], :snapshot => @snapshot) + end + end + end + + def restore_global_resource + @resource=@backup_resource + @project=@backup_project + @snapshot=@backup_snapshot + @dashboard_configuration=@backup_dashboard_configuration + end + end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/widget_properties_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/widget_properties_helper.rb index bf1e4792e4d..165b68b22c1 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/widget_properties_helper.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/widget_properties_helper.rb @@ -37,14 +37,15 @@ module WidgetPropertiesHelper text_field_tag definition.key(), val, :size => 10 elsif definition.type.name()==WidgetProperty::TYPE_FILTER - select_tag definition.key(), ::Filter.all.sort_by(&:id).collect { |f| "<option value='#{f.id}'>#{f.name}</option>" } - - elsif definition.type.name()==WidgetProperty::TYPE_PROJECT - select_tag definition.key(), Project.all(:conditions => {:scope => 'PRJ', :qualifier => 'TRK'}).collect { |f| "<option value='#{f.id}'>#{f.name}</option>" } + select_tag definition.key(), ::Filter.all.sort_by(&:id).collect { |f| "<option value='#{f.id}'" + (value == f.id.to_s ? " selected='selected'" : "") + ">#{f.name}</option>" } else hidden_field_tag definition.key() end end + def resource_value_field(value) + select_tag 'resource_id', Project.all(:conditions => {:scope => 'PRJ', :qualifier => 'TRK'}).collect { |f| "<option value='#{f.id}'" + (value == f.id ? " selected='selected'" : "") + ">#{f.name}</option>" } + end + end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/widget_property.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/widget_property.rb index 114b1440263..a26e8e5dfcb 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/widget_property.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/widget_property.rb @@ -24,7 +24,6 @@ class WidgetProperty < ActiveRecord::Base TYPE_STRING = 'STRING' TYPE_METRIC = 'METRIC' TYPE_FILTER = 'FILTER' - TYPE_PROJECT = 'PROJECT' belongs_to :widget @@ -85,8 +84,6 @@ class WidgetProperty < ActiveRecord::Base Metric.by_key(text) when TYPE_FILTER text.to_i - when TYPE_PROJECT - text.to_i else text end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/dashboard/_configure_widget.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/dashboard/_configure_widget.html.erb index 812e15e3d99..5a68ada50b7 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/dashboard/_configure_widget.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/dashboard/_configure_widget.html.erb @@ -1,16 +1,4 @@ -<% - @backup_resource=@resource - @backup_project=@project - @backup_snapshot=@snapshot - @backup_dashboard_configuration=@dashboard_configuration - - if widget.property_value('project') - @project = @resource = Project.find(widget.property_value('project')) - @snapshot=@resource.last_snapshot - @dashboard_configuration=Api::DashboardConfiguration.new(@dashboard, :period_index => params[:period], :snapshot => @snapshot) - end -%> - +<% switch_to_widget_resource(widget) %> <% begin widget_body=render :inline => widget.java_definition.getTarget().getTemplate(), :locals => {:widget_properties => widget.properties_as_hash, :widget => widget, :dashboard_configuration => @dashboard_configuration} @@ -23,7 +11,7 @@ <div class="widget-header"> <div class="widget-actions"> - <% if widget.java_definition.isEditable() %> + <% if widget.java_definition.isEditable() || (!widget.java_definition.global && @dashboard.global) %> <a class="link-action" onclick="portal.editWidget(<%= widget.id -%>);return false;"><%= message('edit') -%></a> <% end %> <a class="link-action" onclick="portal.deleteWidget(this);return false;"><%= message('delete') -%></a> @@ -64,11 +52,6 @@ <div style="clear: both;"></div> </div> -<% - @resource=@backup_resource - @project=@backup_project - @snapshot=@backup_snapshot - @dashboard_configuration=@backup_dashboard_configuration -%> +<% restore_global_resource %> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/dashboard/_widget.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/dashboard/_widget.html.erb index 474737e744b..3c24067b55e 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/dashboard/_widget.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/dashboard/_widget.html.erb @@ -1,15 +1,4 @@ -<% - @backup_resource=@resource - @backup_project=@project - @backup_snapshot=@snapshot - @backup_dashboard_configuration=@dashboard_configuration - - if widget.property_value('project') - @project = @resource = Project.find(widget.property_value('project')) - @snapshot=@resource.last_snapshot - @dashboard_configuration=Api::DashboardConfiguration.new(@dashboard, :period_index => params[:period], :snapshot => @snapshot) - end -%> +<% switch_to_widget_resource(widget) %> <div class="<%= h widget.key -%>" style="height:100%;"> <% if widget.configured @@ -43,9 +32,4 @@ <div style="clear: both;"></div> </div> -<% - @resource=@backup_resource - @project=@backup_project - @snapshot=@backup_snapshot - @dashboard_configuration=@backup_dashboard_configuration -%> +<% restore_global_resource %> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/dashboard/_widget_properties.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/dashboard/_widget_properties.html.erb index 839de6ccad7..2692fd4a5bf 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/dashboard/_widget_properties.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/dashboard/_widget_properties.html.erb @@ -16,6 +16,14 @@ </td> </tr> <% end %> + + <% if !widget.java_definition.global && @dashboard.global %> + <tr> + <td class="form-key-cell"><%= message('widget.resource_id') %></td> + <td class="form-val-cell" id="row_resource"><%= resource_value_field(widget.resource_id) -%></td> + </tr> + <% end %> + <tr> <td colspan="2"> <%= submit_tag message('save') %> diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/256_add_measures_person.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/256_add_measures_person.rb index 88df6ccc464..34ce0a952e7 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/256_add_measures_person.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/256_add_measures_person.rb @@ -24,7 +24,7 @@ class AddMeasuresPerson < ActiveRecord::Migration def self.up - add_column 'project_measures', 'person_id', :integer, :null => true + add_column 'project_measures', 'person_id', :integer, :null => true end end diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/301_add_resource_id_to_widgets.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/301_add_resource_id_to_widgets.rb new file mode 100644 index 00000000000..7b5e31c7d03 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/301_add_resource_id_to_widgets.rb @@ -0,0 +1,30 @@ +# +# 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 +# + +# +# Sonar 3.1 +# +class AddResourceIdToWidgets < ActiveRecord::Migration + + def self.up + add_column 'widgets', 'resource_id', :integer, :null => true + end + +end |