From 7d94f13928d60789a1367f1f7a4c245e08897e40 Mon Sep 17 00:00:00 2001 From: chiu Date: Wed, 14 Aug 2019 14:57:08 +0800 Subject: [PATCH 01/27] Update personal_books_controller.rb --- app/controllers/personal_books_controller.rb | 56 ++++++++++++++++++-- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/app/controllers/personal_books_controller.rb b/app/controllers/personal_books_controller.rb index 8b587be..8b83b5c 100644 --- a/app/controllers/personal_books_controller.rb +++ b/app/controllers/personal_books_controller.rb @@ -20,7 +20,37 @@ class PersonalBooksController < ApplicationController "book_title" ] end - + if params[:selectbox] !=nil + books = Book.where(:is_hidden=>false) + books_count = books.count + books_temp = books.take(books_count).sort_by{ |tp| [-tp[:year].to_i,-tp[:publication_date].to_i] } + case params[:selectbox] + when "book_title", "extracted_chapters", "default" + if page.custom_string_field == "table" + books_show = books_temp.select {|value| value.send(params[:selectbox]).include? params[:keywords]} + else + books_show = books_temp.select {|value| value.create_link.include? params[:keywords]} + end + when "publish_date", "publication_date" + books_show = books_temp.select {|value| value.publication_date.strftime("%Y/%m").include? params[:keywords]} + when "author_type" + books_show = books_temp.select {|value| value.book_author_types.collect{|bat| bat.title}.join(", ").include? params[:keywords]} + when "language" + books_show = books_temp.select {|value| (!value.language.nil? ? I18n.t("personal_book.#{value.language}") : "").include? params[:keywords]} + else + books_show = books_temp.select {|value| value.send(params[:selectbox]).to_s.include? params[:keywords]} + end + if params[:page_no].nil? + page_to_show = 1 + else + page_to_show = params[:page_no].to_i + end + books_show_last = books_show[(page_to_show-1)*OrbitHelper.page_data_count...page_to_show*OrbitHelper.page_data_count] + books = books_show_last + books_total_pages = (books_show.length/OrbitHelper.page_data_count.to_f).ceil + else + books_total_pages = books.total_pages + end book_list = [] books.each do |book| t = [] @@ -49,7 +79,7 @@ class PersonalBooksController < ApplicationController end book_list << {"books" => t} end - + choice_show = [] headers = [] fields_to_show.each do |fs| col = 2 @@ -58,12 +88,30 @@ class PersonalBooksController < ApplicationController "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 = params[:locale]!='en' ? "——選取分類——" : "——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 = params[:locale]!='en' ? "搜尋類別:" : "search class:" + search_text = params[:locale]!='en' ? "關鍵字搜尋:" : "word to search:" { "book_list" => book_list, - "extras" => {"widget-title" => t("module_name.book")}, + "extras" => {"widget-title" => t("module_name.book"), + "url" => "/"+params[:locale]+params[:url], + "select_text" => select_text, + "search_text" => search_text, + "search_value" => params[:keywords]}, "headers" => headers, - "total_pages" => books.total_pages + "total_pages" => books_total_pages, + "choice" => choice } end From fcbd1d786c3021b87901cf0b684cc0efb0f779a0 Mon Sep 17 00:00:00 2001 From: chiu Date: Wed, 14 Aug 2019 15:03:34 +0800 Subject: [PATCH 02/27] Update personal_books_controller.rb --- app/controllers/personal_books_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/personal_books_controller.rb b/app/controllers/personal_books_controller.rb index 8b83b5c..afcb43a 100644 --- a/app/controllers/personal_books_controller.rb +++ b/app/controllers/personal_books_controller.rb @@ -32,7 +32,7 @@ class PersonalBooksController < ApplicationController books_show = books_temp.select {|value| value.create_link.include? params[:keywords]} end when "publish_date", "publication_date" - books_show = books_temp.select {|value| value.publication_date.strftime("%Y/%m").include? params[:keywords]} + books_show = books_temp.select {|value| value.publication_date.strftime("%Y/%m").to_s.include? params[:keywords]} when "author_type" books_show = books_temp.select {|value| value.book_author_types.collect{|bat| bat.title}.join(", ").include? params[:keywords]} when "language" From d03e62138f017fea2910a1f3655b8a0efb76bd26 Mon Sep 17 00:00:00 2001 From: chiu Date: Wed, 14 Aug 2019 15:07:07 +0800 Subject: [PATCH 03/27] Update personal_books_controller.rb --- app/controllers/personal_books_controller.rb | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/app/controllers/personal_books_controller.rb b/app/controllers/personal_books_controller.rb index afcb43a..fb2fd14 100644 --- a/app/controllers/personal_books_controller.rb +++ b/app/controllers/personal_books_controller.rb @@ -63,12 +63,7 @@ class PersonalBooksController < ApplicationController t << {"value" => "#{book.create_link}"} 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} + t << {"value" => book.publication_date.strftime("%Y/%m/%d")} when "author_type" t << {"value" => (book.book_author_types.collect{|bat| bat.title}.join(", ") rescue "")} when "language" From 44b89ad43cb05fc3b1710e21096c713db06f2acc Mon Sep 17 00:00:00 2001 From: chiu Date: Wed, 14 Aug 2019 15:08:27 +0800 Subject: [PATCH 04/27] Update personal_books_controller.rb --- app/controllers/personal_books_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/personal_books_controller.rb b/app/controllers/personal_books_controller.rb index fb2fd14..316ad4b 100644 --- a/app/controllers/personal_books_controller.rb +++ b/app/controllers/personal_books_controller.rb @@ -67,7 +67,7 @@ class PersonalBooksController < ApplicationController 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 "")} + t << {"value" => (t("personal_book.#{book.language}") if !book.language.nil?} else t << {"value" => book.send(fs)} end From 732a5d6a4005e23a2f9467168acc85fe69504924 Mon Sep 17 00:00:00 2001 From: chiu Date: Wed, 14 Aug 2019 15:10:10 +0800 Subject: [PATCH 05/27] Update personal_books_controller.rb --- app/controllers/personal_books_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/personal_books_controller.rb b/app/controllers/personal_books_controller.rb index 316ad4b..aa87e0e 100644 --- a/app/controllers/personal_books_controller.rb +++ b/app/controllers/personal_books_controller.rb @@ -67,7 +67,7 @@ class PersonalBooksController < ApplicationController when "author_type" t << {"value" => (book.book_author_types.collect{|bat| bat.title}.join(", ") rescue "")} when "language" - t << {"value" => (t("personal_book.#{book.language}") if !book.language.nil?} + t << {"value" => !book.language.nil? t("personal_book.#{book.language}") : ""} else t << {"value" => book.send(fs)} end From b16553aa199dbf4d4bd766fbc98712e217639f05 Mon Sep 17 00:00:00 2001 From: chiu Date: Wed, 14 Aug 2019 15:11:54 +0800 Subject: [PATCH 06/27] Update personal_books_controller.rb --- app/controllers/personal_books_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/personal_books_controller.rb b/app/controllers/personal_books_controller.rb index aa87e0e..2a8bfee 100644 --- a/app/controllers/personal_books_controller.rb +++ b/app/controllers/personal_books_controller.rb @@ -67,7 +67,7 @@ class PersonalBooksController < ApplicationController when "author_type" t << {"value" => (book.book_author_types.collect{|bat| bat.title}.join(", ") rescue "")} when "language" - t << {"value" => !book.language.nil? t("personal_book.#{book.language}") : ""} + t << {"value" => (!book.language.nil? t("personal_book.#{book.language}") : "")} else t << {"value" => book.send(fs)} end From 2c1e8bdde295f6de1d1033ba79733261ede9b40d Mon Sep 17 00:00:00 2001 From: chiu Date: Wed, 14 Aug 2019 15:13:10 +0800 Subject: [PATCH 07/27] Update personal_books_controller.rb --- app/controllers/personal_books_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/personal_books_controller.rb b/app/controllers/personal_books_controller.rb index 2a8bfee..ecbfcfc 100644 --- a/app/controllers/personal_books_controller.rb +++ b/app/controllers/personal_books_controller.rb @@ -67,7 +67,7 @@ class PersonalBooksController < ApplicationController when "author_type" t << {"value" => (book.book_author_types.collect{|bat| bat.title}.join(", ") rescue "")} when "language" - t << {"value" => (!book.language.nil? t("personal_book.#{book.language}") : "")} + t << {"value" => (!book.language.nil? ? t("personal_book.#{book.language}") : "")} else t << {"value" => book.send(fs)} end From 534100fd7c4e8859cfcf37c90411e2096f188dc0 Mon Sep 17 00:00:00 2001 From: chiu Date: Wed, 14 Aug 2019 15:14:46 +0800 Subject: [PATCH 08/27] Update personal_books_controller.rb --- app/controllers/personal_books_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/personal_books_controller.rb b/app/controllers/personal_books_controller.rb index ecbfcfc..91e1f01 100644 --- a/app/controllers/personal_books_controller.rb +++ b/app/controllers/personal_books_controller.rb @@ -67,7 +67,7 @@ class PersonalBooksController < ApplicationController when "author_type" t << {"value" => (book.book_author_types.collect{|bat| bat.title}.join(", ") rescue "")} when "language" - t << {"value" => (!book.language.nil? ? t("personal_book.#{book.language}") : "")} + t << {"value" => (!book.language.nil? ? I18n.t("personal_book.#{book.language}") : "")} else t << {"value" => book.send(fs)} end From 7f5e34934fe1c574aa612a9873a494311fc7858e Mon Sep 17 00:00:00 2001 From: chiu Date: Wed, 14 Aug 2019 15:16:02 +0800 Subject: [PATCH 09/27] Update personal_books_controller.rb --- app/controllers/personal_books_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/personal_books_controller.rb b/app/controllers/personal_books_controller.rb index 91e1f01..74db8ea 100644 --- a/app/controllers/personal_books_controller.rb +++ b/app/controllers/personal_books_controller.rb @@ -67,7 +67,7 @@ class PersonalBooksController < ApplicationController when "author_type" t << {"value" => (book.book_author_types.collect{|bat| bat.title}.join(", ") rescue "")} when "language" - t << {"value" => (!book.language.nil? ? I18n.t("personal_book.#{book.language}") : "")} + t << {"value" => (!book.language.nil? ? I18n.t("personal_book.#{book.language}") : "" rescue "")} else t << {"value" => book.send(fs)} end From c6058905fab41d16bbda1037b13009da17e37ef7 Mon Sep 17 00:00:00 2001 From: chiu Date: Wed, 14 Aug 2019 15:17:48 +0800 Subject: [PATCH 10/27] Update personal_books_controller.rb --- app/controllers/personal_books_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/personal_books_controller.rb b/app/controllers/personal_books_controller.rb index 74db8ea..48d3c80 100644 --- a/app/controllers/personal_books_controller.rb +++ b/app/controllers/personal_books_controller.rb @@ -63,7 +63,7 @@ class PersonalBooksController < ApplicationController t << {"value" => "#{book.create_link}"} end when "publish_date", "publication_date" - t << {"value" => book.publication_date.strftime("%Y/%m/%d")} + t << {"value" => "book.publication_date.strftime('%Y/%m/%d')"} when "author_type" t << {"value" => (book.book_author_types.collect{|bat| bat.title}.join(", ") rescue "")} when "language" From aa0febbd3033f621a7f013b0b273c87128f413bd Mon Sep 17 00:00:00 2001 From: chiu Date: Wed, 14 Aug 2019 15:18:46 +0800 Subject: [PATCH 11/27] Update personal_books_controller.rb --- app/controllers/personal_books_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/personal_books_controller.rb b/app/controllers/personal_books_controller.rb index 48d3c80..68aebc5 100644 --- a/app/controllers/personal_books_controller.rb +++ b/app/controllers/personal_books_controller.rb @@ -17,7 +17,8 @@ class PersonalBooksController < ApplicationController else fields_to_show = [ "year", - "book_title" + "book_title", + "language" ] end if params[:selectbox] !=nil From 01c1e7a0767fee9e5268806b691776264aabfb37 Mon Sep 17 00:00:00 2001 From: chiu Date: Wed, 14 Aug 2019 15:20:32 +0800 Subject: [PATCH 12/27] Update personal_books_controller.rb --- app/controllers/personal_books_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/personal_books_controller.rb b/app/controllers/personal_books_controller.rb index 68aebc5..9dd352f 100644 --- a/app/controllers/personal_books_controller.rb +++ b/app/controllers/personal_books_controller.rb @@ -68,7 +68,7 @@ class PersonalBooksController < ApplicationController when "author_type" t << {"value" => (book.book_author_types.collect{|bat| bat.title}.join(", ") rescue "")} when "language" - t << {"value" => (!book.language.nil? ? I18n.t("personal_book.#{book.language}") : "" rescue "")} + t << {"value" => (!book.language.nil? ? t("personal_book.#{book.language}") : "" rescue "")} else t << {"value" => book.send(fs)} end From 3204aa0b7d603169832a81dab1a24feba88c1e01 Mon Sep 17 00:00:00 2001 From: chiu Date: Wed, 14 Aug 2019 15:21:59 +0800 Subject: [PATCH 13/27] Update personal_books_controller.rb --- app/controllers/personal_books_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/personal_books_controller.rb b/app/controllers/personal_books_controller.rb index 9dd352f..94103f4 100644 --- a/app/controllers/personal_books_controller.rb +++ b/app/controllers/personal_books_controller.rb @@ -68,7 +68,7 @@ class PersonalBooksController < ApplicationController when "author_type" t << {"value" => (book.book_author_types.collect{|bat| bat.title}.join(", ") rescue "")} when "language" - t << {"value" => (!book.language.nil? ? t("personal_book.#{book.language}") : "" rescue "")} + t << {"value" => (!book.language.nil? ? t("#{book.language}") : "" rescue "")} else t << {"value" => book.send(fs)} end From 44ed0018a8b8ab3f7c43d625a62018448cb5c000 Mon Sep 17 00:00:00 2001 From: chiu Date: Wed, 14 Aug 2019 15:29:35 +0800 Subject: [PATCH 14/27] Update personal_books_controller.rb --- app/controllers/personal_books_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/personal_books_controller.rb b/app/controllers/personal_books_controller.rb index 94103f4..5204b63 100644 --- a/app/controllers/personal_books_controller.rb +++ b/app/controllers/personal_books_controller.rb @@ -37,7 +37,7 @@ class PersonalBooksController < ApplicationController when "author_type" books_show = books_temp.select {|value| value.book_author_types.collect{|bat| bat.title}.join(", ").include? params[:keywords]} when "language" - books_show = books_temp.select {|value| (!value.language.nil? ? I18n.t("personal_book.#{value.language}") : "").include? params[:keywords]} + books_show = books_temp.select {|value| (!value.language.nil? ? t("#{value.language}") : "").include? params[:keywords]} else books_show = books_temp.select {|value| value.send(params[:selectbox]).to_s.include? params[:keywords]} end @@ -64,11 +64,11 @@ class PersonalBooksController < ApplicationController t << {"value" => "#{book.create_link}"} end when "publish_date", "publication_date" - t << {"value" => "book.publication_date.strftime('%Y/%m/%d')"} + t << {"value" => (!book.publication_date.nil? ? book.publication_date.strftime('%Y/%m/%d') : "")} when "author_type" t << {"value" => (book.book_author_types.collect{|bat| bat.title}.join(", ") rescue "")} when "language" - t << {"value" => (!book.language.nil? ? t("#{book.language}") : "" rescue "")} + t << {"value" => (!book.language.nil? ? t("#{book.language}") : "")} else t << {"value" => book.send(fs)} end From 9cc10eaa643e6844e5bbfdab10003eb8e76f75c7 Mon Sep 17 00:00:00 2001 From: chiu Date: Wed, 14 Aug 2019 15:32:55 +0800 Subject: [PATCH 15/27] Update personal_books_controller.rb --- app/controllers/personal_books_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/personal_books_controller.rb b/app/controllers/personal_books_controller.rb index 5204b63..849b454 100644 --- a/app/controllers/personal_books_controller.rb +++ b/app/controllers/personal_books_controller.rb @@ -33,7 +33,7 @@ class PersonalBooksController < ApplicationController books_show = books_temp.select {|value| value.create_link.include? params[:keywords]} end when "publish_date", "publication_date" - books_show = books_temp.select {|value| value.publication_date.strftime("%Y/%m").to_s.include? params[:keywords]} + books_show = books_temp.select {|value| value.publish_date.strftime("%Y/%m/%d").to_s.include? params[:keywords]} when "author_type" books_show = books_temp.select {|value| value.book_author_types.collect{|bat| bat.title}.join(", ").include? params[:keywords]} when "language" @@ -64,7 +64,7 @@ class PersonalBooksController < ApplicationController t << {"value" => "#{book.create_link}"} end when "publish_date", "publication_date" - t << {"value" => (!book.publication_date.nil? ? book.publication_date.strftime('%Y/%m/%d') : "")} + t << {"value" => (!book.publish_date.nil? ? book.publish_date.strftime('%Y/%m') : "")} when "author_type" t << {"value" => (book.book_author_types.collect{|bat| bat.title}.join(", ") rescue "")} when "language" From 40f9361ea45fc5af0bfd9306f175bf07e38e04b2 Mon Sep 17 00:00:00 2001 From: chiu Date: Wed, 14 Aug 2019 15:58:13 +0800 Subject: [PATCH 16/27] Update book.rb --- app/models/book.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/book.rb b/app/models/book.rb index 574d744..5d228da 100644 --- a/app/models/book.rb +++ b/app/models/book.rb @@ -118,7 +118,7 @@ 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 From f9f6108f304641e64c13ebe42e0b9e7ae18ffaac Mon Sep 17 00:00:00 2001 From: chiu Date: Wed, 14 Aug 2019 16:01:55 +0800 Subject: [PATCH 17/27] Update book.rb fix language error translation --- app/models/book.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/book.rb b/app/models/book.rb index 5d228da..0b4ba9b 100644 --- a/app/models/book.rb +++ b/app/models/book.rb @@ -164,7 +164,7 @@ class Book end value = value.join(" / ") when "language" - 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" From 6d3b6f5fcb01b32ebd7eb972b432a335145ed246 Mon Sep 17 00:00:00 2001 From: chiu Date: Wed, 14 Aug 2019 16:03:44 +0800 Subject: [PATCH 18/27] Update personal_books_controller.rb --- app/controllers/personal_books_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/personal_books_controller.rb b/app/controllers/personal_books_controller.rb index 849b454..587dac1 100644 --- a/app/controllers/personal_books_controller.rb +++ b/app/controllers/personal_books_controller.rb @@ -33,7 +33,7 @@ class PersonalBooksController < ApplicationController books_show = books_temp.select {|value| value.create_link.include? params[:keywords]} end when "publish_date", "publication_date" - books_show = books_temp.select {|value| value.publish_date.strftime("%Y/%m/%d").to_s.include? params[:keywords]} + books_show = books_temp.select {|value| value.send(params[:selectbox]).strftime("%Y/%m/%d").to_s.include? params[:keywords]} when "author_type" books_show = books_temp.select {|value| value.book_author_types.collect{|bat| bat.title}.join(", ").include? params[:keywords]} when "language" @@ -64,7 +64,7 @@ class PersonalBooksController < ApplicationController t << {"value" => "#{book.create_link}"} end when "publish_date", "publication_date" - t << {"value" => (!book.publish_date.nil? ? book.publish_date.strftime('%Y/%m') : "")} + t << {"value" => (!book.send(fs).nil? ? book.send(fs).strftime('%Y/%m') : "")} when "author_type" t << {"value" => (book.book_author_types.collect{|bat| bat.title}.join(", ") rescue "")} when "language" From ce9f3752212a2be99f2051914aa4d7c8b149787d Mon Sep 17 00:00:00 2001 From: chiu Date: Wed, 14 Aug 2019 16:06:14 +0800 Subject: [PATCH 19/27] Update personal_books_controller.rb --- app/controllers/personal_books_controller.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/controllers/personal_books_controller.rb b/app/controllers/personal_books_controller.rb index 587dac1..217ab9b 100644 --- a/app/controllers/personal_books_controller.rb +++ b/app/controllers/personal_books_controller.rb @@ -17,8 +17,7 @@ class PersonalBooksController < ApplicationController else fields_to_show = [ "year", - "book_title", - "language" + "book_title" ] end if params[:selectbox] !=nil From cbd05be1ea497f0457bd1f14821627cf00daf2b9 Mon Sep 17 00:00:00 2001 From: chiu Date: Thu, 15 Aug 2019 09:55:20 +0800 Subject: [PATCH 20/27] =?UTF-8?q?Update=20personal=5Fbooks=5Fcontroller.rb?= =?UTF-8?q?=20=E4=BF=AE=E6=94=B9=E6=90=9C=E5=B0=8B=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E4=B8=A6=E7=A7=BB=E9=99=A4=E4=B8=8D=E5=BF=85=E8=A6=81=E7=9A=84?= =?UTF-8?q?=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/personal_books_controller.rb | 24 +++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/app/controllers/personal_books_controller.rb b/app/controllers/personal_books_controller.rb index 217ab9b..f420f3f 100644 --- a/app/controllers/personal_books_controller.rb +++ b/app/controllers/personal_books_controller.rb @@ -1,4 +1,9 @@ class PersonalBooksController < ApplicationController + def search_all_words(target,word) + target=target.upcase + words=word.upcase.split(' ') + return words.select{|value| target.include? value}==words + end def index params = OrbitHelper.params books = Book.where(:is_hidden=>false).sort_for_frontend.page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) @@ -21,32 +26,29 @@ class PersonalBooksController < ApplicationController ] end if params[:selectbox] !=nil - books = Book.where(:is_hidden=>false) - books_count = books.count - books_temp = books.take(books_count).sort_by{ |tp| [-tp[:year].to_i,-tp[:publication_date].to_i] } + 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" if page.custom_string_field == "table" - books_show = books_temp.select {|value| value.send(params[:selectbox]).include? params[:keywords]} + books_show = books_temp.select {|value| search_all_words(value.send(params[:selectbox]), params[:keywords])} else - books_show = books_temp.select {|value| value.create_link.include? params[:keywords]} + 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| value.send(params[:selectbox]).strftime("%Y/%m/%d").to_s.include? params[:keywords]} + books_show = books_temp.select {|value| search_all_words(value.send(params[:selectbox]).strftime("%Y/%m/%d").to_s, params[:keywords])} when "author_type" - books_show = books_temp.select {|value| value.book_author_types.collect{|bat| bat.title}.join(", ").include? params[:keywords]} + books_show = books_temp.select {|value| search_all_words(value.book_author_types.collect{|bat| bat.title}.join(", "), params[:keywords])} when "language" - books_show = books_temp.select {|value| (!value.language.nil? ? t("#{value.language}") : "").include? params[:keywords]} + books_show = books_temp.select {|value| search_all_words((!value.language.nil? ? t("#{value.language}") : ""), params[:keywords])} else - books_show = books_temp.select {|value| value.send(params[:selectbox]).to_s.include? params[:keywords]} + books_show = books_temp.select {|value| search_all_words(value.send(params[:selectbox]).to_s, params[:keywords])} end if params[:page_no].nil? page_to_show = 1 else page_to_show = params[:page_no].to_i end - books_show_last = books_show[(page_to_show-1)*OrbitHelper.page_data_count...page_to_show*OrbitHelper.page_data_count] - books = books_show_last + books = books_show[(page_to_show-1)*OrbitHelper.page_data_count...page_to_show*OrbitHelper.page_data_count] books_total_pages = (books_show.length/OrbitHelper.page_data_count.to_f).ceil else books_total_pages = books.total_pages From d004d722ca7ad3cca579b1214c7b5550a65ee806 Mon Sep 17 00:00:00 2001 From: chiu Date: Thu, 15 Aug 2019 09:59:22 +0800 Subject: [PATCH 21/27] Update personal_books_controller.rb fix error --- app/controllers/personal_books_controller.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/controllers/personal_books_controller.rb b/app/controllers/personal_books_controller.rb index f420f3f..8f72c34 100644 --- a/app/controllers/personal_books_controller.rb +++ b/app/controllers/personal_books_controller.rb @@ -29,8 +29,13 @@ class PersonalBooksController < ApplicationController 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" + if params[:selectbox]=="dafault" + search_temp="book_title" + else + search_temp=params[:selectbox] + end if page.custom_string_field == "table" - books_show = books_temp.select {|value| search_all_words(value.send(params[:selectbox]), params[:keywords])} + 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 From 4a9213d5ad4faa59b605d269ff06417771bb5c88 Mon Sep 17 00:00:00 2001 From: chiu Date: Thu, 15 Aug 2019 10:03:39 +0800 Subject: [PATCH 22/27] Update personal_books_controller.rb --- app/controllers/personal_books_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/personal_books_controller.rb b/app/controllers/personal_books_controller.rb index 8f72c34..cc77b5e 100644 --- a/app/controllers/personal_books_controller.rb +++ b/app/controllers/personal_books_controller.rb @@ -29,10 +29,10 @@ class PersonalBooksController < ApplicationController 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" - if params[:selectbox]=="dafault" - search_temp="book_title" + if params[:selectbox] == "dafault" + search_temp = "book_title" else - search_temp=params[:selectbox] + search_temp = params[:selectbox] end if page.custom_string_field == "table" books_show = books_temp.select {|value| search_all_words(value.send(search_temp), params[:keywords])} From e6bcd9af3761930f70471000b610f596f5c2197a Mon Sep 17 00:00:00 2001 From: chiu Date: Thu, 15 Aug 2019 10:14:56 +0800 Subject: [PATCH 23/27] Update personal_books_controller.rb --- app/controllers/personal_books_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/personal_books_controller.rb b/app/controllers/personal_books_controller.rb index cc77b5e..608ac4a 100644 --- a/app/controllers/personal_books_controller.rb +++ b/app/controllers/personal_books_controller.rb @@ -33,6 +33,7 @@ class PersonalBooksController < ApplicationController search_temp = "book_title" else search_temp = params[:selectbox] + trans = params[:selectbox] end if page.custom_string_field == "table" books_show = books_temp.select {|value| search_all_words(value.send(search_temp), params[:keywords])} @@ -110,7 +111,8 @@ class PersonalBooksController < ApplicationController "url" => "/"+params[:locale]+params[:url], "select_text" => select_text, "search_text" => search_text, - "search_value" => params[:keywords]}, + "search_value" => params[:keywords], + "trans" => trans}, "headers" => headers, "total_pages" => books_total_pages, "choice" => choice From f76e785d9f01f018b3ed28360c2596700ac7a9d0 Mon Sep 17 00:00:00 2001 From: chiu Date: Thu, 15 Aug 2019 10:17:48 +0800 Subject: [PATCH 24/27] Update personal_books_controller.rb --- app/controllers/personal_books_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/personal_books_controller.rb b/app/controllers/personal_books_controller.rb index 608ac4a..7a7abb9 100644 --- a/app/controllers/personal_books_controller.rb +++ b/app/controllers/personal_books_controller.rb @@ -30,7 +30,7 @@ class PersonalBooksController < ApplicationController case params[:selectbox] when "book_title", "extracted_chapters", "default" if params[:selectbox] == "dafault" - search_temp = "book_title" + search_temp = 'book_title' else search_temp = params[:selectbox] trans = params[:selectbox] From 6a2ef23e7b7f67f103a657ca0c895bd4f6dcb3df Mon Sep 17 00:00:00 2001 From: chiu Date: Thu, 15 Aug 2019 10:19:55 +0800 Subject: [PATCH 25/27] Update personal_books_controller.rb --- app/controllers/personal_books_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/personal_books_controller.rb b/app/controllers/personal_books_controller.rb index 7a7abb9..c6524dc 100644 --- a/app/controllers/personal_books_controller.rb +++ b/app/controllers/personal_books_controller.rb @@ -29,8 +29,8 @@ class PersonalBooksController < ApplicationController 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" - if params[:selectbox] == "dafault" - search_temp = 'book_title' + if params[:selectbox] == "default" + search_temp = "book_title" else search_temp = params[:selectbox] trans = params[:selectbox] From 0a95f1e957330885be8ef4c1ccc8d275c21177ee Mon Sep 17 00:00:00 2001 From: chiu Date: Thu, 15 Aug 2019 10:21:11 +0800 Subject: [PATCH 26/27] Update personal_books_controller.rb --- app/controllers/personal_books_controller.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/controllers/personal_books_controller.rb b/app/controllers/personal_books_controller.rb index c6524dc..488d562 100644 --- a/app/controllers/personal_books_controller.rb +++ b/app/controllers/personal_books_controller.rb @@ -33,7 +33,6 @@ class PersonalBooksController < ApplicationController search_temp = "book_title" else search_temp = params[:selectbox] - trans = params[:selectbox] end if page.custom_string_field == "table" books_show = books_temp.select {|value| search_all_words(value.send(search_temp), params[:keywords])} @@ -111,8 +110,7 @@ class PersonalBooksController < ApplicationController "url" => "/"+params[:locale]+params[:url], "select_text" => select_text, "search_text" => search_text, - "search_value" => params[:keywords], - "trans" => trans}, + "search_value" => params[:keywords] }, "headers" => headers, "total_pages" => books_total_pages, "choice" => choice From ad892f6e0f19fd14e45693cd17ce3d96faa1a38b Mon Sep 17 00:00:00 2001 From: chiu Date: Thu, 15 Aug 2019 10:48:15 +0800 Subject: [PATCH 27/27] Update personal_books_controller.rb --- app/controllers/personal_books_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/personal_books_controller.rb b/app/controllers/personal_books_controller.rb index 488d562..85288a2 100644 --- a/app/controllers/personal_books_controller.rb +++ b/app/controllers/personal_books_controller.rb @@ -40,7 +40,7 @@ class PersonalBooksController < ApplicationController 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").to_s, params[:keywords])} + 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{|bat| bat.title}.join(", "), params[:keywords])} when "language" @@ -70,7 +70,7 @@ class PersonalBooksController < ApplicationController t << {"value" => "#{book.create_link}"} end when "publish_date", "publication_date" - t << {"value" => (!book.send(fs).nil? ? book.send(fs).strftime('%Y/%m') : "")} + t << {"value" => (!book.send(fs).nil? ? book.send(fs).strftime('%Y/%m') : "" rescue "")} when "author_type" t << {"value" => (book.book_author_types.collect{|bat| bat.title}.join(", ") rescue "")} when "language"