From 43fd27fd0ce4111501c36a6ef162aed61bf3318c Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Thu, 26 Nov 2009 20:12:20 +0000 Subject: Show last update datetime (last attachment added) on document list (#4232). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3095 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/documents_controller.rb | 2 +- app/models/document.rb | 8 ++++++++ app/views/documents/_document.rhtml | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) (limited to 'app') diff --git a/app/controllers/documents_controller.rb b/app/controllers/documents_controller.rb index c9eecf4f7..9d9c5a7d0 100644 --- a/app/controllers/documents_controller.rb +++ b/app/controllers/documents_controller.rb @@ -28,7 +28,7 @@ class DocumentsController < ApplicationController documents = @project.documents.find :all, :include => [:attachments, :category] case @sort_by when 'date' - @grouped = documents.group_by {|d| d.created_on.to_date } + @grouped = documents.group_by {|d| d.updated_on.to_date } when 'title' @grouped = documents.group_by {|d| d.title.first.upcase} when 'author' diff --git a/app/models/document.rb b/app/models/document.rb index a96c278d0..1318e823d 100644 --- a/app/models/document.rb +++ b/app/models/document.rb @@ -34,4 +34,12 @@ class Document < ActiveRecord::Base self.category ||= DocumentCategory.default end end + + def updated_on + unless @updated_on + a = attachments.find(:first, :order => 'created_on DESC') + @updated_on = (a && a.created_on) || created_on + end + @updated_on + end end diff --git a/app/views/documents/_document.rhtml b/app/views/documents/_document.rhtml index 47b450000..94a64ac80 100644 --- a/app/views/documents/_document.rhtml +++ b/app/views/documents/_document.rhtml @@ -1,3 +1,3 @@

<%= link_to h(document.title), :controller => 'documents', :action => 'show', :id => document %>
<% unless document.description.blank? %><%=h(truncate(document.description, :length => 250)) %>
<% end %> -<%= format_time(document.created_on) %>

\ No newline at end of file +<%= format_time(document.updated_on) %>

\ No newline at end of file -- cgit v1.2.3