From 117d22bcf7879699913b553380147bc16ef9bbf9 Mon Sep 17 00:00:00 2001 From: Eric Tsai Date: Mon, 4 Nov 2019 10:52:20 +0800 Subject: [PATCH] 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 }