Skip to content

Commit

Permalink
Add is_marked back
Browse files Browse the repository at this point in the history
  • Loading branch information
zw963 committed Jun 13, 2024
1 parent 7999145 commit 7cc3a0e
Show file tree
Hide file tree
Showing 15 changed files with 126 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class AddIndexToIsMarkedForChongWenBao::V20240613010329 < Avram::Migrator::Migration::V1
def migrate
create_index table_for(ChongWenBao), [:is_marked]
end

def rollback
drop_index table_for(ChongWenBao), [:is_marked], if_exists: true
end
end
2 changes: 1 addition & 1 deletion src/actions/universities/htmx/clear_2020_mark.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Universities::Htmx::Clear2020Mark < HtmxAction
put "/universities/clear_2020_mark" do
chong_wen_baos = ChongWenBaoQuery.new.user_id(current_user.id.not_nil!)
chong_wen_baos = ChongWenBaoQuery.new.user_id(current_user.id)

chong_wen_baos.update(is_marked_2020: false) if chong_wen_baos

Expand Down
2 changes: 1 addition & 1 deletion src/actions/universities/htmx/clear_2021_mark.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Universities::Htmx::Clear2021Mark < HtmxAction
put "/universities/clear_2021_mark" do
chong_wen_baos = ChongWenBaoQuery.new.user_id(current_user.id.not_nil!)
chong_wen_baos = ChongWenBaoQuery.new.user_id(current_user.id)

chong_wen_baos.update(is_marked_2021: false) if chong_wen_baos

Expand Down
2 changes: 1 addition & 1 deletion src/actions/universities/htmx/clear_2022_mark.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Universities::Htmx::Clear2022Mark < HtmxAction
put "/universities/clear_2022_mark" do
chong_wen_baos = ChongWenBaoQuery.new.user_id(current_user.id.not_nil!)
chong_wen_baos = ChongWenBaoQuery.new.user_id(current_user.id)

chong_wen_baos.update(is_marked_2022: false) if chong_wen_baos

Expand Down
2 changes: 1 addition & 1 deletion src/actions/universities/htmx/clear_2023_mark.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Universities::Htmx::Clear2023Mark < HtmxAction
put "/universities/clear_2023_mark" do
chong_wen_baos = ChongWenBaoQuery.new.user_id(current_user.id.not_nil!)
chong_wen_baos = ChongWenBaoQuery.new.user_id(current_user.id)

chong_wen_baos.update(is_marked_2023: false) if chong_wen_baos

Expand Down
11 changes: 11 additions & 0 deletions src/actions/universities/htmx/clear_mark.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Universities::Htmx::ClearMark < HtmxAction
put "/universities/clear_mark" do
chong_wen_baos = ChongWenBaoQuery.new.user_id(current_user.id)

chong_wen_baos.update(is_marked: false) if chong_wen_baos

context.response.headers["HX-Refresh"] = "true"

plain_text "ok"
end
end
15 changes: 15 additions & 0 deletions src/actions/universities/htmx/marked.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Universities::Htmx::Marked < HtmxAction
put "/universities/:university_id/marked" do
user_id = current_user.id

chong_wen_bao = ChongWenBaoQuery.new.user_id(user_id).university_id(university_id).first?

chong_wen_bao = SaveChongWenBao.create!(user_id: user_id, university_id: university_id.to_i64) if chong_wen_bao.nil?

SaveChongWenBao.update!(chong_wen_bao, is_marked: !chong_wen_bao.is_marked)

context.response.headers["HX-Refresh"] = "true"

plain_text "ok"
end
end
7 changes: 4 additions & 3 deletions src/actions/universities/htmx/marked_2020.cr
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
class Universities::Htmx::Marked2020 < HtmxAction
put "/universities/:university_id/marked_2020" do
user_id = current_user.id.not_nil!
university = UniversityQuery.new.preload_chong_wen_baos.find(university_id)
user_id = current_user.id

chong_wen_bao = ChongWenBaoQuery.new.user_id(user_id).university_id(university_id).first?

SaveChongWenBao.update!(chong_wen_bao, is_marked_2020: !chong_wen_bao.is_marked_2020) if chong_wen_bao
chong_wen_bao = SaveChongWenBao.create!(user_id: user_id, university_id: university_id.to_i64) if chong_wen_bao.nil?

SaveChongWenBao.update!(chong_wen_bao, is_marked_2020: !chong_wen_bao.is_marked_2020)

context.response.headers["HX-Refresh"] = "true"

Expand Down
7 changes: 4 additions & 3 deletions src/actions/universities/htmx/marked_2021.cr
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
class Universities::Htmx::Marked2021 < HtmxAction
put "/universities/:university_id/marked_2021" do
user_id = current_user.id.not_nil!
university = UniversityQuery.new.preload_chong_wen_baos.find(university_id)
user_id = current_user.id

chong_wen_bao = ChongWenBaoQuery.new.user_id(user_id).university_id(university_id).first?

SaveChongWenBao.update!(chong_wen_bao, is_marked_2021: !chong_wen_bao.is_marked_2021) if chong_wen_bao
chong_wen_bao = SaveChongWenBao.create!(user_id: user_id, university_id: university_id.to_i64) if chong_wen_bao.nil?

SaveChongWenBao.update!(chong_wen_bao, is_marked_2021: !chong_wen_bao.is_marked_2021)

context.response.headers["HX-Refresh"] = "true"

Expand Down
7 changes: 4 additions & 3 deletions src/actions/universities/htmx/marked_2022.cr
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
class Universities::Htmx::Marked2022 < HtmxAction
put "/universities/:university_id/marked_2022" do
user_id = current_user.id.not_nil!
university = UniversityQuery.new.preload_chong_wen_baos.find(university_id)
user_id = current_user.id

chong_wen_bao = ChongWenBaoQuery.new.user_id(user_id).university_id(university_id).first?

SaveChongWenBao.update!(chong_wen_bao, is_marked_2022: !chong_wen_bao.is_marked_2022) if chong_wen_bao
chong_wen_bao = SaveChongWenBao.create!(user_id: user_id, university_id: university_id.to_i64) if chong_wen_bao.nil?

SaveChongWenBao.update!(chong_wen_bao, is_marked_2022: !chong_wen_bao.is_marked_2022)

context.response.headers["HX-Refresh"] = "true"

Expand Down
7 changes: 4 additions & 3 deletions src/actions/universities/htmx/marked_2023.cr
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
class Universities::Htmx::Marked2023 < HtmxAction
put "/universities/:university_id/marked_2023" do
user_id = current_user.id.not_nil!
university = UniversityQuery.new.preload_chong_wen_baos.find(university_id)
user_id = current_user.id

chong_wen_bao = ChongWenBaoQuery.new.user_id(user_id).university_id(university_id).first?

SaveChongWenBao.update!(chong_wen_bao, is_marked_2023: !chong_wen_bao.is_marked_2023) if chong_wen_bao
chong_wen_bao = SaveChongWenBao.create!(user_id: user_id, university_id: university_id.to_i64) if chong_wen_bao.nil?

SaveChongWenBao.update!(chong_wen_bao, is_marked_2023: !chong_wen_bao.is_marked_2023)

context.response.headers["HX-Refresh"] = "true"

Expand Down
6 changes: 4 additions & 2 deletions src/actions/universities/index.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class Universities::Index < BrowserAction
param is_211 : Bool = false
param is_good : Bool = false
param is_exists_remark : Bool = false
param is_marked : Bool = false
param is_marked_2023 : Bool = false
param is_marked_2022 : Bool = false
param is_marked_2021 : Bool = false
Expand Down Expand Up @@ -58,12 +59,13 @@ class Universities::Index < BrowserAction

query = query.where_chong_wen_baos(user_chong_wen_bao_query.university_remark.is_not_nil) if is_exists_remark

if is_marked_2023 || is_marked_2022 || is_marked_2021 || is_marked_2020 ||
if is_marked_2023 || is_marked_2022 || is_marked_2021 || is_marked_2020 || is_marked ||
chong_2023 || chong_2022 || chong_2021 || chong_2020 ||
wen_2023 || wen_2022 || wen_2021 || wen_2020 ||
bao_2023 || bao_2022 || bao_2021 || bao_2020
cwb_query = user_chong_wen_bao_query

cwb_query = cwb_query.is_marked(true) if is_marked
cwb_query = cwb_query.is_marked_2023(true) if is_marked_2023
cwb_query = cwb_query.is_marked_2022(true) if is_marked_2022
cwb_query = cwb_query.is_marked_2021(true) if is_marked_2021
Expand Down Expand Up @@ -94,7 +96,7 @@ class Universities::Index < BrowserAction
pages, universities = paginate(query.id.desc_order, per_page: 50)

all_name_inputs = [
"q", "is_985", "is_211", "is_good", "is_exists_remark",
"q", "is_985", "is_211", "is_good", "is_exists_remark", "is_marked",
"is_marked_2023", "is_marked_2022", "is_marked_2021", "is_marked_2020",
"order_by", "batch_level", "filter_by_column",
"range_min_value", "range_max_value",
Expand Down
27 changes: 27 additions & 0 deletions src/components/universities/main.cr
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ then set (next <input/>).value to my.value2
div class: "col m2" do
mount CheckBox, "is_exists_remark", "仅显示含备注学校", all_name_inputs
end
div class: "col m2" do
mount CheckBox, "is_marked", "仅显示手动标记的学校", all_name_inputs
end
end

private def render_batch_level_dropdown
Expand Down Expand Up @@ -357,7 +360,9 @@ then set (next <input/>).value to my.value2
marked_2022: university.marked_2022(current_user),
marked_2021: university.marked_2021(current_user),
marked_2020: university.marked_2020(current_user),
marked: university.marked(current_user),
script: "on click set @href of <ul#dropdown3 li a[href='data_edit_url']/> to '#{Edit.with(university).path}'
then set @hx-put of <ul#dropdown3 li input[hx-put='data_marked_url']/> to '#{Universities::Htmx::Marked.with(university.id).path}'
then set @hx-put of <ul#dropdown3 li input[hx-put='data_marked_2023_url']/> to '#{Universities::Htmx::Marked2023.with(university.id).path}'
then set @hx-put of <ul#dropdown3 li input[hx-put='data_marked_2022_url']/> to '#{Universities::Htmx::Marked2022.with(university.id).path}'
then set @hx-put of <ul#dropdown3 li input[hx-put='data_marked_2021_url']/> to '#{Universities::Htmx::Marked2021.with(university.id).path}'
Expand All @@ -383,6 +388,11 @@ then if @marked-2020 as String == 'true'
else
js document.getElementById('marked_2020').checked = false; end
end
then if @marked as String == 'true'
js document.getElementById('marked').checked = true; end
else
js document.getElementById('marked').checked = false; end
end
"
)
end
Expand Down Expand Up @@ -539,6 +549,23 @@ end
span "标记2020"
end
end

li do
label do
input(type: "hidden", name: "university:is_marked", value: "false", id: "marked_unmark")
input(
type: "checkbox",
name: "university:is_marked",
value: "true",
id: "marked",
"hx-put": "data_marked_url",
"hx-swap": "#main",
"hx-indicator": "#spinner",
"hx-include": "[name='_csrf'],input#marked_unmark"
)
span "手动标记"
end
end
end
end
end
Expand Down
10 changes: 10 additions & 0 deletions src/models/university.cr
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ class University < BaseModel
end
end

def marked(user)
cwb = chong_wen_bao_for(user)

if cwb.nil?
false
else
cwb.is_marked
end
end

def marked_2023(user)
cwb = chong_wen_bao_for(user)

Expand Down
48 changes: 30 additions & 18 deletions src/pages/me/show_page.cr
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ class Me::ShowPage < MainLayout
private def clear_chong_wen_bao
div class: "row" do
div class: "col m4" do
link(
a(
"删除 冲 数据",
Me::ClearChong,
href: "#!",
class: "btn",
"hx-put": Me::ClearChong.path,
"hx-swap": "none",
Expand All @@ -40,9 +40,9 @@ class Me::ShowPage < MainLayout
end

div class: "col m4" do
link(
a(
"删除 稳 数据",
Me::ClearWen,
href: "#!",
class: "btn",
"hx-put": Me::ClearWen.path,
"hx-swap": "none",
Expand All @@ -52,9 +52,9 @@ class Me::ShowPage < MainLayout
end

div class: "col m4" do
link(
a(
"删除 保 数据",
Me::ClearChong,
href: "#!",
class: "btn",
"hx-put": Me::ClearBao.path,
"hx-swap": "none",
Expand All @@ -67,10 +67,10 @@ class Me::ShowPage < MainLayout
br

div class: "row" do
div class: "col m3" do
link(
div class: "col m2" do
a(
"删除 2023 标记数据",
Universities::Htmx::Clear2023Mark,
href: "#!",
class: "btn",
"hx-put": Universities::Htmx::Clear2023Mark.path,
"hx-swap": "none",
Expand All @@ -79,10 +79,10 @@ class Me::ShowPage < MainLayout
)
end

div class: "col m3" do
link(
div class: "col m2" do
a(
"删除 2022 标记数据",
Universities::Htmx::Clear2022Mark,
href: "#!",
class: "btn",
"hx-put": Universities::Htmx::Clear2022Mark.path,
"hx-swap": "none",
Expand All @@ -91,10 +91,10 @@ class Me::ShowPage < MainLayout
)
end

div class: "col m3" do
link(
div class: "col m2" do
a(
"删除 2021 标记数据",
Universities::Htmx::Clear2021Mark,
href: "#!",
class: "btn",
"hx-put": Universities::Htmx::Clear2021Mark.path,
"hx-swap": "none",
Expand All @@ -103,17 +103,29 @@ class Me::ShowPage < MainLayout
)
end

div class: "col m3" do
link(
div class: "col m2" do
a(
"删除 2020 标记数据",
Universities::Htmx::Clear2020Mark,
href: "#!",
class: "btn",
"hx-put": Universities::Htmx::Clear2020Mark.path,
"hx-swap": "none",
"hx-include": "[name='_csrf']",
"hx-confirm": "确认要删除 2020 标记数据吗?",
)
end

div class: "col m2" do
a(
"删除 手动 标记数据",
href: "#!",
class: "btn",
"hx-put": Universities::Htmx::ClearMark.path,
"hx-swap": "none",
"hx-include": "[name='_csrf']",
"hx-confirm": "确认要删除 手动 标记数据吗?",
)
end
end
end

Expand Down

0 comments on commit 7cc3a0e

Please sign in to comment.