From ee08037aad7214888b95066cddbdacd91901f3f3 Mon Sep 17 00:00:00 2001 From: manson Date: Fri, 18 Jul 2014 15:06:04 +0800 Subject: [PATCH] Pagination --- app/controllers/admin/projects_controller.rb | 2 +- app/controllers/personal_projects_controller.rb | 5 +++-- app/views/admin/projects/index.html.erb | 3 ++- lib/personal_project/engine.rb | 1 + 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/controllers/admin/projects_controller.rb b/app/controllers/admin/projects_controller.rb index 6f4d1b0..e1206f7 100644 --- a/app/controllers/admin/projects_controller.rb +++ b/app/controllers/admin/projects_controller.rb @@ -5,7 +5,7 @@ class Admin::ProjectsController < OrbitMemberController before_action :get_settings,:only => [:new, :edit, :setting] def index - @projects = Project.all + @projects = Project.order_by(:period_start_date=>'desc',:year=>'desc').page(params[:page]).per(10) end def new diff --git a/app/controllers/personal_projects_controller.rb b/app/controllers/personal_projects_controller.rb index 6d7b8c6..1af1546 100644 --- a/app/controllers/personal_projects_controller.rb +++ b/app/controllers/personal_projects_controller.rb @@ -1,6 +1,6 @@ class PersonalProjectsController < ApplicationController def index - projects = Project.where(:is_hidden=>false).all + projects = Project.where(:is_hidden=>false).order_by(:year=>'desc').page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) project_list = projects.collect do |project| { "duration" => project.duration, @@ -20,7 +20,8 @@ class PersonalProjectsController < ApplicationController "th_job_title" => t('personal_project.job_title'), "th_participator" => t("personal_project.participator"), "th_authors" => t('users.name') - } + }, + "total_pages" => projects.total_pages } end diff --git a/app/views/admin/projects/index.html.erb b/app/views/admin/projects/index.html.erb index 9c54e5f..2f4fc96 100644 --- a/app/views/admin/projects/index.html.erb +++ b/app/views/admin/projects/index.html.erb @@ -10,7 +10,7 @@ - <%= render :partial => 'project', :collection => @projects %> + <%= render 'project' %> @@ -19,5 +19,6 @@ <%= link_to content_tag(:i, nil, :class => 'icon-cog icon-white') + t('setting'), admin_project_setting_path, :class => 'btn btn-primary pull-right' %> \ No newline at end of file diff --git a/lib/personal_project/engine.rb b/lib/personal_project/engine.rb index 015bc20..a584bb6 100644 --- a/lib/personal_project/engine.rb +++ b/lib/personal_project/engine.rb @@ -14,6 +14,7 @@ module PersonalProject frontend_enabled icon_class_no_sidebar "icons-user" + data_count 1..10 end end end