Reduce duplication in moderation sections

We had five almost-identical views. Now we've removed most of the
duplication, although the tables are still similar. We might refactor
them in the future.
This commit is contained in:
Javi Martín
2021-06-27 18:10:23 +02:00
parent 5db6edfbd2
commit d2f38fd276
7 changed files with 83 additions and 190 deletions

View File

@@ -0,0 +1,39 @@
<h2><%= t("moderation.#{i18n_namespace}.index.title") %></h2>
<%= render "shared/filter_subnav", i18n_namespace: "moderation.#{i18n_namespace}.index" %>
<h3 class="inline-block"><%= page_entries_info records %></h3>
<div class="float-right">
<%= t("moderation.#{i18n_namespace}.index.order") %>
<%= render "shared/order_selector", i18n_namespace: "moderation.#{i18n_namespace}.index" %>
</div>
<%= form_tag form_path, method: :put do %>
<p class="float-left js-check">
<%= t("shared.check") %>:
<%= link_to t("shared.check_all"), "#", data: { check_all: field_name } %>
|
<%= link_to t("shared.check_none"), "#", data: { check_none: field_name } %>
</p>
<%= content %>
<%= submit_tag t("moderation.#{i18n_namespace}.index.block_authors"),
name: "block_authors",
class: "button hollow alert",
data: { confirm: t("moderation.#{i18n_namespace}.index.confirm") } %>
<div class="float-right">
<%= submit_tag t("moderation.#{i18n_namespace}.index.hide"),
name: "hide_#{table_name}",
class: "button hollow alert",
data: { confirm: t("moderation.#{i18n_namespace}.index.confirm") } %>
<%= submit_tag t("moderation.#{i18n_namespace}.index.ignore_flags"),
name: "ignore_flags",
class: "button hollow",
data: { confirm: t("moderation.#{i18n_namespace}.index.confirm") } %>
</div>
<%= paginate records %>
<% end %>

View File

@@ -0,0 +1,39 @@
class Moderation::Shared::IndexComponent < ApplicationComponent
attr_reader :records
def initialize(records)
@records = records
end
private
def i18n_namespace
table_name
end
def field_name
"#{records.model.model_name.singular}_ids[]"
end
def form_path
url_for(
request.query_parameters.merge(
controller: "moderation/#{section_name}",
action: "moderate",
only_path: true
)
)
end
def table_name
records.model.table_name
end
def section_name
if table_name == "budget_investments"
"budgets/investments"
else
table_name
end
end
end

View File

@@ -1,21 +1,4 @@
<h2><%= t("moderation.budget_investments.index.title") %></h2> <%= render Moderation::Shared::IndexComponent.new(@budget_investments) do %>
<%= render "shared/filter_subnav", i18n_namespace: "moderation.budget_investments.index" %>
<h3 class="inline-block"><%= page_entries_info @budget_investments %></h3>
<div class="float-right">
<%= t("moderation.budget_investments.index.order") %>
<%= render "shared/order_selector", i18n_namespace: "moderation.budget_investments.index" %>
</div>
<%= form_tag moderate_moderation_budget_investments_path(request.query_parameters), method: :put do %>
<p class="float-left js-check">
<%= t("shared.check") %>:
<%= link_to t("shared.check_all"), "#", data: { check_all: "budget_investment_ids[]" } %>
|
<%= link_to t("shared.check_none"), "#", data: { check_none: "budget_investment_ids[]" } %>
</p>
<table class="clear"> <table class="clear">
<thead> <thead>
<tr> <tr>
@@ -50,24 +33,4 @@
<% end %> <% end %>
</tbody> </tbody>
</table> </table>
<%= submit_tag t("moderation.budget_investments.index.block_authors"),
name: "block_authors",
class: "button hollow alert",
data: { confirm: t("moderation.budget_investments.index.confirm") } %>
<div class="float-right">
<%= submit_tag t("moderation.budget_investments.index.hide"),
name: "hide_budget_investments",
class: "button hollow alert",
data: { confirm: t("moderation.budget_investments.index.confirm") } %>
<%= submit_tag t("moderation.budget_investments.index.ignore_flags"),
name: "ignore_flags",
class: "button hollow",
data: { confirm: t("moderation.budget_investments.index.confirm") } %>
</div>
<%= paginate @budget_investments %>
<% end %> <% end %>

View File

@@ -1,21 +1,4 @@
<h2><%= t("moderation.comments.index.title") %></h2> <%= render Moderation::Shared::IndexComponent.new(@comments) do %>
<%= render "shared/filter_subnav", i18n_namespace: "moderation.comments.index" %>
<h3 class="inline-block"><%= page_entries_info @comments %></h3>
<div class="float-right">
<%= t("moderation.comments.index.order") %>
<%= render "shared/order_selector", i18n_namespace: "moderation.comments.index" %>
</div>
<%= form_tag moderate_moderation_comments_path(request.query_parameters), method: :put do %>
<p class="float-left js-check">
<%= t("shared.check") %>:
<%= link_to t("shared.check_all"), "#", data: { check_all: "comment_ids[]" } %>
|
<%= link_to t("shared.check_none"), "#", data: { check_none: "comment_ids[]" } %>
</p>
<table class="clear"> <table class="clear">
<thead> <thead>
<tr> <tr>
@@ -48,24 +31,4 @@
<% end %> <% end %>
</tbody> </tbody>
</table> </table>
<%= submit_tag t("moderation.comments.index.block_authors"),
name: "block_authors",
class: "button hollow alert",
data: { confirm: t("moderation.comments.index.confirm") } %>
<div class="float-right">
<%= submit_tag t("moderation.comments.index.hide"),
name: "hide_comments",
class: "button hollow alert",
data: { confirm: t("moderation.comments.index.confirm") } %>
<%= submit_tag t("moderation.comments.index.ignore_flags"),
name: "ignore_flags",
class: "button hollow",
data: { confirm: t("moderation.comments.index.confirm") } %>
</div>
<%= paginate @comments %>
<% end %> <% end %>

View File

@@ -1,21 +1,4 @@
<h2><%= t("moderation.debates.index.title") %></h2> <%= render Moderation::Shared::IndexComponent.new(@debates) do %>
<%= render "shared/filter_subnav", i18n_namespace: "moderation.debates.index" %>
<h3 class="inline-block"><%= page_entries_info @debates %></h3>
<div class="float-right">
<%= t("moderation.debates.index.order") %>
<%= render "shared/order_selector", i18n_namespace: "moderation.debates.index" %>
</div>
<%= form_tag moderate_moderation_debates_path(request.query_parameters), method: :put do %>
<p class="float-left js-check">
<%= t("shared.check") %>:
<%= link_to t("shared.check_all"), "#", data: { check_all: "debate_ids[]" } %>
|
<%= link_to t("shared.check_none"), "#", data: { check_none: "debate_ids[]" } %>
</p>
<table class="clear"> <table class="clear">
<thead> <thead>
<tr> <tr>
@@ -47,24 +30,4 @@
<% end %> <% end %>
</tbody> </tbody>
</table> </table>
<%= submit_tag t("moderation.debates.index.block_authors"),
name: "block_authors",
class: "button hollow alert",
data: { confirm: t("moderation.debates.index.confirm") } %>
<div class="float-right">
<%= submit_tag t("moderation.debates.index.hide"),
name: "hide_debates",
class: "button hollow alert",
data: { confirm: t("moderation.debates.index.confirm") } %>
<%= submit_tag t("moderation.debates.index.ignore_flags"),
name: "ignore_flags",
class: "button hollow",
data: { confirm: t("moderation.debates.index.confirm") } %>
</div>
<%= paginate @debates %>
<% end %> <% end %>

View File

@@ -1,21 +1,4 @@
<h2><%= t("moderation.proposal_notifications.index.title") %></h2> <%= render Moderation::Shared::IndexComponent.new(@proposal_notifications) do %>
<%= render "shared/filter_subnav", i18n_namespace: "moderation.proposal_notifications.index" %>
<h3 class="inline-block"><%= page_entries_info @proposal_notifications %></h3>
<div class="float-right">
<%= t("moderation.proposal_notifications.index.order") %>
<%= render "shared/order_selector", i18n_namespace: "moderation.proposal_notifications.index" %>
</div>
<%= form_tag moderate_moderation_proposal_notifications_path(request.query_parameters), method: :put do %>
<p class="float-left js-check">
<%= t("shared.check") %>:
<%= link_to t("shared.check_all"), "#", data: { check_all: "proposal_notification_ids[]" } %>
|
<%= link_to t("shared.check_none"), "#", data: { check_none: "proposal_notification_ids[]" } %>
</p>
<table class="clear"> <table class="clear">
<thead> <thead>
<tr> <tr>
@@ -46,24 +29,4 @@
<% end %> <% end %>
</tbody> </tbody>
</table> </table>
<%= submit_tag t("moderation.proposal_notifications.index.block_authors"),
name: "block_authors",
class: "button hollow alert",
data: { confirm: t("moderation.proposal_notifications.index.confirm") } %>
<div class="float-right">
<%= submit_tag t("moderation.proposal_notifications.index.hide"),
name: "hide_proposal_notifications",
class: "button hollow alert",
data: { confirm: t("moderation.proposal_notifications.index.confirm") } %>
<%= submit_tag t("moderation.proposal_notifications.index.ignore_flags"),
name: "ignore_flags",
class: "button hollow",
data: { confirm: t("moderation.proposal_notifications.index.confirm") } %>
</div>
<%= paginate @proposal_notifications %>
<% end %> <% end %>

View File

@@ -1,21 +1,4 @@
<h2><%= t("moderation.proposals.index.title") %></h2> <%= render Moderation::Shared::IndexComponent.new(@proposals) do %>
<%= render "shared/filter_subnav", i18n_namespace: "moderation.proposals.index" %>
<h3 class="inline-block"><%= page_entries_info @proposals %></h3>
<div class="float-right">
<%= t("moderation.proposals.index.order") %>
<%= render "shared/order_selector", i18n_namespace: "moderation.proposals.index" %>
</div>
<%= form_tag moderate_moderation_proposals_path(request.query_parameters), method: :put do %>
<p class="float-left js-check">
<%= t("shared.check") %>:
<%= link_to t("shared.check_all"), "#", data: { check_all: "proposal_ids[]" } %>
|
<%= link_to t("shared.check_none"), "#", data: { check_none: "proposal_ids[]" } %>
</p>
<table class="clear"> <table class="clear">
<thead> <thead>
<tr> <tr>
@@ -47,24 +30,4 @@
<% end %> <% end %>
</tbody> </tbody>
</table> </table>
<%= submit_tag t("moderation.proposals.index.block_authors"),
name: "block_authors",
class: "button hollow alert",
data: { confirm: t("moderation.proposals.index.confirm") } %>
<div class="float-right">
<%= submit_tag t("moderation.proposals.index.hide"),
name: "hide_proposals",
class: "button hollow alert",
data: { confirm: t("moderation.proposals.index.confirm") } %>
<%= submit_tag t("moderation.proposals.index.ignore_flags"),
name: "ignore_flags",
class: "button hollow",
data: { confirm: t("moderation.proposals.index.confirm") } %>
</div>
<%= paginate @proposals %>
<% end %> <% end %>