Compare commits

...

87 Commits

Author SHA1 Message Date
Harry Bomrah 9cbe3c7148 Update 'lib/personal_book/engine.rb' 2023-12-29 08:27:17 +00:00
邱博亞 e49c54c8aa Fix author text bug. 2023-11-17 07:19:20 +08:00
BoHung Chiu 1e1ac607db Fix author text bug. 2023-10-03 21:12:29 +08:00
BoHung Chiu 6c7d7ad339 Fix author text bug. 2023-10-03 00:16:54 +08:00
BoHung Chiu ffbf29d912 Fix indent. 2023-10-03 00:16:43 +08:00
BoHung Chiu c901f08b33 Add hide time fields setting file for create_link. 2023-01-07 10:26:01 +08:00
BoHung Chiu 3b9e5d1536 Fix link. 2022-12-15 18:16:30 +08:00
BoHung Chiu 79f3aa17bd Fix link. 2022-12-15 17:31:12 +08:00
BoHung Chiu cb8acf3f8c Fix vulnerable. 2022-10-24 16:23:41 +08:00
BoHung Chiu d54176b635 Fix bug. 2022-07-26 19:31:41 +08:00
BoHung Chiu 8f6a823516 Update sort. 2022-07-26 19:13:36 +08:00
BoHung Chiu 7d65070611 Fix link bug. 2022-01-03 22:42:39 +08:00
BoHung Chiu c4ae7af68e Fix bug. 2021-12-16 15:19:12 +08:00
BoHung Chiu 017c357179 Fix bug. 2021-12-16 10:39:06 +08:00
BoHung Chiu 38e3b5fb77 Fix bug. 2021-12-16 10:24:39 +08:00
BoHung Chiu 3c474256a2 Fix authors show. 2021-12-16 10:21:24 +08:00
BoHung Chiu 3ecbccfe35 Fix bug. 2021-07-23 16:35:37 +08:00
BoHung Chiu 3ff8f93aa6 Fix a tag bug. 2020-11-27 15:11:01 +08:00
chiu b84067e061 fix error when locale not setting and prevent xss attack 2020-04-29 18:07:09 +08:00
chiu 77cfa55859 fix error 2020-04-29 13:46:13 +08:00
chiu ee134378b6 add xss protection 2020-04-26 12:39:31 +08:00
chiu 8202a92098 fix error 2020-04-26 00:13:51 +08:00
chiu 600fb11553 remove rm 2020-02-21 09:18:34 +08:00
EricTYL 748c99394b Merge branch 'master' into 'master'
add link to member front page for show view

add link to member front page for show view

See merge request !9
2020-01-02 17:08:28 +08:00
EricTYL 7a0e669775 add link to member front page for show view 2020-01-02 11:56:37 +08:00
wmcheng e8478468de Merge branch 'master' into 'master'
fix link error



See merge request !8
2019-11-18 15:34:08 +08:00
chiu 393873135f fix link error 2019-11-16 13:52:49 +08:00
wmcheng dbd65617d3 Merge branch 'master' into 'master'
fix problem of showing author for admin's index



See merge request !7
2019-11-13 13:36:42 +08:00
chiu 7d0194e620 Update _writing_book.html.erb
fix the problem of showing author
2019-11-13 12:26:30 +08:00
chiu 0d6ab9100c Update personal_books_helper.rb
add show member method
2019-11-13 12:24:41 +08:00
wmcheng ea6f6c07c8 Merge branch 'master' into 'master'
fix undefined method(book_paper_type)



See merge request !6
2019-11-12 22:57:04 +08:00
chiu d53e9a48c7 Update book.rb
fix error
2019-11-12 22:23:52 +08:00
chiu 25449e9803 Update book.rb
fix error
2019-11-12 22:18:37 +08:00
wmcheng e42460f559 Merge branch 'master' into 'master'
fix the problem of creating multiple authors



See merge request !5
2019-11-11 17:26:58 +08:00
chiu 45d49bc290 fix the problem of creating multiple authors 2019-11-11 00:13:52 +08:00
wmcheng 0e2ba7ab1b Merge branch 'master' into 'master'
Master

add update modules feature and fix error

See merge request !4
2019-08-22 00:00:02 +08:00
chiu 52413762a3 Update personal_book.gemspec 2019-08-21 17:21:46 +08:00
chiu 46bf1679b2 Update personal_book.gemspec 2019-08-21 17:12:12 +08:00
chiu cf3b7ebc2b Upload new file 2019-08-21 15:02:16 +08:00
chiu 6a058ebbab Upload new file 2019-08-21 15:02:03 +08:00
chiu cd9c36c283 Upload new file 2019-08-21 15:01:51 +08:00
chiu 100bce4208 Upload new file 2019-08-21 15:01:39 +08:00
chiu 05d57635ca Upload new file 2019-08-21 15:01:13 +08:00
chiu 6864592244 Add new directory 2019-08-21 15:01:01 +08:00
chiu 1a373605ef Add new directory 2019-08-21 15:00:50 +08:00
chiu fda398e8a8 Add new directory
modules
2019-08-21 15:00:26 +08:00
chiu fe636d4aa2 Update personal_book.gemspec
add update modules feature
2019-08-21 14:56:39 +08:00
chiu 7c58b3fee6 Update personal_books_controller.rb
fix style
2019-08-20 14:15:53 +08:00
chiu 8a8fe31ec3 Update personal_books_controller.rb
fix coding style
2019-08-20 12:17:59 +08:00
chiu ea1be9befa Update book.rb
fix error
2019-08-19 16:49:50 +08:00
chiu 7f4b994670 Update personal_books_controller.rb
搜尋改為多語言
2019-08-19 16:32:10 +08:00
chiu e523087b96 Update zh_tw.yml
add translation
2019-08-19 16:30:56 +08:00
chiu 868d87886b Update en.yml
add translation
2019-08-19 16:30:27 +08:00
chiu 4bc6962248 Update personal_books_controller.rb
fix error
2019-08-19 16:18:35 +08:00
chiu 7c338ff4bc Update personal_books_controller.rb
fix error
2019-08-19 16:14:01 +08:00
chiu 20d35e7162 Update personal_books_controller.rb
coding style fix
2019-08-19 16:12:47 +08:00
chiu 4d4a2dc766 Update personal_books_controller.rb
fix error?
2019-08-19 16:05:56 +08:00
chiu 823feb3f6b Update personal_books_controller.rb
add rescue
2019-08-19 14:23:57 +08:00
Allen Cheng 44449e9188 Merge branch 'master' into 'master'
Master

I add search function and fix some translation error

See merge request !3
2019-08-16 13:04:03 +08:00
Allen Cheng 3d6f57086b Merge branch 'master' into 'master'
# Conflicts:
#   app/models/book.rb
2019-08-16 13:03:39 +08:00
chiu ad892f6e0f Update personal_books_controller.rb 2019-08-15 10:48:15 +08:00
chiu 0a95f1e957 Update personal_books_controller.rb 2019-08-15 10:21:11 +08:00
chiu 6a2ef23e7b Update personal_books_controller.rb 2019-08-15 10:19:55 +08:00
chiu f76e785d9f Update personal_books_controller.rb 2019-08-15 10:17:48 +08:00
chiu e6bcd9af37 Update personal_books_controller.rb 2019-08-15 10:14:56 +08:00
chiu 4a9213d5ad Update personal_books_controller.rb 2019-08-15 10:03:39 +08:00
chiu d004d722ca Update personal_books_controller.rb
fix error
2019-08-15 09:59:22 +08:00
chiu cbd05be1ea Update personal_books_controller.rb
修改搜尋功能並移除不必要的字
2019-08-15 09:55:20 +08:00
chiu ce9f375221 Update personal_books_controller.rb 2019-08-14 16:06:14 +08:00
chiu 6d3b6f5fcb Update personal_books_controller.rb 2019-08-14 16:03:44 +08:00
chiu f9f6108f30 Update book.rb
fix language error translation
2019-08-14 16:01:55 +08:00
chiu 40f9361ea4 Update book.rb 2019-08-14 15:58:13 +08:00
chiu 9cc10eaa64 Update personal_books_controller.rb 2019-08-14 15:32:55 +08:00
chiu 44ed0018a8 Update personal_books_controller.rb 2019-08-14 15:29:35 +08:00
chiu 3204aa0b7d Update personal_books_controller.rb 2019-08-14 15:21:59 +08:00
chiu 01c1e7a076 Update personal_books_controller.rb 2019-08-14 15:20:32 +08:00
chiu aa0febbd30 Update personal_books_controller.rb 2019-08-14 15:18:46 +08:00
chiu c6058905fa Update personal_books_controller.rb 2019-08-14 15:17:48 +08:00
chiu 7f5e34934f Update personal_books_controller.rb 2019-08-14 15:16:02 +08:00
chiu 534100fd7c Update personal_books_controller.rb 2019-08-14 15:14:46 +08:00
chiu 2c1e8bdde2 Update personal_books_controller.rb 2019-08-14 15:13:10 +08:00
chiu b16553aa19 Update personal_books_controller.rb 2019-08-14 15:11:54 +08:00
chiu 732a5d6a40 Update personal_books_controller.rb 2019-08-14 15:10:10 +08:00
chiu 44b89ad43c Update personal_books_controller.rb 2019-08-14 15:08:27 +08:00
chiu d03e62138f Update personal_books_controller.rb 2019-08-14 15:07:07 +08:00
chiu fcbd1d786c Update personal_books_controller.rb 2019-08-14 15:03:34 +08:00
chiu 7d94f13928 Update personal_books_controller.rb 2019-08-14 14:57:08 +08:00
22 changed files with 564 additions and 146 deletions

View File

@ -8,9 +8,47 @@ class Admin::BooksController < OrbitMemberController
before_action :need_access_right
before_action :allow_admin_only, :only => [:index, :setting]
def merge_process
params['book_id'].each do |book_id|
book_ids = book_id.split('/')
books = Book.find(book_ids)
member_ids = books.collect(&:member_profile_id).uniq
books.each_with_index do |book,index1|
if index1== 0
book.member_profile_id = member_ids
book.save!
else
book.delete
end
end
end
redirect_to :action=> 'index'
end
def merge
@books=Book.sort_year_date.map{|value| value}.group_by{|v| [v[:book_title],v[:isbn]]}
@books.each do |key,value|
if value.length<=1
@books.delete key
end
end
if params['mode']!='simple'
@books.each do |key,value|
@books[key] = value.group_by{|v| [get_publisher(v),get_author_type(v),get_paper_type(v),get_publication_date(v)]}
@books[key].each do |key1,value1|
if value1.length<=1
@books[key].delete key1
end
end
if @books[key].length==0
@books.delete key
end
end
end
end
def index
@writing_books = Book.order_by(:year=>'desc').page(params[:page]).per(10)
@writing_books = Book.sort_year_date.page(params[:page]).per(10)
respond_to do |format|
format.html # index.html.erb
format.js { }
@ -49,14 +87,15 @@ class Admin::BooksController < OrbitMemberController
end
def edit
@member = @book.member_profile
@member = get_member(@book)
if params[:desktop]
render :layout => false
end
end
def update
@member = @book.member_profile
@member = get_member(@book)
book_params['member_profile_id'] = params[:author_members]
@book.update_attributes(book_params)
@book.save
if params[:desktop] == "true"
@ -68,7 +107,7 @@ class Admin::BooksController < OrbitMemberController
def new
@book = Book.new
@member = MemberProfile.find_by(:uid=>params['uid']) rescue nil
@member = Array(MemberProfile.find_by(:uid=>params['uid'].to_s)) rescue nil
if params[:desktop]
render :layout => false
end
@ -90,9 +129,9 @@ class Admin::BooksController < OrbitMemberController
elsif !params[:author_members].blank?
params[:author_members].each do |author_member|
#params[:author_members].each do |author_member|
book_params['member_profile_id'] = author_member
book_params['member_profile_id'] = params[:author_members]
@book = Book.new(book_params)
@book.save
@ -100,7 +139,7 @@ class Admin::BooksController < OrbitMemberController
render json: {"data" => get_paper_list}.to_json
end
end
#end
redirect_to params['referer_url']
@ -174,7 +213,7 @@ class Admin::BooksController < OrbitMemberController
end
def frontend_setting
@member = MemberProfile.find_by(:uid=>params['uid']) rescue nil
@member = MemberProfile.find_by(:uid=>params['uid'].to_s) rescue nil
@intro = BookIntro.find_by(:member_profile_id=>@member.id) rescue nil
@intro = @intro.nil? ? BookIntro.new({:member_profile_id=>@member.id}) : @intro
end

View File

@ -1,132 +1,206 @@
class PersonalBooksController < ApplicationController
include Admin::PersonalBooksHelper
def index
params = OrbitHelper.params
books = Book.where(:is_hidden=>false).sort_for_frontend.page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count)
page = Page.where(:page_id => params[:page_id]).first rescue nil
page_data_count = OrbitHelper.page_data_count
books = Book.sort_for_frontend.page(OrbitHelper.params[:page_no]).per(page_data_count)
page = Page.where(page_id: params[:page_id]).first rescue nil
if page.custom_string_field == "table"
if page.custom_string_field == 'table'
fields_to_show = page.custom_array_field rescue []
fields_to_show = [
"authors",
"book_title",
"extracted_chapters",
"publisher",
"isbn",
"publish_date"
] if fields_to_show.blank?
if fields_to_show.blank?
fields_to_show = %w[
authors
book_title
extracted_chapters
publisher
isbn
publish_date
]
end
else
fields_to_show = [
"year",
"book_title"
fields_to_show = %w[
year
book_title
]
end
if !params[:selectbox].nil?
books_temp = Book.where(is_hidden: false).sort_by { |tp| [-tp[:year].to_i, -tp[:publication_date].to_i] }
case params[:selectbox]
when 'book_title', 'extracted_chapters', 'default'
search_temp = if params[:selectbox] == 'default'
'book_title'
else
params[:selectbox]
end
if page.custom_string_field == 'table'
books_show = books_temp.select { |value| search_all_words(value.send(search_temp), params[:keywords]) }
else
books_show = books_temp.select { |value| search_all_words(value.create_link, params[:keywords]) }
end
when 'publish_date', 'publication_date'
books_show = books_temp.select { |value| search_all_words((value.send(params[:selectbox]).strftime('%Y/%m/%d') rescue ''), params[:keywords]) }
when 'author_type'
books_show = books_temp.select { |value| search_all_words(value.book_author_types.collect(&:title).join(', '), params[:keywords]) }
when 'book_paper_type'
books_show = books_temp.select { |value| search_all_words((value.book_type.title rescue ''), params[:keywords]) }
when 'language'
books_show = books_temp.select { |value| search_all_words((!value.language.nil? ? t(value.language.to_s) : ''), params[:keywords]) }
when 'authors'
books_show = books_temp.select { |value| search_all_words(get_authors_text(value), params[:keywords]) }
when 'note'
books_show = books_temp.select { |value| search_all_words(Nokogiri::HTML(value.note).text, params[:keywords]) }
else
if fields_to_show.include?(params[:selectbox])
books_show = books_temp.select { |value| search_all_words(value.send(params[:selectbox]).to_s, params[:keywords]) }
else
books_show = books_temp
end
end
page_to_show = params[:page_no].nil? ? 1 : params[:page_no].to_i
books = books_show[(page_to_show - 1) * page_data_count...page_to_show * page_data_count]
books_total_pages = (books_show.length / page_data_count.to_f).ceil
else
books_total_pages = books.total_pages
end
book_list = []
books.each do |book|
t = []
fields_to_show.each do |fs|
case fs
when "book_title", "extracted_chapters"
if page.custom_string_field == "table"
t << {"value" => "<a href='#{OrbitHelper.url_to_show(book.to_param)}'>#{book.send(fs)}</a>"}
else
t << {"value" => "<a href='#{OrbitHelper.url_to_show(book.to_param)}'>#{book.create_link}</a>"}
end
when "publish_date", "publication_date"
pd = ""
if !book.publication_date.nil?
pd = book.publication_date.strftime("%Y-%m-%d").split('-')
pd = pd[0]+"/"+pd[1]
end
t << {"value" => pd}
when "author_type"
t << {"value" => (book.book_author_types.collect{|bat| bat.title}.join(", ") rescue "")}
when "language"
t << {"value" => (I18n.t("personal_book.#{book.language}") if !book.language.nil? rescue "")}
when 'book_title', 'extracted_chapters'
t << if page.custom_string_field == 'table'
{ 'value' => "<a href='#{OrbitHelper.url_to_show(book.to_param)}'>#{book.send(fs)}</a>" }
else
{ 'value' => "<a href='#{OrbitHelper.url_to_show(book.to_param)}'>#{book.create_link}</a>" }
end
when 'publish_date', 'publication_date'
t << { 'value' => (!book.send(fs).nil? ? book.send(fs).strftime('%Y/%m') : '' rescue '') }
when 'author_type'
t << { 'value' => (book.book_author_types.collect(&:title).join(', ') rescue '') }
when 'language'
t << { 'value' => (!book.language.nil? ? t(book.language.to_s) : '') }
when 'book_paper_type'
t << { 'value' => (book.book_type.title rescue '') }
when 'url'
t << { 'value' => book.url.to_s.blank? ? "" : "<a href='#{book.url}'>#{book.url}</a>"}
when 'authors'
t << { 'value' => get_authors_show(book) }
else
t << {"value" => book.send(fs)}
t << { 'value' => (book.send(fs) rescue '') }
end
end
book_list << {"books" => t}
book_list << { 'books' => t }
end
choice_show = []
headers = []
fields_to_show.each do |fs|
col = 2
col = 3 if fs == "paper_title"
col = 3 if fs == 'paper_title'
headers << {
"head-title" => t("personal_book.#{fs}"),
"col" => col
'head-title' => t("personal_book.#{fs}"),
'col' => col
}
choice_show << t("personal_book.#{fs}")
end
choice_value = fields_to_show
choice_value.unshift('default')
choice_select = choice_value.map { |iter| iter == params[:selectbox] ? 'selected' : '' }
choice_select = choice_select.map { |value| { 'choice_select' => value } }
choice_value = choice_value.map { |value| { 'choice_value' => value } }
choice_default = t('personal_book.select_class')
choice_show.unshift(choice_default)
choice_show = choice_show.map { |value| { 'choice_show' => value } }
choice = choice_value.zip(choice_show, choice_select)
choice = choice.map { |value| value.inject :merge }
select_text = t('personal_book.search_class')
search_text = t('personal_book.word_to_search')
@_request = OrbitHelper.request
csrf_value = form_authenticity_token
{
"book_list" => book_list,
"extras" => {"widget-title" => t("module_name.book")},
"headers" => headers,
"total_pages" => books.total_pages
'book_list' => book_list,
'extras' => { 'widget-title' => t('module_name.book'),
'url' => '/' + I18n.locale.to_s + params[:url],
'select_text' => select_text,
'search_text' => search_text,
'search_value' => params[:keywords].to_s.gsub(/\"/,''),
'csrf_value' => csrf_value },
'headers' => headers,
'total_pages' => books_total_pages,
'choice' => choice
}
end
def show
params = OrbitHelper.params
plugin = Book.where(:is_hidden=>false).find_by(uid: params[:uid])
fields_to_show = [
"year",
"book_title",
"authors",
"book_paper_type",
"extracted_chapters",
"publisher",
"publish_date",
"pages",
"editor",
"author_type",
"number_of_authors",
"isbn",
"url",
"publication_date",
"language"
plugin = Book.where(is_hidden: false).find_by(uid: params[:uid].to_s)
fields_to_show = %w[
year
book_title
authors
book_paper_type
extracted_chapters
publisher
publish_date
pages
editor
author_type
number_of_authors
isbn
url
file
publication_date
language
note
]
{"plugin_datas"=>plugin.get_plugin_data(fields_to_show)}
{ 'plugin_datas' => plugin.get_plugin_data(fields_to_show) }
end
def get_fields_for_index
@page = Page.find(params[:page_id]) rescue nil
@fields_to_show = [
"year",
"book_title",
"authors",
"book_paper_type",
"extracted_chapters",
"publisher",
"publish_date",
"pages",
"editor",
"author_type",
"number_of_authors",
"isbn",
"url",
"file",
"publication_date",
"language"
@fields_to_show = %w[
year
book_title
authors
book_paper_type
extracted_chapters
publisher
publish_date
pages
editor
author_type
number_of_authors
isbn
url
publication_date
language
note
]
@fields_to_show = @fields_to_show.map{|fs| [t("personal_book.#{fs}"), fs]}
@default_fields_to_show = [
"authors",
"book_title",
"extracted_chapters",
"publisher",
"isbn",
"publish_date"
@fields_to_show = @fields_to_show.map { |fs| [t("personal_book.#{fs}"), fs] }
@default_fields_to_show = %w[
authors
book_title
extracted_chapters
publisher
isbn
publish_date
]
render :layout => false
render layout: false
end
def save_index_fields
page = Page.find(params[:page_id]) rescue nil
page.custom_array_field = params[:keys]
page.save
render :json => {"success" => true}.to_json
render json: { 'success' => true }.to_json
end
end
private
def search_all_words(target, word)
target = target.upcase
words = word.upcase.split(' ')
words.select { |value| target.include? value } == words
end
end

View File

@ -1,5 +1,64 @@
module Admin::PersonalBooksHelper
def get_authors_text(book)
authors_text = Nokogiri::HTML(book.authors.to_s).text
split_text = authors_text.match(/[、,,\/]/)
split_text = split_text.nil? ? '/' : split_text[0]
if authors_text.present?
authors_names = authors_text.split(split_text)
else
authors_names = []
end
full_authors_names = get_member(book).collect do |member|
member_name = member.name
idx = authors_names.index{|a| a.match(/(^|[ \(\[])#{::Regexp.escape(member_name)}([ \)\]\*]|$)/)}
if idx
member_name = authors_names[idx]
authors_names[idx] = nil
end
member_name
end
full_authors_names += authors_names.compact
full_authors_names.join(split_text)
end
def get_authors_show(book)
authors_text = Nokogiri::HTML(book.authors.to_s).text
split_text = authors_text.match(/[、,,\/]/)
split_text = split_text.nil? ? '/' : split_text[0]
if authors_text.present?
authors_names = authors_text.split(split_text)
else
authors_names = []
end
full_authors = get_member(book).collect do |member|
member_name = member.name
idx = authors_names.index{|a| a.match(/(^|[ \(\[])#{::Regexp.escape(member_name)}([ \)\]\*]|$)/)}
if idx
member_name = authors_names[idx]
authors_names[idx] = nil
end
"<a href='#{OrbitHelper.url_to_plugin_show(member.to_param,'member')}' title='#{member_name}'>#{member_name}</a>"
end
full_authors += authors_names.compact
full_authors.join(split_text)
end
def get_member(book)
Array(MemberProfile.where(:id.in=>Array(book).collect(&:member_profile_id).flatten))
end
def get_member_show(book)
get_member(book).collect{|member| "<a href='#{OrbitHelper.url_to_plugin_show(member.to_param,'member')}' title='#{member.name}'>#{member.name}</a>"}.join('/')
end
def get_publisher(book)
book.publisher
end
def get_author_type(book)
book.book_author_types.collect(&:title).join(', ') rescue ''
end
def get_paper_type(book)
!book.book_type.blank? ? book.book_type.title : nil
end
def get_publication_date(book)
book.publication_date.strftime('%Y/%m/%d') rescue ''
end
def get_paper_list
user = current_user.nil? ? OrbitHelper.current_user : current_user
user_profile = user.member_profile

View File

@ -2,11 +2,11 @@ class Book
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::Attributes::Dynamic
include Admin::PersonalBooksHelper
include OrbitModel::Status
include MemberHelper
include Slug
HideTimeInLinK = (File.exist?("#{Rails.root}/hide_time_fields_for_plugins.txt") rescue false)
field :book_title, as: :slug_title, localize: true
field :extracted_chapters, type: String, localize: true
field :publisher, type: String, localize: true
@ -39,8 +39,12 @@ class Book
before_validation :add_http
scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(:year => "desc", :publish_date => "desc", :publication_date => "desc") }
index({year: -1, :publish_date => -1, :publication_date => -1, _id: -1}, { unique: false, background: false })
scope :sort_year_date, ->{ order_by(:year => "desc", :publish_date => "desc", :publication_date => "desc", :id => "desc") }
scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(:year => "desc", :publish_date => "desc", :publication_date => "desc", :id => "desc") }
def book_paper_type
self.book_type.title rescue ""
end
def create_link
title = []
# title << self.member_profile.name if self.member_profile.present?
@ -49,15 +53,16 @@ class Book
title << self.extracted_chapters if self.extracted_chapters.present?
title << self.publisher if self.publisher.present?
title << self.isbn if self.isbn.present?
if !self.publish_date.nil?
pd = self.publish_date.strftime("%Y-%m-%d").split('-')
title << pd[0]+"/"+pd[1]
end
title << self.pages if self.pages.present?
# title << self.year
unless HideTimeInLinK
if self.publish_date
title << (self.publish_date.strftime("%b. %Y") rescue nil)
elsif self.publication_date
title << (self.publication_date.strftime("%b. %Y") rescue nil)
elsif self.year.present?
title << self.year
end
end
title.join(', ')
end
@ -107,7 +112,10 @@ class Book
if !page.nil? && page.custom_string_field == "table"
case t
when "book_title", "extracted_chapters"
pd_data << { "data_title" => "<a href='#{OrbitHelper.url_to_plugin_show(p.to_param,'personal_book')}' title='#{p.send(t)}' target='_blank'>#{p.send(t)}</a>" }
link = OrbitHelper.url_to_plugin_show(p.to_param,'personal_book')
url_to_plugin_show_blank = OrbitHelper.instance_variable_get(:@url_to_plugin_show_blank)
tmp_title = p.send(t)
pd_data << { "data_title" => (url_to_plugin_show_blank ? tmp_title : "<a title=\"#{tmp_title}\" href=\"#{link}\" target=\"_blank\">#{tmp_title}</a>") }
when "publish_date", "publication_date"
pd = ""
if !p.publication_date.nil?
@ -118,13 +126,16 @@ class Book
when "author_type"
pd_data << {"data_title" => (p.book_author_types.collect{|bat| bat.title}.join(", ") rescue "")}
when "language"
pd_data << {"data_title" => (I18n.t("personal_book.#{p.language}") if !p.language.nil? rescue "")}
pd_data << {"data_title" => (I18n.t("#{p.language}") if !p.language.nil? rescue "")}
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')}' title='#{p.create_link}' target='_blank'>#{p.create_link}</a>" }
link = OrbitHelper.url_to_plugin_show(p.to_param,'personal_book')
url_to_plugin_show_blank = OrbitHelper.instance_variable_get(:@url_to_plugin_show_blank)
tmp_title = p.create_link
pd_data << { "data_title" => (url_to_plugin_show_blank ? tmp_title : "<a title=\"#{tmp_title}\" href=\"#{link}\" target=\"_blank\">#{tmp_title}</a>") }
else
pd_data << { "data_title" => p.send(t) }
end
@ -152,32 +163,36 @@ class Book
def get_plugin_field_data(field)
case field
when "book_paper_type"
value = self.book_type.title rescue ""
value = (self.book_type.title rescue "")
when "author_type"
value = self.book_author_types.collect{|type| type.title}.join(',') rescue ""
value = (self.book_author_types.collect{|type| type.title}.join(',') rescue "")
when "author_name"
value = []
name_translations = self.member_profile.name_translations rescue {}
([I18n.locale]+(Site.first.in_use_locales-[I18n.locale])).each do |locale|
if self.member_profile.first_name_translations[locale] || self.member_profile.last_name_translations[locale]
value << "#{self.member_profile.first_name_translations[locale]} #{self.member_profile.last_name_translations[locale]}"
if name_translations[locale]
value << name_translations[locale]
end
end
value = value.join(" / ")
when "language"
value = I18n.t(self.language) if !self.language.nil? rescue ""
# value = I18n.t("personal_book.#{self.language}") if !self.language.nil? rescue ""
value = I18n.t("#{self.language}") if !self.language.nil? rescue ""
when "publish_date", "publication_date"
value = self.send(field).to_date.strftime("%Y-%m-%d") rescue nil
when "file"
files = []
self.book_files.each do |book_file|
url = book_file.member_book_file.url
title = (book_file.title.blank? ? File.basename(book_file.member_book_file.path) : book_file.title)
files << "<li><a href='#{url}'' target='_blank'>#{title}</li>"
title = ((book_file.title.blank? ? File.basename(book_file.member_book_file.path) : book_file.title) rescue "")
files << (url.nil? ? "" : "<li><a href='#{url}'' target='_blank'>#{title}</a></li>")
end
value = files.join("")
when "url"
value = self.url.to_s.blank? ? "" : "<a href='#{self.url}'>#{self.url}</a>"
when "authors"
value = get_authors_show(self) rescue ""
else
value = self.send(field) rescue ""
value = (self.send(field) rescue "")
end
value = (value =~ /\A#{URI::regexp(['http', 'https'])}\z/) ? "<a href='#{value}' target='blank'>#{value}</a>" : value

View File

@ -87,7 +87,7 @@
<label class="control-label muted"><%= t("personal_book.authors") %></label>
<div class="controls">
<%= f.fields_for :authors_translations do |f| %>
<%= f.text_area locale, class: "input-block-level", placeholder: t("personal_book.authors"), value: (@book.authors_translations[locale] rescue nil) %>
<%= f.text_area locale, class: "ckeditor input-block-level", placeholder: t("personal_book.authors"), value: (@book.authors_translations[locale] rescue nil) %>
<% end %>
</div>
</div>
@ -141,26 +141,17 @@
<!-- Basic Module -->
<div class="tab-pane fade in active" id="basic">
<% if !@member.nil? %>
<div class="control-group big-group">
<label class="control-label muted"><%= t("personal_plugins.author") %></label>
<div class="controls">
<%= @member.name rescue ''%>
<%= f.hidden_field :member_profile_id, :value => @member.id %>
</div>
</div>
<% else %>
<div class="control-group big-group">
<label class="control-label muted"><%= t("personal_plugins.author") %></label>
<div class="controls">
<%= render partial: 'admin/member_selects/email_selection_box', locals: {field: 'author_members[]', email_members:[]} %>
<% if !@member.nil? %>
<%= render partial: 'admin/member_selects/email_selection_box', locals: {field: 'author_members[]', email_members:@member} %>
<% else %>
<%= render partial: 'admin/member_selects/email_selection_box', locals: {field: 'author_members[]', email_members:[]} %>
<% end %>
</div>
</div>
<% end %>
<!-- year -->
<div class="control-group">
@ -263,7 +254,7 @@
<div class="control-group big-group">
<label class="control-label muted"><%= t("personal_book.note") %></label>
<div class="controls">
<%= f.text_area :note, rows: 2, class: "input-block-level" %>
<%= f.text_area :note, rows: 2, class: "ckeditor input-block-level" %>
</div>
</div>

View File

@ -2,7 +2,7 @@
<tr id="<%= dom_id writing_book %>" class="with_action">
<td class="span1"><%= writing_book.year %></td>
<td class="span1">
<%= link_to writing_book.create_link, OrbitHelper.url_to_plugin_show(writing_book.to_param,'personal_book'), target: "blank" %>
<%= link_to Nokogiri::HTML(writing_book.create_link).text, OrbitHelper.url_to_plugin_show(writing_book.to_param,'personal_book'), target: "blank" %>
<div class="quick-edit">
<ul class="nav nav-pills hide">
<% if current_user.is_admin? %>
@ -12,6 +12,6 @@
</ul>
</div>
</td>
<td><%= writing_book.member_profile.name rescue "" %></td>
<td><%= get_member_show(writing_book).html_safe %></td>
</tr>
<% end %>

View File

@ -1,3 +1,9 @@
<script src="https://kit.fontawesome.com/1fa49cfdc9.js" crossorigin="anonymous"></script>
<script>
function MergeUrl(){
location.href = '<%= merge_admin_books_path %>'
}
</script>
<table class="table main-list">
<thead>
<tr>
@ -14,8 +20,12 @@
<div class="bottomnav clearfix">
<div class="action pull-right">
<div class="dropup upload-button">
<button class="btn btn-primary" type="button" onclick="MergeUrl()">
<i class="far fa-object-group"></i>
<span class="group"></span><%= t('personal_book.merge') %>
</button>
<button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">
<i class="icon-upload-alt icon-white"></i>上傳
<i class="icon-upload-alt icon-white"></i><%= t('personal_book.upload') %>
<span class="caret"></span>
</button>
<div class="dropdown-menu upload-box">

View File

@ -0,0 +1,118 @@
<%= csrf_meta_tags %>
<% content_for :page_specific_css do %>
<%= stylesheet_link_tag "lib/main-forms" %>
<%= stylesheet_link_tag "lib/fileupload" %>
<%= stylesheet_link_tag "lib/main-list" %>
<%= stylesheet_link_tag "lib/main-form-col2" %>
<style>
table.table.main-list.tablet.footable-loaded td{
vertical-align: middle;
}
</style>
<% end %>
<script>
function change_mode(){
var value = $("form[name='mode_form']").find("input[type='checkbox']")[0].checked
if (value){
$("input[name='mode']").val("strict")
}
else{
$("input[name='mode']").val("simple")
}
document.mode_form.submit()
}
</script>
<nobr>
<form method="get" action='?' name='mode_form'>
<%= t('strict_compare_mode') +':' %>
<input type='hidden' name='mode' value=''>
<% if params['mode']!='simple' %>
<input type="checkbox" onchange='change_mode()' checked><span style="margin-right: 2em;"><%= t('yes_') %></span>
<% else %>
<input type="checkbox" onchange='change_mode()'><span style="margin-right: 2em;"><%= t('no_') %></span>
<% end %>
<button type="button" onclick="merge_form.submit()"><%= t('personal_conference.merge') %></button>
</form>
</nobr>
<form method="post" action='/admin/books/merge_process?' name='merge_form'>
<%= token_tag(nil) %>
<table class="table main-list">
<thead>
<tr>
<th><%= t('personal_book.book_title') %></th>
<th><%= t('personal_book.isbn') %></th>
<% if params['mode']!='simple' %>
<th><%= t('personal_book.publisher') %></th>
<th><%= t('personal_book.author_type') %></th>
<th><%= t('personal_book.book_paper_type') %></th>
<th><%= t('personal_book.publication_date') %></th>
<% end %>
<th><%= t("personal_book.merge") %></th>
<th><%= t("personal_book.author") %></th>
</tr>
</thead>
<tbody>
<% @books.each do |key,books| %>
<tr>
<% if params['mode']=='simple'
len = books.length
else
len = books.values.reduce(0){|sum,num| sum+num.length}
end
%>
<td rowspan="<%= len %>">
<%= key[0].values.map{|v| v=="" ? t('personal_book.no_input') : v}.join('/') rescue t('personal_book.no_input') %>
</td>
<td rowspan="<%= len %>">
<%= key[1] %>
</td>
<% if params['mode']=='simple' %>
<td rowspan="<%= len %>">
<input type="checkbox" class="checkbox" name="books_id[]" value="<%= books.collect(&:id).join('/') %>">
</td>
<% books.each_with_index do |book,i| %>
<td>
<a href="<%= edit_admin_book_path(book) %>" target="_blank">
<%= get_member(book).collect(&:name).join(' / ') rescue t('personal_book.no_input') %>
</a>
</td>
<% if len!=(i+1) %>
</tr>
<tr>
<% end %>
<% end %>
<% else %>
<% i=0 %>
<% books.each do |k,v| %>
<% len1 = v.length %>
<% k.each do |keychild| %>
<td rowspan="<%= len1 %>">
<%= keychild.to_s.blank? ? t('personal_book.no_input') : keychild %>
</td>
<% end %>
<td rowspan="<%= len1 %>">
<input type="checkbox" class="checkbox" name="book_id[]" value="<%= v.collect(&:id).join('/') %>">
</td>
<% v.each_with_index do |book_child,index1| %>
<td>
<a href="<%= edit_admin_book_path(book_child) %>" target="_blank">
<%= get_member(book_child).collect(&:name).join(' / ') rescue t('personal_book.no_input') %>
</a>
</td>
<% if len1!=index1 %>
</tr>
<tr>
<% end %>
<% end %>
<% if len1!=(i+1) %>
</tr>
<tr>
<% end %>
<% i =i+1 %>
<% end %>
<% end %>
</tr>
<% end %>
</tbody>
</table>
</form>

View File

@ -7,9 +7,9 @@
<%
if has_access?
@books = Book.where(member_profile_id: @member.id).desc(:year).page(params[:page]).per(10)
@books = Book.where(member_profile_id: @member.id).sort_year_date.page(params[:page]).per(10)
else
@books = Book.where(is_hidden: false, member_profile_id: @member.id).desc(:year).page(params[:page]).per(10)
@books = Book.where(is_hidden: false, member_profile_id: @member.id).sort_year_date.page(params[:page]).per(10)
end
%>
@ -47,7 +47,8 @@
<% end -%>
<td><%= book.year %></td>
<td>
<%= link_to book.create_link, OrbitHelper.url_to_plugin_show(book.to_param,'personal_book'), target: "blank"%>
<% link = OrbitHelper.url_to_plugin_show(book.to_param,'personal_book') %>
<%= (link == "#" ? book.create_link : link_to(book.create_link, link , target: "blank")) %>
<% if has_access? %>
<div class="quick-edit">
<ul class="nav nav-pills hide">

View File

@ -4,6 +4,12 @@ en:
book_paper: "Book / Book Chapter"
personal_book: "Book / Book Chapter"
personal_book:
merge: Merge
upload: Upload
no_input: No Input
select_class: "——select class——"
search_class: "search class:"
word_to_search: "word to search:"
paper_title : "Paper Title"
book_title : "Book Title"
extracted_chapters : "Extracted Chapters"
@ -40,7 +46,7 @@ en:
graph_by : "Graph By"
frontend:
writing_books: "Book Frontend"
strict_compare_mode: Strict Compare mode
create_success : "Successfully Create"
update_success : "Successfully Update"
delete_success : "Successfully Delete"

View File

@ -4,6 +4,12 @@ zh_tw:
book_paper: "專書 / 專書章節"
personal_book : "專書 / 專書章節"
personal_book:
merge: "合併"
upload: "上傳"
no_input: "未輸入"
select_class: "——選取分類——"
search_class: "搜尋類別:"
word_to_search: "關鍵字搜尋:"
paper_title : "論文名稱"
book_title : "書名"
extracted_chapters : "部份章節"
@ -40,7 +46,7 @@ zh_tw:
graph_by : "Graph By"
frontend:
writing_books: "專書前台"
strict_compare_mode: "嚴格比較模式"
create_success : "新增完成!!"
update_success : "更新完成!!"
delete_success : "刪除成功!!"

View File

@ -8,6 +8,8 @@ Rails.application.routes.draw do
resources :books do
collection do
post 'merge_process' => 'books#merge_process'
get 'merge' => 'books#merge'
get 'toggle_hide' => 'books#toggle_hide'
get 'analysis'
get 'analysis_report'

View File

@ -14,6 +14,8 @@ module PersonalBook
update_info 'some update_info'
frontend_enabled
icon_class_no_sidebar "icons-user"
authorizable
is_personal_plugin true
data_count 1..10
end
end

0
modules/.gitkeep Normal file
View File

View File

View File

@ -0,0 +1,14 @@
<table class="table table-hover table-striped journal-papers-index">
<caption><h1>{{widget-title}}</h1></caption>
<thead>
<tr data-level="0" data-list="headers">
<th class="col-md-{{col}}">{{head-title}}</th>
</tr>
</thead>
<tbody data-level="0" data-list="book_list">
<tr data-level="1" data-list="books">
<td>{{value}}</td>
</tr>
</tbody>
</table>
{{pagination_goes_here}}

View File

@ -0,0 +1,38 @@
<script type="text/javascript">
$( ".selectbox" ).ready(function() {
var option_len = $(".search-widget option").length
for (var i=0;i<option_len;i++){
if($(".search-widget option").eq(i).data('selected')=="selected"){
$(".search-widget option").eq(i).attr('selected','selected')
}
}
});
</script>
<h3>{{widget-title}}</h3>
<div class="search-widget">
<form action="{{url}}" method="get">
<input type="hidden" name="authenticity_token" value="{{csrf_value}}">
{{select_text}}
<select class="selectbox" name="selectbox" data-level="0" data-list="choice">
<option value={{choice_value}} data-selected='{{choice_select}}' >
{{choice_show}}</option>
</select>
{{search_text}}
<input name="keywords" placeholder="Keywords" type="text" value="{{search_value}}">
<button>Go</button>
<a id="filter" style="" href="{{url}}">Clear</a>
</form>
</div>
<table class="table table-hover table-striped book-index">
<thead>
<tr data-level="0" data-list="headers">
<th class="col-md-{{col}}">{{head-title}}</th>
</tr>
</thead>
<tbody data-level="0" data-list="book_list">
<tr data-level="1" data-list="books">
<td>{{value}}</td>
</tr>
</tbody>
</table>
{{pagination_goes_here}}

View File

@ -0,0 +1,20 @@
{
"frontend": [
{
"filename" : "index",
"name" : {
"zh_tw" : "1. 列表",
"en" : "1. List"
},
"thumbnail" : "thumb.png"
},
{
"filename" : "index_search1",
"name" : {
"zh_tw" : "2. 列表(含搜尋)",
"en" : "2. List which includes search"
},
"thumbnail" : "thumb.png"
}
]
}

View File

@ -0,0 +1,8 @@
<table class="table table-striped plugin-show-table">
<tbody data-list="plugin_datas" data-level="0">
<tr>
<th class="{{title_class}}">{{title}}</th>
<td class="{{value_class}}">{{value}}</td>
</tr>
</tbody>
</table>

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

View File

@ -2,7 +2,22 @@ $:.push File.expand_path("../lib", __FILE__)
# Maintain your gem's version:
require "personal_book/version"
bundle_update_flag = ARGV[0]=='update' || ARGV[0]=='install'
if bundle_update_flag
app_path = File.expand_path(__dir__)
template_path = ENV['PWD'] + '/app/templates'
all_template = Dir.glob(template_path+'/*/')
puts 'copying module'
all_template.each do |folder|
if folder.split('/')[-1] != 'mobile'
begin
system ('cp -r '+ app_path + '/modules/ ' + folder)
rescue
puts 'error copy'
end
end
end
end
# Describe your gem and declare its dependencies:
Gem::Specification.new do |s|
s.name = "personal_book"