added one line and table type
This commit is contained in:
parent
2d222037c0
commit
09591e8ae5
|
@ -1,24 +1,63 @@
|
|||
class PersonalBooksController < ApplicationController
|
||||
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)
|
||||
book_list = books.collect do |book|
|
||||
{
|
||||
"book_title" => book.create_link,
|
||||
"author" => book.authors,
|
||||
"year" => book.year,
|
||||
"book_paper_type" => (book.book_type.title rescue nil),
|
||||
"link_to_show" => OrbitHelper.url_to_show(book.to_param)
|
||||
page = Page.where(:page_id => params[:page_id]).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 = [
|
||||
"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
|
||||
{
|
||||
"books" => book_list,
|
||||
"extras" => {
|
||||
"widget-title" => t("module_name.book"),
|
||||
"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')
|
||||
},
|
||||
"book_list" => book_list,
|
||||
"extras" => {"widget-title" => t("module_name.book")},
|
||||
"headers" => headers,
|
||||
"total_pages" => books.total_pages
|
||||
}
|
||||
end
|
||||
|
|
|
@ -62,10 +62,22 @@ class Book
|
|||
end
|
||||
|
||||
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 = [
|
||||
"year",
|
||||
"book_title"
|
||||
]
|
||||
end
|
||||
|
||||
fields_to_remove = []
|
||||
|
||||
|
@ -88,12 +100,28 @@ class Book
|
|||
|
||||
pd_data = []
|
||||
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"
|
||||
pd_data << { "data_title" => "<a href='#{OrbitHelper.url_to_plugin_show(p.to_param,'personal_book')}' target='_blank'>#{p.create_link}</a>" }
|
||||
else
|
||||
pd_data << { "data_title" => p.send(t) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
{
|
||||
"pd_datas" => pd_data
|
||||
|
|
|
@ -4,7 +4,7 @@ module PersonalBook
|
|||
OrbitApp.registration "PersonalBook",:type=> 'ModuleApp' do
|
||||
module_label 'module_name.book'
|
||||
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"
|
||||
desktop_enabled true
|
||||
|
|
Loading…
Reference in New Issue