From 1157d48769148780ad46699d0bae8ddb349b60bf Mon Sep 17 00:00:00 2001 From: simonbrandhof Date: Tue, 11 Oct 2011 22:19:38 +0200 Subject: [PATCH] SONAR-2771 Allow to render a single widget --- .../app/controllers/widget_controller.rb | 52 +++++++++++++++++++ .../WEB-INF/app/views/widget/index.html.erb | 3 ++ 2 files changed, 55 insertions(+) create mode 100644 sonar-server/src/main/webapp/WEB-INF/app/controllers/widget_controller.rb create mode 100644 sonar-server/src/main/webapp/WEB-INF/app/views/widget/index.html.erb diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/widget_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/widget_controller.rb new file mode 100644 index 00000000000..5cf7d9027a8 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/widget_controller.rb @@ -0,0 +1,52 @@ +# +# Sonar, entreprise quality control tool. +# Copyright (C) 2008-2011 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 +# +class WidgetController < ApplicationController + helper :dashboard + + SECTION=Navigation::SECTION_RESOURCE + + def index + begin + load_widget + load_resource + params[:layout]='false' + render :action => 'index' + + rescue Exception => e + render :text => e + end + end + + private + + def load_resource + @resource=Project.by_key(params[:resource]) + return access_denied unless has_role?(:user, @resource) + @snapshot = @resource.last_snapshot + end + + def load_widget + @widget=Widget.find(:first, :conditions => {:widget_key => params[:id]}) + if @widget + @widget_definition = java_facade.getWidget(@widget.key) + @dashboard_configuration=Api::DashboardConfiguration.new(nil, :period_index => params[:period], :snapshot => @snapshot) + end + end +end \ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/widget/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/widget/index.html.erb new file mode 100644 index 00000000000..a00dea3781f --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/widget/index.html.erb @@ -0,0 +1,3 @@ +
+ <%= render :partial => 'dashboard/widget', :locals => {:widget => @widget, :definition => @widget_definition} %> +
\ No newline at end of file -- 2.39.5