From 6a2c01b11907028cc07896fec429aed04085b6e2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Javi=20Mart=C3=ADn?= <%= group.headings.count %>
<%= render Admin::TableActionsComponent.new(group) do |actions| %>
- <%= actions.link_to t("admin.budget_groups.headings_manage"),
- headings_path(actions, group),
- class: "headings-link" %>
+ <%= actions.action(:headings,
+ text: t("admin.budget_groups.headings_manage"),
+ path: headings_path(group)) %>
<% end %>
diff --git a/app/components/admin/budget_groups/groups_component.rb b/app/components/admin/budget_groups/groups_component.rb
index 51bf60649..09ba87bbf 100644
--- a/app/components/admin/budget_groups/groups_component.rb
+++ b/app/components/admin/budget_groups/groups_component.rb
@@ -1,4 +1,5 @@
class Admin::BudgetGroups::GroupsComponent < ApplicationComponent
+ include Admin::Namespace
attr_reader :groups
def initialize(groups)
@@ -11,7 +12,7 @@ class Admin::BudgetGroups::GroupsComponent < ApplicationComponent
@budget ||= groups.first.budget
end
- def headings_path(table_actions_component, group)
- send("#{table_actions_component.namespace}_budget_group_headings_path", group.budget, group)
+ def headings_path(group)
+ send("#{namespace}_budget_group_headings_path", group.budget, group)
end
end
diff --git a/app/components/admin/budgets/table_actions_component.html.erb b/app/components/admin/budgets/table_actions_component.html.erb
index 90677909e..7a57c9134 100644
--- a/app/components/admin/budgets/table_actions_component.html.erb
+++ b/app/components/admin/budgets/table_actions_component.html.erb
@@ -1,22 +1,25 @@
<%= render Admin::TableActionsComponent.new(budget,
destroy_confirmation: t("admin.actions.confirm_delete", resource_name: t("admin.budgets.shared.resource_name"),
name: budget.name)
- ) do %>
- <%= link_to t("admin.budgets.index.budget_investments"),
- admin_budget_budget_investments_path(budget_id: budget.id),
- class: "investments-link" %>
- <%= link_to t("admin.budgets.index.edit_groups"),
- admin_budget_groups_path(budget),
- class: "groups-link" %>
+ ) do |actions| %>
+ <%= actions.action(:investments,
+ text: t("admin.budgets.index.budget_investments"),
+ path: admin_budget_budget_investments_path(budget_id: budget.id)) %>
+ <%= actions.action(:groups,
+ text: t("admin.budgets.index.edit_groups"),
+ path: admin_budget_groups_path(budget)) %>
<% if budget.poll.present? %>
- <%= link_to t("admin.budgets.index.admin_ballots"),
- admin_poll_booth_assignments_path(budget.poll),
- class: "ballots-link" %>
+ <%= actions.action(:ballots,
+ text: t("admin.budgets.index.admin_ballots"),
+ path: admin_poll_booth_assignments_path(budget.poll)) %>
<% else %>
- <%= link_to_create_budget_poll %>
+ <%= actions.action(:ballots,
+ text: t("admin.budgets.index.admin_ballots"),
+ path: create_budget_poll_path,
+ method: :post) %>
<% end %>
- <%= link_to t("admin.budgets.actions.preview"),
- budget_path(budget),
- target: "_blank",
- class: "preview-link" %>
+ <%= actions.action(:preview,
+ text: t("admin.budgets.actions.preview"),
+ path: budget_path(budget),
+ target: "_blank") %>
<% end %>
diff --git a/app/components/admin/budgets/table_actions_component.rb b/app/components/admin/budgets/table_actions_component.rb
index 9a90a3799..0e0dfde97 100644
--- a/app/components/admin/budgets/table_actions_component.rb
+++ b/app/components/admin/budgets/table_actions_component.rb
@@ -7,17 +7,14 @@ class Admin::Budgets::TableActionsComponent < ApplicationComponent
private
- def link_to_create_budget_poll
+ def create_budget_poll_path
balloting_phase = budget.phases.find_by(kind: "balloting")
- link_to t("admin.budgets.index.admin_ballots"),
- admin_polls_path(poll: {
- name: budget.name,
- budget_id: budget.id,
- starts_at: balloting_phase.starts_at,
- ends_at: balloting_phase.ends_at
- }),
- class: "ballots-link",
- method: :post
+ admin_polls_path(poll: {
+ name: budget.name,
+ budget_id: budget.id,
+ starts_at: balloting_phase.starts_at,
+ ends_at: balloting_phase.ends_at
+ })
end
end
diff --git a/app/components/admin/hidden_table_actions_component.html.erb b/app/components/admin/hidden_table_actions_component.html.erb
index dad308a78..e8a444900 100644
--- a/app/components/admin/hidden_table_actions_component.html.erb
+++ b/app/components/admin/hidden_table_actions_component.html.erb
@@ -1,12 +1,14 @@
-<%= render Admin::TableActionsComponent.new(actions: []) do %>
- <%= link_to restore_text, restore_path,
- method: :put,
- data: { confirm: t("admin.actions.confirm") },
- class: "restore-link" %>
+<%= render Admin::TableActionsComponent.new(record, actions: []) do |actions| %>
+ <%= actions.action(:restore,
+ text: restore_text,
+ path: restore_path,
+ method: :put,
+ confirm: true) %>
<% unless record.confirmed_hide? %>
- <%= link_to confirm_hide_text, confirm_hide_path,
- method: :put,
- class: "confirm-hide-link" %>
+ <%= actions.action(:confirm_hide,
+ text: confirm_hide_text,
+ path: confirm_hide_path,
+ method: :put) %>
<% end %>
<% end %>
diff --git a/app/components/admin/organizations/table_actions_component.html.erb b/app/components/admin/organizations/table_actions_component.html.erb
index dd9c521a1..ce93ebf14 100644
--- a/app/components/admin/organizations/table_actions_component.html.erb
+++ b/app/components/admin/organizations/table_actions_component.html.erb
@@ -1,13 +1,13 @@
-<%= render Admin::TableActionsComponent.new(actions: []) do %>
+<%= render Admin::TableActionsComponent.new(organization, actions: []) do |actions| %>
<% if can_verify? %>
- <%= link_to t("admin.organizations.index.verify"),
- verify_admin_organization_path(organization, request.query_parameters),
- method: :put, class: "verify-link" %>
+ <%= actions.action(:verify,
+ text: t("admin.organizations.index.verify"),
+ method: :put) %>
<% end %>
<% if can_reject? %>
- <%= link_to t("admin.organizations.index.reject"),
- reject_admin_organization_path(organization, request.query_parameters),
- method: :put, class: "reject-link" %>
+ <%= actions.action(:reject,
+ text: t("admin.organizations.index.reject"),
+ method: :put) %>
<% end %>
<% end %>
diff --git a/app/components/admin/poll/officers/officers_component.html.erb b/app/components/admin/poll/officers/officers_component.html.erb
index 3ef36fd13..f35ae2793 100644
--- a/app/components/admin/poll/officers/officers_component.html.erb
+++ b/app/components/admin/poll/officers/officers_component.html.erb
@@ -23,11 +23,11 @@
destroy_options: { class: "destroy-officer-link" }
) %>
<% else %>
- <%= render Admin::TableActionsComponent.new(actions: []) do |actions| %>
- <%= actions.link_to t("admin.poll_officers.officer.add"),
- add_user_path(officer),
- method: :post,
- class: "create-officer-link" %>
+ <%= render Admin::TableActionsComponent.new(officer, actions: []) do |actions| %>
+ <%= actions.action(:create_officer,
+ text: t("admin.poll_officers.officer.add"),
+ path: add_user_path(officer),
+ method: :post) %>
<% end %>
<% end %>
diff --git a/app/components/admin/roles/table_actions_component.html.erb b/app/components/admin/roles/table_actions_component.html.erb
index 59aed5763..305c18ed4 100644
--- a/app/components/admin/roles/table_actions_component.html.erb
+++ b/app/components/admin/roles/table_actions_component.html.erb
@@ -4,7 +4,7 @@
destroy_options: { class: "destroy-role-link" }
) %>
<% else %>
- <%= render Admin::TableActionsComponent.new(actions: []) do %>
- <%= link_to add_user_text, add_user_path, method: :post, class: "create-role-link" %>
+ <%= render Admin::TableActionsComponent.new(record, actions: []) do |actions| %>
+ <%= actions.action(:create_role, text: add_user_text, path: add_user_path, method: :post) %>
<% end %>
<% end %>
diff --git a/app/components/admin/table_actions_component.html.erb b/app/components/admin/table_actions_component.html.erb
index b5430cf8a..0bc434bac 100644
--- a/app/components/admin/table_actions_component.html.erb
+++ b/app/components/admin/table_actions_component.html.erb
@@ -2,10 +2,10 @@
<%= content %>
<% if actions.include?(:edit) %>
- <%= link_to edit_text, edit_path, edit_options %>
+ <%= action(:edit, edit_options.merge(text: edit_text, path: edit_path)) %>
<% end %>
<% if actions.include?(:destroy) %>
- <%= link_to destroy_text, destroy_path, destroy_options %>
+ <%= action(:destroy, destroy_options.merge(text: destroy_text, path: destroy_path)) %>
<% end %>
diff --git a/app/components/admin/table_actions_component.rb b/app/components/admin/table_actions_component.rb
index f920447bc..9a159e8ab 100644
--- a/app/components/admin/table_actions_component.rb
+++ b/app/components/admin/table_actions_component.rb
@@ -1,12 +1,15 @@
class Admin::TableActionsComponent < ApplicationComponent
- include Admin::Namespace
attr_reader :record, :options
- def initialize(record = nil, **options)
+ def initialize(record, **options)
@record = record
@options = options
end
+ def action(action_name, **args)
+ render Admin::ActionComponent.new(action_name, record, **args)
+ end
+
private
def actions
@@ -14,15 +17,15 @@ class Admin::TableActionsComponent < ApplicationComponent
end
def edit_text
- options[:edit_text] || t("admin.actions.edit")
+ options[:edit_text]
end
def edit_path
- options[:edit_path] || namespaced_polymorphic_path(namespace, record, action: :edit)
+ options[:edit_path]
end
def edit_options
- { class: "edit-link" }.merge(options[:edit_options] || {})
+ options[:edit_options] || {}
end
def destroy_text
@@ -30,18 +33,13 @@ class Admin::TableActionsComponent < ApplicationComponent
end
def destroy_path
- options[:destroy_path] || namespaced_polymorphic_path(namespace, record)
+ options[:destroy_path]
end
def destroy_options
{
method: :delete,
- class: "destroy-link",
- data: { confirm: destroy_confirmation }
+ confirm: options[:destroy_confirmation] || true
}.merge(options[:destroy_options] || {})
end
-
- def destroy_confirmation
- options[:destroy_confirmation] || t("admin.actions.confirm")
- end
end
diff --git a/app/views/admin/admin_notifications/index.html.erb b/app/views/admin/admin_notifications/index.html.erb
index d51ac2c8b..c8fbe4900 100644
--- a/app/views/admin/admin_notifications/index.html.erb
+++ b/app/views/admin/admin_notifications/index.html.erb
@@ -31,15 +31,11 @@
<% if admin_notification.draft? %>
<%= render Admin::TableActionsComponent.new(admin_notification) do |actions| %>
- <%= actions.link_to t("admin.admin_notifications.index.preview"),
- admin_admin_notification_path(admin_notification),
- class: "preview-link" %>
+ <%= actions.action(:preview, text: t("admin.admin_notifications.index.preview")) %>
<% end %>
<% else %>
- <%= render Admin::TableActionsComponent.new(actions: []) do |actions| %>
- <%= actions.link_to t("admin.admin_notifications.index.view"),
- admin_admin_notification_path(admin_notification),
- class: "show-link" %>
+ <%= render Admin::TableActionsComponent.new(admin_notification, actions: []) do |actions| %>
+ <%= actions.action(:show, text: t("admin.admin_notifications.index.view")) %>
<% end %>
<% end %>
diff --git a/app/views/admin/audits/_audits.html.erb b/app/views/admin/audits/_audits.html.erb
index aa72d36b8..ff84c3c11 100644
--- a/app/views/admin/audits/_audits.html.erb
+++ b/app/views/admin/audits/_audits.html.erb
@@ -34,10 +34,8 @@
<%= audit.user&.name %>
- <%= render Admin::TableActionsComponent.new(actions: []) do |actions| %>
- <%= actions.link_to t("shared.show"),
- admin_polymorphic_path(audit),
- class: "show-link" %>
+ <%= render Admin::TableActionsComponent.new(audit, actions: []) do |actions| %>
+ <%= actions.action(:show, text: t("shared.show")) %>
<% end %>
diff --git a/app/views/admin/dashboard/actions/_default_actions.html.erb b/app/views/admin/dashboard/actions/_default_actions.html.erb
index 896c02a7e..94ec8b79f 100644
--- a/app/views/admin/dashboard/actions/_default_actions.html.erb
+++ b/app/views/admin/dashboard/actions/_default_actions.html.erb
@@ -6,6 +6,7 @@
<%= render Admin::TableActionsComponent.new(
+ action,
actions: [:edit],
edit_path: admin_settings_path(anchor: "tab-proposals"),
) %>
diff --git a/app/views/admin/newsletters/index.html.erb b/app/views/admin/newsletters/index.html.erb
index e5c0e2427..46270436b 100644
--- a/app/views/admin/newsletters/index.html.erb
+++ b/app/views/admin/newsletters/index.html.erb
@@ -30,9 +30,7 @@
<%= render Admin::TableActionsComponent.new(newsletter) do |actions| %>
- <%= actions.link_to t("admin.newsletters.index.preview"),
- admin_newsletter_path(newsletter),
- class: "preview-link" %>
+ <%= actions.action :preview, text: t("admin.newsletters.index.preview") %>
<% end %>
diff --git a/app/views/admin/officials/index.html.erb b/app/views/admin/officials/index.html.erb
index 6212778cc..7517b6e3d 100644
--- a/app/views/admin/officials/index.html.erb
+++ b/app/views/admin/officials/index.html.erb
@@ -27,6 +27,7 @@
<%= render Admin::TableActionsComponent.new(
+ official,
actions: [:edit],
edit_path: edit_admin_official_path(official)
) %>
diff --git a/app/views/admin/officials/search.html.erb b/app/views/admin/officials/search.html.erb
index bf9706207..5e361d9e7 100644
--- a/app/views/admin/officials/search.html.erb
+++ b/app/views/admin/officials/search.html.erb
@@ -33,6 +33,7 @@
<%= render Admin::TableActionsComponent.new(
+ user,
actions: [:edit],
edit_path: edit_admin_official_path(user),
edit_text: (t("admin.officials.search.make_official") unless user.official?)
diff --git a/app/views/admin/poll/booth_assignments/_booth_assignment.html.erb b/app/views/admin/poll/booth_assignments/_booth_assignment.html.erb
index a4060f8aa..3da870b1f 100644
--- a/app/views/admin/poll/booth_assignments/_booth_assignment.html.erb
+++ b/app/views/admin/poll/booth_assignments/_booth_assignment.html.erb
@@ -26,12 +26,12 @@
<% unless @poll.expired? %>
- <%= render Admin::TableActionsComponent.new(actions: []) do |actions| %>
- <%= actions.link_to t("admin.booth_assignments.manage.actions.assign"),
- admin_poll_booth_assignments_path(@poll, booth_id: booth.id),
- method: :post,
- remote: true,
- class: "assign-booth-link" %>
+ <%= render Admin::TableActionsComponent.new(booth, actions: []) do |actions| %>
+ <%= actions.action(:assign_booth,
+ text: t("admin.booth_assignments.manage.actions.assign"),
+ path: admin_poll_booth_assignments_path(@poll, booth_id: booth.id),
+ method: :post,
+ remote: true) %>
<% end %>
<% end %>
diff --git a/app/views/admin/poll/booths/_booth.html.erb b/app/views/admin/poll/booths/_booth.html.erb
index efa5a172c..7dfda2ae8 100644
--- a/app/views/admin/poll/booths/_booth.html.erb
+++ b/app/views/admin/poll/booths/_booth.html.erb
@@ -7,10 +7,10 @@
<% if controller_name == "shifts" || controller_name == "booths" && action_name == "available" %>
- <%= render Admin::TableActionsComponent.new(actions: []) do |actions| %>
- <%= actions.link_to t("admin.booths.booth.shifts"),
- new_admin_booth_shift_path(booth),
- class: "shifts-link" %>
+ <%= render Admin::TableActionsComponent.new(booth, actions: []) do |actions| %>
+ <%= actions.action(:shifts,
+ text: t("admin.booths.booth.shifts"),
+ path: new_admin_booth_shift_path(booth)) %>
<% end %>
<% else %>
<%= render Admin::TableActionsComponent.new(booth, actions: [:edit]) %>
diff --git a/app/views/admin/poll/polls/_poll.html.erb b/app/views/admin/poll/polls/_poll.html.erb
index 364cc24db..a578bfe60 100644
--- a/app/views/admin/poll/polls/_poll.html.erb
+++ b/app/views/admin/poll/polls/_poll.html.erb
@@ -10,9 +10,7 @@
<%= render Admin::TableActionsComponent.new(poll,
destroy_confirmation: t("admin.polls.destroy.alert")
) do |actions| %>
- <%= actions.link_to t("admin.actions.configure"),
- admin_poll_path(poll),
- class: "configure-link" %>
+ <%= actions.action(:configure) %>
<% end %>
diff --git a/app/views/admin/poll/polls/_questions.html.erb b/app/views/admin/poll/polls/_questions.html.erb
index 2cde94099..b13a86be2 100644
--- a/app/views/admin/poll/polls/_questions.html.erb
+++ b/app/views/admin/poll/polls/_questions.html.erb
@@ -29,8 +29,7 @@
<%= render Admin::TableActionsComponent.new(question) do |actions| %>
- <%= actions.link_to t("admin.polls.show.edit_answers"), admin_question_path(question),
- class: "answers-link" %>
+ <%= actions.action(:answers, text: t("admin.polls.show.edit_answers")) %>
<% end %>
diff --git a/app/views/admin/poll/polls/booth_assignments.html.erb b/app/views/admin/poll/polls/booth_assignments.html.erb
index ece854d29..401ef0011 100644
--- a/app/views/admin/poll/polls/booth_assignments.html.erb
+++ b/app/views/admin/poll/polls/booth_assignments.html.erb
@@ -15,10 +15,10 @@
<%= l poll.starts_at.to_date %> - <%= l poll.ends_at.to_date %>
- <%= render Admin::TableActionsComponent.new(actions: []) do |actions| %>
- <%= actions.link_to t("admin.booth_assignments.manage_assignments"),
- manage_admin_poll_booth_assignments_path(poll),
- class: "manage-link" %>
+ <%= render Admin::TableActionsComponent.new(poll, actions: []) do |actions| %>
+ <%= actions.action(:manage,
+ text: t("admin.booth_assignments.manage_assignments"),
+ path: manage_admin_poll_booth_assignments_path(poll)) %>
<% end %>
diff --git a/app/views/admin/poll/questions/_questions.html.erb b/app/views/admin/poll/questions/_questions.html.erb
index e8ce0402e..100425478 100644
--- a/app/views/admin/poll/questions/_questions.html.erb
+++ b/app/views/admin/poll/questions/_questions.html.erb
@@ -26,8 +26,7 @@
<%= render Admin::TableActionsComponent.new(question) do |actions| %>
- <%= actions.link_to t("admin.polls.show.edit_answers"), admin_question_path(question),
- class: "answers-link" %>
+ <%= actions.action(:answers, text: t("admin.polls.show.edit_answers")) %>
<% end %>
diff --git a/app/views/admin/poll/questions/_successful_proposals.html.erb b/app/views/admin/poll/questions/_successful_proposals.html.erb
index 1a4b06aad..669d76c94 100644
--- a/app/views/admin/poll/questions/_successful_proposals.html.erb
+++ b/app/views/admin/poll/questions/_successful_proposals.html.erb
@@ -15,11 +15,11 @@