Browse Source

SONAR-3512 Make it possible to share a dashboard without following it

tags/3.2
David Gageot 12 years ago
parent
commit
e167b3c546

+ 16
- 14
plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties View File

@@ -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

+ 31
- 39
sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboards_controller.rb View File

@@ -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('<br/>')

@@ -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('<br/>')
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


+ 3
- 5
sonar-server/src/main/webapp/WEB-INF/app/views/admin_dashboards/_list.html.erb View File

@@ -2,7 +2,7 @@
<thead>
<tr>
<th class="name"><%= message('name') -%></th>
<th class="shared"><%= message('shared_by') -%></th>
<th class="owner"><%= message('shared_by') -%></th>
<th class="order"><%= message('order') -%></th>
<th class="operations"><%= message('operations') -%></th>
</tr>
@@ -19,10 +19,8 @@
<div><%= h(active.name(true)) -%></div>
<div class="description"><%= active.dashboard.description -%></div>
</td>
<td class="shared">
<% if active.dashboard.shared %>
<%= h(active.dashboard.user_name || message('dashboard.username.default')) -%>
<% end %>
<td class="owner">
<%= h(active.dashboard.user_name || message('dashboard.username.default')) -%>
</td>
<td class="order">
<% if index > 0 %>

+ 3
- 5
sonar-server/src/main/webapp/WEB-INF/app/views/admin_dashboards/index.html.erb View File

@@ -19,7 +19,7 @@
<thead>
<tr>
<th class="name"><%= message('name') -%></th>
<th class="shared"><%= message('shared_by') -%></th>
<th class="owner"><%= message('shared_by') -%></th>
<th class="global"><%= message('global') -%></th>
<th class="operations"><%= message('operations') -%></th>
</tr>
@@ -36,10 +36,8 @@
<div><%= h(dashboard.name(true)) -%></div>
<div class="description"><%= dashboard.description -%></div>
</td>
<td class="shared">
<% if dashboard.shared %>
<%= h(dashboard.user_name || message('dashboard.username.default')) -%>
<% end %>
<td class="owner">
<%= h(dashboard.user_name || message('dashboard.username.default')) -%>
</td>
<td class="global">
<%= boolean_icon(dashboard.global) -%>

+ 24
- 16
sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/index.html.erb View File

@@ -8,7 +8,8 @@
<thead>
<tr>
<th class="name"><%= message('name') -%></th>
<th class="shared"><%= message('shared_by') -%></th>
<th class="shared"><%= message('shared') -%></th>
<th class="owner"><%= message('owner') -%></th>
<th class="order"><%= message('order') -%></th>
<th class="operations"><%= message('operations') -%></th>
</tr>
@@ -20,15 +21,16 @@
</tr>
<% else %>
<% @actives.each_with_index do |active, index| %>
<tr id="dashboard-<%= u active.name -%>" class="<%= cycle('even', 'odd', :name => 'dashboard') -%>">
<tr id="dashboard-<%= active.id -%>" class="<%= cycle('even', 'odd', :name => 'dashboard') -%>">
<td>
<%= active.name(true) -%>
<div class="description"><%= h active.dashboard.description -%></div>
</td>
<td class="shared">
<% if active.dashboard.shared %>
<%= h(active.dashboard.user_name || message('dashboard.username.default')) -%>
<% end %>
<%= boolean_icon(active.dashboard.shared) -%>
</td>
<td class="owner">
<%= h(active.dashboard.user_name || message('dashboard.username.default')) -%>
</td>
<td class="order">
<% 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 @@
</tbody>
</table>

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

<table class="data" id="shared-dashboards">
<thead>
<tr>
<th class="name"><%= message('name') -%></th>
<th class="shared"><%= message('shared_by') -%></th>
<th class="shared"><%= message('shared') -%></th>
<th class="owner"><%= message('owner') -%></th>
<th class="order">&nbsp;</th>
<th class="operations"><%= message('operations') -%></th>
</tr>
@@ -89,15 +90,16 @@
<%
else
@shared_dashboards.each do |dashboard| %>
<tr id="shared-dashboard-<%= u dashboard.name -%>" class="<%= cycle('even', 'odd', :name => 'shared') -%>">
<tr id="dashboard-<%= dashboard.id -%>" class="<%= cycle('even', 'odd', :name => 'shared') -%>">
<td>
<%= dashboard.name(true) -%>
<div class="description"><%= h dashboard.description -%></div>
</td>
<td class="shared">
<% if dashboard.shared %>
<%= h(dashboard.user_name || message('dashboard.username.default')) -%>
<% end %>
<%= boolean_icon(dashboard.shared) -%>
</td>
<td class="owner">
<%= h(dashboard.user_name || message('dashboard.username.default')) -%>
</td>
<td class="order">&nbsp;</td>
<td class="thin nowrap operations">
@@ -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' %>
</td>
</tr>
@@ -123,3 +125,9 @@
<%= render :partial => 'dashboards/create' %>
</div>
</div>

<% if params[:highlight] %>
<script type="text/javascript">
new Effect.Highlight('dashboard-<%= h params[:highlight] -%>', {duration: 2, startcolor: '#cae3f2'});
</script>
<% end %>

+ 7
- 2
sonar-server/src/main/webapp/stylesheets/dashboard.css View File

@@ -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;
}


Loading…
Cancel
Save