From 203ad5c90ea80e2b4bf173795899827a23f6b5cb Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Wed, 4 Jun 2008 15:44:44 -0700 Subject: [PATCH] Adding helper to show or hide elements based on permissions. #1138 --- app/helpers/deliverables_helper.rb | 4 ++++ app/views/deliverables/_deliverable.html.erb | 10 ++++++---- app/views/deliverables/_list.html.erb | 4 ++-- app/views/deliverables/_sidebar.html.erb | 2 +- app/views/deliverables/index.html.erb | 21 ++++++++++++++++++++ 5 files changed, 34 insertions(+), 7 deletions(-) diff --git a/app/helpers/deliverables_helper.rb b/app/helpers/deliverables_helper.rb index bae4336..592df33 100644 --- a/app/helpers/deliverables_helper.rb +++ b/app/helpers/deliverables_helper.rb @@ -15,4 +15,8 @@ module DeliverablesHelper content_tag(:span, label) + h(data)) end + + def allowed_management? + return User.current.allowed_to?(:manage_budget, @project) + end end diff --git a/app/views/deliverables/_deliverable.html.erb b/app/views/deliverables/_deliverable.html.erb index 32fd8ad..5f5a98f 100644 --- a/app/views/deliverables/_deliverable.html.erb +++ b/app/views/deliverables/_deliverable.html.erb @@ -1,10 +1,10 @@ <% css = cycle('odd','even') %> <%= content_tag(:td, deliverable.id) %> - <%= content_tag(:td, h(deliverable.score.to_i), :class => 'score') %> + <%= content_tag(:td, h(deliverable.score.to_i), :class => 'score') if allowed_management? %> <%= content_tag(:td, h(deliverable.subject), :class => 'subject') %> <%= content_tag(:td, number_to_currency(deliverable.budget, :precision => 0), :class => 'budget') %> - <%= content_tag(:td, number_to_currency(deliverable.spent, :precision => 0), :class => 'spent') %> + <%= content_tag(:td, number_to_currency(deliverable.spent, :precision => 0), :class => 'spent') if allowed_management? %> <%= content_tag(:td, format_date(deliverable.due), :class => 'due_date') %> <%= content_tag(:td, progress_bar(deliverable.progress, :width => '100%', :class => 'dont_ratio')) %> <%= content_tag(:td, link_to_function("Details", "$('deliverable-details-#{deliverable.id}').toggle();"), :class => 'actions') %> @@ -27,8 +27,9 @@ <%= content_tag(:p,link_to("Assigned Issues", :action => 'issues', :id => @project.id, :deliverable_id => deliverable.id)) -%> - <%= content_tag(:p,link_to("Edit", :action => 'edit', :id => @project.id, :deliverable_id => deliverable.id)) -%> - <%= content_tag(:p,link_to("Delete", { :action => 'destroy', :id => @project.id, :deliverable_id => deliverable.id}, :confirm => l(:text_are_you_sure))) -%> + <%= content_tag(:p,link_to("Edit", :action => 'edit', :id => @project.id, :deliverable_id => deliverable.id)) if allowed_management? -%> + <%= content_tag(:p,link_to("Delete", { :action => 'destroy', :id => @project.id, :deliverable_id => deliverable.id}, :confirm => l(:text_are_you_sure))) if allowed_management? %> + <% if allowed_management? %>
<% form_for :deliverable, deliverable, :url => { :action => "bulk_assign_issues", :id => @project.id, :deliverable_id => deliverable.id} do |f| %> @@ -37,5 +38,6 @@ <%= submit_tag(l(:button_change)) %> <% end %>
+ <% end %> diff --git a/app/views/deliverables/_list.html.erb b/app/views/deliverables/_list.html.erb index 3dc2ccd..d2f5f05 100644 --- a/app/views/deliverables/_list.html.erb +++ b/app/views/deliverables/_list.html.erb @@ -1,10 +1,10 @@ <%= sort_header_tag("#{Deliverable.table_name}.id", :caption => '#', :default_order => 'desc') %> - <%= sort_header_tag("score", :caption => 'Score', :default_order => 'desc') %> + <%= sort_header_tag("score", :caption => 'Score', :default_order => 'desc') if allowed_management? %> <%= sort_header_tag("#{Deliverable.table_name}.subject", :caption => 'Subject') %> <%= sort_header_tag("#{Deliverable.table_name}.budget", :caption => 'Budget') %> - <%= sort_header_tag("spent", :caption => 'Spent') %> + <%= sort_header_tag("spent", :caption => 'Spent') if allowed_management? %> <%= sort_header_tag("#{Deliverable.table_name}.due", :caption => 'Due') %> <%= sort_header_tag("progress", :caption => 'Progress') %> <%= content_tag('th', "Actions") %> diff --git a/app/views/deliverables/_sidebar.html.erb b/app/views/deliverables/_sidebar.html.erb index c1773c9..c3f3b7c 100644 --- a/app/views/deliverables/_sidebar.html.erb +++ b/app/views/deliverables/_sidebar.html.erb @@ -1,3 +1,3 @@

Budget

<%= link_to l(:label_issue_view_all), { :controller => 'issues', :action => 'index', :project_id => @project, :set_filter => 1 } %>
-<%= link_to_function "New Deliverable", "$('new-deliverable').toggle();" %>
+<%= link_to_function "New Deliverable", "$('new-deliverable').toggle();" if allowed_management? %>
diff --git a/app/views/deliverables/index.html.erb b/app/views/deliverables/index.html.erb index a79f222..89d32cf 100644 --- a/app/views/deliverables/index.html.erb +++ b/app/views/deliverables/index.html.erb @@ -1,35 +1,55 @@

Budget

+<% if allowed_management? %>

Project Budget: <%= h number_to_currency(@budget.budget, :precision => 0) %>

+<% end %> + +<% if allowed_management? %>

Budget Spent: <%= h number_to_currency(@budget.spent, :precision => 0) %>

+<% end %> + +<% if allowed_management? %>

Budget Remaining: <%= h number_to_currency(@budget.left, :precision => 0) %>

+<% end %> +

Progress: <%= h @budget.progress %>

+ +<% if allowed_management? %>

Budget Score: <%= h @budget.score %>

+<% end %> + +<% if allowed_management? %>

Overruns: <%= h number_to_currency(@budget.overruns, :precision => 0) %>

+<% end %> +

Next Due Date: <%= h distance_of_time_in_words_to_now(@budget.next_due_date) if @budget.next_due_date %>

Completion: <%= h distance_of_time_in_words_to_now(@budget.final_due_date) if @budget.final_due_date %>

+ +<% if allowed_management? %>

Profit: <%= h number_to_currency(@budget.profit, :precision => 0) %>

+<% end %>
+<% if allowed_management? %> +<% end %>
<% if @deliverables.empty? %>