Allow custom URLs in links to actions
There were a couple of cases where these links didn't point to the default actions.
This commit is contained in:
@@ -1,12 +1,10 @@
|
|||||||
<% if actions.include?(:edit) %>
|
<% if actions.include?(:edit) %>
|
||||||
<%= link_to edit_text,
|
<%= link_to edit_text, edit_path, class: "button hollow" %>
|
||||||
admin_polymorphic_path(record, action: :edit),
|
|
||||||
class: "button hollow" %>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% if actions.include?(:destroy) %>
|
<% if actions.include?(:destroy) %>
|
||||||
<%= link_to destroy_text,
|
<%= link_to destroy_text,
|
||||||
admin_polymorphic_path(record),
|
destroy_path,
|
||||||
method: :delete,
|
method: :delete,
|
||||||
class: "button hollow alert",
|
class: "button hollow alert",
|
||||||
data: { confirm: t("admin.actions.confirm") } %>
|
data: { confirm: t("admin.actions.confirm") } %>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
class Admin::TableActionsComponent < ApplicationComponent
|
class Admin::TableActionsComponent < ApplicationComponent
|
||||||
attr_reader :record, :options
|
attr_reader :record, :options
|
||||||
|
|
||||||
def initialize(record, **options)
|
def initialize(record = nil, **options)
|
||||||
@record = record
|
@record = record
|
||||||
@options = options
|
@options = options
|
||||||
end
|
end
|
||||||
@@ -16,7 +16,15 @@ class Admin::TableActionsComponent < ApplicationComponent
|
|||||||
options[:edit_text] || t("admin.actions.edit")
|
options[:edit_text] || t("admin.actions.edit")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def edit_path
|
||||||
|
options[:edit_path] || admin_polymorphic_path(record, action: :edit)
|
||||||
|
end
|
||||||
|
|
||||||
def destroy_text
|
def destroy_text
|
||||||
options[:destroy_text] || t("admin.actions.delete")
|
options[:destroy_text] || t("admin.actions.delete")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def destroy_path
|
||||||
|
options[:destroy_path] || admin_polymorphic_path(record)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -5,9 +5,10 @@
|
|||||||
<td class="text-center"><%= t("admin.dashboard.actions.index.active") %></td>
|
<td class="text-center"><%= t("admin.dashboard.actions.index.active") %></td>
|
||||||
<td colspan="4"> </td>
|
<td colspan="4"> </td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
<%= link_to t("admin.dashboard.actions.index.edit"),
|
<%= render Admin::TableActionsComponent.new(
|
||||||
admin_settings_path(anchor: "tab-proposals"),
|
actions: [:edit],
|
||||||
class: "button hollow" %>
|
edit_path: admin_settings_path(anchor: "tab-proposals"),
|
||||||
|
) %>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -28,8 +28,11 @@
|
|||||||
<%= t("admin.officials.level_#{official.official_level}") %>
|
<%= t("admin.officials.level_#{official.official_level}") %>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<%= link_to t("admin.officials.search.edit_official"),
|
<%= render Admin::TableActionsComponent.new(
|
||||||
edit_admin_official_path(official), class: "button hollow expanded" %>
|
actions: [:edit],
|
||||||
|
edit_path: edit_admin_official_path(official),
|
||||||
|
edit_text: t("admin.officials.search.edit_official")
|
||||||
|
) %>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -32,15 +32,11 @@
|
|||||||
<%= t("admin.officials.level_#{user.official_level}") %>
|
<%= t("admin.officials.level_#{user.official_level}") %>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<% if user.official? %>
|
<%= render Admin::TableActionsComponent.new(
|
||||||
<%= link_to t("admin.officials.search.edit_official"),
|
actions: [:edit],
|
||||||
edit_admin_official_path(user),
|
edit_path: edit_admin_official_path(user),
|
||||||
class: "button hollow expanded" %>
|
edit_text: user.official? ? t("admin.officials.search.edit_official") : t("admin.officials.search.make_official")
|
||||||
<% else %>
|
) %>
|
||||||
<%= link_to t("admin.officials.search.make_official"),
|
|
||||||
edit_admin_official_path(user),
|
|
||||||
class: "button expanded" %>
|
|
||||||
<% end %>
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -42,11 +42,10 @@
|
|||||||
rel: "nofollow",
|
rel: "nofollow",
|
||||||
class: "button hollow" %>
|
class: "button hollow" %>
|
||||||
|
|
||||||
<%= link_to t("admin.shared.delete"),
|
<%= render Admin::TableActionsComponent.new(document,
|
||||||
document_path(document),
|
actions: [:destroy],
|
||||||
method: :delete,
|
destroy_path: document_path(document)
|
||||||
class: "button hollow alert",
|
) %>
|
||||||
data: { confirm: t("admin.actions.confirm") } %>
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -25,9 +25,11 @@
|
|||||||
<%= user.email %>
|
<%= user.email %>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
<%= link_to t("admin.poll_shifts.new.edit_shifts"),
|
<%= render Admin::TableActionsComponent.new(
|
||||||
new_admin_booth_shift_path(officer_id: user.poll_officer.id),
|
actions: [:edit],
|
||||||
class: "button hollow" %>
|
edit_text: t("admin.poll_shifts.new.edit_shifts"),
|
||||||
|
edit_path: new_admin_booth_shift_path(officer_id: user.poll_officer.id)
|
||||||
|
) %>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -17,14 +17,8 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<%= link_to t("admin.actions.edit"),
|
<%= render Admin::TableActionsComponent.new(card,
|
||||||
edit_admin_widget_card_path(card, page_id: params[:page_id]),
|
edit_path: edit_admin_widget_card_path(card, page_id: params[:page_id])
|
||||||
class: "button hollow" %>
|
) %>
|
||||||
|
|
||||||
<%= link_to t("admin.actions.delete"),
|
|
||||||
admin_widget_card_path(card, page_id: params[:page_id]),
|
|
||||||
method: :delete,
|
|
||||||
data: { confirm: t("admin.actions.confirm") },
|
|
||||||
class: "button hollow alert" %>
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -46,9 +46,11 @@
|
|||||||
<td><%= link_to "#{content_block.heading.name} (#{content_block.locale})", admin_site_customization_edit_heading_content_block_path(content_block) %></td>
|
<td><%= link_to "#{content_block.heading.name} (#{content_block.locale})", admin_site_customization_edit_heading_content_block_path(content_block) %></td>
|
||||||
<td><%= raw content_block.body %></td>
|
<td><%= raw content_block.body %></td>
|
||||||
<td>
|
<td>
|
||||||
<%= link_to t("admin.site_customization.content_blocks.index.delete"),
|
<%= render Admin::TableActionsComponent.new(
|
||||||
admin_site_customization_delete_heading_content_block_path(content_block.id),
|
actions: [:destroy],
|
||||||
method: :delete, class: "button hollow alert" %>
|
destroy_text: t("admin.site_customization.content_blocks.index.delete"),
|
||||||
|
destroy_path: admin_site_customization_delete_heading_content_block_path(content_block)
|
||||||
|
) %>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -26,11 +26,10 @@
|
|||||||
<td><%= link_to document.title, document.attachment.url, target: :blank %></td>
|
<td><%= link_to document.title, document.attachment.url, target: :blank %></td>
|
||||||
<td>
|
<td>
|
||||||
<div class="small-12 medium-6 column">
|
<div class="small-12 medium-6 column">
|
||||||
<%= link_to t("admin.shared.delete"),
|
<%= render Admin::TableActionsComponent.new(
|
||||||
admin_site_customization_document_path(document),
|
actions: [:destroy],
|
||||||
method: :delete,
|
destroy_path: admin_site_customization_document_path(document)
|
||||||
class: "button hollow alert",
|
) %>
|
||||||
data: { confirm: t("admin.actions.confirm") } %>
|
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -359,7 +359,6 @@ en:
|
|||||||
index:
|
index:
|
||||||
description: "When users create proposals they can access a dashboard of their proposal, where you can propose resources and recommendations to get support for their idea."
|
description: "When users create proposals they can access a dashboard of their proposal, where you can propose resources and recommendations to get support for their idea."
|
||||||
create: Create resource or action
|
create: Create resource or action
|
||||||
edit: Edit
|
|
||||||
active: 'Yes'
|
active: 'Yes'
|
||||||
inactive: 'No'
|
inactive: 'No'
|
||||||
title: Resources and actions
|
title: Resources and actions
|
||||||
@@ -1289,7 +1288,6 @@ en:
|
|||||||
author: Author
|
author: Author
|
||||||
content: Content
|
content: Content
|
||||||
created_at: Created at
|
created_at: Created at
|
||||||
delete: Delete
|
|
||||||
color_help: Hexadecimal format
|
color_help: Hexadecimal format
|
||||||
show_results_and_stats: "Show results and stats"
|
show_results_and_stats: "Show results and stats"
|
||||||
results_and_stats_reminder: "Marking these checkboxes the results and/or stats will be publicly available and every user will see them."
|
results_and_stats_reminder: "Marking these checkboxes the results and/or stats will be publicly available and every user will see them."
|
||||||
|
|||||||
@@ -359,7 +359,6 @@ es:
|
|||||||
index:
|
index:
|
||||||
description: "Cuando los usuarios crean propuestas pueden acceder a un panel de progreso de su propuesta, donde se le puede proponer recursos y recomendaciones para conseguir apoyos a su idea."
|
description: "Cuando los usuarios crean propuestas pueden acceder a un panel de progreso de su propuesta, donde se le puede proponer recursos y recomendaciones para conseguir apoyos a su idea."
|
||||||
create: Crear recurso o acción
|
create: Crear recurso o acción
|
||||||
edit: Editar
|
|
||||||
active: 'Si'
|
active: 'Si'
|
||||||
inactive: 'No'
|
inactive: 'No'
|
||||||
title: Recursos y acciones
|
title: Recursos y acciones
|
||||||
@@ -1288,7 +1287,6 @@ es:
|
|||||||
author: Autor
|
author: Autor
|
||||||
content: Contenido
|
content: Contenido
|
||||||
created_at: Fecha de creación
|
created_at: Fecha de creación
|
||||||
delete: Eliminar
|
|
||||||
color_help: Formato hexadecimal
|
color_help: Formato hexadecimal
|
||||||
show_results_and_stats: "Mostrar resultados y estadísticas"
|
show_results_and_stats: "Mostrar resultados y estadísticas"
|
||||||
results_and_stats_reminder: "Si marcas estas casillas los resultados y/o estadísticas serán públicos y podrán verlos todos los usuarios."
|
results_and_stats_reminder: "Si marcas estas casillas los resultados y/o estadísticas serán públicos y podrán verlos todos los usuarios."
|
||||||
|
|||||||
@@ -35,4 +35,11 @@ describe Admin::TableActionsComponent, type: :component do
|
|||||||
expect(page).not_to have_link "Delete"
|
expect(page).not_to have_link "Delete"
|
||||||
expect(page).not_to have_link "Edit"
|
expect(page).not_to have_link "Edit"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "allows custom URLs" do
|
||||||
|
render_inline Admin::TableActionsComponent.new(edit_path: "/myedit", destroy_path: "/mydestroy")
|
||||||
|
|
||||||
|
expect(page).to have_link "Edit", href: "/myedit"
|
||||||
|
expect(page).to have_link "Delete", href: "/mydestroy"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user