From: David Gageot Date: Tue, 19 Jun 2012 12:46:02 +0000 (+0200) Subject: SONAR-3512 Make it possible to share a dashboard without following it X-Git-Tag: 3.2~309 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2429fd3fb4d70b7a5be8774ae5101ec350100299;p=sonarqube.git SONAR-3512 Make it possible to share a dashboard without following it Any dashboard can be edited or configured --- 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 5729a5283ee..eedcb926c5d 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 @@ -143,33 +143,38 @@ class DashboardController < ApplicationController private def load_dashboard - @active=nil + active=nil + @dashboard=nil if logged_in? if params[:did] - @active=ActiveDashboard.find(:first, :include => 'dashboard', :conditions => ['active_dashboards.dashboard_id=? AND active_dashboards.user_id=?', params[:did].to_i, current_user.id]) + @dashboard=Dashboard.find(:first, :conditions => ['id=? AND user_id=?', params[:did].to_i, current_user.id]) elsif params[:name] - @active=ActiveDashboard.find(:first, :include => 'dashboard', :conditions => ['dashboards.name=? AND active_dashboards.user_id=?', params[:name], current_user.id]) + @dashboard=Dashboard.find(:first, :conditions => ['name=? AND user_id=?', params[:name], current_user.id]) elsif params[:id] - @active=ActiveDashboard.user_dashboards(current_user, false).first + active=ActiveDashboard.user_dashboards(current_user, false).first else - @active=ActiveDashboard.user_dashboards(current_user, true).first + active=ActiveDashboard.user_dashboards(current_user, true).first end end - if @active.nil? + unless active or @dashboard # anonymous or not found in user dashboards if params[:did] - @active=ActiveDashboard.find(:first, :include => 'dashboard', :conditions => ['active_dashboards.dashboard_id=? AND active_dashboards.user_id IS NULL', params[:did].to_i]) + @dashboard=Dashboard.find(:first, :conditions => ['id=? AND shared=?', params[:did].to_i, true]) elsif params[:name] - @active=ActiveDashboard.find(:first, :include => 'dashboard', :conditions => ['dashboards.name=? AND active_dashboards.user_id IS NULL', params[:name]]) + @dashboard=Dashboard.find(:first, :conditions => ['name=? AND shared=?', params[:name], true]) elsif params[:id] - @active=ActiveDashboard.user_dashboards(nil, false).first + active=ActiveDashboard.user_dashboards(nil, false).first else - @active=ActiveDashboard.user_dashboards(nil, true).first + active=ActiveDashboard.user_dashboards(nil, true).first end end - @dashboard=(@active ? @active.dashboard : nil) + + unless @dashboard + @dashboard=(active ? active.dashboard : nil) + end + @dashboard_configuration=Api::DashboardConfiguration.new(@dashboard, :period_index => params[:period], :snapshot => @snapshot) if @dashboard && @snapshot end 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 786ca5a2a73..2a6c7dabc78 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 @@ -1,18 +1,15 @@

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

-

<%= message('dashboard.global_dashboards.description') -%>

<%= render :partial => 'list', :locals => {:active_dashboards => @actives.select(&:global?), :group => 'activeGlobal'} %>

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

-

<%= message('dashboard.project_dashboards.description') -%>

<%= render :partial => 'list', :locals => {:active_dashboards => @actives.reject(&:global?), :group => 'activeProject'} %>

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

-

<%= message('dashboard.shared_dashboards.description') -%>

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 2bce07ee61c..4293e203b7c 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,13 +2,13 @@ <% if logged_in? %> <% end %> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_available_dashboards.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_available_dashboards.html.erb new file mode 100644 index 00000000000..ca88843c2cd --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_available_dashboards.html.erb @@ -0,0 +1,51 @@ +
+ + + + + + + + + + + <% if @shared_dashboards.nil? || @shared_dashboards.empty? %> + + + + <% + else + @shared_dashboards.each do |dashboard| %> + + + + + + + + <% end + end + %> + +
<%= message('name') -%><%= message('shared') -%><%= message('owner') -%> <%= message('operations') -%>
<%= message('dashboard.no_dashboard') -%>
+ <%= link_to h(dashboard.name(true)), {:controller => :dashboard, :action => :index, :did => dashboard.id, :id => (params[:resource] unless dashboard.global?)}, + :id => "view-#{u dashboard.name}", :class => 'link-action' %> +
<%= h dashboard.description -%>
+
+ <%= boolean_icon(dashboard.shared) -%> + + <%= h(dashboard.user_name || message('dashboard.username.default')) -%> +   + <% if dashboard.editable_by?(current_user) %> + <%= link_to message('dashboard.configure_widgets'), {:controller => :dashboard, :action => :configure, :did => dashboard.id, :id => (params[:resource] unless dashboard.global?)}, + :id => "configure-#{u dashboard.name}", :class => 'link-action' %> + | + <%= link_to_remote message('edit'), {:update => "create_dashboard", :url => {:action => :edit, :id => dashboard.id, :resource => params[:resource]}}, + {:id => "edit-#{u dashboard.name}", :method => :get, :class => 'link-action'} %> + | + <%= link_to message('delete'), {:action => :delete, :id => dashboard.id, :resource => params[:resource]}, :method => :post, + :confirm => message('dashboard.do_you_want_to_delete_dashboard'), :id => "delete-#{u dashboard.name}", :class => 'link-action' %> + | + <% end %> + <%= link_to message('follow'), {:action => :follow, :id => dashboard.id, :resource => params[:resource]}, :method => :post, :id => "follow-#{u dashboard.name}", :class => 'link-action' %> +
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_my_dashboards.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_my_dashboards.html.erb new file mode 100644 index 00000000000..f6cd8d762a1 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_my_dashboards.html.erb @@ -0,0 +1,66 @@ + + + + + + + + + + + + <% if @actives.nil? || @actives.empty? %> + + + + <% else %> + <% @actives.map(&:dashboard).each_with_index do |dashboard, index| %> + + + + + + + + <% end + end + %> + +
<%= message('name') -%><%= message('shared') -%><%= message('owner') -%><%= message('order') -%><%= message('operations') -%>
<%= message('dashboard.no_dashboard') -%>
+ <%= link_to h(dashboard.name(true)), {:controller => :dashboard, :action => :index, :did => dashboard.id, :id => (params[:resource] unless dashboard.global?)}, + :id => "view-#{u dashboard.name}", :class => 'link-action' %> +
<%= h dashboard.description -%>
+
+ <%= boolean_icon(dashboard.shared) -%> + + <%= h(dashboard.user_name || message('dashboard.username.default')) -%> + + <% if index > 0 %> + <%= link_to image_tag('blue-up.png'), {:action => :up, :id => dashboard.id, :resource => params[:resource]}, :method => :post, :id => "up-#{u dashboard.name}" %> + <% else %> + <%= image_tag('transparent_16.gif') %> + <% end %> + <% if index < @actives.size-1 %> + <%= link_to image_tag('blue-down.png'), {:action => :down, :id => dashboard.id, :resource => params[:resource]}, :method => :post, :id => "down-#{u dashboard.name}" %> + <% else %> + <%= image_tag('transparent_16.gif') %> + <% end %> + + <% if dashboard.editable_by?(current_user) %> + <%= link_to message('dashboard.configure_widgets'), {:controller => :dashboard, :action => :configure, :did => dashboard.id, :id => (params[:resource] unless dashboard.global?)}, + :id => "configure-#{u dashboard.name}", :class => 'link-action' %> + | + <%= link_to_remote message('edit'), {:update => "create_dashboard", :url => {:action => :edit, :id => dashboard.id, :resource => params[:resource]}}, + {:id => "edit-#{u dashboard.name}", :method => :get, :class => 'link-action'} %> + <% if @actives.size() > 1 %> + | + <%= link_to message('delete'), {:action => :delete, :id => dashboard.id, :resource => params[:resource]}, :method => :post, + :confirm => message('dashboard.do_you_want_to_delete_dashboard'), :id => "delete-#{u dashboard.name}", :class => 'link-action' %> + | + <% end %> + <% end %> + <% if @actives.size() > 1 %> + <%= link_to message('unfollow'), {:action => :unfollow, :id => dashboard.id, :resource => params[:resource]}, :method => :post, + :id => "unfollow-#{u dashboard.name}", :class => 'link-action' %> + <% end %> +
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 8a34a2cab72..2fda8e73f69 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 @@ -1,124 +1,10 @@ -<% is_admin=is_admin? %> -

<%= message(@global ? 'dashboard.my_global_dashboards' : 'dashboard.my_project_dashboards') -%>

- - - - - - - - - - - - - <% if @actives.nil? || @actives.empty? %> - - - - <% else %> - <% @actives.each_with_index do |active, index| %> - - - - - - - - <% end - end - %> - -
<%= message('name') -%><%= message('shared') -%><%= message('owner') -%><%= message('order') -%><%= message('operations') -%>
<%= message('dashboard.no_dashboard') -%>
- <%= active.name(true) -%> -
<%= h active.dashboard.description -%>
-
- <%= boolean_icon(active.dashboard.shared) -%> - - <%= h(active.dashboard.user_name || message('dashboard.username.default')) -%> - - <% if index > 0 %> - <%= link_to image_tag('blue-up.png'), {:action => :up, :id => active.dashboard_id, :resource => params[:resource]}, :method => :post, :id => "up-#{u active.name}" %> - <% else %> - <%= image_tag('transparent_16.gif') %> - <% end %> - <% if index < @actives.size-1 %> - <%= link_to image_tag('blue-down.png'), {:action => :down, :id => active.dashboard_id, :resource => params[:resource]}, :method => :post, :id => "down-#{u active.name}" %> - <% else %> - <%= image_tag('transparent_16.gif') %> - <% end %> - - <% if active.editable_by?(current_user) %> - <%= link_to message('dashboard.configure_widgets'), {:controller => :dashboard, :action => :configure, :did => active.dashboard_id, :id => (params[:resource] unless active.global?)}, - :id => "configure-#{u active.name}", :class => 'link-action' %> - | - <%= link_to_remote message('edit'), {:update => "create_dashboard", :url => {:action => :edit, :id => active.dashboard_id, :resource => params[:resource]}}, - {:id => "edit-#{u active.name}", :method => :get, :class => 'link-action'} %> - <% if @actives.size() > 1 %> - | - <%= link_to message('delete'), {:action => :delete, :id => active.dashboard_id, :resource => params[:resource]}, :method => :post, - :confirm => message('dashboard.do_you_want_to_delete_dashboard'), :id => "delete-#{u active.name}", :class => 'link-action' %> - | - <% end %> - <% end %> - <% if @actives.size() > 1 %> - <%= link_to message('unfollow'), {:action => :unfollow, :id => active.dashboard_id, :resource => params[:resource]}, :method => :post, - :id => "unfollow-#{u active.name}", :class => 'link-action' %> - <% end %> -
+ <%= render_partial :partial => 'my_dashboards', :locals => { :is_admin => is_admin? } %>

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

- - - - - - - - - - - - - <% if @shared_dashboards.nil? || @shared_dashboards.empty? %> - - - - <% - else - @shared_dashboards.each do |dashboard| %> - - - - - - - - <% end - end - %> - -
<%= message('name') -%><%= message('shared') -%><%= message('owner') -%> <%= message('operations') -%>
<%= message('dashboard.no_dashboard') -%>
- <%= dashboard.name(true) -%> -
<%= h dashboard.description -%>
-
- <%= boolean_icon(dashboard.shared) -%> - - <%= h(dashboard.user_name || message('dashboard.username.default')) -%> -   - <% if dashboard.editable_by?(current_user) %> - <%= link_to_remote message('edit'), {:update => "create_dashboard", :url => {:action => :edit, :id => dashboard.id, :resource => params[:resource]}}, - {:id => "edit-#{u dashboard.name}", :method => :get, :class => 'link-action'} %> - | - <%= link_to message('delete'), {:action => :delete, :id => dashboard.id, :resource => params[:resource]}, :method => :post, - :confirm => message('dashboard.do_you_want_to_delete_dashboard'), :id => "delete-#{u dashboard.name}", :class => 'link-action' %> - | - <% end %> - <%= link_to message('follow'), {:action => :follow, :id => dashboard.id, :resource => params[:resource]}, :method => :post, :id => "follow-#{u dashboard.name}", :class => 'link-action' %> -
+ <%= render_partial :partial => 'available_dashboards', :locals => { :is_admin => is_admin? } %>