Skip to content

Commit

Permalink
fix param Int32 bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
zw963 committed May 22, 2024
1 parent 178625b commit a915db1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
5 changes: 5 additions & 0 deletions src/actions/universities/index.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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?
Expand Down
12 changes: 4 additions & 8 deletions src/components/universities/main.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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",
Expand All @@ -97,13 +96,10 @@ then put my.value2 into the next <span/>
then set (previous <input/>).value to my.value1
then set (next <input/>).value to my.value2
",
# script: "
# on change set (previous <input/>).value and (previous <span/>).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
Expand Down

0 comments on commit a915db1

Please sign in to comment.