课程、项目模块增加分页功能
This commit is contained in:
parent
3343e1c413
commit
16d86a1fbd
|
@ -38,6 +38,17 @@ class FilesController < ApplicationController
|
||||||
@isproject = true
|
@isproject = true
|
||||||
@containers = [ Project.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@project.id)]
|
@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
|
@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?
|
render :layout => !request.xhr?
|
||||||
elsif params[:course_id]
|
elsif params[:course_id]
|
||||||
@isproject = false
|
@isproject = false
|
||||||
|
@ -67,6 +78,18 @@ class FilesController < ApplicationController
|
||||||
else
|
else
|
||||||
@containers = [ Course.includes(:attachments).reorder("#{Attachment.table_name}.created_on desc").find(@course.id)]
|
@containers = [ Course.includes(:attachments).reorder("#{Attachment.table_name}.created_on desc").find(@course.id)]
|
||||||
end
|
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'
|
render :layout => 'base_courses'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -29,9 +29,9 @@ class Attachment < ActiveRecord::Base
|
||||||
include UserScoreHelper
|
include UserScoreHelper
|
||||||
|
|
||||||
validates_presence_of :filename, :author
|
validates_presence_of :filename, :author
|
||||||
validates_length_of :filename, :maximum => 255
|
validates_length_of :filename, :maximum => 254
|
||||||
validates_length_of :disk_filename, :maximum => 255
|
validates_length_of :disk_filename, :maximum => 254
|
||||||
validates_length_of :description, :maximum => 255
|
validates_length_of :description, :maximum => 254
|
||||||
validate :validate_max_file_size
|
validate :validate_max_file_size
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -25,60 +25,70 @@
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<% @containers.each do |container| %>
|
<%# @containers.each do |container| %>
|
||||||
<% next if container.attachments.empty? -%>
|
<%# next if container.attachments.empty? -%>
|
||||||
<% if container.is_a?(Version) -%>
|
<%# if container.is_a?(Version) -%>
|
||||||
<tr>
|
<!--<tr>
|
||||||
<th colspan="5" align="left" style="line-height: 30px; font-size: 14px; ">
|
<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>
|
</th>
|
||||||
</tr>
|
</tr>-->
|
||||||
<% end -%>
|
<%# end -%>
|
||||||
<% container.attachments.each do |file| %>
|
<% if @curse_attachments != nil %>
|
||||||
<%if file.is_public == 0 && !User.current.member_of_course?(@course)%>
|
<% @curse_attachments.each do |file| %>
|
||||||
<%next%>
|
<%if file.is_public == 0 && !User.current.member_of_course?(@course)%>
|
||||||
<%end%>
|
<%next%>
|
||||||
<tr class="file <%= cycle("odd", "odd") %>">
|
<%end%>
|
||||||
<td class="filename" style="font-size: 13px; "><%= link_to_attachment file, :download => true, :title => file.filename+"\n"+file.description.to_s, :style => "width: 230px; overflow: hidden; white-space: nowrap;text-overflow: ellipsis;" %></td>
|
<tr class="file <%= cycle("odd", "odd") %>">
|
||||||
<!-- <td class="created_on"><%#= format_time(file.created_on) %></td> -->
|
<td class="filename" style="font-size: 13px; "><%= link_to_attachment file, :download => true, :title => file.filename+"\n"+file.description.to_s, :style => "width: 230px; overflow: hidden; white-space: nowrap;text-overflow: ellipsis;" %></td>
|
||||||
<td class="filesize"><%= number_to_human_size(file.filesize) %></td>
|
<!-- <td class="created_on"><%#= format_time(file.created_on) %></td> -->
|
||||||
<td class="attach_type">
|
<td class="filesize"><%= number_to_human_size(file.filesize) %></td>
|
||||||
<span id="attach_type_id_label<%= file.id %>" style="white-space:nowrap;"><%= file.attachmentstype.typeName unless file.attachmentstype.nil? %></span>
|
<td class="attach_type">
|
||||||
|
<span id="attach_type_id_label<%= file.id %>" style="white-space:nowrap;"><%= file.attachmentstype.typeName unless file.attachmentstype.nil? %></span>
|
||||||
<span id="attach_type_id_edit<%= file.id %>" style="white-space:nowrap;">
|
<span id="attach_type_id_edit<%= file.id %>" style="white-space:nowrap;">
|
||||||
<%= render :partial => 'attachments/course_type_edit', :locals => {:attachmenttypes => attachmenttypes, :attachment => file, :contentype => selContentType} %>
|
<%= render :partial => 'attachments/course_type_edit', :locals => {:attachmenttypes => attachmenttypes, :attachment => file, :contentype => selContentType} %>
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
<td class="content_type"><%= file.show_suffix_type %></td>
|
<td class="content_type"><%= file.show_suffix_type %></td>
|
||||||
<td class="field_file_dense">
|
<td class="field_file_dense">
|
||||||
<span id="field_file_dense_id_label<%= file.id %>" style="white-space:nowrap;"><%= file.file_dense_str %></span>
|
<span id="field_file_dense_id_label<%= file.id %>" style="white-space:nowrap;"><%= file.file_dense_str %></span>
|
||||||
|
|
||||||
<span id="field_file_dense_id_edit<%= file.id %>" style="white-space:nowrap;">
|
<span id="field_file_dense_id_edit<%= file.id %>" style="white-space:nowrap;">
|
||||||
<%= render :partial => 'course_file_dense_edit', :locals => {:file_dense_list => file.file_dense_list,
|
<%= render :partial => 'course_file_dense_edit', :locals => {:file_dense_list => file.file_dense_list,
|
||||||
:attachment => file} %>
|
:attachment => file} %>
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
<td class="downloads"><%= file.downloads %></td>
|
<td class="downloads"><%= file.downloads %></td>
|
||||||
<!-- <td class="digest" width="300px"><%= file.description %></td> -->
|
<!-- <td class="digest" width="300px"><%= file.description %></td> -->
|
||||||
<td align="center">
|
<td align="center">
|
||||||
<%= link_to(image_tag('delete.png'), attachment_path(file),
|
<%= link_to(image_tag('delete.png'), attachment_path(file),
|
||||||
:data => {:confirm => l(:text_are_you_sure)}, :method => :delete) if delete_allowed %>
|
:data => {:confirm => l(:text_are_you_sure)}, :method => :delete) if delete_allowed %>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td class='description' colspan="6">
|
<td class='description' colspan="6">
|
||||||
<div class="tags_area">
|
<div class="tags_area">
|
||||||
<%# @preTags = %w|预设A 预设B 预设C 预设D 预设E 预设Z | %>
|
<%# @preTags = %w|预设A 预设B 预设C 预设D 预设E 预设Z | %>
|
||||||
<%= render :partial => 'tags/tag', :locals => {:obj => file, :object_flag => "6"} %>
|
<%= render :partial => 'tags/tag', :locals => {:obj => file, :object_flag => "6"} %>
|
||||||
<div class="tags_gradint"></div>
|
<div class="tags_gradint"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="read-more hidden"><a href="javascript:void(0);" onclick="readmore(this);"> 更多 </a></div>
|
<div class="read-more hidden"><a href="javascript:void(0);" onclick="readmore(this);"> 更多 </a></div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end -%>
|
|
||||||
<% reset_cycle %>
|
|
||||||
<% end -%>
|
<% end -%>
|
||||||
|
<% end %>
|
||||||
|
<%# reset_cycle %>
|
||||||
|
<%# end -%>
|
||||||
<!-- %= h downloadAll(@containers) % -->
|
<!-- %= h downloadAll(@containers) % -->
|
||||||
<!-- %= link_to "download all file", (downloadAll(@containers)) % -->
|
<!-- %= link_to "download all file", (downloadAll(@containers)) % -->
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
<!--分页-->
|
||||||
|
<div class="pagination" style="float:left;">
|
||||||
|
<ul>
|
||||||
|
<%= pagination_links_full @feedback_pages %>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
|
@ -25,16 +25,17 @@
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<% @containers.each do |container| %>
|
<%# @containers.each do |container| %>
|
||||||
<% next if container.attachments.empty? -%>
|
<%# next if container.attachments.empty? -%>
|
||||||
<% if container.is_a?(Version) -%>
|
<%# if container.is_a?(Version) -%>
|
||||||
<tr>
|
<!--tr>
|
||||||
<th colspan="5" align="left" style="line-height: 30px; font-size: 14px; ">
|
<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>
|
</th>
|
||||||
</tr>
|
</tr-->
|
||||||
<% end -%>
|
<%# end -%>
|
||||||
<% container.attachments.each do |file| %>
|
<% if @curse_attachments != nil %>
|
||||||
|
<% @curse_attachments.each do |file| %>
|
||||||
<%if file.is_public == 0 && !User.current.member_of?(@project)%>
|
<%if file.is_public == 0 && !User.current.member_of?(@project)%>
|
||||||
<%next%>
|
<%next%>
|
||||||
<%end%>
|
<%end%>
|
||||||
|
@ -75,10 +76,17 @@
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end -%>
|
<% end -%>
|
||||||
<% reset_cycle %>
|
<%# reset_cycle %>
|
||||||
<% end -%>
|
<% end -%>
|
||||||
<!-- %= h downloadAll(@containers) % -->
|
<!-- %= h downloadAll(@containers) % -->
|
||||||
<!-- %= link_to "download all file", (downloadAll(@containers)) % -->
|
<!-- %= link_to "download all file", (downloadAll(@containers)) % -->
|
||||||
|
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
<!--分页-->
|
||||||
|
<div class="pagination" style="float:left;">
|
||||||
|
<ul>
|
||||||
|
<%= pagination_links_full @feedback_pages %>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue