diff --git a/app/components/admin/proposals/toggle_selection_component.html.erb b/app/components/admin/proposals/toggle_selection_component.html.erb new file mode 100644 index 000000000..a63c1b4a9 --- /dev/null +++ b/app/components/admin/proposals/toggle_selection_component.html.erb @@ -0,0 +1 @@ +<%= link_to_toggle_proposal_selection %> diff --git a/app/components/admin/proposals/toggle_selection_component.rb b/app/components/admin/proposals/toggle_selection_component.rb new file mode 100644 index 000000000..c7d3cd117 --- /dev/null +++ b/app/components/admin/proposals/toggle_selection_component.rb @@ -0,0 +1,26 @@ +class Admin::Proposals::ToggleSelectionComponent < ApplicationComponent + attr_reader :proposal + + def initialize(proposal) + @proposal = proposal + end + + def link_to_toggle_proposal_selection + if proposal.selected? + button_text = t("admin.proposals.index.selected") + html_class = "button expanded" + else + button_text = t("admin.proposals.index.select") + html_class = "button hollow expanded" + end + + case proposal.class.to_s + when "Proposal" + path = toggle_selection_admin_proposal_path(proposal) + when "Legislation::Proposal" + path = toggle_selection_admin_legislation_process_proposal_path(proposal.process, proposal) + end + + link_to button_text, path, remote: true, method: :patch, class: html_class + end +end diff --git a/app/helpers/proposals_helper.rb b/app/helpers/proposals_helper.rb index f2b82e8dc..a497c7037 100644 --- a/app/helpers/proposals_helper.rb +++ b/app/helpers/proposals_helper.rb @@ -64,25 +64,6 @@ module ProposalsHelper proposals_current_view == "default" ? "minimal" : "default" end - def link_to_toggle_proposal_selection(proposal) - if proposal.selected? - button_text = t("admin.proposals.index.selected") - html_class = "button expanded" - else - button_text = t("admin.proposals.index.select") - html_class = "button hollow expanded" - end - - case proposal.class.to_s - when "Proposal" - path = toggle_selection_admin_proposal_path(proposal) - when "Legislation::Proposal" - path = toggle_selection_admin_legislation_process_proposal_path(proposal.process, proposal) - end - - link_to button_text, path, remote: true, method: :patch, class: html_class - end - def css_for_proposal_info_row(proposal) if proposal.image.present? if params[:selected].present? diff --git a/app/views/admin/legislation/proposals/_proposals.html.erb b/app/views/admin/legislation/proposals/_proposals.html.erb index 264f92cda..c63bdf977 100644 --- a/app/views/admin/legislation/proposals/_proposals.html.erb +++ b/app/views/admin/legislation/proposals/_proposals.html.erb @@ -19,7 +19,7 @@ <%= proposal.id %> <%= proposal.title %> <%= proposal.votes_score %> - <%= render "select_proposal", proposal: proposal %> + <%= render Admin::Proposals::ToggleSelectionComponent.new(proposal) %> <% end %> diff --git a/app/views/admin/legislation/proposals/_select_proposal.html.erb b/app/views/admin/legislation/proposals/_select_proposal.html.erb deleted file mode 100644 index d5d2069ab..000000000 --- a/app/views/admin/legislation/proposals/_select_proposal.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= link_to_toggle_proposal_selection(proposal) %> diff --git a/app/views/admin/legislation/proposals/toggle_selection.js.erb b/app/views/admin/legislation/proposals/toggle_selection.js.erb index d38292e9d..8b0507552 100644 --- a/app/views/admin/legislation/proposals/toggle_selection.js.erb +++ b/app/views/admin/legislation/proposals/toggle_selection.js.erb @@ -1 +1,3 @@ -$("#<%= dom_id(@proposal) %> .select").html("<%= j render("select_proposal", proposal: @proposal) %>"); +$("#<%= dom_id(@proposal) %> .select").html( + "<%= j render(Admin::Proposals::ToggleSelectionComponent.new(@proposal)) %>" +); diff --git a/app/views/admin/proposals/_select_proposal.html.erb b/app/views/admin/proposals/_select_proposal.html.erb deleted file mode 100644 index d5d2069ab..000000000 --- a/app/views/admin/proposals/_select_proposal.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= link_to_toggle_proposal_selection(proposal) %> diff --git a/app/views/admin/proposals/index.html.erb b/app/views/admin/proposals/index.html.erb index 5cad75632..23f5388f4 100644 --- a/app/views/admin/proposals/index.html.erb +++ b/app/views/admin/proposals/index.html.erb @@ -27,7 +27,7 @@ <%= link_to proposal.title, admin_proposal_path(proposal) %> <%= proposal.author.username %> <%= proposal.milestones.count %> - <%= render "select_proposal", proposal: proposal %> + <%= render Admin::Proposals::ToggleSelectionComponent.new(proposal) %> <% end %> diff --git a/app/views/admin/proposals/toggle_selection.js.erb b/app/views/admin/proposals/toggle_selection.js.erb index 0f7f171ba..bb832e071 100644 --- a/app/views/admin/proposals/toggle_selection.js.erb +++ b/app/views/admin/proposals/toggle_selection.js.erb @@ -1 +1,3 @@ -$("#<%= dom_id(@proposal) %> .js-select").html("<%= j render("select_proposal", proposal: @proposal) %>"); +$("#<%= dom_id(@proposal) %> .js-select").html( + "<%= j render(Admin::Proposals::ToggleSelectionComponent.new(@proposal)) %>" +);