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