From a915db1091a15faafa52c89d912b6ad4ffcb5c00 Mon Sep 17 00:00:00 2001 From: "Billy.Zheng" Date: Wed, 22 May 2024 23:40:39 +0800 Subject: [PATCH] fix param Int32 bug. --- src/actions/universities/index.cr | 5 +++++ src/components/universities/main.cr | 12 ++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/actions/universities/index.cr b/src/actions/universities/index.cr index 13eedc3..604ae24 100644 --- a/src/actions/universities/index.cr +++ b/src/actions/universities/index.cr @@ -36,6 +36,8 @@ class Universities::Index < BrowserAction # 检测在哪一个 tab head 上点击, 只要每次点击一次, 就判断有没有 cookie # 如果没有, 就默认排序, 如果有, 就反转 if click_on.presence + params.from_query["click_on"] = "" + case click_on when "score_2023_min" if cookies.get?("order_by") == "score_2023_min_asc_order" @@ -151,6 +153,9 @@ class Universities::Index < BrowserAction max_value = range_max_value.zero? ? range_max.to_i : range_max_value if filter_by_column.presence + params.from_query["range_min_value"] = min_value.to_s + params.from_query["range_max_value"] = max_value.to_s + case filter_by_column when "ranking_2023" query = query.ranking_2023_min.gte(min_value).ranking_2023_min.lte(max_value) if !min_value.nil? && !max_value.nil? diff --git a/src/components/universities/main.cr b/src/components/universities/main.cr index 42ecfef..fd9a23b 100644 --- a/src/components/universities/main.cr +++ b/src/components/universities/main.cr @@ -57,17 +57,16 @@ class Universities::Main < BaseComponent id: "dropdown2", class: "dropdown-content", hx_target: "#main", - hx_push_url: "true", hx_include: all_name_inputs.reject { |x| x.in? ["filter_by_column"] }.join(",") { |e| "[name='#{e}']" } ) do li do - a href: "#!", hx_get: Index.path, hx_vals: "{\"filter_by_column\": \"\", \"range_min_value\": \"\", \"range_max_value\": \"\"}", id: "filter_by_column", hx_indicator: "#spinner" do + a href: "#!", hx_get: Index.path, hx_vals: "{\"filter_by_column\": \"\", \"range_min_value\": \"0\", \"range_max_value\": \"0\"}", id: "filter_by_column", hx_indicator: "#spinner" do text "取消过滤" end end list.each do |k, v| li do - a href: "#!", hx_get: Index.path, hx_vals: "{\"filter_by_column\": \"#{k}\", \"range_min_value\": \"\", \"range_max_value\": \"\"}", id: "filter_by_column", hx_indicator: "#spinner" do + a href: "#!", hx_get: Index.path, hx_vals: "{\"filter_by_column\": \"#{k}\", \"range_min_value\": \"0\", \"range_max_value\": \"0\"}", id: "filter_by_column", hx_indicator: "#spinner" do text v end end @@ -80,7 +79,7 @@ class Universities::Main < BaseComponent default_max = context.request.query_params["range_max_value"]?.presence || range_max.to_s para class: "range-field col m8", style: "margin-right: 120px; margin-left: 30px;" do - input type: "hidden", name: "range_min_value", value: context.request.query_params["range_min_value"]?.to_s + input type: "hidden", name: "range_min_value", value: default_min span default_min, style: "margin-right: 10px;" tag( "tc-range-slider", @@ -97,13 +96,10 @@ then put my.value2 into the next then set (previous ).value to my.value1 then set (next ).value to my.value2 ", -# script: " -# on change set (previous ).value and (previous ).innerHTML to my.value1 -# " ) do end span default_max, style: "margin-left: 10px;" - input type: "hidden", name: "range_max_value", value: context.request.query_params["range_max_value"]?.to_s + input type: "hidden", name: "range_max_value", value: default_max end div class: "col m1 valign-wrapper" do