课程、项目模块增加分页功能

This commit is contained in:
sw 2014-08-21 10:37:53 +08:00
parent 3343e1c413
commit 16d86a1fbd
4 changed files with 95 additions and 54 deletions

View File

@ -38,6 +38,17 @@ class FilesController < ApplicationController
@isproject = true
@containers = [ Project.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@project.id)]
@containers += @project.versions.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").all.sort
all_attachments = []
@containers.each do |container|
all_attachments += container.attachments
end
@limit = 10
@feedback_count = all_attachments.count
@feedback_pages = Paginator.new @feedback_count, @limit, params['page']
@offset ||= @feedback_pages.offset
@curse_attachments = all_attachments[@offset, @limit]
render :layout => !request.xhr?
elsif params[:course_id]
@isproject = false
@ -67,6 +78,18 @@ class FilesController < ApplicationController
else
@containers = [ Course.includes(:attachments).reorder("#{Attachment.table_name}.created_on desc").find(@course.id)]
end
all_attachments = []
@containers.each do |container|
all_attachments += container.attachments
end
@limit = 10
@feedback_count = all_attachments.count
@feedback_pages = Paginator.new @feedback_count, @limit, params['page']
@offset ||= @feedback_pages.offset
@curse_attachments = all_attachments[@offset, @limit]
render :layout => 'base_courses'
end
end

View File

@ -29,9 +29,9 @@ class Attachment < ActiveRecord::Base
include UserScoreHelper
validates_presence_of :filename, :author
validates_length_of :filename, :maximum => 255
validates_length_of :disk_filename, :maximum => 255
validates_length_of :description, :maximum => 255
validates_length_of :filename, :maximum => 254
validates_length_of :disk_filename, :maximum => 254
validates_length_of :description, :maximum => 254
validate :validate_max_file_size

View File

@ -25,16 +25,17 @@
</tr>
</thead>
<tbody>
<% @containers.each do |container| %>
<% next if container.attachments.empty? -%>
<% if container.is_a?(Version) -%>
<tr>
<%# @containers.each do |container| %>
<%# next if container.attachments.empty? -%>
<%# if container.is_a?(Version) -%>
<!--<tr>
<th colspan="5" align="left" style="line-height: 30px; font-size: 14px; ">
<%= link_to(h(container), {:controller => 'versions', :action => 'show', :id => container}, :class => "icon icon-package", :style => "color: #666666;") %>
<%#= link_to(h(container), {:controller => 'versions', :action => 'show', :id => container}, :class => "icon icon-package", :style => "color: #666666;") %>
</th>
</tr>
<% end -%>
<% container.attachments.each do |file| %>
</tr>-->
<%# end -%>
<% if @curse_attachments != nil %>
<% @curse_attachments.each do |file| %>
<%if file.is_public == 0 && !User.current.member_of_course?(@course)%>
<%next%>
<%end%>
@ -75,10 +76,19 @@
</td>
</tr>
<% end -%>
<% reset_cycle %>
<% end -%>
<% end %>
<%# reset_cycle %>
<%# end -%>
<!-- %= h downloadAll(@containers) % -->
<!-- %= link_to "download all file", (downloadAll(@containers)) % -->
</tbody>
</table>
<!--分页-->
<div class="pagination" style="float:left;">
<ul>
<%= pagination_links_full @feedback_pages %>
</ul>
</div>

View File

@ -25,16 +25,17 @@
</tr>
</thead>
<tbody>
<% @containers.each do |container| %>
<% next if container.attachments.empty? -%>
<% if container.is_a?(Version) -%>
<tr>
<%# @containers.each do |container| %>
<%# next if container.attachments.empty? -%>
<%# if container.is_a?(Version) -%>
<!--tr>
<th colspan="5" align="left" style="line-height: 30px; font-size: 14px; ">
<%= link_to(h(container), {:controller => 'versions', :action => 'show', :id => container}, :class => "icon icon-package", :style => "color: #666666;") %>
<%#= link_to(h(container), {:controller => 'versions', :action => 'show', :id => container}, :class => "icon icon-package", :style => "color: #666666;") %>
</th>
</tr>
<% end -%>
<% container.attachments.each do |file| %>
</tr-->
<%# end -%>
<% if @curse_attachments != nil %>
<% @curse_attachments.each do |file| %>
<%if file.is_public == 0 && !User.current.member_of?(@project)%>
<%next%>
<%end%>
@ -75,10 +76,17 @@
</td>
</tr>
<% end -%>
<% reset_cycle %>
<%# reset_cycle %>
<% end -%>
<!-- %= h downloadAll(@containers) % -->
<!-- %= link_to "download all file", (downloadAll(@containers)) % -->
</tbody>
</table>
<!--分页-->
<div class="pagination" style="float:left;">
<ul>
<%= pagination_links_full @feedback_pages %>
</ul>
</div>