From fde23fea9a61f0481ed29c550b925f9ac3babdff Mon Sep 17 00:00:00 2001 From: David Gageot Date: Fri, 4 May 2012 17:28:18 +0200 Subject: [PATCH] SONAR-1927 GUI to manage global dashboards --- .../app/controllers/dashboards_controller.rb | 20 ++++++++------- .../webapp/WEB-INF/app/models/dashboard.rb | 8 ++++-- .../app/views/admin_dashboards/index.html.erb | 25 ++++++++++++------- .../app/views/dashboard/_header.html.erb | 4 +-- .../app/views/dashboards/_create.html.erb | 14 +++++------ .../app/views/dashboards/_edit.html.erb | 19 ++++++++------ .../app/views/dashboards/index.html.erb | 12 ++++++--- .../app/views/layouts/_layout.html.erb | 6 ++--- 8 files changed, 62 insertions(+), 46 deletions(-) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboards_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboards_controller.rb index ca2d9141c9b..6df53e1107f 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboards_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboards_controller.rb @@ -30,15 +30,17 @@ class DashboardsController < ApplicationController active_dashboard_ids=@actives.map { |a| a.dashboard_id } @shared_dashboards.reject! { |d| active_dashboard_ids.include?(d.id) } - @resource=Project.by_key(params[:resource]) - if @resource.nil? + if params[:resource] + @resource=Project.by_key(params[:resource]) + if @resource.nil? # TODO display error page - redirect_to home_path - return false + redirect_to home_path + return false + end + access_denied unless has_role?(:user, @resource) + @snapshot = @resource.last_snapshot + @project=@resource # variable name used in old widgets end - access_denied unless has_role?(:user, @resource) - @snapshot = @resource.last_snapshot - @project=@resource # variable name used in old widgets end def create @@ -54,7 +56,7 @@ class DashboardsController < ApplicationController add_default_dashboards_if_first_user_dashboard last_active_dashboard=current_user.active_dashboards.max { |x, y| x.order_index<=>y.order_index } current_user.active_dashboards.create(:dashboard => @dashboard, :user_id => current_user.id, :order_index => (last_active_dashboard ? last_active_dashboard.order_index+1 : 1)) - redirect_to :controller => 'dashboard', :action => 'configure', :did => @dashboard.id, :id => params[:resource] + redirect_to :controller => 'dashboard', :action => 'configure', :did => @dashboard.id, :id => (params[:resource] unless @dashboard.global) else flash[:error]=@dashboard.errors.full_messages.join('
') redirect_to :controller => 'dashboards', :action => 'index', :resource => params[:resource] @@ -171,7 +173,7 @@ class DashboardsController < ApplicationController def load_dashboard_from_params(dashboard) dashboard.name=params[:name] dashboard.description=params[:description] - dashboard.global=(params[:global].present?) + dashboard.is_global=(params[:global].present?) dashboard.shared=(params[:shared].present? && is_admin?) dashboard.user_id=current_user.id dashboard.column_layout=Dashboard::DEFAULT_LAYOUT if !dashboard.column_layout diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/dashboard.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/dashboard.rb index 2fde1aa8544..1dfdc522b57 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/dashboard.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/dashboard.rb @@ -46,8 +46,12 @@ class Dashboard < ActiveRecord::Base read_attribute(:shared) || false end - def global? - read_attribute(:is_global) || false + def global=(global) + write_attribute(:is_global, global) + end + + def global + read_attribute(:is_global) end def layout diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/admin_dashboards/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/admin_dashboards/index.html.erb index 9590cd4ef35..ef900b49c1e 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/admin_dashboards/index.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/admin_dashboards/index.html.erb @@ -3,12 +3,12 @@ - - - - - - + + + + + + <% if @actives.empty? %> @@ -23,6 +23,9 @@
<%= active.dashboard.description %> + <% if is_admin %> <% end %> + @@ -96,6 +97,9 @@

<%= h dashboard.description -%>

<% end %> + diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb index d9be65e9e0b..9c1d3a854c8 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb @@ -42,9 +42,9 @@
  • <%= message('dependencies.page') -%>
  • - <% ActiveDashboard.user_dashboards(current_user).select { |active_dashboard| active_dashboard.dashboard.global? }.each do |active_dashboard| %> + <% ActiveDashboard.user_dashboards(current_user).select { |active_dashboard| active_dashboard.dashboard.global }.each do |active_dashboard| %>
  • - <%= active_dashboard.dashboard.name(true) -%> + <%= active_dashboard.dashboard.name(true) -%>
  • <% end %> @@ -57,7 +57,7 @@ <% end %> <% elsif selected_section==Navigation::SECTION_RESOURCE %> - <% ActiveDashboard.user_dashboards(current_user).select { |active_dashboard| !active_dashboard.dashboard.global? }.each do |active_dashboard| %> + <% ActiveDashboard.user_dashboards(current_user).select { |active_dashboard| !active_dashboard.dashboard.global }.each do |active_dashboard| %>
  • "><%= active_dashboard.dashboard.name(true) -%>
  • -- 2.39.5
    NameShared byOrderOperations
    <%= message('name') -%><%= message('global') -%><%= message('shared_by') -%><%= message('operations') -%>
    + <%= boolean_icon(active.dashboard.global) -%> + <%= h(active.dashboard.user.name) if active.dashboard.user %> <% if index>0 %> @@ -50,9 +53,10 @@ - - - + + + + @@ -68,6 +72,9 @@
    <%= dashboard.description %> + - - @@ -18,16 +18,14 @@ - - <% if is_admin? %> - + <% if is_admin? %> - - <% end %> + <% end %> + - diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_edit.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_edit.html.erb index 38a5c31c732..2b616de9166 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_edit.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_edit.html.erb @@ -5,28 +5,31 @@ - - - <% if is_admin? %> + <% if is_admin? %> + <% end %> -
    NameShared byOperations<%= message('name') -%><%= message('global') -%><%= message('shared_by') -%><%= message('operations') -%>
    + <%= boolean_icon(dashboard.global) -%> + <%= h(dashboard.user.name) if dashboard.user %> <%= link_to 'Add to defaults', {:action => 'add', :id => dashboard.id}, {:method => :post, :id => "add-#{u dashboard.name}", :class => 'link-action'} %> 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 20963d490eb..88350d6c99c 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 @@ -8,9 +8,7 @@
  • <%= link_to message('dashboard.configure_widgets'), dashboard_action(:configure) -%>
  • <%= link_to message('dashboard.edit_layout'), dashboard_action(:edit_layout) -%>
  • <% end %> - <% if @resource %> -
  • <%= link_to message('dashboard.manage_dashboards'), {:controller => :dashboards, :action => :index, :resource => @resource.id} -%>
  • - <% end %> +
  • <%= link_to message('dashboard.manage_dashboards'), {:controller => :dashboards, :action => :index, :resource => (@resource.id if @resource)} -%>
  • <% end %> <% end %> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_create.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_create.html.erb index 57e76dfc193..ce07999c2f4 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_create.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_create.html.erb @@ -5,12 +5,12 @@

    <%= message('dashboard.create_dashboard') -%>

    + <%= message('name') -%>:
    + <%= message('description') -%>:
    <%= message('global') -%>:
    <%= message('shared') -%>:
    +

    <%= message('dashboard.edit_dashboard') -%>

    + <%= message('name') -%>:
    + <%= message('description') -%>:
    - <%= message('shared') -%>:
    > + <%= message('global') -%>:
    >
    + <%= message('shared') -%>:
    > +
    - - <%= message('cancel') -%> + + + <%= message('cancel') -%>
    - \ No newline at end of file + diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/index.html.erb index e876fad2cc1..1398baf8de2 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/index.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/index.html.erb @@ -26,17 +26,17 @@ @actives.each_with_index do |active, index| %>
    - <%= link_to active.name(true), {:controller => :dashboard, :action => :index, :did => active.dashboard_id, :id => params[:resource]} -%> + <%= link_to active.name(true), {:controller => :dashboard, :action => :index, :did => active.dashboard_id, :id => (params[:resource] unless active.dashboard.global) } -%> <% if active.dashboard.description.present? %>

    <%= h active.dashboard.description -%>

    <% end %>
    - <%= boolean_icon(active.dashboard.global?) -%> + <%= boolean_icon(active.dashboard.global) -%> - <%= boolean_icon(active.dashboard.shared?) -%> + <%= boolean_icon(active.dashboard.shared) -%> @@ -51,7 +51,7 @@ <% if active.owner?(current_user) %> - <%= link_to message('dashboard.configure_widgets'), {:controller => :dashboard, :action => 'configure', :did => active.dashboard_id, :id => params[:resource]}, + <%= link_to message('dashboard.configure_widgets'), {:controller => :dashboard, :action => 'configure', :did => active.dashboard_id, :id => (params[:resource] unless active.dashboard.global)}, :id => "configure-#{u active.name}", :class => 'link-action' %> | <%= link_to_remote message('edit'), {:update => "admin_form", :url => {:action => "edit", :id => active.dashboard_id, :resource => params[:resource]}}, @@ -77,6 +77,7 @@
    <%= message('name') -%><%= message('global') -%> <%= message('shared_by') -%> <%= message('operations') -%>
    + <%= boolean_icon(dashboard.global) -%> + <%= dashboard.user_name -%>