From 06c1446a5ba3fc00e313d7be50bef0eea5262b71 Mon Sep 17 00:00:00 2001 From: Eric Tsai Date: Mon, 4 Nov 2019 10:40:59 +0800 Subject: [PATCH 1/3] auto indent app/controllers/personal_honors_controller.rb --- app/controllers/personal_honors_controller.rb | 86 +++++++++---------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/app/controllers/personal_honors_controller.rb b/app/controllers/personal_honors_controller.rb index 853e580..b0ae582 100644 --- a/app/controllers/personal_honors_controller.rb +++ b/app/controllers/personal_honors_controller.rb @@ -18,22 +18,22 @@ class PersonalHonorsController < ApplicationController honors.each do |honor| t = [] fields_to_show.each do |fs| - case fs - when "award_name" - t << {"value" => "" + (honor.send(fs) rescue "") + ""} - when "honor_type" - t << {"value" => (honor.send("honor_type").title rescue "")} - when "authors" - t << {"value" => (honor.send(:member_profile).name rescue "")} - when "award_date" - t << {"value" => (honor.send(fs).strftime("%Y/%m") rescue "")} - else - t << {"value" => (honor.send(fs) rescue "")} - end - end - honor_list << {"personal_honors" => t} + case fs + when "award_name" + t << {"value" => "" + (honor.send(fs) rescue "") + ""} + when "honor_type" + t << {"value" => (honor.send("honor_type").title rescue "")} + when "authors" + t << {"value" => (honor.send(:member_profile).name rescue "")} + when "award_date" + t << {"value" => (honor.send(fs).strftime("%Y/%m") rescue "")} + else + t << {"value" => (honor.send(fs) rescue "")} + end + end + honor_list << {"personal_honors" => t} end - + headers = [] fields_to_show.each do |fs| col = 2 @@ -73,35 +73,35 @@ class PersonalHonorsController < ApplicationController end def get_fields_for_index - @page = Page.find(params[:page_id]) rescue nil - @fields_to_show = [ - "year", - "award_name", - "awarding_unit", - "honor_type", - "award_date", - "country", - "keywords", - "url", - "note", - "authors", - "award_winner" - ] - @fields_to_show = @fields_to_show.map{|fs| [(fs == "authors" ? t("users.name") : t("personal_honor.#{fs}")), fs]} - @default_fields_to_show = [ - "honor_type", - "year", - "award_name", - "authors", - "awarding_unit" - ] - render :layout => false + @page = Page.find(params[:page_id]) rescue nil + @fields_to_show = [ + "year", + "award_name", + "awarding_unit", + "honor_type", + "award_date", + "country", + "keywords", + "url", + "note", + "authors", + "award_winner" + ] + @fields_to_show = @fields_to_show.map{|fs| [(fs == "authors" ? t("users.name") : t("personal_honor.#{fs}")), fs]} + @default_fields_to_show = [ + "honor_type", + "year", + "award_name", + "authors", + "awarding_unit" + ] + 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 + page = Page.find(params[:page_id]) rescue nil + page.custom_array_field = params[:keys] + page.save + render :json => {"success" => true}.to_json end -end \ No newline at end of file +end From 117d22bcf7879699913b553380147bc16ef9bbf9 Mon Sep 17 00:00:00 2001 From: Eric Tsai Date: Mon, 4 Nov 2019 10:52:20 +0800 Subject: [PATCH 2/3] add honor type filter --- app/controllers/personal_honors_controller.rb | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/app/controllers/personal_honors_controller.rb b/app/controllers/personal_honors_controller.rb index b0ae582..b0c370a 100644 --- a/app/controllers/personal_honors_controller.rb +++ b/app/controllers/personal_honors_controller.rb @@ -1,7 +1,16 @@ class PersonalHonorsController < ApplicationController def index params = OrbitHelper.params - honors = Honor.where(:award_name.ne => nil).or(:award_name.ne => "").sort_for_frontend.page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) + filter_value = params[:honors_filter_value] + honors = nil + + if filter_value.nil? || filter_value == 'all' || filter_value.empty? + honors = Honor.where(:award_name.ne => nil).or(:award_name.ne => "").sort_for_frontend.page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) + else + honor_type_id = HonorType.or({ 'title.en' => filter_value }, { 'title.zh_tw' => filter_value }).first.id + honors = Honor.where(honor_type_id: honor_type_id).sort_for_frontend.page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) + end + fields_to_show = Page.where(:page_id => params[:page_id]).first.custom_array_field rescue [] if fields_to_show.blank? @@ -45,9 +54,15 @@ class PersonalHonorsController < ApplicationController } end + current_locale = I18n.locale + honor_types = HonorType.all.pluck(:title).map { |title| { 'honor_type' => title[current_locale] } } + honor_types.unshift({ 'honor_type' => 'all' }) + { "honors" => honor_list, - "extras" => {"widget-title" => t("module_name.personal_honor")}, + "honor_types" => honor_types, + "extras" => { "widget-title" => t("module_name.personal_honor"), + "url" => '/' + current_locale.to_s + params[:url] }, "headers" => headers, "total_pages" => honors.total_pages } From 04d59309fc1a70ebc2c2d28f26dfce85cb03b293 Mon Sep 17 00:00:00 2001 From: Eric Tsai Date: Mon, 4 Nov 2019 11:02:23 +0800 Subject: [PATCH 3/3] i18n for query all kinds of honors --- app/controllers/personal_honors_controller.rb | 4 ++-- config/locales/en.yml | 3 ++- config/locales/zh_tw.yml | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/controllers/personal_honors_controller.rb b/app/controllers/personal_honors_controller.rb index b0c370a..da7e199 100644 --- a/app/controllers/personal_honors_controller.rb +++ b/app/controllers/personal_honors_controller.rb @@ -4,7 +4,7 @@ class PersonalHonorsController < ApplicationController filter_value = params[:honors_filter_value] honors = nil - if filter_value.nil? || filter_value == 'all' || filter_value.empty? + if filter_value.nil? || filter_value == t("personal_honor.honor_types_all") || filter_value.empty? honors = Honor.where(:award_name.ne => nil).or(:award_name.ne => "").sort_for_frontend.page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) else honor_type_id = HonorType.or({ 'title.en' => filter_value }, { 'title.zh_tw' => filter_value }).first.id @@ -56,7 +56,7 @@ class PersonalHonorsController < ApplicationController current_locale = I18n.locale honor_types = HonorType.all.pluck(:title).map { |title| { 'honor_type' => title[current_locale] } } - honor_types.unshift({ 'honor_type' => 'all' }) + honor_types.unshift({ 'honor_type' => t("personal_honor.honor_types_all") }) { "honors" => honor_list, diff --git a/config/locales/en.yml b/config/locales/en.yml index 6005be9..220653b 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -9,6 +9,7 @@ en: awarding_unit : "Awarding Unit" honor_category : "Honor Category" honor_type: "Honor Category" + honor_types_all: "All Honor Types" extracted_chapters : "Extracted Chapters" publishers : "Publishers" honoree: "Honoree" @@ -59,4 +60,4 @@ en: save: "save" hintText: "Type in a search term" noResultsText: "No results" - searchingText: "Searching…" \ No newline at end of file + searchingText: "Searching…" diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 81c0ee1..d44f0c7 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -9,6 +9,7 @@ zh_tw: awarding_unit : "頒獎單位" honor_category : "類別" honor_type: "類別" + honor_types_all: "所有榮譽項目" honoree: "受獎人" authors : "作者" tags : "領域" @@ -55,4 +56,4 @@ zh_tw: save: "儲存" hintText: "請輸入搜尋關鍵字" noResultsText: "沒有相關的比對結果" - searchingText: "搜尋中…" \ No newline at end of file + searchingText: "搜尋中…"