From 5d63400fca0e4d4a9b2736934f7567ca6eda2a7e Mon Sep 17 00:00:00 2001 From: lukemelia Date: Sun, 25 Mar 2007 04:26:39 +0000 Subject: [PATCH] Added number of notes to project listing page. Fixes #128. Interested in feedback on this... Which is higher value: the simplicity of only showing the number of actions or the utility of showing the number of notes as well? git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@485 a4c988fc-2ded-0310-b66e-134b36920a42 --- tracks/app/controllers/projects_controller.rb | 7 +++++++ tracks/app/helpers/application_helper.rb | 6 ++++++ tracks/app/views/projects/_project_listing.rhtml | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/tracks/app/controllers/projects_controller.rb b/tracks/app/controllers/projects_controller.rb index 9fc59708..faad0fc0 100644 --- a/tracks/app/controllers/projects_controller.rb +++ b/tracks/app/controllers/projects_controller.rb @@ -136,6 +136,13 @@ class ProjectsController < ApplicationController @active_projects = @projects.select{ |p| p.active? } @hidden_projects = @projects.select{ |p| p.hidden? } @completed_projects = @projects.select{ |p| p.completed? } + project_note_counts = Note.count(:group => 'project_id') + @projects.each do |project| + #define a singlton method "notes_count" on each project object + class << project; self end.send(:define_method, :notes_count) do + project_note_counts[project.id] || 0 + end + end @new_project = @user.projects.build render end diff --git a/tracks/app/helpers/application_helper.rb b/tracks/app/helpers/application_helper.rb index ab3a91da..e21212cb 100644 --- a/tracks/app/helpers/application_helper.rb +++ b/tracks/app/helpers/application_helper.rb @@ -97,6 +97,12 @@ module ApplicationHelper def count_undone_todos_phrase_text(todos_parent, string="actions") count_undone_todos_phrase(todos_parent, string).gsub(" "," ") end + + def count_undone_todos_and_notes_phrase(project, string="actions") + s = count_undone_todos_phrase(project, string) + s += ", #{pluralize(project.notes_count, 'note')}" unless project.notes_count == 0 + s + end def link_to_context(context, descriptor = sanitize(context.name)) link_to( descriptor, context_path(context), :title => "View context: #{context.name}" ) diff --git a/tracks/app/views/projects/_project_listing.rhtml b/tracks/app/views/projects/_project_listing.rhtml index a2d99242..736897d7 100644 --- a/tracks/app/views/projects/_project_listing.rhtml +++ b/tracks/app/views/projects/_project_listing.rhtml @@ -7,7 +7,7 @@ DRAG
- <%= link_to_project( project ) %><%= " (" + count_undone_todos_phrase(project,"actions") + ")" %> + <%= link_to_project( project ) %><%= " (" + count_undone_todos_and_notes_phrase(project,"actions") + ")" %>
<%= project.current_state.to_s.upcase %>