From f6e2d47c355e40ea21026c250bcfb9ec5105baec Mon Sep 17 00:00:00 2001 From: chiu Date: Thu, 15 Aug 2019 11:07:10 +0800 Subject: [PATCH 1/4] Update personal_projects_controller.rb add search function --- .../personal_projects_controller.rb | 52 +++++++++++++++++-- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/app/controllers/personal_projects_controller.rb b/app/controllers/personal_projects_controller.rb index 3bf8408..7457a67 100644 --- a/app/controllers/personal_projects_controller.rb +++ b/app/controllers/personal_projects_controller.rb @@ -1,4 +1,9 @@ class PersonalProjectsController < 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 projects = Project.where(:project_title.ne => nil,:project_title.ne => "").sort_for_frontend.page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) @@ -14,7 +19,28 @@ class PersonalProjectsController < ApplicationController "unit" ] end - + if params[:selectbox] !=nil + projects_temp = Project.where(:is_hidden=>false).sort_by{ |tp| [-tp[:year].to_i,-tp[:publication_date].to_i] } + case params[:selectbox] + when "project_type" + projects_show = projects_temp.select {|value| search_all_words(value.send("project_type").title.to_s, params[:keywords])} + when "project_title","default" + projects_show = projects_temp.select {|value| search_all_words(value.send("project_title").to_s), params[:keywords])} + when "period" + projects_show = projects_temp.select {|value| search_all_words(value.send("duration").to_s, params[:keywords])} + else + projects_show = projects_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 + projects = projects_show[(page_to_show-1)*OrbitHelper.page_data_count...page_to_show*OrbitHelper.page_data_count] + projects_total_pages = (projects_show.length/OrbitHelper.page_data_count.to_f).ceil + else + projects_total_pages = projects.total_pages + end project_list = [] projects.each do |project| t = [] @@ -32,7 +58,7 @@ class PersonalProjectsController < ApplicationController end project_list << {"project" => t} end - + choice_show = [] headers = [] fields_to_show.each do |fs| col = 2 @@ -41,12 +67,30 @@ class PersonalProjectsController < ApplicationController "head-title" => t("personal_project.#{fs}"), "col" => col } + choice_show << t("personal_project.#{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:" { "projects" => project_list, "headers" => headers, - "extras" => {"widget-title" => t("module_name.personal_project")}, - "total_pages" => projects.total_pages + "extras" => {"widget-title" => t("module_name.personal_project"), + "url" => "/"+params[:locale]+params[:url], + "select_text" => select_text, + "search_text" => search_text, + "search_value" => params[:keywords] }, + "total_pages" => projects_total_pages, + "choice" => choice } end From 96af616d2d88b6e71b9b2ead33229bd3e8ee0f0a Mon Sep 17 00:00:00 2001 From: chiu Date: Thu, 15 Aug 2019 11:10:55 +0800 Subject: [PATCH 2/4] Update personal_projects_controller.rb fix error --- app/controllers/personal_projects_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/personal_projects_controller.rb b/app/controllers/personal_projects_controller.rb index 7457a67..843dbd4 100644 --- a/app/controllers/personal_projects_controller.rb +++ b/app/controllers/personal_projects_controller.rb @@ -25,7 +25,7 @@ class PersonalProjectsController < ApplicationController when "project_type" projects_show = projects_temp.select {|value| search_all_words(value.send("project_type").title.to_s, params[:keywords])} when "project_title","default" - projects_show = projects_temp.select {|value| search_all_words(value.send("project_title").to_s), params[:keywords])} + projects_show = projects_temp.select {|value| search_all_words(value.send("project_title").to_s, params[:keywords])} when "period" projects_show = projects_temp.select {|value| search_all_words(value.send("duration").to_s, params[:keywords])} else From aa35cd4de686780be39a4d678e33b2e1823ffc68 Mon Sep 17 00:00:00 2001 From: chiu Date: Thu, 15 Aug 2019 11:13:44 +0800 Subject: [PATCH 3/4] Update personal_projects_controller.rb --- app/controllers/personal_projects_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/personal_projects_controller.rb b/app/controllers/personal_projects_controller.rb index 843dbd4..ed546c1 100644 --- a/app/controllers/personal_projects_controller.rb +++ b/app/controllers/personal_projects_controller.rb @@ -23,7 +23,7 @@ class PersonalProjectsController < ApplicationController projects_temp = Project.where(:is_hidden=>false).sort_by{ |tp| [-tp[:year].to_i,-tp[:publication_date].to_i] } case params[:selectbox] when "project_type" - projects_show = projects_temp.select {|value| search_all_words(value.send("project_type").title.to_s, params[:keywords])} + projects_show = projects_temp.select {|value| search_all_words((value.send("project_type").title rescue ""), params[:keywords])} when "project_title","default" projects_show = projects_temp.select {|value| search_all_words(value.send("project_title").to_s, params[:keywords])} when "period" From 05a285a47284648bfed3607eb5d24b9541136960 Mon Sep 17 00:00:00 2001 From: chiu Date: Thu, 15 Aug 2019 11:20:54 +0800 Subject: [PATCH 4/4] Update personal_projects_controller.rb fix language not translated --- app/controllers/personal_projects_controller.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/controllers/personal_projects_controller.rb b/app/controllers/personal_projects_controller.rb index ed546c1..4c4245e 100644 --- a/app/controllers/personal_projects_controller.rb +++ b/app/controllers/personal_projects_controller.rb @@ -28,6 +28,8 @@ class PersonalProjectsController < ApplicationController projects_show = projects_temp.select {|value| search_all_words(value.send("project_title").to_s, params[:keywords])} when "period" projects_show = projects_temp.select {|value| search_all_words(value.send("duration").to_s, params[:keywords])} + when "language" + projects_show = projects_temp.select {|value| search_all_words(t(value.send("language")), params[:keywords])} else projects_show = projects_temp.select {|value| search_all_words(value.send(params[:selectbox]).to_s, params[:keywords])} end @@ -52,6 +54,8 @@ class PersonalProjectsController < ApplicationController t << {"value" => "" + (project.send(fs) rescue "") + ""} when "period" t << {"value" => (project.send("duration") rescue "")} + when "language" + t << {"value" => (t(project.send("language")) rescue "")} else t << {"value" => (project.send(fs) rescue "")} end