diff --git a/app/controllers/my_projects_overviews_controller.rb b/app/controllers/my_projects_overviews_controller.rb index 07196b7aaf..71be3e4b04 100644 --- a/app/controllers/my_projects_overviews_controller.rb +++ b/app/controllers/my_projects_overviews_controller.rb @@ -18,9 +18,7 @@ class MyProjectsOverviewsController < ApplicationController unloadable - before_filter :find_project, :find_user, :find_my_project_overview - before_filter :find_page_blocks, :find_project_details - before_filter :find_attachments + before_filter :find_project, :find_user before_filter :authorize before_filter :jump_to_project_menu_item, :only => :index @@ -47,9 +45,6 @@ class MyProjectsOverviewsController < ApplicationController # User's page layout configuration def page_layout - @block_options = [] - BLOCKS.each {|k, v| @block_options << [l("my.blocks.#{v}", :default => [v, v.to_s.humanize]), k.dasherize]} - @block_options << [l(:label_custom_element), :custom_element] end def update_custom_element @@ -59,13 +54,13 @@ class MyProjectsOverviewsController < ApplicationController if params["attachments"] # Attach files and save them - attachments = Attachment.attach_files(@overview, params["attachments"]) + attachments = Attachment.attach_files(overview, params["attachments"]) unless attachments[:unsaved].blank? flash[:error] = l(:warning_attachments_not_saved, attachments[:unsaved].size) end end - @overview.save_custom_element(block_name, block_title, textile) + overview.save_custom_element(block_name, block_title, textile) redirect_to :back end @@ -77,23 +72,21 @@ class MyProjectsOverviewsController < ApplicationController block = params[:block].to_s.underscore if (BLOCKS.keys.include? block) # remove if already present in a group - %w(top left right hidden).each {|f| @overview.send(f).delete block } + %w(top left right hidden).each {|f| overview.send(f).delete block } # add it hidden - @overview.hidden.unshift block - @overview.save! - render(:partial => "block", - :locals => { :user => @user, - :project => @project, - :block_name => block}) + overview.hidden.unshift block + overview.save! + render :partial => "block", + :locals => { :block_name => block } elsif block == "custom_element" - @overview.hidden.unshift @overview.new_custom_element - @overview.save! + overview.hidden.unshift overview.new_custom_element + overview.save! render(:partial => "block_textilizable", - :locals => { :user => @user, - :project => @project, - :block_title => l(:label_custom_element), - :block_name => @overview.hidden.first.first, - :textile => @overview.hidden.first.last}) + :locals => { :user => user, + :project => project, + :block_title => l(:label_custom_element), + :block_name => overview.hidden.first.first, + :textile => overview.hidden.first.last}) else render :nothing => true end @@ -103,8 +96,8 @@ class MyProjectsOverviewsController < ApplicationController # params[:block] : id of the block to remove def remove_block block = param_to_block(params[:block]) - %w(top left right hidden).each {|f| @overview.send(f).delete block } - @overview.save! + %w(top left right hidden).each {|f| overview.send(f).delete block } + overview.save! render :nothing => true end @@ -115,14 +108,14 @@ class MyProjectsOverviewsController < ApplicationController group = params[:group] if group.is_a?(String) group_items = (params["list-#{group}"] || []).collect {|x| param_to_block(x) } - unless group_items.size < @overview.send(group).size + unless group_items.size < overview.send(group).size # We are adding or re-ordering, not removing # Remove group blocks if they are presents in other groups - @overview.update_attributes('top' => (@overview.top - group_items), - 'left' => (@overview.left - group_items), - 'right' => (@overview.right - group_items), - 'hidden' => (@overview.hidden - group_items)) - @overview.update_attribute(group, group_items) + overview.update_attributes('top' => (overview.top - group_items), + 'left' => (overview.left - group_items), + 'right' => (overview.right - group_items), + 'hidden' => (overview.hidden - group_items)) + overview.update_attribute(group, group_items) end end render :nothing => true @@ -131,69 +124,129 @@ class MyProjectsOverviewsController < ApplicationController def param_to_block(param) block = param.to_s.underscore unless (BLOCKS.keys.include? block) - block = @overview.custom_elements.detect {|ary| ary.first == block} + block = overview.custom_elements.detect {|ary| ary.first == block} end block end def destroy_attachment - if @user.allowed_to?(:edit_project, @project) + if user.allowed_to?(:edit_project, project) begin att = Attachment.find(params[:attachment_id].to_i) - @overview.attachments.delete(att) - @overview.save + overview.attachments.delete(att) + overview.save rescue ActiveRecord::RecordNotFound end end - @attachments -= [att] + attachments -= [att] render :partial => 'page_layout_attachments' end - private + helper_method :users_by_role, + :childprojects, + :recent_news, + :trackers, + :open_issues_by_tracker, + :total_issues_by_tracker, + :assigned_issues, + :total_hours, + :project, + :user, + :blocks, + :block_options, + :overview, + :attachments, + :render_block, + :object_callback - def find_my_project_overview - @overview = MyProjectsOverview.find(:first, :conditions => "project_id = #{@project.id}") - # Auto-create missing overviews - @overview ||= MyProjectsOverview.create!(:project_id => @project.id) + def render_block name end - def find_user - @user = User.current + def users_by_role + @users_by_role ||= project.users_by_role end - def find_page_blocks - @blocks = { - 'top' => @overview.top, - 'left' => @overview.left, - 'right' => @overview.right, - 'hidden' => @overview.hidden - } + def childprojects + @childprojects ||= project.children.visible.all end - def find_project_details - @users_by_role = @project.users_by_role - @subprojects = @project.children.visible.all - @news = @project.news.find(:all, :limit => 5, + def recent_news + @news ||= project.news.all :limit => 5, :include => [ :author, :project ], - :order => "#{News.table_name}.created_on DESC") - @trackers = @project.rolled_up_trackers + :order => "#{News.table_name}.created_on DESC" - cond = @project.project_condition(Setting.display_subprojects_issues?) + end - @open_issues_by_tracker = Issue.visible.count(:group => :tracker, - :include => [:project, :status, :tracker], - :conditions => ["(#{cond}) AND #{IssueStatus.table_name}.is_closed=?", false]) - @total_issues_by_tracker = Issue.visible.count(:group => :tracker, - :include => [:project, :status, :tracker], - :conditions => cond) + def trackers + @trackers ||= project.rolled_up_trackers + end - if User.current.allowed_to?(:view_time_entries, @project) - @total_hours = TimeEntry.visible.sum(:hours, :include => :project, :conditions => cond).to_f + def open_issues_by_tracker + @open_issues_by_tracker ||= Issue.visible.count(:group => :tracker, + :include => [:project, :status, :tracker], + :conditions => ["(#{subproject_condition}) AND #{IssueStatus.table_name}.is_closed=?", false]) + end + + def total_issues_by_tracker + @total_issues_by_tracker ||= Issue.visible.count(:group => :tracker, + :include => [:project, :status, :tracker], + :conditions => subproject_condition) + + end + + def assigned_issues + @assigned_issues ||= Issue.visible.open.find(:all, + :conditions => { :assigned_to_id => User.current.id }, + :limit => 10, + :include => [ :status, :project, :tracker, :priority ], + :order => "#{IssuePriority.table_name}.position DESC, #{Issue.table_name}.updated_on DESC") + end + + def total_hours + if User.current.allowed_to?(:view_time_entries, project) + @total_hours ||= TimeEntry.visible.sum(:hours, :include => :project, :conditions => subproject_condition).to_f end end - def find_attachments - @attachments = @overview.attachments || [] + def project + @project + end + + def user + @user + end + + def blocks + @blocks ||= { + 'top' => overview.top, + 'left' => overview.left, + 'right' => overview.right, + 'hidden' => overview.hidden + } + end + + def block_options + @block_options = [] + BLOCKS.each {|k, v| @block_options << [l("my.blocks.#{v}", :default => [v, v.to_s.humanize]), k.dasherize]} + @block_options << [l(:label_custom_element), :custom_element] + end + + def overview + @overview ||= MyProjectsOverview.find_or_create_by_project_id(project.id) + end + + def attachments + @attachments = overview.attachments || [] + end + + private + + def subproject_condition + @subproject_condition ||= project.project_condition(Setting.display_subprojects_issues?) + end + + def find_user + @user = User.current end def default_breadcrumb @@ -203,7 +256,7 @@ class MyProjectsOverviewsController < ApplicationController def jump_to_project_menu_item if params[:jump] # try to redirect to the requested menu item - redirect_to_project_menu_item(@project, params[:jump]) && return + redirect_to_project_menu_item(project, params[:jump]) && return end end end diff --git a/app/views/my_projects_overviews/_page_layout_attachments.rhtml b/app/views/my_projects_overviews/_page_layout_attachments.rhtml index 987b8b9b4c..9fb634eb67 100644 --- a/app/views/my_projects_overviews/_page_layout_attachments.rhtml +++ b/app/views/my_projects_overviews/_page_layout_attachments.rhtml @@ -1,9 +1,9 @@ -<% for attachment in @attachments %> +<% for attachment in attachments %>

<%= link_to_attachment attachment, :class => 'icon icon-attachment' -%> <%= h(" - #{attachment.description}") unless attachment.description.blank? %> (<%= number_to_human_size attachment.filesize %>) <%= link_to_remote image_tag('delete.png'), - :url => { :action => 'destroy_attachment', :attachment_id => attachment.id, :id => @project.id }, + :url => { :action => 'destroy_attachment', :attachment_id => attachment.id, :id => project.id }, :confirm => l(:text_are_you_sure), :class => 'delete', :title => l(:button_delete), diff --git a/app/views/my_projects_overviews/blocks/_issuetracking.rhtml b/app/views/my_projects_overviews/blocks/_issuetracking.rhtml index a4772f3cbc..33552757a4 100644 --- a/app/views/my_projects_overviews/blocks/_issuetracking.rhtml +++ b/app/views/my_projects_overviews/blocks/_issuetracking.rhtml @@ -1,24 +1,24 @@

<%=l(:label_issue_tracking)%>

<%=l(:label_issue_tracking)%>

-<% if User.current.allowed_to?(:view_issues, @project) %> +<% if User.current.allowed_to?(:view_issues, project) %>

- <%= link_to l(:label_issue_view_all), :controller => 'issues', :action => 'index', :project_id => @project, :set_filter => 1 %> - <% if User.current.allowed_to?(:view_calendar, @project, :global => true) %> - | <%= link_to(l(:label_calendar), :controller => 'calendars', :action => 'show', :project_id => @project) %> + <%= link_to l(:label_issue_view_all), :controller => 'issues', :action => 'index', :project_id => project, :set_filter => 1 %> + <% if User.current.allowed_to?(:view_calendar, project, :global => true) %> + | <%= link_to(l(:label_calendar), :controller => 'calendars', :action => 'show', :project_id => project) %> <% end %> - <% if User.current.allowed_to?(:view_gantt, @project, :global => true) %> - | <%= link_to(l(:label_gantt), :controller => 'gantts', :action => 'show', :project_id => @project) %> + <% if User.current.allowed_to?(:view_gantt, project, :global => true) %> + | <%= link_to(l(:label_gantt), :controller => 'gantts', :action => 'show', :project_id => project) %> <% end %>

diff --git a/app/views/my_projects_overviews/blocks/_members.rhtml b/app/views/my_projects_overviews/blocks/_members.rhtml index 73a1df31c3..febe3b8f6d 100644 --- a/app/views/my_projects_overviews/blocks/_members.rhtml +++ b/app/views/my_projects_overviews/blocks/_members.rhtml @@ -1,9 +1,11 @@

<%=l(:label_member_plural)%>

<%=l(:label_member_plural)%>

-<% if @users_by_role.any? %> +<% if users_by_role.any? %>
-

<% @users_by_role.keys.sort.each do |role| %> - <%=h role %>: <%= @users_by_role[role].sort.collect{|u| link_to_user u}.join(", ") %>
- <% end %>

+

+ <% users_by_role.keys.sort.each do |role| %> + <%=h role %>: <%= users_by_role[role].sort.collect{ |u| link_to_user u }.join(", ") %>
+ <% end %> +

<% end %> diff --git a/app/views/my_projects_overviews/blocks/_news.rhtml b/app/views/my_projects_overviews/blocks/_news.rhtml index ef2f84e4a1..bf2e8bbf7a 100644 --- a/app/views/my_projects_overviews/blocks/_news.rhtml +++ b/app/views/my_projects_overviews/blocks/_news.rhtml @@ -1,8 +1,13 @@

<%=l(:label_news)%>

<%=l(:label_news_latest)%>

-<% if @news.any? && authorize_for('news', 'index') %> +<% if recent_news.any? && authorize_for('news', 'index') %>
- <%= render :partial => 'news/news', :collection => @news %> -

<%= link_to l(:label_news_view_all), :controller => 'news', :action => 'index', :project_id => @project %>

+ <%= render :partial => 'news/news', :collection => recent_news %> +

+ <%= link_to l(:label_news_view_all), + :controller => 'news', + :action => 'index', + :project_id => project %> +

<% end %> diff --git a/app/views/my_projects_overviews/blocks/_projectdetails.rhtml b/app/views/my_projects_overviews/blocks/_projectdetails.rhtml index 4aaaf253c6..24bfda68b0 100644 --- a/app/views/my_projects_overviews/blocks/_projectdetails.rhtml +++ b/app/views/my_projects_overviews/blocks/_projectdetails.rhtml @@ -2,12 +2,12 @@

<%=l(:label_project_details)%>