Kaynağa Gözat

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

tags/3.2
David Gageot 12 yıl önce
ebeveyn
işleme
e167b3c546

+ 16
- 14
plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties Dosyayı Görüntüle

all=All all=All
and=And and=And
any=Any any=Any
ascending=Ascending
assignee=Assignee assignee=Assignee
author=Author author=Author
ascending=Ascending
back=Back back=Back
backup_verb=Backup backup_verb=Backup
blocker=Blocker blocker=Blocker
bold=Bold bold=Bold
build_date=Build date build_date=Build date
build_time=Build time build_time=Build time
calendar=Calendar
cancel=Cancel cancel=Cancel
category=Category category=Category
calendar=Calendar
change_verb=Change
changelog=Changelog changelog=Changelog
configure=Configure
change_verb=Change
class=Class class=Class
classes=Classes classes=Classes
closed=Closed closed=Closed
code=Code code=Code
color=Color color=Color
compare=Compare compare=Compare
configure=Configure
copy=Copy copy=Copy
create=Create create=Create
created=Created created=Created
delete=Delete delete=Delete
descending=Descending descending=Descending
description=Description description=Description
directory=Directory
directories=Directories directories=Directories
directory=Directory
display=Display display=Display
download_verb=Download download_verb=Download
edit=Edit edit=Edit
global=Global global=Global
hide=Hide hide=Hide
identifier_abbreviated=Id identifier_abbreviated=Id
info=Info
inactive=Inactive inactive=Inactive
info=Info
inheritance=Inheritance inheritance=Inheritance
key=Key key=Key
language=Language language=Language
operations=Operations operations=Operations
optional=Optional optional=Optional
order=Order order=Order
owner=Owner
package=Package package=Package
packages=Packages packages=Packages
parameters=Parameters parameters=Parameters
project=Project project=Project
projects=Projects projects=Projects
raw=Raw raw=Raw
rename=Rename
reset_verb=Reset reset_verb=Reset
result=Result result=Result
results=Results results=Results
rule=Rule
rules=Rules
rename=Rename
review=Review review=Review
reviews=Reviews reviews=Reviews
review_verb=Review review_verb=Review
rule=Rule
rules=Rules
save=Save save=Save
search_verb=Search search_verb=Search
select_verb=Select
select_all=Select all select_all=Select all
select_verb=Select
severity=Severity severity=Severity
severity_abbreviated=Se. severity_abbreviated=Se.
shared=Shared shared=Shared
to=To to=To
treemap=Treemap treemap=Treemap
true=True true=True
update_verb=Update
updated=Updated
unfollow=Unfollow unfollow=Unfollow
unit_test=Unit test unit_test=Unit test
unit_tests=Unit tests unit_tests=Unit tests
unselect_verb=Unselect
unselect_all=Unselect all unselect_all=Unselect all
unselect_verb=Unselect
updated=Updated
update_verb=Update
user=User user=User
value=Value value=Value
variation=Variation variation=Variation
version=Version
view=View view=View
views=Views views=Views
violations=Violations violations=Violations
version=Version




#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
dashboard.my_project_dashboards=My project dashboards dashboard.my_project_dashboards=My project dashboards
dashboard.no_dashboard=No dashboard dashboard.no_dashboard=No dashboard
dashboard.do_you_want_to_delete_dashboard=Do you want to delete this 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.shared_dashboards=Shared dashboards
dashboard.create_dashboard=New dashboard dashboard.create_dashboard=New dashboard
dashboard.create_project_dashboard=Create project dashboard dashboard.create_project_dashboard=Create project dashboard

+ 31
- 39
sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboards_controller.rb Dosyayı Görüntüle

@global = !params[:resource] @global = !params[:resource]


@actives=ActiveDashboard.user_dashboards(current_user, @global) @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) active_ids=@actives.map(&:dashboard_id)
@shared_dashboards.reject! { |d| active_ids.include?(d.id) } @shared_dashboards.reject! { |d| active_ids.include?(d.id) }
@shared_dashboards=Api::Utils.insensitive_sort(@shared_dashboards, &:name)


if params[:resource] if params[:resource]
@resource=Project.by_key(params[:resource]) @resource=Project.by_key(params[:resource])
elsif @dashboard.save elsif @dashboard.save
add_default_dashboards_if_first_user_dashboard(@dashboard.global?) add_default_dashboards_if_first_user_dashboard(@dashboard.global?)
last_index=current_user.active_dashboards.max_by(&:order_index).order_index 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 else
flash[:error]=@dashboard.errors.full_messages.join('<br/>') flash[:error]=@dashboard.errors.full_messages.join('<br/>')




if dashboard.save if dashboard.save
unless dashboard.shared? 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 end
else else
flash[:error]=dashboard.errors.full_messages.join('<br/>') flash[:error]=dashboard.errors.full_messages.join('<br/>')
end end
else
# TODO explicit error
end end

redirect_to :action => 'index', :resource => params[:resource] redirect_to :action => 'index', :resource => params[:resource]
end end


def delete def delete
dashboard=Dashboard.find(params[:id]) dashboard=Dashboard.find(params[:id])
bad_request('Unknown dashboard') unless dashboard
access_denied unless dashboard.editable_by?(current_user) access_denied unless dashboard.editable_by?(current_user)


if dashboard.destroy 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 else
flash[:error]=Api::Utils.message('dashboard.error_delete_default') flash[:error]=Api::Utils.message('dashboard.error_delete_default')
end end
redirect_to :action => 'index', :resource => params[:resource]


redirect_to :action => 'index', :resource => params[:resource]
end end


def down def down
end end


def follow 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 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 end

redirect_to :action => 'index', :resource => params[:resource] redirect_to :action => 'index', :resource => params[:resource]
end end


def unfollow 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 end

redirect_to :action => 'index', :resource => params[:resource] redirect_to :action => 'index', :resource => params[:resource]
end end


private private


def position(offset) 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
end end



redirect_to :action => 'index', :resource => params[:resource] redirect_to :action => 'index', :resource => params[:resource]
end end



+ 3
- 5
sonar-server/src/main/webapp/WEB-INF/app/views/admin_dashboards/_list.html.erb Dosyayı Görüntüle

<thead> <thead>
<tr> <tr>
<th class="name"><%= message('name') -%></th> <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="order"><%= message('order') -%></th>
<th class="operations"><%= message('operations') -%></th> <th class="operations"><%= message('operations') -%></th>
</tr> </tr>
<div><%= h(active.name(true)) -%></div> <div><%= h(active.name(true)) -%></div>
<div class="description"><%= active.dashboard.description -%></div> <div class="description"><%= active.dashboard.description -%></div>
</td> </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>
<td class="order"> <td class="order">
<% if index > 0 %> <% if index > 0 %>

+ 3
- 5
sonar-server/src/main/webapp/WEB-INF/app/views/admin_dashboards/index.html.erb Dosyayı Görüntüle

<thead> <thead>
<tr> <tr>
<th class="name"><%= message('name') -%></th> <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="global"><%= message('global') -%></th>
<th class="operations"><%= message('operations') -%></th> <th class="operations"><%= message('operations') -%></th>
</tr> </tr>
<div><%= h(dashboard.name(true)) -%></div> <div><%= h(dashboard.name(true)) -%></div>
<div class="description"><%= dashboard.description -%></div> <div class="description"><%= dashboard.description -%></div>
</td> </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>
<td class="global"> <td class="global">
<%= boolean_icon(dashboard.global) -%> <%= boolean_icon(dashboard.global) -%>

+ 24
- 16
sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/index.html.erb Dosyayı Görüntüle

<thead> <thead>
<tr> <tr>
<th class="name"><%= message('name') -%></th> <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="order"><%= message('order') -%></th>
<th class="operations"><%= message('operations') -%></th> <th class="operations"><%= message('operations') -%></th>
</tr> </tr>
</tr> </tr>
<% else %> <% else %>
<% @actives.each_with_index do |active, index| %> <% @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> <td>
<%= active.name(true) -%> <%= active.name(true) -%>
<div class="description"><%= h active.dashboard.description -%></div> <div class="description"><%= h active.dashboard.description -%></div>
</td> </td>
<td class="shared"> <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>
<td class="order"> <td class="order">
<% if index > 0 %> <% if index > 0 %>
| |
<%= link_to message('delete'), {:action => :delete, :id => active.dashboard_id, :resource => params[:resource]}, :method => :post, <%= 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' %> :confirm => message('dashboard.do_you_want_to_delete_dashboard'), :id => "delete-#{u active.name}", :class => 'link-action' %>
|
<% end %> <% end %>
<% 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, <%= link_to message('unfollow'), {:action => :unfollow, :id => active.dashboard_id, :resource => params[:resource]}, :method => :post,
:id => "unfollow-#{u active.name}", :class => 'link-action' %> :id => "unfollow-#{u active.name}", :class => 'link-action' %>
<% end %> <% end %>
</tbody> </tbody>
</table> </table>


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


<table class="data" id="shared-dashboards"> <table class="data" id="shared-dashboards">
<thead> <thead>
<tr> <tr>
<th class="name"><%= message('name') -%></th> <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="order">&nbsp;</th>
<th class="operations"><%= message('operations') -%></th> <th class="operations"><%= message('operations') -%></th>
</tr> </tr>
<% <%
else else
@shared_dashboards.each do |dashboard| %> @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> <td>
<%= dashboard.name(true) -%> <%= dashboard.name(true) -%>
<div class="description"><%= h dashboard.description -%></div> <div class="description"><%= h dashboard.description -%></div>
</td> </td>
<td class="shared"> <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>
<td class="order">&nbsp;</td> <td class="order">&nbsp;</td>
<td class="thin nowrap operations"> <td class="thin nowrap operations">
<%= link_to message('delete'), {:action => :delete, :id => dashboard.id, :resource => params[:resource]}, :method => :post, <%= 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' %> :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' %> <%= link_to message('follow'), {:action => :follow, :id => dashboard.id, :resource => params[:resource]}, :method => :post, :id => "follow-#{u dashboard.name}", :class => 'link-action' %>
</td> </td>
</tr> </tr>
<%= render :partial => 'dashboards/create' %> <%= render :partial => 'dashboards/create' %>
</div> </div>
</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 Dosyayı Görüntüle

text-align: right; text-align: right;
} }


.admin_page .shared {
.admin_page .owner {
width: 140px; width: 140px;
text-align: center; text-align: center;
} }


.admin_page .shared {
width: 40px;
text-align: center;
}

.admin_page .order, .admin_page .global { .admin_page .order, .admin_page .global {
width: 60px;
width: 45px;
text-align: center; text-align: center;
} }



Loading…
İptal
Kaydet