From c48688951a43985f3f96f42d6ed68aa61457ac86 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Wed, 9 May 2012 15:35:55 +0200 Subject: [PATCH] SONAR-1927 Add resource_id to widgets --- .../core/widgets/TestComplexityWidget.java | 9 +----- .../resources/org/sonar/l10n/core.properties | 2 ++ .../org/sonar/core/dashboard/WidgetDto.java | 17 +++++++++++ .../core/persistence/DatabaseVersion.java | 2 +- .../core/dashboard/WidgetMapper-oracle.xml | 4 +-- .../org/sonar/core/dashboard/WidgetMapper.xml | 4 +-- .../org/sonar/core/persistence/rows-derby.sql | 1 + .../sonar/core/persistence/schema-derby.ddl | 3 +- .../DashboardDaoTest/shouldInsert-result.xml | 1 + ...shouldInsertWithNullableColumns-result.xml | 1 + .../org/sonar/api/web/WidgetPropertyType.java | 3 +- .../app/controllers/dashboard_controller.rb | 3 +- .../WEB-INF/app/helpers/dashboard_helper.rb | 24 +++++++++++++++ .../app/helpers/widget_properties_helper.rb | 9 +++--- .../WEB-INF/app/models/widget_property.rb | 3 -- .../dashboard/_configure_widget.html.erb | 23 ++------------ .../app/views/dashboard/_widget.html.erb | 20 ++----------- .../dashboard/_widget_properties.html.erb | 8 +++++ .../db/migrate/256_add_measures_person.rb | 2 +- .../migrate/301_add_resource_id_to_widgets.rb | 30 +++++++++++++++++++ 20 files changed, 106 insertions(+), 63 deletions(-) create mode 100644 sonar-server/src/main/webapp/WEB-INF/db/migrate/301_add_resource_id_to_widgets.rb diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/TestComplexityWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/TestComplexityWidget.java index 28164e7130e..2f17f6d480b 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/TestComplexityWidget.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/TestComplexityWidget.java @@ -19,20 +19,13 @@ */ package org.sonar.plugins.core.widgets; -import org.sonar.api.web.WidgetCategory; - import org.sonar.api.web.AbstractRubyTemplate; import org.sonar.api.web.RubyRailsWidget; +import org.sonar.api.web.WidgetCategory; import org.sonar.api.web.WidgetGlobal; -import org.sonar.api.web.WidgetProperties; -import org.sonar.api.web.WidgetProperty; -import org.sonar.api.web.WidgetPropertyType; @WidgetCategory({"Global", "Complexity"}) @WidgetGlobal -@WidgetProperties({ - @WidgetProperty(key = "project", type = WidgetPropertyType.PROJECT, defaultValue = "1") -}) public class TestComplexityWidget extends AbstractRubyTemplate implements RubyRailsWidget { public String getId() { diff --git a/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties index ec5569bc335..ec8b5fc9958 100644 --- a/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties +++ b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties @@ -763,6 +763,8 @@ widget.image.description=Shows an image with a link widget.filter.name=Filter widget.filter.description=Shows a pre-configured filter +widget.resource_id=Project + #------------------------------------------------------------------------------ # # COMPONENTS diff --git a/sonar-core/src/main/java/org/sonar/core/dashboard/WidgetDto.java b/sonar-core/src/main/java/org/sonar/core/dashboard/WidgetDto.java index 26ae0bd6bc3..87c62115f54 100644 --- a/sonar-core/src/main/java/org/sonar/core/dashboard/WidgetDto.java +++ b/sonar-core/src/main/java/org/sonar/core/dashboard/WidgetDto.java @@ -37,6 +37,7 @@ public final class WidgetDto { private boolean configured; private Date createdAt; private Date updatedAt; + private Integer resourceId; private List widgetPropertyDtos = Lists.newArrayList(); /** @@ -193,4 +194,20 @@ public final class WidgetDto { widgetPropertyDtos.add(widgetPropertyDto); } + /** + * @return the resourceId + * @since 3.1 + */ + public Integer getResourceId() { + return resourceId; + } + + /** + * @param resourceId the resourceId to set + * @since 3.1 + */ + public void setResourceId(Integer resourceId) { + this.resourceId = resourceId; + } + } diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java index d26b251ea91..d5d6342afd0 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java @@ -32,7 +32,7 @@ import java.util.List; */ public class DatabaseVersion implements BatchComponent, ServerComponent { - public static final int LAST_VERSION = 300; + public static final int LAST_VERSION = 301; public static enum Status { UP_TO_DATE, REQUIRES_UPGRADE, REQUIRES_DOWNGRADE, FRESH_INSTALL diff --git a/sonar-core/src/main/resources/org/sonar/core/dashboard/WidgetMapper-oracle.xml b/sonar-core/src/main/resources/org/sonar/core/dashboard/WidgetMapper-oracle.xml index c0cd07c75f5..7a9360e602e 100644 --- a/sonar-core/src/main/resources/org/sonar/core/dashboard/WidgetMapper-oracle.xml +++ b/sonar-core/src/main/resources/org/sonar/core/dashboard/WidgetMapper-oracle.xml @@ -7,9 +7,9 @@ select widgets_seq.NEXTVAL from DUAL - INSERT INTO widgets (id, dashboard_id, widget_key, name, description, column_index, row_index, configured, created_at, updated_at) + INSERT INTO widgets (id, dashboard_id, widget_key, name, description, column_index, row_index, configured, created_at, updated_at, resource_id) VALUES (#{id}, #{dashboardId}, #{key}, #{name, jdbcType=VARCHAR}, #{description, jdbcType=VARCHAR}, #{columnIndex, jdbcType=INTEGER}, - #{rowIndex, jdbcType=INTEGER}, #{configured}, #{createdAt, jdbcType=TIMESTAMP}, #{updatedAt, jdbcType=TIMESTAMP}) + #{rowIndex, jdbcType=INTEGER}, #{configured}, #{createdAt, jdbcType=TIMESTAMP}, #{updatedAt, jdbcType=TIMESTAMP}, #{resource_id, jdbcType=INTEGER}) diff --git a/sonar-core/src/main/resources/org/sonar/core/dashboard/WidgetMapper.xml b/sonar-core/src/main/resources/org/sonar/core/dashboard/WidgetMapper.xml index e5346f86178..c9e42294df8 100644 --- a/sonar-core/src/main/resources/org/sonar/core/dashboard/WidgetMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/dashboard/WidgetMapper.xml @@ -4,9 +4,9 @@ - INSERT INTO widgets (dashboard_id, widget_key, name, description, column_index, row_index, configured, created_at, updated_at) + INSERT INTO widgets (dashboard_id, widget_key, name, description, column_index, row_index, configured, created_at, updated_at, resource_id) VALUES (#{dashboardId}, #{key}, #{name, jdbcType=VARCHAR}, #{description, jdbcType=VARCHAR}, #{columnIndex, jdbcType=INTEGER}, - #{rowIndex, jdbcType=INTEGER}, #{configured}, #{createdAt, jdbcType=TIMESTAMP}, #{updatedAt, jdbcType=TIMESTAMP}) + #{rowIndex, jdbcType=INTEGER}, #{configured}, #{createdAt, jdbcType=TIMESTAMP}, #{updatedAt, jdbcType=TIMESTAMP}, #{resourceId, jdbcType=INTEGER}) diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-derby.sql b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-derby.sql index 73cd0a3d508..fa11486724e 100644 --- a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-derby.sql +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-derby.sql @@ -188,6 +188,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('285'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('286'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('287'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('300'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('301'); INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, 'admin', 'Administrator', '', 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '2011-09-26 22:27:48.0', '2011-09-26 22:27:48.0', null, null); ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2; diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-derby.ddl b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-derby.ddl index 01c32cb84a8..7fc40b9ab99 100644 --- a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-derby.ddl +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-derby.ddl @@ -86,7 +86,8 @@ CREATE TABLE "WIDGETS" ( "ROW_INDEX" INTEGER, "CONFIGURED" BOOLEAN, "CREATED_AT" TIMESTAMP, - "UPDATED_AT" TIMESTAMP + "UPDATED_AT" TIMESTAMP, + "RESOURCE_ID" INTEGER ); CREATE TABLE "FILTER_COLUMNS" ( diff --git a/sonar-core/src/test/resources/org/sonar/core/dashboard/DashboardDaoTest/shouldInsert-result.xml b/sonar-core/src/test/resources/org/sonar/core/dashboard/DashboardDaoTest/shouldInsert-result.xml index 68bd31b0ba2..88d85435cdd 100644 --- a/sonar-core/src/test/resources/org/sonar/core/dashboard/DashboardDaoTest/shouldInsert-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/dashboard/DashboardDaoTest/shouldInsert-result.xml @@ -19,6 +19,7 @@ column_index="13" row_index="14" configured="[true]" + resource_id="[null]" /> 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| "" } - - elsif definition.type.name()==WidgetProperty::TYPE_PROJECT - select_tag definition.key(), Project.all(:conditions => {:scope => 'PRJ', :qualifier => 'TRK'}).collect { |f| "" } + select_tag definition.key(), ::Filter.all.sort_by(&:id).collect { |f| "" } 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| "" } + 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 @@
- <% if widget.java_definition.isEditable() %> + <% if widget.java_definition.isEditable() || (!widget.java_definition.global && @dashboard.global) %> <%= message('edit') -%> <% end %> <%= message('delete') -%> @@ -64,11 +52,6 @@
-<% - @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) %>
<% if widget.configured @@ -43,9 +32,4 @@
-<% - @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 @@ <% end %> + + <% if !widget.java_definition.global && @dashboard.global %> + + <%= message('widget.resource_id') %> + <%= resource_value_field(widget.resource_id) -%> + + <% end %> + <%= 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 -- 2.39.5