mirror of
https://github.com/meineerde/redmine.git
synced 2026-04-07 08:21:43 +00:00
Show recent documents first (#29725).
Patch by Yuichi HARADA. git-svn-id: http://svn.redmine.org/redmine/trunk@17972 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
c5c335924b
commit
e26ab0d4a2
@ -33,7 +33,8 @@ class DocumentsController < ApplicationController
|
|||||||
documents = @project.documents.includes(:attachments, :category).to_a
|
documents = @project.documents.includes(:attachments, :category).to_a
|
||||||
case @sort_by
|
case @sort_by
|
||||||
when 'date'
|
when 'date'
|
||||||
@grouped = documents.group_by {|d| d.updated_on.to_date }
|
documents.sort!{|a,b| b.updated_on <=> a.updated_on}
|
||||||
|
@grouped = documents.group_by {|d| d.updated_on.to_date}
|
||||||
when 'title'
|
when 'title'
|
||||||
@grouped = documents.group_by {|d| d.title.first.upcase}
|
@grouped = documents.group_by {|d| d.title.first.upcase}
|
||||||
when 'author'
|
when 'author'
|
||||||
|
|||||||
@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
<% if @grouped.empty? %><p class="nodata"><%= l(:label_no_data) %></p><% end %>
|
<% if @grouped.empty? %><p class="nodata"><%= l(:label_no_data) %></p><% end %>
|
||||||
|
|
||||||
<% @grouped.keys.sort.each do |group| %>
|
<% @grouped.keys.sort.__send__(@sort_by == 'date' ? :reverse_each : :each) do |group| %>
|
||||||
<h3><%= group %></h3>
|
<h3><%= group %></h3>
|
||||||
<%= render :partial => 'documents/document', :collection => @grouped[group] %>
|
<%= render :partial => 'documents/document', :collection => @grouped[group] %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
13
test/fixtures/attachments.yml
vendored
13
test/fixtures/attachments.yml
vendored
@ -268,3 +268,16 @@ attachments_020:
|
|||||||
filename: root_attachment.txt
|
filename: root_attachment.txt
|
||||||
filesize: 54
|
filesize: 54
|
||||||
author_id: 2
|
author_id: 2
|
||||||
|
attachments_021:
|
||||||
|
created_on: 2007-03-05 15:08:27 +01:00
|
||||||
|
container_type: Document
|
||||||
|
container_id: 3
|
||||||
|
downloads: 0
|
||||||
|
disk_filename: 060719210727_archive.zip
|
||||||
|
disk_directory: "2006/07"
|
||||||
|
digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
|
||||||
|
id: 21
|
||||||
|
filesize: 157
|
||||||
|
filename: archive.zip
|
||||||
|
author_id: 1
|
||||||
|
content_type: application/zip
|
||||||
|
|||||||
7
test/fixtures/documents.yml
vendored
7
test/fixtures/documents.yml
vendored
@ -12,3 +12,10 @@ documents_002:
|
|||||||
id: 2
|
id: 2
|
||||||
description: ""
|
description: ""
|
||||||
category_id: 1
|
category_id: 1
|
||||||
|
documents_003:
|
||||||
|
created_on: 2007-03-05 15:08:27 +01:00
|
||||||
|
project_id: 1
|
||||||
|
title: "An other document 2"
|
||||||
|
id: 3
|
||||||
|
description: ""
|
||||||
|
category_id: 3
|
||||||
|
|||||||
@ -47,13 +47,32 @@ class DocumentsControllerTest < Redmine::ControllerTest
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_index_grouped_by_category
|
||||||
|
get :index, :params => {
|
||||||
|
:project_id => 'ecookbook',
|
||||||
|
:sort_by => 'category'
|
||||||
|
}
|
||||||
|
assert_response :success
|
||||||
|
assert_select '#content' do
|
||||||
|
# ascending order of DocumentCategory#id.
|
||||||
|
['Uncategorized', 'Technical documentation'].each_with_index do |text,idx|
|
||||||
|
assert_select "h3:nth-of-type(#{idx + 1})", :text => text
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_index_grouped_by_date
|
def test_index_grouped_by_date
|
||||||
get :index, :params => {
|
get :index, :params => {
|
||||||
:project_id => 'ecookbook',
|
:project_id => 'ecookbook',
|
||||||
:sort_by => 'date'
|
:sort_by => 'date'
|
||||||
}
|
}
|
||||||
assert_response :success
|
assert_response :success
|
||||||
assert_select 'h3', :text => '2007-02-12'
|
assert_select '#content' do
|
||||||
|
# descending order of date.
|
||||||
|
['2007-03-05', '2007-02-12'].each_with_index do |text,idx|
|
||||||
|
assert_select "h3:nth-of-type(#{idx + 1})", :text => text
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_index_grouped_by_title
|
def test_index_grouped_by_title
|
||||||
@ -62,7 +81,12 @@ class DocumentsControllerTest < Redmine::ControllerTest
|
|||||||
:sort_by => 'title'
|
:sort_by => 'title'
|
||||||
}
|
}
|
||||||
assert_response :success
|
assert_response :success
|
||||||
assert_select 'h3', :text => 'T'
|
assert_select '#content' do
|
||||||
|
# ascending order of title.
|
||||||
|
['A', 'T'].each_with_index do |text,idx|
|
||||||
|
assert_select "h3:nth-of-type(#{idx + 1})", :text => text
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_index_grouped_by_author
|
def test_index_grouped_by_author
|
||||||
@ -71,8 +95,13 @@ class DocumentsControllerTest < Redmine::ControllerTest
|
|||||||
:sort_by => 'author'
|
:sort_by => 'author'
|
||||||
}
|
}
|
||||||
assert_response :success
|
assert_response :success
|
||||||
assert_select 'h3', :text => 'John Smith'
|
assert_select '#content' do
|
||||||
end
|
# ascending order of author.
|
||||||
|
['John Smith', 'Redmine Admin'].each_with_index do |text,idx|
|
||||||
|
assert_select "h3:nth-of-type(#{idx + 1})", :text => text
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_index_with_long_description
|
def test_index_with_long_description
|
||||||
# adds a long description to the first document
|
# adds a long description to the first document
|
||||||
|
|||||||
@ -371,7 +371,7 @@ class ProjectCopyTest < ActiveSupport::TestCase
|
|||||||
source_project = Project.find(1)
|
source_project = Project.find(1)
|
||||||
assert @project.copy(source_project)
|
assert @project.copy(source_project)
|
||||||
|
|
||||||
assert_equal 2, @project.documents.size
|
assert_equal 3, @project.documents.size
|
||||||
@project.documents.each do |document|
|
@project.documents.each do |document|
|
||||||
assert !source_project.documents.include?(document)
|
assert !source_project.documents.include?(document)
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user