Skip to content

Commit

Permalink
鼠标 hover 显示位次相较前一年的浮动
Browse files Browse the repository at this point in the history
  • Loading branch information
zw963 committed Jun 4, 2024
1 parent 9977cb4 commit 14e8d78
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 7 deletions.
33 changes: 31 additions & 2 deletions src/actions/mixins/page_helpers.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module PageHelpers
def show_ranking_number(ranking_value)
def show_ranking_info(university, year, ranking_value)
if ranking_value.blank?
""
else
Expand All @@ -13,7 +13,36 @@ module PageHelpers
size = low_ranking.size
high_ranking = high_ranking.ljust(size, '0')

"#{low_ranking.to_i - high_ranking.to_i}"
same_ranking_count = low_ranking.to_i - high_ranking.to_i

case year
when 2023
unless university.ranking_2023_min.nil? || university.ranking_2022_min.nil?
ranking_offset = university.ranking_2023_min.not_nil!.to_i - university.ranking_2022_min.not_nil!.to_i
end
when 2022
unless university.ranking_2022_min.nil? || university.ranking_2021_min.nil?
ranking_offset = university.ranking_2022_min.not_nil!.to_i - university.ranking_2021_min.not_nil!.to_i
end
when 2021
unless university.ranking_2021_min.nil? || university.ranking_2020_min.nil?
ranking_offset = university.ranking_2021_min.not_nil!.to_i - university.ranking_2020_min.not_nil!.to_i
end
end

str = String.build do |io|
io << "同分段 #{same_ranking_count}"

unless ranking_offset.nil?
io << "\n相较前一年位次 "
if ranking_offset > 0
io << "+"
end
io << ranking_offset
end
end

str
end
end
end
11 changes: 10 additions & 1 deletion src/actions/universities/update.cr
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,22 @@ class Universities::Update < BrowserAction
column_name = param_value[0]
column_value = param_value[1]

case column_name
when /2023/
year = 2023
when /2022/
year = 2022
when /2021/
year = 2021
end

component(
ClickEditTD,
id: university.id.to_s,
column_name: column_name,
column_value: column_value,
action: "/htmx/v1/universities/render_update_score_input",
tooltip: show_ranking_number(column_value),
tooltip: show_ranking_info(university, year, column_value),
current_user: current_user
)
elsif hx_trigger.in? [
Expand Down
8 changes: 4 additions & 4 deletions src/components/universities/main.cr
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ then set (next <input/>).value to my.value2
column_value: university.ranking_2023_min.to_s,
column_name: "ranking_2023_min",
action: "/htmx/v1/universities/render_update_score_input",
tooltip: show_ranking_number(university.ranking_2023_min),
tooltip: show_ranking_info(university, 2023, university.ranking_2023_min),
current_user: current_user
)
mount(
Expand All @@ -341,7 +341,7 @@ then set (next <input/>).value to my.value2
column_value: university.ranking_2022_min.to_s,
column_name: "ranking_2022_min",
action: "/htmx/v1/universities/render_update_score_input",
tooltip: show_ranking_number(university.ranking_2022_min),
tooltip: show_ranking_info(university, 2022, university.ranking_2022_min),
current_user: current_user
)
mount(
Expand All @@ -359,7 +359,7 @@ then set (next <input/>).value to my.value2
column_value: university.ranking_2021_min.to_s,
column_name: "ranking_2021_min",
action: "/htmx/v1/universities/render_update_score_input",
tooltip: show_ranking_number(university.ranking_2021_min),
tooltip: show_ranking_info(university, 2021, university.ranking_2021_min),
current_user: current_user
)
mount(
Expand All @@ -377,7 +377,7 @@ then set (next <input/>).value to my.value2
column_value: university.ranking_2020_min.to_s,
column_name: "ranking_2020_min",
action: "/htmx/v1/universities/render_update_score_input",
tooltip: show_ranking_number(university.ranking_2020_min),
tooltip: show_ranking_info(university, 2020, university.ranking_2020_min),
current_user: current_user
)
end
Expand Down
2 changes: 2 additions & 0 deletions src/pages/universities/index_page.cr
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class Universities::IndexPage < MainLayout
def content
h3 do
link "所有学校", Index

span " 2024 年山西省考生: 三十五万, 临汾市考生: 三万八千"
end

div class: "row" do
Expand Down

0 comments on commit 14e8d78

Please sign in to comment.