From e167b3c546f0a6ea1cb50348b29cac9f6f242e36 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Mon, 18 Jun 2012 16:46:35 +0200 Subject: [PATCH] SONAR-3512 Make it possible to share a dashboard without following it --- .../resources/org/sonar/l10n/core.properties | 30 ++++---- .../app/controllers/dashboards_controller.rb | 70 ++++++++----------- .../app/views/admin_dashboards/_list.html.erb | 8 +-- .../app/views/admin_dashboards/index.html.erb | 8 +-- .../app/views/dashboards/index.html.erb | 40 ++++++----- .../src/main/webapp/stylesheets/dashboard.css | 9 ++- 6 files changed, 84 insertions(+), 81 deletions(-) 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 b973de86df5..74b8ddaf518 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 @@ -12,27 +12,27 @@ alerts=Alerts all=All and=And any=Any +ascending=Ascending assignee=Assignee author=Author -ascending=Ascending back=Back backup_verb=Backup blocker=Blocker bold=Bold build_date=Build date build_time=Build time +calendar=Calendar cancel=Cancel category=Category -calendar=Calendar -change_verb=Change changelog=Changelog -configure=Configure +change_verb=Change class=Class classes=Classes closed=Closed code=Code color=Color compare=Compare +configure=Configure copy=Copy create=Create created=Created @@ -44,8 +44,8 @@ default=Default delete=Delete descending=Descending description=Description -directory=Directory directories=Directories +directory=Directory display=Display download_verb=Download edit=Edit @@ -58,8 +58,8 @@ follow=Follow global=Global hide=Hide identifier_abbreviated=Id -info=Info inactive=Inactive +info=Info inheritance=Inheritance key=Key language=Language @@ -82,6 +82,7 @@ open_verb=Open operations=Operations optional=Optional order=Order +owner=Owner package=Package packages=Packages parameters=Parameters @@ -92,19 +93,19 @@ plugin=Plugin project=Project projects=Projects raw=Raw +rename=Rename reset_verb=Reset result=Result results=Results -rule=Rule -rules=Rules -rename=Rename review=Review reviews=Reviews review_verb=Review +rule=Rule +rules=Rules save=Save search_verb=Search -select_verb=Select select_all=Select all +select_verb=Select severity=Severity severity_abbreviated=Se. shared=Shared @@ -122,20 +123,20 @@ title=Title to=To treemap=Treemap true=True -update_verb=Update -updated=Updated unfollow=Unfollow unit_test=Unit test unit_tests=Unit tests -unselect_verb=Unselect unselect_all=Unselect all +unselect_verb=Unselect +updated=Updated +update_verb=Update user=User value=Value variation=Variation +version=Version view=View views=Views violations=Violations -version=Version #------------------------------------------------------------------------------ @@ -529,6 +530,7 @@ dashboard.my_global_dashboards=My global dashboards dashboard.my_project_dashboards=My project dashboards dashboard.no_dashboard=No dashboard dashboard.do_you_want_to_delete_dashboard=Do you want to delete this dashboard ? +dashboard.available_dashboards=Available dashboards dashboard.shared_dashboards=Shared dashboards dashboard.create_dashboard=New dashboard dashboard.create_project_dashboard=Create project dashboard 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 3d2d0a4d6a0..b07c19fc1c5 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 @@ -28,9 +28,10 @@ class DashboardsController < ApplicationController @global = !params[:resource] @actives=ActiveDashboard.user_dashboards(current_user, @global) - @shared_dashboards=Dashboard.find(:all, :conditions => ['(user_id<>? OR user_id IS NULL) AND shared=? AND is_global=?', current_user.id, true, @global]).sort { |a, b| a.name.downcase<=>b.name.downcase } + @shared_dashboards=Dashboard.find(:all, :conditions => ['(shared=? or user_id=?) and is_global=?', true, current_user.id, @global]) active_ids=@actives.map(&:dashboard_id) @shared_dashboards.reject! { |d| active_ids.include?(d.id) } + @shared_dashboards=Api::Utils.insensitive_sort(@shared_dashboards, &:name) if params[:resource] @resource=Project.by_key(params[:resource]) @@ -58,9 +59,8 @@ class DashboardsController < ApplicationController elsif @dashboard.save add_default_dashboards_if_first_user_dashboard(@dashboard.global?) last_index=current_user.active_dashboards.max_by(&:order_index).order_index - current_user.active_dashboards.create(:dashboard => @dashboard, :user_id => current_user.id, :order_index => last_index+1) - redirect_to :controller => 'dashboard', :action => 'configure', :did => @dashboard.id, :id => (params[:resource] unless @dashboard.global) + redirect_to :action => 'index', :resource => params[:resource], :highlight => @dashboard.id else flash[:error]=@dashboard.errors.full_messages.join('
') @@ -84,29 +84,28 @@ class DashboardsController < ApplicationController if dashboard.save unless dashboard.shared? - ActiveDashboard.destroy_all(['dashboard_id = ? and (user_id<>? OR user_id IS NULL)', dashboard.id, current_user.id]) + ActiveDashboard.destroy_all(:dashboard_id => dashboard.id) end else flash[:error]=dashboard.errors.full_messages.join('
') end - else - # TODO explicit error end + redirect_to :action => 'index', :resource => params[:resource] end def delete dashboard=Dashboard.find(params[:id]) - bad_request('Unknown dashboard') unless dashboard + access_denied unless dashboard.editable_by?(current_user) if dashboard.destroy - flash[:warning]=Api::Utils.message('dashboard.default_restored') if ActiveDashboard.count(:conditions => ['user_id=?', current_user.id])==0 + flash[:warning]=Api::Utils.message('dashboard.default_restored') if ActiveDashboard.count(:conditions => {:user_id => current_user.id})==0 else flash[:error]=Api::Utils.message('dashboard.error_delete_default') end - redirect_to :action => 'index', :resource => params[:resource] + redirect_to :action => 'index', :resource => params[:resource] end def down @@ -118,58 +117,51 @@ class DashboardsController < ApplicationController end def follow - dashboard=Dashboard.find(:first, :conditions => ['shared=? and id=? and (user_id is null or user_id<>?)', true, params[:id].to_i, current_user.id]) - if dashboard - add_default_dashboards_if_first_user_dashboard(dashboard.global?) + dashboard=Dashboard.find(params[:id]) - active_dashboard = current_user.active_dashboards.to_a.find { |ad| ad.name==dashboard.name } - if active_dashboard - flash[:error]=Api::Utils.message('dashboard.error_follow_existing_name') - else - last_active_dashboard=current_user.active_dashboards.max_by(&:order_index) - current_user.active_dashboards.create(:dashboard => dashboard, :user => current_user, :order_index => (last_active_dashboard ? last_active_dashboard.order_index+1 : 1)) - end + add_default_dashboards_if_first_user_dashboard(dashboard.global?) + active_dashboard = current_user.active_dashboards.to_a.find { |ad| ad.name==dashboard.name } + if active_dashboard + flash[:error]=Api::Utils.message('dashboard.error_follow_existing_name') else - bad_request('Unknown dashboard') + last_active_dashboard=current_user.active_dashboards.max_by(&:order_index) + current_user.active_dashboards.create(:dashboard => dashboard, :user => current_user, :order_index => (last_active_dashboard ? last_active_dashboard.order_index+1 : 1)) end + redirect_to :action => 'index', :resource => params[:resource] end def unfollow - dashboard=Dashboard.find(:first, :conditions => ['shared=? and id=? and (user_id is null or user_id<>?)', true, params[:id].to_i, current_user.id]) - if dashboard - add_default_dashboards_if_first_user_dashboard(dashboard.global?) + dashboard=Dashboard.find(params[:id]) - ActiveDashboard.destroy_all(['user_id=? AND dashboard_id=?', current_user.id, params[:id].to_i]) + add_default_dashboards_if_first_user_dashboard(dashboard.global?) + ActiveDashboard.destroy_all(:user_id => current_user.id, :dashboard_id => params[:id].to_i) - if ActiveDashboard.count(:conditions => ['user_id=?', current_user.id])==0 - flash[:notice]=Api::Utils.message('dashboard.default_restored') - end + if ActiveDashboard.count(:conditions => {:user_id => current_user.id})==0 + flash[:notice]=Api::Utils.message('dashboard.default_restored') end + redirect_to :action => 'index', :resource => params[:resource] end private def position(offset) - dashboard=Dashboard.find(params[:id].to_i) - if dashboard - add_default_dashboards_if_first_user_dashboard(dashboard.global?) + dashboard=Dashboard.find(params[:id]) - actives=current_user.active_dashboards.select { |a| a.global? == dashboard.global? }.sort_by(&:order_index) + add_default_dashboards_if_first_user_dashboard(dashboard.global?) + actives=current_user.active_dashboards.select { |a| a.global? == dashboard.global? }.sort_by(&:order_index) - index = actives.index { |a| a.dashboard_id == dashboard.id } - if index - actives[index], actives[index + offset] = actives[index + offset], actives[index] + index = actives.index { |a| a.dashboard_id == dashboard.id } + if index + actives[index], actives[index + offset] = actives[index + offset], actives[index] - actives.each_with_index do |a, i| - a.order_index=i+1 - a.save - end + actives.each_with_index do |a, i| + a.order_index=i+1 + a.save end end - redirect_to :action => 'index', :resource => params[:resource] end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/admin_dashboards/_list.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/admin_dashboards/_list.html.erb index d903d2d4f11..682cfc64979 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/admin_dashboards/_list.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/admin_dashboards/_list.html.erb @@ -2,7 +2,7 @@ <%= message('name') -%> - <%= message('shared_by') -%> + <%= message('shared_by') -%> <%= message('order') -%> <%= message('operations') -%> @@ -19,10 +19,8 @@
<%= h(active.name(true)) -%>
<%= active.dashboard.description -%>
- - <% if active.dashboard.shared %> - <%= h(active.dashboard.user_name || message('dashboard.username.default')) -%> - <% end %> + + <%= h(active.dashboard.user_name || message('dashboard.username.default')) -%> <% if index > 0 %> 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 32bc6ad7aa6..786ca5a2a73 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 @@ -19,7 +19,7 @@ <%= message('name') -%> - <%= message('shared_by') -%> + <%= message('shared_by') -%> <%= message('global') -%> <%= message('operations') -%> @@ -36,10 +36,8 @@
<%= h(dashboard.name(true)) -%>
<%= dashboard.description -%>
- - <% if dashboard.shared %> - <%= h(dashboard.user_name || message('dashboard.username.default')) -%> - <% end %> + + <%= h(dashboard.user_name || message('dashboard.username.default')) -%> <%= boolean_icon(dashboard.global) -%> 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 500e94de9d2..8a34a2cab72 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 @@ -8,7 +8,8 @@ <%= message('name') -%> - <%= message('shared_by') -%> + <%= message('shared') -%> + <%= message('owner') -%> <%= message('order') -%> <%= message('operations') -%> @@ -20,15 +21,16 @@ <% else %> <% @actives.each_with_index do |active, index| %> - + <%= active.name(true) -%>
<%= h active.dashboard.description -%>
- <% if active.dashboard.shared %> - <%= h(active.dashboard.user_name || message('dashboard.username.default')) -%> - <% end %> + <%= boolean_icon(active.dashboard.shared) -%> + + + <%= h(active.dashboard.user_name || message('dashboard.username.default')) -%> <% if index > 0 %> @@ -53,12 +55,10 @@ | <%= 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 and active.shared? and !active.dashboard.owner?(current_user) %> - <% if active.editable_by?(current_user) %> - | - <% 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 %> @@ -70,13 +70,14 @@ -

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

+

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

- + + @@ -89,15 +90,16 @@ <% else @shared_dashboards.each do |dashboard| %> - + + @@ -123,3 +125,9 @@ <%= render :partial => 'dashboards/create' %> + +<% if params[:highlight] %> + +<% end %> diff --git a/sonar-server/src/main/webapp/stylesheets/dashboard.css b/sonar-server/src/main/webapp/stylesheets/dashboard.css index 4c3d4187add..b548d9fc502 100644 --- a/sonar-server/src/main/webapp/stylesheets/dashboard.css +++ b/sonar-server/src/main/webapp/stylesheets/dashboard.css @@ -137,13 +137,18 @@ text-align: right; } -.admin_page .shared { +.admin_page .owner { width: 140px; text-align: center; } +.admin_page .shared { + width: 40px; + text-align: center; +} + .admin_page .order, .admin_page .global { - width: 60px; + width: 45px; text-align: center; } -- 2.39.5
<%= message('name') -%><%= message('shared_by') -%><%= message('shared') -%><%= message('owner') -%>   <%= message('operations') -%>
<%= dashboard.name(true) -%>
<%= h dashboard.description -%>
- <% if dashboard.shared %> - <%= h(dashboard.user_name || message('dashboard.username.default')) -%> - <% end %> + <%= boolean_icon(dashboard.shared) -%> + + <%= h(dashboard.user_name || message('dashboard.username.default')) -%>   @@ -108,7 +110,7 @@ <%= 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 %> <%= link_to message('follow'), {:action => :follow, :id => dashboard.id, :resource => params[:resource]}, :method => :post, :id => "follow-#{u dashboard.name}", :class => 'link-action' %>