added one line and table type

This commit is contained in:
Harry Bomrah 2016-03-22 18:06:03 +08:00
parent 2d222037c0
commit 09591e8ae5
3 changed files with 90 additions and 23 deletions

View File

@ -1,24 +1,63 @@
class PersonalBooksController < ApplicationController class PersonalBooksController < ApplicationController
def index def index
params = OrbitHelper.params
books = Book.where(:is_hidden=>false).order_by(:year=>'desc').page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) books = Book.where(:is_hidden=>false).order_by(:year=>'desc').page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count)
book_list = books.collect do |book| page = Page.where(:page_id => params[:page_id]).first rescue nil
{
"book_title" => book.create_link, if page.custom_string_field == "table"
"author" => book.authors, fields_to_show = [
"year" => book.year, "authors",
"book_paper_type" => (book.book_type.title rescue nil), "book_title",
"link_to_show" => OrbitHelper.url_to_show(book.to_param) "extracted_chapters",
"publisher",
"isbn",
"publish_date"
]
else
fields_to_show = [
"year",
"book_title"
]
end
book_list = []
books.each do |book|
t = []
fields_to_show.each do |fs|
case fs
when "book_title"
if page.custom_string_field == "table"
t << {"value" => "<a href='#{OrbitHelper.url_to_show(book.to_param)}'>#{book.book_title}</a>"}
else
t << {"value" => "<a href='#{OrbitHelper.url_to_show(book.to_param)}'>#{book.create_link}</a>"}
end
when "publish_date"
pd = ""
if !book.publish_date.nil?
pd = book.publish_date.strftime("%Y-%m-%d").split('-')
pd = pd[0]+"/"+pd[1]
end
t << {"value" => pd}
else
t << {"value" => book.send(fs)}
end
end
book_list << {"books" => t}
end
headers = []
fields_to_show.each do |fs|
col = 2
col = 3 if fs == "paper_title"
headers << {
"head-title" => t("personal_book.#{fs}"),
"col" => col
} }
end end
{ {
"books" => book_list, "book_list" => book_list,
"extras" => { "extras" => {"widget-title" => t("module_name.book")},
"widget-title" => t("module_name.book"), "headers" => headers,
"th_year" => t('personal_plugins.year'),
"th_title" => t("personal_book.book_title"),
"th_book_paper_type" => t("personal_book.book_paper_type"),
"th_author" => t('personal_book.authors')
},
"total_pages" => books.total_pages "total_pages" => books.total_pages
} }
end end

View File

@ -62,10 +62,22 @@ class Book
end end
def self.get_plugin_datas_to_member(datas) def self.get_plugin_datas_to_member(datas)
page = Page.where(:module => "personal_book").first rescue nil
if page.custom_string_field == "table"
fields_to_show = [
"authors",
"book_title",
"extracted_chapters",
"publisher",
"isbn",
"publish_date"
]
else
fields_to_show = [ fields_to_show = [
"year", "year",
"book_title" "book_title"
] ]
end
fields_to_remove = [] fields_to_remove = []
@ -88,12 +100,28 @@ class Book
pd_data = [] pd_data = []
fields_to_show.collect do |t| fields_to_show.collect do |t|
if page.custom_string_field == "table"
case t
when "book_title"
pd_data << { "data_title" => "<a href='#{OrbitHelper.url_to_plugin_show(p.to_param,'personal_book')}' target='_blank'>#{p.book_title}</a>" }
when "publish_date"
pd = ""
if !p.publish_date.nil?
pd = p.publish_date.strftime("%Y-%m-%d").split('-')
pd = pd[0]+"/"+pd[1]
end
pd_data << {"data_title" => pd}
else
pd_data << { "data_title" => p.send(t) }
end
else
if t == "book_title" if t == "book_title"
pd_data << { "data_title" => "<a href='#{OrbitHelper.url_to_plugin_show(p.to_param,'personal_book')}' target='_blank'>#{p.create_link}</a>" } pd_data << { "data_title" => "<a href='#{OrbitHelper.url_to_plugin_show(p.to_param,'personal_book')}' target='_blank'>#{p.create_link}</a>" }
else else
pd_data << { "data_title" => p.send(t) } pd_data << { "data_title" => p.send(t) }
end end
end end
end
{ {
"pd_datas" => pd_data "pd_datas" => pd_data

View File

@ -4,7 +4,7 @@ module PersonalBook
OrbitApp.registration "PersonalBook",:type=> 'ModuleApp' do OrbitApp.registration "PersonalBook",:type=> 'ModuleApp' do
module_label 'module_name.book' module_label 'module_name.book'
base_url File.expand_path File.dirname(__FILE__) base_url File.expand_path File.dirname(__FILE__)
personal_plugin :enable => true, :sort_number => '25', :app_name=>"Book", :intro_app_name=>"BookIntro",:path=>"/plugin/personal_book/profile",:front_path=>"/profile",:admin_path=>"/admin/books",:i18n=>'module_name.book',:module_app_name=>'PersonalBook' personal_plugin :enable => true, :sort_number => '25', :app_name=>"Book", :intro_app_name=>"BookIntro",:path=>"/plugin/personal_book/profile",:front_path=>"/profile",:admin_path=>"/admin/books",:i18n=>'module_name.book',:module_app_name=>'PersonalBook', :one_line_title => true
version "0.1" version "0.1"
desktop_enabled true desktop_enabled true