##// END OF EJS Templates
Show last update datetime (last attachment added) on document list (#4232)....
Jean-Philippe Lang -
r2981:43fd27fd0ce4
parent child
Show More
@@ -1,88 +1,88
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class DocumentsController < ApplicationController
19 19 default_search_scope :documents
20 20 before_filter :find_project, :only => [:index, :new]
21 21 before_filter :find_document, :except => [:index, :new]
22 22 before_filter :authorize
23 23
24 24 helper :attachments
25 25
26 26 def index
27 27 @sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category'
28 28 documents = @project.documents.find :all, :include => [:attachments, :category]
29 29 case @sort_by
30 30 when 'date'
31 @grouped = documents.group_by {|d| d.created_on.to_date }
31 @grouped = documents.group_by {|d| d.updated_on.to_date }
32 32 when 'title'
33 33 @grouped = documents.group_by {|d| d.title.first.upcase}
34 34 when 'author'
35 35 @grouped = documents.select{|d| d.attachments.any?}.group_by {|d| d.attachments.last.author}
36 36 else
37 37 @grouped = documents.group_by(&:category)
38 38 end
39 39 @document = @project.documents.build
40 40 render :layout => false if request.xhr?
41 41 end
42 42
43 43 def show
44 44 @attachments = @document.attachments.find(:all, :order => "created_on DESC")
45 45 end
46 46
47 47 def new
48 48 @document = @project.documents.build(params[:document])
49 49 if request.post? and @document.save
50 50 attach_files(@document, params[:attachments])
51 51 flash[:notice] = l(:notice_successful_create)
52 52 redirect_to :action => 'index', :project_id => @project
53 53 end
54 54 end
55 55
56 56 def edit
57 57 @categories = DocumentCategory.all
58 58 if request.post? and @document.update_attributes(params[:document])
59 59 flash[:notice] = l(:notice_successful_update)
60 60 redirect_to :action => 'show', :id => @document
61 61 end
62 62 end
63 63
64 64 def destroy
65 65 @document.destroy
66 66 redirect_to :controller => 'documents', :action => 'index', :project_id => @project
67 67 end
68 68
69 69 def add_attachment
70 70 attachments = attach_files(@document, params[:attachments])
71 71 Mailer.deliver_attachments_added(attachments) if !attachments.empty? && Setting.notified_events.include?('document_added')
72 72 redirect_to :action => 'show', :id => @document
73 73 end
74 74
75 75 private
76 76 def find_project
77 77 @project = Project.find(params[:project_id])
78 78 rescue ActiveRecord::RecordNotFound
79 79 render_404
80 80 end
81 81
82 82 def find_document
83 83 @document = Document.find(params[:id])
84 84 @project = @document.project
85 85 rescue ActiveRecord::RecordNotFound
86 86 render_404
87 87 end
88 88 end
@@ -1,37 +1,45
1 1 # redMine - project management software
2 2 # Copyright (C) 2006 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class Document < ActiveRecord::Base
19 19 belongs_to :project
20 20 belongs_to :category, :class_name => "DocumentCategory", :foreign_key => "category_id"
21 21 acts_as_attachable :delete_permission => :manage_documents
22 22
23 23 acts_as_searchable :columns => ['title', "#{table_name}.description"], :include => :project
24 24 acts_as_event :title => Proc.new {|o| "#{l(:label_document)}: #{o.title}"},
25 25 :author => Proc.new {|o| (a = o.attachments.find(:first, :order => "#{Attachment.table_name}.created_on ASC")) ? a.author : nil },
26 26 :url => Proc.new {|o| {:controller => 'documents', :action => 'show', :id => o.id}}
27 27 acts_as_activity_provider :find_options => {:include => :project}
28 28
29 29 validates_presence_of :project, :title, :category
30 30 validates_length_of :title, :maximum => 60
31 31
32 32 def after_initialize
33 33 if new_record?
34 34 self.category ||= DocumentCategory.default
35 35 end
36 36 end
37
38 def updated_on
39 unless @updated_on
40 a = attachments.find(:first, :order => 'created_on DESC')
41 @updated_on = (a && a.created_on) || created_on
42 end
43 @updated_on
44 end
37 45 end
@@ -1,3 +1,3
1 1 <p><%= link_to h(document.title), :controller => 'documents', :action => 'show', :id => document %><br />
2 2 <% unless document.description.blank? %><%=h(truncate(document.description, :length => 250)) %><br /><% end %>
3 <em><%= format_time(document.created_on) %></em></p> No newline at end of file
3 <em><%= format_time(document.updated_on) %></em></p> No newline at end of file
@@ -1,124 +1,136
1 1 ---
2 2 attachments_001:
3 3 created_on: 2006-07-19 21:07:27 +02:00
4 4 downloads: 0
5 5 content_type: text/plain
6 6 disk_filename: 060719210727_error281.txt
7 7 container_id: 3
8 8 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
9 9 id: 1
10 10 container_type: Issue
11 11 filesize: 28
12 12 filename: error281.txt
13 13 author_id: 2
14 14 attachments_002:
15 created_on: 2006-07-19 21:07:27 +02:00
15 created_on: 2007-01-27 15:08:27 +01:00
16 16 downloads: 0
17 17 content_type: text/plain
18 18 disk_filename: 060719210727_document.txt
19 19 container_id: 1
20 20 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
21 21 id: 2
22 22 container_type: Document
23 23 filesize: 28
24 24 filename: document.txt
25 25 author_id: 2
26 26 attachments_003:
27 27 created_on: 2006-07-19 21:07:27 +02:00
28 28 downloads: 0
29 29 content_type: image/gif
30 30 disk_filename: 060719210727_logo.gif
31 31 container_id: 4
32 32 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
33 33 id: 3
34 34 container_type: WikiPage
35 35 filesize: 280
36 36 filename: logo.gif
37 37 description: This is a logo
38 38 author_id: 2
39 39 attachments_004:
40 40 created_on: 2006-07-19 21:07:27 +02:00
41 41 container_type: Issue
42 42 container_id: 3
43 43 downloads: 0
44 44 disk_filename: 060719210727_source.rb
45 45 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
46 46 id: 4
47 47 filesize: 153
48 48 filename: source.rb
49 49 author_id: 2
50 50 description: This is a Ruby source file
51 51 content_type: application/x-ruby
52 52 attachments_005:
53 53 created_on: 2006-07-19 21:07:27 +02:00
54 54 container_type: Issue
55 55 container_id: 3
56 56 downloads: 0
57 57 disk_filename: 060719210727_changeset.diff
58 58 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
59 59 id: 5
60 60 filesize: 687
61 61 filename: changeset.diff
62 62 author_id: 2
63 63 content_type: text/x-diff
64 64 attachments_006:
65 65 created_on: 2006-07-19 21:07:27 +02:00
66 66 container_type: Issue
67 67 container_id: 3
68 68 downloads: 0
69 69 disk_filename: 060719210727_archive.zip
70 70 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
71 71 id: 6
72 72 filesize: 157
73 73 filename: archive.zip
74 74 author_id: 2
75 75 content_type: application/octet-stream
76 76 attachments_007:
77 77 created_on: 2006-07-19 21:07:27 +02:00
78 78 container_type: Issue
79 79 container_id: 4
80 80 downloads: 0
81 81 disk_filename: 060719210727_archive.zip
82 82 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
83 83 id: 7
84 84 filesize: 157
85 85 filename: archive.zip
86 86 author_id: 1
87 87 content_type: application/octet-stream
88 88 attachments_008:
89 89 created_on: 2006-07-19 21:07:27 +02:00
90 90 container_type: Project
91 91 container_id: 1
92 92 downloads: 0
93 93 disk_filename: 060719210727_project_file.zip
94 94 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
95 95 id: 8
96 96 filesize: 320
97 97 filename: project_file.zip
98 98 author_id: 2
99 99 content_type: application/octet-stream
100 100 attachments_009:
101 101 created_on: 2006-07-19 21:07:27 +02:00
102 102 container_type: Version
103 103 container_id: 1
104 104 downloads: 0
105 105 disk_filename: 060719210727_version_file.zip
106 106 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
107 107 id: 9
108 108 filesize: 452
109 109 filename: version_file.zip
110 110 author_id: 2
111 111 content_type: application/octet-stream
112 112 attachments_010:
113 113 created_on: 2006-07-19 21:07:27 +02:00
114 114 container_type: Issue
115 115 container_id: 2
116 116 downloads: 0
117 117 disk_filename: 060719210727_picture.jpg
118 118 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
119 119 id: 10
120 120 filesize: 452
121 121 filename: picture.jpg
122 122 author_id: 2
123 123 content_type: image/jpeg
124 attachments_011:
125 created_on: 2007-02-12 15:08:27 +01:00
126 container_type: Document
127 container_id: 1
128 downloads: 0
129 disk_filename: 060719210727_picture.jpg
130 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
131 id: 11
132 filesize: 452
133 filename: picture.jpg
134 author_id: 2
135 content_type: image/jpeg
124 136 No newline at end of file
@@ -1,7 +1,14
1 1 documents_001:
2 2 created_on: 2007-01-27 15:08:27 +01:00
3 3 project_id: 1
4 4 title: "Test document"
5 5 id: 1
6 6 description: "Document description"
7 category_id: 1 No newline at end of file
7 category_id: 1
8 documents_002:
9 created_on: 2007-02-12 15:08:27 +01:00
10 project_id: 1
11 title: "An other document"
12 id: 2
13 description: ""
14 category_id: 2 No newline at end of file
@@ -1,46 +1,58
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2008 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.dirname(__FILE__) + '/../test_helper'
19 19
20 20 class DocumentTest < ActiveSupport::TestCase
21 fixtures :projects, :enumerations, :documents
21 fixtures :projects, :enumerations, :documents, :attachments
22 22
23 23 def test_create
24 24 doc = Document.new(:project => Project.find(1), :title => 'New document', :category => Enumeration.find_by_name('User documentation'))
25 25 assert doc.save
26 26 end
27 27
28 28 def test_create_should_send_email_notification
29 29 ActionMailer::Base.deliveries.clear
30 30 Setting.notified_events << 'document_added'
31 31 doc = Document.new(:project => Project.find(1), :title => 'New document', :category => Enumeration.find_by_name('User documentation'))
32 32
33 33 assert doc.save
34 34 assert_equal 1, ActionMailer::Base.deliveries.size
35 35 end
36 36
37 37 def test_create_with_default_category
38 38 # Sets a default category
39 39 e = Enumeration.find_by_name('Technical documentation')
40 40 e.update_attributes(:is_default => true)
41 41
42 42 doc = Document.new(:project => Project.find(1), :title => 'New document')
43 43 assert_equal e, doc.category
44 44 assert doc.save
45 45 end
46
47 def test_updated_on_with_attachments
48 d = Document.find(1)
49 assert d.attachments.any?
50 assert_equal d.attachments.map(&:created_on).max, d.updated_on
51 end
52
53 def test_updated_on_without_attachments
54 d = Document.find(2)
55 assert d.attachments.empty?
56 assert_equal d.created_on, d.updated_on
57 end
46 58 end
General Comments 0
You need to be logged in to leave comments. Login now