From 457533154a70e7050dd7cd58775a78371589ed0c Mon Sep 17 00:00:00 2001 From: manson Date: Fri, 18 Jul 2014 14:29:33 +0800 Subject: [PATCH] Pagination --- app/controllers/admin/books_controller.rb | 2 +- app/controllers/books_controller.rb | 13 ++++++-- app/views/admin/books/_writing_book.html.erb | 32 +++++++++++--------- app/views/admin/books/index.html.erb | 5 ++- lib/personal_book/engine.rb | 1 + 5 files changed, 33 insertions(+), 20 deletions(-) diff --git a/app/controllers/admin/books_controller.rb b/app/controllers/admin/books_controller.rb index d922f57..9845722 100644 --- a/app/controllers/admin/books_controller.rb +++ b/app/controllers/admin/books_controller.rb @@ -8,7 +8,7 @@ class Admin::BooksController < OrbitMemberController before_action :set_plugin def index - @writing_books = Book.all + @writing_books = Book.order_by(:year=>'desc').page(params[:page]).per(10) respond_to do |format| format.html # index.html.erb format.js { } diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index 346b5b6..f8ee1d2 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -1,16 +1,23 @@ class BooksController < ApplicationController def index - books = Book.asc(:created_at) + books = Book.order_by(:year=>'desc').page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) book_list = books.collect do |book| { "book_title" => book.book_title, - "authors" => book.authors, + "author" => book.authors, + "year" => book.year, "link_to_show" => OrbitHelper.url_to_show(book.to_param) } end { "books" => book_list, - "extras" => {"widget-title" => "Books"} + "extras" => { + "widget-title" => t("module_name.book"), + "th_year" => t('personal_plugins.year'), + "th_title" => t("personal_book.book_title"), + "th_author" => t('personal_plugins.author') + }, + "total_pages" => books.total_pages } end diff --git a/app/views/admin/books/_writing_book.html.erb b/app/views/admin/books/_writing_book.html.erb index 75c4b45..4cde60e 100644 --- a/app/views/admin/books/_writing_book.html.erb +++ b/app/views/admin/books/_writing_book.html.erb @@ -1,15 +1,17 @@ - - <%= writing_book.year %> - - <%= link_to writing_book.create_link, page_for_book(writing_book), target: "blank" %> -
- -
- - <%= writing_book.authors%> - \ No newline at end of file +<% @writing_books.each do |writing_book| %> + + <%= writing_book.year %> + + <%= link_to writing_book.create_link, page_for_book(writing_book), target: "blank" %> +
+ +
+ + <%= writing_book.authors%> + +<% end %> \ No newline at end of file diff --git a/app/views/admin/books/index.html.erb b/app/views/admin/books/index.html.erb index e96a2cc..3ef33ce 100644 --- a/app/views/admin/books/index.html.erb +++ b/app/views/admin/books/index.html.erb @@ -7,7 +7,7 @@ - <%= render :partial => 'writing_book', :collection => @writing_books %> + <%= render 'writing_book' %> @@ -16,4 +16,7 @@ <%= link_to content_tag(:i, nil, :class => 'icon-cog icon-white') + t('setting'), admin_book_setting_path, :class => 'btn btn-primary pull-right' %> <%= link_to content_tag(:i, nil, :class => 'icon-plus icon-white') + t('announcement.add_new'), new_admin_book_path, :class => 'btn btn-primary pull-right' %> + \ No newline at end of file diff --git a/lib/personal_book/engine.rb b/lib/personal_book/engine.rb index 1aeeac1..916141a 100644 --- a/lib/personal_book/engine.rb +++ b/lib/personal_book/engine.rb @@ -13,6 +13,7 @@ module PersonalBook update_info 'some update_info' frontend_enabled icon_class_no_sidebar "icons-user" + data_count 1..10 end end end