##// END OF EJS Templates
Adds pagination to admin project list....
Jean-Philippe Lang -
r15373:daab32923d85
parent child
Show More
@@ -34,7 +34,10 class AdminController < ApplicationController
34
34
35 scope = Project.status(@status).sorted
35 scope = Project.status(@status).sorted
36 scope = scope.like(params[:name]) if params[:name].present?
36 scope = scope.like(params[:name]) if params[:name].present?
37 @projects = scope.to_a
37
38 @project_count = scope.count
39 @project_pages = Paginator.new @project_count, per_page_option, params['page']
40 @projects = scope.limit(@project_pages.per_page).offset(@project_pages.offset).to_a
38
41
39 render :action => "projects", :layout => false if request.xhr?
42 render :action => "projects", :layout => false if request.xhr?
40 end
43 end
@@ -192,14 +192,14 class ProjectsController < ApplicationController
192 unless @project.archive
192 unless @project.archive
193 flash[:error] = l(:error_can_not_archive_project)
193 flash[:error] = l(:error_can_not_archive_project)
194 end
194 end
195 redirect_to admin_projects_path(:status => params[:status])
195 redirect_to_referer_or admin_projects_path(:status => params[:status])
196 end
196 end
197
197
198 def unarchive
198 def unarchive
199 unless @project.active?
199 unless @project.active?
200 @project.unarchive
200 @project.unarchive
201 end
201 end
202 redirect_to admin_projects_path(:status => params[:status])
202 redirect_to_referer_or admin_projects_path(:status => params[:status])
203 end
203 end
204
204
205 def close
205 def close
@@ -371,8 +371,8 module ApplicationHelper
371 # Yields the given block for each project with its level in the tree
371 # Yields the given block for each project with its level in the tree
372 #
372 #
373 # Wrapper for Project#project_tree
373 # Wrapper for Project#project_tree
374 def project_tree(projects, &block)
374 def project_tree(projects, options={}, &block)
375 Project.project_tree(projects, &block)
375 Project.project_tree(projects, options, &block)
376 end
376 end
377
377
378 def principals_check_box_tags(name, principals)
378 def principals_check_box_tags(name, principals)
@@ -816,8 +816,11 class Project < ActiveRecord::Base
816 end
816 end
817
817
818 # Yields the given block for each project with its level in the tree
818 # Yields the given block for each project with its level in the tree
819 def self.project_tree(projects, &block)
819 def self.project_tree(projects, options={}, &block)
820 ancestors = []
820 ancestors = []
821 if options[:init_level] && projects.first
822 ancestors = projects.first.ancestors.to_a
823 end
821 projects.sort_by(&:lft).each do |project|
824 projects.sort_by(&:lft).each do |project|
822 while (ancestors.any? && !project.is_descendant_of?(ancestors.last))
825 while (ancestors.any? && !project.is_descendant_of?(ancestors.last))
823 ancestors.pop
826 ancestors.pop
@@ -25,7 +25,7
25 <th></th>
25 <th></th>
26 </tr></thead>
26 </tr></thead>
27 <tbody>
27 <tbody>
28 <% project_tree(@projects) do |project, level| %>
28 <% project_tree(@projects, :init_level => true) do |project, level| %>
29 <tr class="<%= cycle("odd", "even") %> <%= project.css_classes %> <%= level > 0 ? "idnt idnt-#{level}" : nil %>">
29 <tr class="<%= cycle("odd", "even") %> <%= project.css_classes %> <%= level > 0 ? "idnt idnt-#{level}" : nil %>">
30 <td class="name"><span><%= link_to_project_settings(project, {}, :title => project.short_description) %></span></td>
30 <td class="name"><span><%= link_to_project_settings(project, {}, :title => project.short_description) %></span></td>
31 <td><%= checked_image project.is_public? %></td>
31 <td><%= checked_image project.is_public? %></td>
@@ -41,3 +41,4
41 </tbody>
41 </tbody>
42 </table>
42 </table>
43 </div>
43 </div>
44 <span class="pagination"><%= pagination_links_full @project_pages, @project_count %></span> No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now