From 25a3c2652683be1d459503b371ae7a270073a019 Mon Sep 17 00:00:00 2001 From: "Billy.Zheng" Date: Thu, 9 May 2024 19:16:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=98=BE=E7=A4=BA=20ranking=20=E7=9A=84?= =?UTF-8?q?=E4=BA=BA=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/universities/click_edit_td.cr | 33 +++++++++++++++---- .../htmx/updated_score_input_page.cr | 3 +- src/pages/universities/index_page.cr | 24 +++++++++----- 3 files changed, 44 insertions(+), 16 deletions(-) diff --git a/src/components/universities/click_edit_td.cr b/src/components/universities/click_edit_td.cr index 0e13dd5..9eb12d2 100644 --- a/src/components/universities/click_edit_td.cr +++ b/src/components/universities/click_edit_td.cr @@ -3,19 +3,38 @@ class Universities::ClickEditTD < BaseComponent needs column_name : String needs column_value : String needs action : String + needs tooltip : String def render - td( - "hx-trigger": "click", - "hx-swap": "outerHTML", - "hx-get": action, - "hx-vals": "{ + if tooltip.blank? + td( + "hx-trigger": "click", + "hx-swap": "outerHTML", + "hx-get": action, + "hx-vals": "{ \"id\":\"#{id}\", \"column_name\":\"#{column_name}\", \"column_value\": \"#{column_value}\" }", - ) do - text column_value + ) do + text column_value + end + else + td( + class: "tooltipped", + "data-position": "top", + "data-tooltip": tooltip, + "hx-trigger": "click", + "hx-swap": "outerHTML", + "hx-get": action, + "hx-vals": "{ +\"id\":\"#{id}\", +\"column_name\":\"#{column_name}\", +\"column_value\": \"#{column_value}\" +}", + ) do + text column_value + end end end end diff --git a/src/pages/universities/htmx/updated_score_input_page.cr b/src/pages/universities/htmx/updated_score_input_page.cr index d5d226b..12616b3 100644 --- a/src/pages/universities/htmx/updated_score_input_page.cr +++ b/src/pages/universities/htmx/updated_score_input_page.cr @@ -10,7 +10,8 @@ class Universities::Htmx::UpdatedScoreInputPage < NoLayout id: id, column_value: column_value, column_name: column_name, - action: action + action: action, + tooltip: show_ranking_number(column_value) ) end end diff --git a/src/pages/universities/index_page.cr b/src/pages/universities/index_page.cr index 797765e..e555ce2 100644 --- a/src/pages/universities/index_page.cr +++ b/src/pages/universities/index_page.cr @@ -238,56 +238,64 @@ class Universities::IndexPage < MainLayout id: university.id.to_s, column_value: university.score_2023_min.to_s, column_name: "score_2023_min", - action: "/htmx/v1/universities/render_update_score_input" + action: "/htmx/v1/universities/render_update_score_input", + tooltip: "" ) mount( ClickEditTD, id: university.id.to_s, column_value: university.ranking_2023_min.to_s, column_name: "ranking_2023_min", - action: "/htmx/v1/universities/render_update_score_input" + action: "/htmx/v1/universities/render_update_score_input", + tooltip: show_ranking_number(university.ranking_2023_min) ) mount( ClickEditTD, id: university.id.to_s, column_value: university.score_2022_min.to_s, column_name: "score_2022_min", - action: "/htmx/v1/universities/render_update_score_input" + action: "/htmx/v1/universities/render_update_score_input", + tooltip: "" ) mount( ClickEditTD, id: university.id.to_s, column_value: university.ranking_2022_min.to_s, column_name: "ranking_2022_min", - action: "/htmx/v1/universities/render_update_score_input" + action: "/htmx/v1/universities/render_update_score_input", + tooltip: show_ranking_number(university.ranking_2022_min) ) mount( ClickEditTD, id: university.id.to_s, column_value: university.score_2021_min.to_s, column_name: "score_2021_min", - action: "/htmx/v1/universities/render_update_score_input" + action: "/htmx/v1/universities/render_update_score_input", + tooltip: "" ) mount( ClickEditTD, id: university.id.to_s, column_value: university.ranking_2021_min.to_s, column_name: "ranking_2021_min", - action: "/htmx/v1/universities/render_update_score_input" + action: "/htmx/v1/universities/render_update_score_input", + tooltip: show_ranking_number(university.ranking_2021_min) ) mount( ClickEditTD, id: university.id.to_s, column_value: university.score_2020_min.to_s, column_name: "score_2020_min", - action: "/htmx/v1/universities/render_update_score_input" + action: "/htmx/v1/universities/render_update_score_input", + tooltip: "" ) mount( ClickEditTD, id: university.id.to_s, column_value: university.ranking_2020_min.to_s, column_name: "ranking_2020_min", - action: "/htmx/v1/universities/render_update_score_input" + action: "/htmx/v1/universities/render_update_score_input", + tooltip: show_ranking_number(university.ranking_2022_min) ) end end