From f76930aab647135290ea570b6458eeecd8db0efb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Mon, 8 Jun 2020 22:56:23 +0200 Subject: [PATCH 01/18] Simplify URL to destroy a booth assignment We can find the booth through the booth assignment, so we don't need to pass it in the URL. Since the parameter is in the URL and not sent through a form, we can also use `params[:poll_id]` directly, and so we can reuse the `load_poll` method. --- app/controllers/admin/poll/booth_assignments_controller.rb | 7 +++---- .../poll/booth_assignments/_booth_assignment.html.erb | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/controllers/admin/poll/booth_assignments_controller.rb b/app/controllers/admin/poll/booth_assignments_controller.rb index a784c5bd9..5ad38435d 100644 --- a/app/controllers/admin/poll/booth_assignments_controller.rb +++ b/app/controllers/admin/poll/booth_assignments_controller.rb @@ -1,5 +1,5 @@ class Admin::Poll::BoothAssignmentsController < Admin::Poll::BaseController - before_action :load_poll, except: [:create, :destroy] + before_action :load_poll, except: [:create] def index @booth_assignments = @poll.booth_assignments.includes(:booth).order("poll_booths.name") @@ -36,9 +36,8 @@ class Admin::Poll::BoothAssignmentsController < Admin::Poll::BaseController end def destroy - @poll = Poll.find(booth_assignment_params[:poll_id]) - @booth = Poll::Booth.find(booth_assignment_params[:booth_id]) - @booth_assignment = ::Poll::BoothAssignment.find(params[:id]) + @booth_assignment = @poll.booth_assignments.find(params[:id]) + @booth = @booth_assignment.booth @booth_assignment.destroy! 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 13857144a..8f159a264 100644 --- a/app/views/admin/poll/booth_assignments/_booth_assignment.html.erb +++ b/app/views/admin/poll/booth_assignments/_booth_assignment.html.erb @@ -12,7 +12,7 @@ <%= link_to t("admin.booth_assignments.manage.actions.unassign"), - admin_poll_booth_assignment_path(@poll, booth_assignment, booth_id: booth.id), + admin_poll_booth_assignment_path(@poll, booth_assignment), method: :delete, remote: true, title: t("admin.booth_assignments.manage.actions.unassign"), From 94a1865217c35c610fc56207530e405c1dd60257 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Mon, 8 Jun 2020 22:57:40 +0200 Subject: [PATCH 02/18] Make polymorphic_path work with booth assignments --- config/initializers/routes_hierarchy.rb | 2 +- config/routes/admin.rb | 4 ++++ spec/routing/polymorphic_routes_spec.rb | 9 +++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/config/initializers/routes_hierarchy.rb b/config/initializers/routes_hierarchy.rb index 54addcc95..1f5084041 100644 --- a/config/initializers/routes_hierarchy.rb +++ b/config/initializers/routes_hierarchy.rb @@ -16,7 +16,7 @@ module ActionDispatch::Routing::UrlFor end def admin_polymorphic_path(resource, options = {}) - if %w[Budget::Group Budget::Heading Poll::Booth Poll::Officer + if %w[Budget::Group Budget::Heading Poll::Booth Poll::BoothAssignment Poll::Officer Poll::Question Poll::Question::Answer::Video].include?(resource.class.name) resolve = resolve_for(resource) resolve_options = resolve.pop diff --git a/config/routes/admin.rb b/config/routes/admin.rb index a71c32ba2..54af7ace3 100644 --- a/config/routes/admin.rb +++ b/config/routes/admin.rb @@ -278,6 +278,10 @@ resolve "Poll::Booth" do |booth, options| [:booth, options.merge(id: booth)] end +resolve "Poll::BoothAssignment" do |assignment, options| + [assignment.poll, :booth_assignment, options.merge(id: assignment)] +end + resolve "Poll::Officer" do |officer, options| [:officer, options.merge(id: officer)] end diff --git a/spec/routing/polymorphic_routes_spec.rb b/spec/routing/polymorphic_routes_spec.rb index 778f089c6..c6e14d26c 100644 --- a/spec/routing/polymorphic_routes_spec.rb +++ b/spec/routing/polymorphic_routes_spec.rb @@ -148,6 +148,15 @@ describe "Polymorphic routes" do ) end + it "routes booth assignments" do + poll = create(:poll) + assignment = create(:poll_booth_assignment, poll: poll) + + expect(admin_polymorphic_path(assignment)).to eq( + admin_poll_booth_assignment_path(poll, assignment) + ) + end + it "supports routes for actions like edit" do proposal = create(:proposal) milestone = create(:milestone, milestoneable: proposal) From 289eb96561201e247e9b8be28836cfc7a4012184 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 9 Jun 2020 00:14:27 +0200 Subject: [PATCH 03/18] Make polymorphic_path work with poll shifts --- config/initializers/routes_hierarchy.rb | 2 +- config/routes/admin.rb | 4 ++++ spec/routing/polymorphic_routes_spec.rb | 7 +++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/config/initializers/routes_hierarchy.rb b/config/initializers/routes_hierarchy.rb index 1f5084041..fd096a64a 100644 --- a/config/initializers/routes_hierarchy.rb +++ b/config/initializers/routes_hierarchy.rb @@ -17,7 +17,7 @@ module ActionDispatch::Routing::UrlFor def admin_polymorphic_path(resource, options = {}) if %w[Budget::Group Budget::Heading Poll::Booth Poll::BoothAssignment Poll::Officer - Poll::Question Poll::Question::Answer::Video].include?(resource.class.name) + Poll::Question Poll::Question::Answer::Video Poll::Shift].include?(resource.class.name) resolve = resolve_for(resource) resolve_options = resolve.pop diff --git a/config/routes/admin.rb b/config/routes/admin.rb index 54af7ace3..5121fec3b 100644 --- a/config/routes/admin.rb +++ b/config/routes/admin.rb @@ -282,6 +282,10 @@ resolve "Poll::BoothAssignment" do |assignment, options| [assignment.poll, :booth_assignment, options.merge(id: assignment)] end +resolve "Poll::Shift" do |shift, options| + [:booth, :shift, options.merge(booth_id: shift.booth, id: shift)] +end + resolve "Poll::Officer" do |officer, options| [:officer, options.merge(id: officer)] end diff --git a/spec/routing/polymorphic_routes_spec.rb b/spec/routing/polymorphic_routes_spec.rb index c6e14d26c..8ab22512b 100644 --- a/spec/routing/polymorphic_routes_spec.rb +++ b/spec/routing/polymorphic_routes_spec.rb @@ -157,6 +157,13 @@ describe "Polymorphic routes" do ) end + it "routes poll shifts" do + booth = create(:poll_booth) + shift = create(:poll_shift, booth: booth) + + expect(admin_polymorphic_path(shift)).to eq(admin_booth_shift_path(booth, shift)) + end + it "supports routes for actions like edit" do proposal = create(:proposal) milestone = create(:milestone, milestoneable: proposal) From 4e604246789a5726ba842c0bba3dec134a206237 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sat, 6 Jun 2020 18:28:45 +0200 Subject: [PATCH 04/18] Extract partial for edit and destroy links --- .../admin/admin_notifications/index.html.erb | 27 +++++-------------- app/views/admin/administrators/index.html.erb | 8 +----- .../admin/administrators/search.html.erb | 5 +--- app/views/admin/budget_groups/index.html.erb | 8 +----- .../admin/budget_headings/index.html.erb | 8 +----- .../admin/dashboard/actions/index.html.erb | 9 +------ app/views/admin/geozones/index.html.erb | 12 +-------- app/views/admin/homepage/_card.html.erb | 10 +------ .../legislation/processes/index.html.erb | 4 +-- .../_local_census_record.html.erb | 10 +------ app/views/admin/managers/index.html.erb | 5 +--- app/views/admin/managers/search.html.erb | 5 +--- .../admin/milestone_statuses/index.html.erb | 7 +---- app/views/admin/moderators/index.html.erb | 5 +--- app/views/admin/moderators/search.html.erb | 5 +--- app/views/admin/newsletters/index.html.erb | 14 +++------- .../admin/poll/polls/_questions.html.erb | 16 +++-------- .../admin/poll/questions/_questions.html.erb | 7 +---- .../questions/answers/videos/index.html.erb | 10 +------ .../progress_bars/_progress_bars.html.erb | 9 +------ .../admin/valuator_groups/_group.html.erb | 8 +----- .../admin/valuators/_valuator_row.html.erb | 8 +----- app/views/shared/_table_actions.html.erb | 13 +++++++++ config/locales/en/admin.yml | 14 ---------- config/locales/es/admin.yml | 14 ---------- 25 files changed, 45 insertions(+), 196 deletions(-) create mode 100644 app/views/shared/_table_actions.html.erb diff --git a/app/views/admin/admin_notifications/index.html.erb b/app/views/admin/admin_notifications/index.html.erb index c4d8b9c43..14c88ab1c 100644 --- a/app/views/admin/admin_notifications/index.html.erb +++ b/app/views/admin/admin_notifications/index.html.erb @@ -30,27 +30,14 @@ <% if admin_notification.draft? %> -
- <%= link_to t("admin.admin_notifications.index.edit"), - edit_admin_admin_notification_path(admin_notification), - class: "button expanded hollow" %> -
-
- <%= link_to t("admin.admin_notifications.index.delete"), - admin_admin_notification_path(admin_notification), - method: :delete, class: "button expanded hollow alert" %> -
-
- <%= link_to t("admin.admin_notifications.index.preview"), - admin_admin_notification_path(admin_notification), - class: "button expanded" %> -
+ <%= render "shared/table_actions", record: admin_notification, actions: [:edit, :destroy] %> + <%= link_to t("admin.admin_notifications.index.preview"), + admin_admin_notification_path(admin_notification), + class: "button" %> <% else %> -
- <%= link_to t("admin.admin_notifications.index.view"), - admin_admin_notification_path(admin_notification), - class: "button expanded" %> -
+ <%= link_to t("admin.admin_notifications.index.view"), + admin_admin_notification_path(admin_notification), + class: "button" %> <% end %> diff --git a/app/views/admin/administrators/index.html.erb b/app/views/admin/administrators/index.html.erb index db08c5933..fa70f0bf0 100644 --- a/app/views/admin/administrators/index.html.erb +++ b/app/views/admin/administrators/index.html.erb @@ -29,13 +29,7 @@ <%= administrator.description %> - <%= link_to t("admin.actions.edit"), - edit_admin_administrator_path(administrator), - class: "button hollow" %> - <%= link_to t("admin.administrators.administrator.delete"), - admin_administrator_path(administrator), - method: :delete, - class: "button hollow alert" %> + <%= render "shared/table_actions", record: administrator, actions: [:edit, :destroy] %> <% end %> diff --git a/app/views/admin/administrators/search.html.erb b/app/views/admin/administrators/search.html.erb index 89064f298..07cd39cb3 100644 --- a/app/views/admin/administrators/search.html.erb +++ b/app/views/admin/administrators/search.html.erb @@ -19,10 +19,7 @@ <%= user.email %> <% if user.administrator? && user.administrator.persisted? %> - <%= link_to t("admin.administrators.administrator.delete"), - admin_administrator_path(user.administrator), - method: :delete, - class: "button hollow alert expanded" %> + <%= render "shared/table_actions", record: user.administrator, actions: [:destroy] %> <% else %> <%= link_to t("admin.administrators.administrator.add"), { controller: "admin/administrators", diff --git a/app/views/admin/budget_groups/index.html.erb b/app/views/admin/budget_groups/index.html.erb index 4df47b16d..915635975 100644 --- a/app/views/admin/budget_groups/index.html.erb +++ b/app/views/admin/budget_groups/index.html.erb @@ -29,13 +29,7 @@ <%= link_to t("admin.budget_groups.headings_manage"), admin_budget_group_headings_path(@budget, group) %> - <%= link_to t("admin.actions.edit"), - edit_admin_budget_group_path(@budget, group), - class: "button hollow" %> - <%= link_to t("admin.actions.delete"), - admin_budget_group_path(@budget, group), - method: :delete, - class: "button hollow alert" %> + <%= render "shared/table_actions", record: group, actions: [:edit, :destroy] %> <% end %> diff --git a/app/views/admin/budget_headings/index.html.erb b/app/views/admin/budget_headings/index.html.erb index 0abc51073..bed3d5688 100644 --- a/app/views/admin/budget_headings/index.html.erb +++ b/app/views/admin/budget_headings/index.html.erb @@ -34,13 +34,7 @@ <%= heading.allow_custom_content ? t("admin.shared.true_value") : t("admin.shared.false_value") %> - <%= link_to t("admin.actions.edit"), - edit_admin_budget_group_heading_path(@budget, @group, heading), - class: "button hollow" %> - <%= link_to t("admin.actions.delete"), - admin_budget_group_heading_path(@budget, @group, heading), - method: :delete, - class: "button hollow alert" %> + <%= render "shared/table_actions", record: heading, actions: [:edit, :destroy] %> <% end %> diff --git a/app/views/admin/dashboard/actions/index.html.erb b/app/views/admin/dashboard/actions/index.html.erb index 7a4a736c4..2bf3a91d9 100644 --- a/app/views/admin/dashboard/actions/index.html.erb +++ b/app/views/admin/dashboard/actions/index.html.erb @@ -32,14 +32,7 @@ <%= number_with_delimiter(action.required_supports, delimiter: ".") %> <%= action.order %> - <%= link_to t("admin.dashboard.actions.index.edit"), - edit_admin_dashboard_action_path(action), - class: "button hollow" %> - <%= link_to t("admin.dashboard.actions.index.delete"), - admin_dashboard_action_path(action), - method: :delete, - class: "button hollow alert", - data: { confirm: t("admin.actions.confirm") } %> + <%= render "shared/table_actions", record: action, actions: [:edit, :destroy] %> <% end %> diff --git a/app/views/admin/geozones/index.html.erb b/app/views/admin/geozones/index.html.erb index 5c2162a02..3db62760a 100644 --- a/app/views/admin/geozones/index.html.erb +++ b/app/views/admin/geozones/index.html.erb @@ -22,17 +22,7 @@ <%= geozone.census_code %> <%= geozone.html_map_coordinates %> -
- <%= link_to t("admin.geozones.index.edit"), - edit_admin_geozone_path(geozone), - class: "button hollow expanded" %> -
-
- <%= link_to t("admin.geozones.index.delete"), - admin_geozone_path(geozone), - method: :delete, - class: "button hollow alert expanded" %> -
+ <%= render "shared/table_actions", record: geozone, actions: [:edit, :destroy] %> <% end %> diff --git a/app/views/admin/homepage/_card.html.erb b/app/views/admin/homepage/_card.html.erb index 7e5481a08..2b1c64453 100644 --- a/app/views/admin/homepage/_card.html.erb +++ b/app/views/admin/homepage/_card.html.erb @@ -17,14 +17,6 @@ <% end %> - <%= link_to t("admin.actions.edit"), - edit_admin_widget_card_path(card), - class: "button hollow" %> - - <%= link_to t("admin.actions.delete"), - admin_widget_card_path(card), - method: :delete, - data: { confirm: t("admin.actions.confirm") }, - class: "button hollow alert" %> + <%= render "shared/table_actions", record: card, actions: [:edit, :destroy] %> diff --git a/app/views/admin/legislation/processes/index.html.erb b/app/views/admin/legislation/processes/index.html.erb index 5e2a647c3..d57e85994 100644 --- a/app/views/admin/legislation/processes/index.html.erb +++ b/app/views/admin/legislation/processes/index.html.erb @@ -35,9 +35,7 @@ <%= I18n.l process.end_date %> <%= process.total_comments %> - <%= link_to t("admin.legislation.processes.index.delete"), admin_legislation_process_path(process), - method: :delete, - class: "button hollow alert expanded" %> + <%= render "shared/table_actions", record: process, actions: [:destroy] %> <% end %> diff --git a/app/views/admin/local_census_records/_local_census_record.html.erb b/app/views/admin/local_census_records/_local_census_record.html.erb index e8bd618f3..22beea26e 100644 --- a/app/views/admin/local_census_records/_local_census_record.html.erb +++ b/app/views/admin/local_census_records/_local_census_record.html.erb @@ -12,14 +12,6 @@ <%= local_census_record.postal_code %> - <%= link_to t("admin.actions.edit"), - edit_admin_local_census_record_path(local_census_record), - class: "button hollow" %> - - <%= link_to t("admin.actions.delete"), - admin_local_census_record_path(local_census_record), - method: :delete, - class: "button hollow alert", - data: { confirm: t("admin.actions.confirm") } %> + <%= render "shared/table_actions", record: local_census_record, actions: [:edit, :destroy] %> diff --git a/app/views/admin/managers/index.html.erb b/app/views/admin/managers/index.html.erb index 0ff1971c4..2dc28ffcb 100644 --- a/app/views/admin/managers/index.html.erb +++ b/app/views/admin/managers/index.html.erb @@ -22,10 +22,7 @@ <%= manager.email %> - <%= link_to t("admin.managers.manager.delete"), - admin_manager_path(manager), - method: :delete, - class: "button hollow alert expanded" %> + <%= render "shared/table_actions", record: manager, actions: [:destroy] %> <% end %> diff --git a/app/views/admin/managers/search.html.erb b/app/views/admin/managers/search.html.erb index bc6005d42..a03d7b72d 100644 --- a/app/views/admin/managers/search.html.erb +++ b/app/views/admin/managers/search.html.erb @@ -19,10 +19,7 @@ <%= user.email %> <% if user.manager? && user.manager.persisted? %> - <%= link_to t("admin.managers.manager.delete"), - admin_manager_path(user.manager), - method: :delete, - class: "button hollow alert expanded" %> + <%= render "shared/table_actions", record: user.manager, actions: [:destroy] %> <% else %> <%= link_to t("admin.managers.manager.add"), { controller: "admin/managers", diff --git a/app/views/admin/milestone_statuses/index.html.erb b/app/views/admin/milestone_statuses/index.html.erb index bf1940a64..e7bf0c720 100644 --- a/app/views/admin/milestone_statuses/index.html.erb +++ b/app/views/admin/milestone_statuses/index.html.erb @@ -23,12 +23,7 @@ <%= status.description %> - <%= link_to t("admin.statuses.index.edit"), - edit_admin_milestone_status_path(status), - class: "button hollow" %> - <%= link_to t("admin.statuses.index.delete"), - admin_milestone_status_path(status), - method: :delete, class: "button hollow alert" %> + <%= render "shared/table_actions", record: status, actions: [:edit, :destroy] %> <% end %> diff --git a/app/views/admin/moderators/index.html.erb b/app/views/admin/moderators/index.html.erb index 770fd77c5..0594fb2d3 100644 --- a/app/views/admin/moderators/index.html.erb +++ b/app/views/admin/moderators/index.html.erb @@ -24,10 +24,7 @@ <%= moderator.email %> - <%= link_to t("admin.moderators.moderator.delete"), - admin_moderator_path(moderator), - method: :delete, - class: "button hollow alert expanded" %> + <%= render "shared/table_actions", record: moderator, actions: [:destroy] %> <% end %> diff --git a/app/views/admin/moderators/search.html.erb b/app/views/admin/moderators/search.html.erb index 358e67043..f07ab647b 100644 --- a/app/views/admin/moderators/search.html.erb +++ b/app/views/admin/moderators/search.html.erb @@ -19,10 +19,7 @@ <%= user.email %> <% if user.moderator? && user.moderator.persisted? %> - <%= link_to t("admin.moderators.moderator.delete"), - admin_moderator_path(user.moderator), - method: :delete, - class: "button hollow alert expanded" %> + <%= render "shared/table_actions", record: user.moderator, actions: [:destroy] %> <% else %> <%= link_to t("admin.moderators.moderator.add"), { controller: "admin/moderators", diff --git a/app/views/admin/newsletters/index.html.erb b/app/views/admin/newsletters/index.html.erb index 7bbabde90..a1ac52803 100644 --- a/app/views/admin/newsletters/index.html.erb +++ b/app/views/admin/newsletters/index.html.erb @@ -29,18 +29,10 @@ <% end %> -
- <%= link_to t("admin.newsletters.index.edit"), edit_admin_newsletter_path(newsletter), - class: "button hollow expanded" %> -
-
- <%= link_to t("admin.newsletters.index.delete"), admin_newsletter_path(newsletter), - method: :delete, class: "button hollow alert expanded" %> -
-
+ <%= render "shared/table_actions", record: newsletter, actions: [:edit, :destroy] %> + <%= link_to t("admin.newsletters.index.preview"), admin_newsletter_path(newsletter), - class: "button expanded" %> -
+ class: "button" %> <% end %> diff --git a/app/views/admin/poll/polls/_questions.html.erb b/app/views/admin/poll/polls/_questions.html.erb index ee5f174ed..6aacb275e 100644 --- a/app/views/admin/poll/polls/_questions.html.erb +++ b/app/views/admin/poll/polls/_questions.html.erb @@ -30,19 +30,9 @@ <% end %> -
- <%= link_to t("admin.polls.show.edit_answers"), admin_question_path(question), - class: "button hollow expanded" %> -
-
- <%= link_to t("shared.edit"), edit_admin_question_path(question), - class: "button hollow expanded" %> -
-
- <%= link_to t("shared.delete"), admin_question_path(question), - class: "button hollow alert expanded", - method: :delete %> -
+ <%= link_to t("admin.polls.show.edit_answers"), admin_question_path(question), + class: "button hollow" %> + <%= render "shared/table_actions", record: question, actions: [:edit, :destroy] %> <% end %> diff --git a/app/views/admin/poll/questions/_questions.html.erb b/app/views/admin/poll/questions/_questions.html.erb index 489a700f6..0099b3c10 100644 --- a/app/views/admin/poll/questions/_questions.html.erb +++ b/app/views/admin/poll/questions/_questions.html.erb @@ -27,12 +27,7 @@ <% end %> -
- <%= link_to t("shared.edit"), edit_admin_question_path(question), class: "button hollow expanded" %> -
-
- <%= link_to t("shared.delete"), admin_question_path(question), class: "button hollow alert expanded", method: :delete %> -
+ <%= render "shared/table_actions", record: question, actions: [:edit, :destroy] %> <% end %> diff --git a/app/views/admin/poll/questions/answers/videos/index.html.erb b/app/views/admin/poll/questions/answers/videos/index.html.erb index 0ea64c570..d74762dda 100644 --- a/app/views/admin/poll/questions/answers/videos/index.html.erb +++ b/app/views/admin/poll/questions/answers/videos/index.html.erb @@ -29,15 +29,7 @@ <%= video.title %> <%= link_to "#{video.url}", video.url %> - - <%= link_to t("shared.edit"), - edit_admin_video_path(video), - class: "button hollow" %> - - <%= link_to t("shared.delete"), - admin_video_path(video), - class: "button hollow alert", - method: :delete %> + <%= render "shared/table_actions", record: video, actions: [:edit, :destroy] %> <% end %> diff --git a/app/views/admin/progress_bars/_progress_bars.html.erb b/app/views/admin/progress_bars/_progress_bars.html.erb index 1ac03e331..e0d87e3ee 100644 --- a/app/views/admin/progress_bars/_progress_bars.html.erb +++ b/app/views/admin/progress_bars/_progress_bars.html.erb @@ -36,14 +36,7 @@ <%= number_to_percentage(progress_bar.percentage, strip_insignificant_zeros: true) %> - <%= link_to t("admin.actions.edit"), - admin_polymorphic_path(progress_bar, action: :edit), - class: "button hollow" %> - - <%= link_to t("admin.actions.delete"), - admin_polymorphic_path(progress_bar), - method: :delete, - class: "button hollow alert" %> + <%= render "shared/table_actions", record: progress_bar, actions: [:edit, :destroy] %> <% end %> diff --git a/app/views/admin/valuator_groups/_group.html.erb b/app/views/admin/valuator_groups/_group.html.erb index ea69515f7..ea67ffd76 100644 --- a/app/views/admin/valuator_groups/_group.html.erb +++ b/app/views/admin/valuator_groups/_group.html.erb @@ -6,12 +6,6 @@ <%= group.valuators.count %> - <%= link_to t("admin.actions.delete"), - admin_valuator_group_path(group), - method: :delete, class: "button hollow alert" %> - - <%= link_to t("admin.actions.edit"), - edit_admin_valuator_group_path(group), - class: "button hollow" %> + <%= render "shared/table_actions", record: group, actions: [:edit, :destroy] %> diff --git a/app/views/admin/valuators/_valuator_row.html.erb b/app/views/admin/valuators/_valuator_row.html.erb index a09e9fd51..7b0ce40bf 100644 --- a/app/views/admin/valuators/_valuator_row.html.erb +++ b/app/views/admin/valuators/_valuator_row.html.erb @@ -19,12 +19,6 @@ <%= valuator_abilities(valuator) %> - <%= link_to t("admin.actions.edit"), - edit_admin_valuator_path(valuator), - class: "button hollow" %> - <%= link_to t("admin.valuators.valuator.delete"), - admin_valuator_path(valuator), - method: :delete, - class: "button hollow alert" %> + <%= render "shared/table_actions", record: valuator, actions: [:edit, :destroy] %> diff --git a/app/views/shared/_table_actions.html.erb b/app/views/shared/_table_actions.html.erb new file mode 100644 index 000000000..d12beda51 --- /dev/null +++ b/app/views/shared/_table_actions.html.erb @@ -0,0 +1,13 @@ +<% if actions.include?(:edit) %> + <%= link_to t("admin.actions.edit"), + admin_polymorphic_path(record, action: :edit), + class: "button hollow" %> +<% end %> + +<% if actions.include?(:destroy) %> + <%= link_to t("admin.actions.delete"), + admin_polymorphic_path(record), + method: :delete, + class: "button hollow alert", + data: { confirm: t("admin.actions.confirm") } %> +<% end %> diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 2ec0222ef..6cbf33afe 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -297,8 +297,6 @@ en: table_name: Name table_description: Description table_actions: Actions - delete: Delete - edit: Edit edit: title: Edit milestone status update: @@ -362,7 +360,6 @@ en: 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 edit: Edit - delete: Delete active: 'Yes' inactive: 'No' title: Resources and actions @@ -497,7 +494,6 @@ en: banner_title: Header colors index: create: New process - delete: Delete title: Collaborative legislation filters: active: Active @@ -629,7 +625,6 @@ en: no_managers: There are no managers. manager: add: Add - delete: Delete search: title: "Managers: User search" menu: @@ -709,7 +704,6 @@ en: no_administrators: There are no administrators. administrator: add: Add - delete: Delete restricted_removal: "Sorry, you can't remove yourself from the administrators" search: title: "Administrators: User search" @@ -724,7 +718,6 @@ en: no_moderators: There are no moderators. moderator: add: Add - delete: Delete search: title: "Moderators: User search" segment_recipient: @@ -751,8 +744,6 @@ en: sent: Sent actions: Actions draft: Draft - edit: Edit - delete: Delete preview: Preview empty_newsletters: There are no newsletters to show new: @@ -788,8 +779,6 @@ en: sent: Sent actions: Actions draft: Draft - edit: Edit - delete: Delete preview: Preview view: View empty_notifications: There are no notifications to show @@ -887,7 +876,6 @@ en: can_edit_dossier: "Can edit dossier" valuator: add: Add to valuators - delete: Delete search: title: "Valuators: User search" form: @@ -1309,8 +1297,6 @@ en: index: title: Geozone create: Create geozone - edit: Edit - delete: Delete geozone: name: Name external_code: External code diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 6323c3b74..575518f56 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -297,8 +297,6 @@ es: table_name: Nombre table_description: Descripción table_actions: Acciones - delete: Borrar - edit: Editar edit: title: Editar estado de seguimiento update: @@ -362,7 +360,6 @@ es: 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 edit: Editar - delete: Borrar active: 'Si' inactive: 'No' title: Recursos y acciones @@ -497,7 +494,6 @@ es: banner_title: Colores del encabezado index: create: Nuevo proceso - delete: Borrar title: Procesos de legislación colaborativa filters: active: Activos @@ -628,7 +624,6 @@ es: no_managers: No hay gestores. manager: add: Añadir como gestor - delete: Borrar search: title: "Gestores: Búsqueda de usuarios" menu: @@ -708,7 +703,6 @@ es: no_administrators: No hay administradores. administrator: add: Añadir como Administrador - delete: Borrar restricted_removal: "Lo sentimos, no puedes eliminarte a ti mismo de la lista" search: title: "Administradores: Búsqueda de usuarios" @@ -723,7 +717,6 @@ es: no_moderators: No hay moderadores. moderator: add: Añadir como Moderador - delete: Borrar search: title: "Moderadores: Búsqueda de usuarios" segment_recipient: @@ -750,8 +743,6 @@ es: sent: Enviado actions: Acciones draft: Borrador - edit: Editar - delete: Borrar preview: Previsualizar empty_newsletters: No hay newsletters para mostrar new: @@ -787,8 +778,6 @@ es: sent: Enviado actions: Acciones draft: Borrador - edit: Editar - delete: Borrar preview: Previsualizar view: Visualizar empty_notifications: No hay notificaciones para mostrar @@ -886,7 +875,6 @@ es: can_edit_dossier: "Puede editar informes" valuator: add: Añadir como evaluador - delete: Borrar search: title: "Evaluadores: Búsqueda de usuarios" form: @@ -1308,8 +1296,6 @@ es: index: title: Zonas create: Crear una zona - edit: Editar - delete: Borrar geozone: name: Nombre external_code: Código externo From baefc249f02512510b2f0d2a0ddf049560bc20fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 9 Jun 2020 00:18:15 +0200 Subject: [PATCH 05/18] Allow using components with view_component While Rails provides a lot of functionality by default, there's one missing piece which is present in frameworks like Django or Phoenix: the so-called "view models", or "components". It isn't easy to extract methods in a standard Rails view/partial, since extracting them to a helper will make them available to all views, and so two helper methods can't have the same name. It's also hard to organize the code in modules, and due to that it's hard to figure out where a certain helper method is supposed to be called from. Furthermore, object-oriented techniques like inheritance can't be applied, and so in CONSUL customizing views is harder that customizing models. Components fix all these issues, and work the way Ruby objects usually do. Components are also a pattern whose popularity has increased a lot in the last few years, with JavaScript frameworks like React using them heavily. While React's components aren't exactly the same as the components we're going to use, the concept is really similar. I've always liked the idea of components. However, there wasn't a stable gem we could safely use. The most popular gem (cells) hasn't been maintained for years, and we have to be very careful choosing which gems CONSUL should depend on. The view_component gem is maintained by GitHub, which is as a guarantee of future maintenance as it can be (not counting the Rails core team), and its usage started growing after RailsConf 2019. While that's certainly not a huge amount of time, it's not that we're using an experimental gem either. There's currently a conflict between view_component and wicked_pdf. We're adding a monkey-patch with the fix until it's merged in wicked_pdf. --- Gemfile | 1 + Gemfile.lock | 3 +++ app/components/application_component.rb | 2 ++ config/application.rb | 1 + config/initializers/wicked_pdf.rb | 24 ++++++++++++++++++++++++ spec/rails_helper.rb | 5 +++++ 6 files changed, 36 insertions(+) create mode 100644 app/components/application_component.rb diff --git a/Gemfile b/Gemfile index 32e1f6f0a..9f26113fe 100644 --- a/Gemfile +++ b/Gemfile @@ -59,6 +59,7 @@ gem "translator-text", "~> 0.1.0" gem "turbolinks", "~> 5.2.1" gem "turnout", "~> 2.5.0" gem "uglifier", "~> 4.2.0" +gem "view_component", "~> 2.19.1", require: "view_component/engine" gem "whenever", "~> 1.0.0", require: false gem "wicked_pdf", "~> 2.1.0" gem "wkhtmltopdf-binary", "~> 0.12.4" diff --git a/Gemfile.lock b/Gemfile.lock index 89922ea49..e44bb04ed 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -608,6 +608,8 @@ GEM uniform_notifier (1.13.0) user_agent_parser (2.6.0) uuidtools (2.1.5) + view_component (2.19.1) + activesupport (>= 5.0.0, < 7.0) warden (1.2.9) rack (>= 2.0.9) wasabi (3.5.0) @@ -728,6 +730,7 @@ DEPENDENCIES turbolinks (~> 5.2.1) turnout (~> 2.5.0) uglifier (~> 4.2.0) + view_component (~> 2.19.1) web-console (~> 3.7.0) webdrivers (~> 4.4.1) whenever (~> 1.0.0) diff --git a/app/components/application_component.rb b/app/components/application_component.rb new file mode 100644 index 000000000..3db4d0451 --- /dev/null +++ b/app/components/application_component.rb @@ -0,0 +1,2 @@ +class ApplicationComponent < ViewComponent::Base +end diff --git a/config/application.rb b/config/application.rb index 819918788..935dffa93 100644 --- a/config/application.rb +++ b/config/application.rb @@ -112,6 +112,7 @@ module Consul # * English: https://github.com/consul/consul/blob/master/CUSTOMIZE_EN.md # * Spanish: https://github.com/consul/consul/blob/master/CUSTOMIZE_ES.md # + config.autoload_paths << "#{Rails.root}/app/components/custom" config.autoload_paths << "#{Rails.root}/app/controllers/custom" config.autoload_paths << "#{Rails.root}/app/models/custom" config.paths["app/views"].unshift(Rails.root.join("app", "views", "custom")) diff --git a/config/initializers/wicked_pdf.rb b/config/initializers/wicked_pdf.rb index 824095dc3..37820d285 100644 --- a/config/initializers/wicked_pdf.rb +++ b/config/initializers/wicked_pdf.rb @@ -1,3 +1,27 @@ +class WickedPdf + # Wicked Pdf magic breaks ViewComponent + # https://github.com/mileszs/wicked_pdf/pull/925 + module PdfHelper + def render(*args) + options = args.first + if options.is_a?(Hash) && options.key?(:pdf) + render_with_wicked_pdf(options) + else + super + end + end + + def render_to_string(*args) + options = args.first + if options.is_a?(Hash) && options.key?(:pdf) + render_to_string_with_wicked_pdf(options) + else + super + end + end + end +end + # WickedPDF Global Configuration # # Use this to set up shared configuration options for your entire application. diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index c4756dd02..717007659 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -11,6 +11,11 @@ require "spec_helper" require "capybara/rails" require "capybara/rspec" require "selenium/webdriver" +require "view_component/test_helpers" + +RSpec.configure do |config| + config.include ViewComponent::TestHelpers, type: :component +end Rails.application.load_tasks if Rake::Task.tasks.empty? From 10c095d821ad470584b248c09cfdec79fe454271 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 9 Jun 2020 00:47:41 +0200 Subject: [PATCH 06/18] Move table actions partial to a component This partial was going to get too complex since in some places we've got different texts, different URLs or different confirmation messages. While we should probably try to be more consistent and that would make the partial work in most cases, there'll always be some exceptions, and using a partial (with, perhaps, some helper methods) will become messy really quickly. --- .../admin/table_actions_component.html.erb} | 0 .../admin/table_actions_component.rb | 8 +++++ .../admin/admin_notifications/index.html.erb | 2 +- app/views/admin/administrators/index.html.erb | 2 +- .../admin/administrators/search.html.erb | 2 +- app/views/admin/budget_groups/index.html.erb | 2 +- .../admin/budget_headings/index.html.erb | 2 +- .../admin/dashboard/actions/index.html.erb | 2 +- app/views/admin/geozones/index.html.erb | 2 +- app/views/admin/homepage/_card.html.erb | 2 +- .../legislation/processes/index.html.erb | 2 +- .../_local_census_record.html.erb | 2 +- app/views/admin/managers/index.html.erb | 2 +- app/views/admin/managers/search.html.erb | 2 +- .../admin/milestone_statuses/index.html.erb | 2 +- app/views/admin/moderators/index.html.erb | 2 +- app/views/admin/moderators/search.html.erb | 2 +- app/views/admin/newsletters/index.html.erb | 2 +- .../admin/poll/polls/_questions.html.erb | 2 +- .../admin/poll/questions/_questions.html.erb | 2 +- .../questions/answers/videos/index.html.erb | 2 +- .../progress_bars/_progress_bars.html.erb | 2 +- .../admin/valuator_groups/_group.html.erb | 2 +- .../admin/valuators/_valuator_row.html.erb | 2 +- .../admin/table_actions_component_spec.rb | 29 +++++++++++++++++++ 25 files changed, 59 insertions(+), 22 deletions(-) rename app/{views/shared/_table_actions.html.erb => components/admin/table_actions_component.html.erb} (100%) create mode 100644 app/components/admin/table_actions_component.rb create mode 100644 spec/components/admin/table_actions_component_spec.rb diff --git a/app/views/shared/_table_actions.html.erb b/app/components/admin/table_actions_component.html.erb similarity index 100% rename from app/views/shared/_table_actions.html.erb rename to app/components/admin/table_actions_component.html.erb diff --git a/app/components/admin/table_actions_component.rb b/app/components/admin/table_actions_component.rb new file mode 100644 index 000000000..c1a95dff7 --- /dev/null +++ b/app/components/admin/table_actions_component.rb @@ -0,0 +1,8 @@ +class Admin::TableActionsComponent < ApplicationComponent + attr_reader :record, :actions + + def initialize(record, actions: [:edit, :destroy]) + @record = record + @actions = actions + end +end diff --git a/app/views/admin/admin_notifications/index.html.erb b/app/views/admin/admin_notifications/index.html.erb index 14c88ab1c..48f132461 100644 --- a/app/views/admin/admin_notifications/index.html.erb +++ b/app/views/admin/admin_notifications/index.html.erb @@ -30,7 +30,7 @@ <% if admin_notification.draft? %> - <%= render "shared/table_actions", record: admin_notification, actions: [:edit, :destroy] %> + <%= render Admin::TableActionsComponent.new(admin_notification) %> <%= link_to t("admin.admin_notifications.index.preview"), admin_admin_notification_path(admin_notification), class: "button" %> diff --git a/app/views/admin/administrators/index.html.erb b/app/views/admin/administrators/index.html.erb index fa70f0bf0..4c5620b3a 100644 --- a/app/views/admin/administrators/index.html.erb +++ b/app/views/admin/administrators/index.html.erb @@ -29,7 +29,7 @@ <%= administrator.description %> - <%= render "shared/table_actions", record: administrator, actions: [:edit, :destroy] %> + <%= render Admin::TableActionsComponent.new(administrator) %> <% end %> diff --git a/app/views/admin/administrators/search.html.erb b/app/views/admin/administrators/search.html.erb index 07cd39cb3..671b6efb2 100644 --- a/app/views/admin/administrators/search.html.erb +++ b/app/views/admin/administrators/search.html.erb @@ -19,7 +19,7 @@ <%= user.email %> <% if user.administrator? && user.administrator.persisted? %> - <%= render "shared/table_actions", record: user.administrator, actions: [:destroy] %> + <%= render Admin::TableActionsComponent.new(user.administrator, actions: [:destroy]) %> <% else %> <%= link_to t("admin.administrators.administrator.add"), { controller: "admin/administrators", diff --git a/app/views/admin/budget_groups/index.html.erb b/app/views/admin/budget_groups/index.html.erb index 915635975..3634e4bdc 100644 --- a/app/views/admin/budget_groups/index.html.erb +++ b/app/views/admin/budget_groups/index.html.erb @@ -29,7 +29,7 @@ <%= link_to t("admin.budget_groups.headings_manage"), admin_budget_group_headings_path(@budget, group) %> - <%= render "shared/table_actions", record: group, actions: [:edit, :destroy] %> + <%= render Admin::TableActionsComponent.new(group) %> <% end %> diff --git a/app/views/admin/budget_headings/index.html.erb b/app/views/admin/budget_headings/index.html.erb index bed3d5688..bfb878ec9 100644 --- a/app/views/admin/budget_headings/index.html.erb +++ b/app/views/admin/budget_headings/index.html.erb @@ -34,7 +34,7 @@ <%= heading.allow_custom_content ? t("admin.shared.true_value") : t("admin.shared.false_value") %> - <%= render "shared/table_actions", record: heading, actions: [:edit, :destroy] %> + <%= render Admin::TableActionsComponent.new(heading) %> <% end %> diff --git a/app/views/admin/dashboard/actions/index.html.erb b/app/views/admin/dashboard/actions/index.html.erb index 2bf3a91d9..c6aee28f1 100644 --- a/app/views/admin/dashboard/actions/index.html.erb +++ b/app/views/admin/dashboard/actions/index.html.erb @@ -32,7 +32,7 @@ <%= number_with_delimiter(action.required_supports, delimiter: ".") %> <%= action.order %> - <%= render "shared/table_actions", record: action, actions: [:edit, :destroy] %> + <%= render Admin::TableActionsComponent.new(action) %> <% end %> diff --git a/app/views/admin/geozones/index.html.erb b/app/views/admin/geozones/index.html.erb index 3db62760a..31bae3f73 100644 --- a/app/views/admin/geozones/index.html.erb +++ b/app/views/admin/geozones/index.html.erb @@ -22,7 +22,7 @@ <%= geozone.census_code %> <%= geozone.html_map_coordinates %> - <%= render "shared/table_actions", record: geozone, actions: [:edit, :destroy] %> + <%= render Admin::TableActionsComponent.new(geozone) %> <% end %> diff --git a/app/views/admin/homepage/_card.html.erb b/app/views/admin/homepage/_card.html.erb index 2b1c64453..94025a7b1 100644 --- a/app/views/admin/homepage/_card.html.erb +++ b/app/views/admin/homepage/_card.html.erb @@ -17,6 +17,6 @@ <% end %> - <%= render "shared/table_actions", record: card, actions: [:edit, :destroy] %> + <%= render Admin::TableActionsComponent.new(card) %> diff --git a/app/views/admin/legislation/processes/index.html.erb b/app/views/admin/legislation/processes/index.html.erb index d57e85994..ddef4a150 100644 --- a/app/views/admin/legislation/processes/index.html.erb +++ b/app/views/admin/legislation/processes/index.html.erb @@ -35,7 +35,7 @@ <%= I18n.l process.end_date %> <%= process.total_comments %> - <%= render "shared/table_actions", record: process, actions: [:destroy] %> + <%= render Admin::TableActionsComponent.new(process, actions: [:destroy]) %> <% end %> diff --git a/app/views/admin/local_census_records/_local_census_record.html.erb b/app/views/admin/local_census_records/_local_census_record.html.erb index 22beea26e..85a32e39b 100644 --- a/app/views/admin/local_census_records/_local_census_record.html.erb +++ b/app/views/admin/local_census_records/_local_census_record.html.erb @@ -12,6 +12,6 @@ <%= local_census_record.postal_code %> - <%= render "shared/table_actions", record: local_census_record, actions: [:edit, :destroy] %> + <%= render Admin::TableActionsComponent.new(local_census_record) %> diff --git a/app/views/admin/managers/index.html.erb b/app/views/admin/managers/index.html.erb index 2dc28ffcb..62ca1f189 100644 --- a/app/views/admin/managers/index.html.erb +++ b/app/views/admin/managers/index.html.erb @@ -22,7 +22,7 @@ <%= manager.email %> - <%= render "shared/table_actions", record: manager, actions: [:destroy] %> + <%= render Admin::TableActionsComponent.new(manager, actions: [:destroy]) %> <% end %> diff --git a/app/views/admin/managers/search.html.erb b/app/views/admin/managers/search.html.erb index a03d7b72d..a834a9d80 100644 --- a/app/views/admin/managers/search.html.erb +++ b/app/views/admin/managers/search.html.erb @@ -19,7 +19,7 @@ <%= user.email %> <% if user.manager? && user.manager.persisted? %> - <%= render "shared/table_actions", record: user.manager, actions: [:destroy] %> + <%= render Admin::TableActionsComponent.new(user.manager, actions: [:destroy]) %> <% else %> <%= link_to t("admin.managers.manager.add"), { controller: "admin/managers", diff --git a/app/views/admin/milestone_statuses/index.html.erb b/app/views/admin/milestone_statuses/index.html.erb index e7bf0c720..1d66b8703 100644 --- a/app/views/admin/milestone_statuses/index.html.erb +++ b/app/views/admin/milestone_statuses/index.html.erb @@ -23,7 +23,7 @@ <%= status.description %> - <%= render "shared/table_actions", record: status, actions: [:edit, :destroy] %> + <%= render Admin::TableActionsComponent.new(status) %> <% end %> diff --git a/app/views/admin/moderators/index.html.erb b/app/views/admin/moderators/index.html.erb index 0594fb2d3..1c60e1d6d 100644 --- a/app/views/admin/moderators/index.html.erb +++ b/app/views/admin/moderators/index.html.erb @@ -24,7 +24,7 @@ <%= moderator.email %> - <%= render "shared/table_actions", record: moderator, actions: [:destroy] %> + <%= render Admin::TableActionsComponent.new(moderator, actions: [:destroy]) %> <% end %> diff --git a/app/views/admin/moderators/search.html.erb b/app/views/admin/moderators/search.html.erb index f07ab647b..3cda8819e 100644 --- a/app/views/admin/moderators/search.html.erb +++ b/app/views/admin/moderators/search.html.erb @@ -19,7 +19,7 @@ <%= user.email %> <% if user.moderator? && user.moderator.persisted? %> - <%= render "shared/table_actions", record: user.moderator, actions: [:destroy] %> + <%= render Admin::TableActionsComponent.new(user.moderator, actions: [:destroy]) %> <% else %> <%= link_to t("admin.moderators.moderator.add"), { controller: "admin/moderators", diff --git a/app/views/admin/newsletters/index.html.erb b/app/views/admin/newsletters/index.html.erb index a1ac52803..f9cf9b604 100644 --- a/app/views/admin/newsletters/index.html.erb +++ b/app/views/admin/newsletters/index.html.erb @@ -29,7 +29,7 @@ <% end %> - <%= render "shared/table_actions", record: newsletter, actions: [:edit, :destroy] %> + <%= render Admin::TableActionsComponent.new(newsletter) %> <%= link_to t("admin.newsletters.index.preview"), admin_newsletter_path(newsletter), class: "button" %> diff --git a/app/views/admin/poll/polls/_questions.html.erb b/app/views/admin/poll/polls/_questions.html.erb index 6aacb275e..59964d6e6 100644 --- a/app/views/admin/poll/polls/_questions.html.erb +++ b/app/views/admin/poll/polls/_questions.html.erb @@ -32,7 +32,7 @@ <%= link_to t("admin.polls.show.edit_answers"), admin_question_path(question), class: "button hollow" %> - <%= render "shared/table_actions", record: question, actions: [:edit, :destroy] %> + <%= render Admin::TableActionsComponent.new(question) %> <% end %> diff --git a/app/views/admin/poll/questions/_questions.html.erb b/app/views/admin/poll/questions/_questions.html.erb index 0099b3c10..784d3e73b 100644 --- a/app/views/admin/poll/questions/_questions.html.erb +++ b/app/views/admin/poll/questions/_questions.html.erb @@ -27,7 +27,7 @@ <% end %> - <%= render "shared/table_actions", record: question, actions: [:edit, :destroy] %> + <%= render Admin::TableActionsComponent.new(question) %> <% end %> diff --git a/app/views/admin/poll/questions/answers/videos/index.html.erb b/app/views/admin/poll/questions/answers/videos/index.html.erb index d74762dda..1a7d41402 100644 --- a/app/views/admin/poll/questions/answers/videos/index.html.erb +++ b/app/views/admin/poll/questions/answers/videos/index.html.erb @@ -29,7 +29,7 @@ <%= video.title %> <%= link_to "#{video.url}", video.url %> - <%= render "shared/table_actions", record: video, actions: [:edit, :destroy] %> + <%= render Admin::TableActionsComponent.new(video) %> <% end %> diff --git a/app/views/admin/progress_bars/_progress_bars.html.erb b/app/views/admin/progress_bars/_progress_bars.html.erb index e0d87e3ee..3615342b9 100644 --- a/app/views/admin/progress_bars/_progress_bars.html.erb +++ b/app/views/admin/progress_bars/_progress_bars.html.erb @@ -36,7 +36,7 @@ <%= number_to_percentage(progress_bar.percentage, strip_insignificant_zeros: true) %> - <%= render "shared/table_actions", record: progress_bar, actions: [:edit, :destroy] %> + <%= render Admin::TableActionsComponent.new(progress_bar) %> <% end %> diff --git a/app/views/admin/valuator_groups/_group.html.erb b/app/views/admin/valuator_groups/_group.html.erb index ea67ffd76..4de3e2e03 100644 --- a/app/views/admin/valuator_groups/_group.html.erb +++ b/app/views/admin/valuator_groups/_group.html.erb @@ -6,6 +6,6 @@ <%= group.valuators.count %> - <%= render "shared/table_actions", record: group, actions: [:edit, :destroy] %> + <%= render Admin::TableActionsComponent.new(group) %> diff --git a/app/views/admin/valuators/_valuator_row.html.erb b/app/views/admin/valuators/_valuator_row.html.erb index 7b0ce40bf..a93d492d7 100644 --- a/app/views/admin/valuators/_valuator_row.html.erb +++ b/app/views/admin/valuators/_valuator_row.html.erb @@ -19,6 +19,6 @@ <%= valuator_abilities(valuator) %> - <%= render "shared/table_actions", record: valuator, actions: [:edit, :destroy] %> + <%= render Admin::TableActionsComponent.new(valuator) %> diff --git a/spec/components/admin/table_actions_component_spec.rb b/spec/components/admin/table_actions_component_spec.rb new file mode 100644 index 000000000..d4161b2d2 --- /dev/null +++ b/spec/components/admin/table_actions_component_spec.rb @@ -0,0 +1,29 @@ +require "rails_helper" + +describe Admin::TableActionsComponent, type: :component do + let(:record) { create(:banner) } + + it "renders links to edit and destroy a record by default" do + render_inline Admin::TableActionsComponent.new(record) + + expect(page).to have_css "a", count: 2 + expect(page).to have_css "a[href*='edit']", text: "Edit" + expect(page).to have_css "a[data-method='delete']", text: "Delete" + end + + context "actions parameter is passed" do + it "renders a link to edit a record if passed" do + render_inline Admin::TableActionsComponent.new(record, actions: [:edit]) + + expect(page).to have_link "Edit" + expect(page).not_to have_link "Delete" + end + + it "renders a link to destroy a record if passed" do + render_inline Admin::TableActionsComponent.new(record, actions: [:destroy]) + + expect(page).to have_link "Delete" + expect(page).not_to have_link "Edit" + end + end +end From 738646a565be7c6d49f31cecd6147b6c78c1d5e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 9 Jun 2020 16:51:02 +0200 Subject: [PATCH 07/18] Allow different texts in links to actions The texts were different for a few models, so the component needs to be updated. --- .../admin/table_actions_component.html.erb | 4 +-- .../admin/table_actions_component.rb | 20 ++++++++++++--- app/views/admin/banners/index.html.erb | 13 +++------- .../administrator_tasks/index.html.erb | 7 +++--- .../admin/milestones/_milestones.html.erb | 8 +++--- app/views/admin/poll/booths/_booth.html.erb | 7 +++--- .../admin/poll/officers/_officer.html.erb | 8 +++--- app/views/admin/poll/officers/index.html.erb | 9 +++---- app/views/admin/poll/shifts/_shifts.html.erb | 10 ++++---- .../content_blocks/index.html.erb | 7 +++--- .../site_customization/pages/index.html.erb | 25 ++++++++----------- app/views/admin/tags/index.html.erb | 2 +- .../admin/table_actions_component_spec.rb | 9 +++++++ 13 files changed, 73 insertions(+), 56 deletions(-) diff --git a/app/components/admin/table_actions_component.html.erb b/app/components/admin/table_actions_component.html.erb index d12beda51..dac471bc8 100644 --- a/app/components/admin/table_actions_component.html.erb +++ b/app/components/admin/table_actions_component.html.erb @@ -1,11 +1,11 @@ <% if actions.include?(:edit) %> - <%= link_to t("admin.actions.edit"), + <%= link_to edit_text, admin_polymorphic_path(record, action: :edit), class: "button hollow" %> <% end %> <% if actions.include?(:destroy) %> - <%= link_to t("admin.actions.delete"), + <%= link_to destroy_text, admin_polymorphic_path(record), method: :delete, class: "button hollow alert", diff --git a/app/components/admin/table_actions_component.rb b/app/components/admin/table_actions_component.rb index c1a95dff7..b016cadc1 100644 --- a/app/components/admin/table_actions_component.rb +++ b/app/components/admin/table_actions_component.rb @@ -1,8 +1,22 @@ class Admin::TableActionsComponent < ApplicationComponent - attr_reader :record, :actions + attr_reader :record, :options - def initialize(record, actions: [:edit, :destroy]) + def initialize(record, **options) @record = record - @actions = actions + @options = options end + + private + + def actions + options[:actions] || [:edit, :destroy] + end + + def edit_text + options[:edit_text] || t("admin.actions.edit") + end + + def destroy_text + options[:destroy_text] || t("admin.actions.delete") + end end diff --git a/app/views/admin/banners/index.html.erb b/app/views/admin/banners/index.html.erb index 4b3e97230..1a0783c2a 100644 --- a/app/views/admin/banners/index.html.erb +++ b/app/views/admin/banners/index.html.erb @@ -21,15 +21,10 @@ <%= banner.post_started_at %> <%= banner.post_ended_at %> -
- <%= link_to t("admin.banners.index.edit"), edit_admin_banner_path(banner), - class: "button hollow expanded" %> -
-
- <%= link_to t("admin.banners.index.delete"), admin_banner_path(banner), - method: :delete, - class: "button hollow alert expanded" %> -
+ <%= render Admin::TableActionsComponent.new(banner, + edit_text: t("admin.banners.index.edit"), + destroy_text: t("admin.banners.index.delete") + ) %> diff --git a/app/views/admin/dashboard/administrator_tasks/index.html.erb b/app/views/admin/dashboard/administrator_tasks/index.html.erb index 748272a34..93cebb001 100644 --- a/app/views/admin/dashboard/administrator_tasks/index.html.erb +++ b/app/views/admin/dashboard/administrator_tasks/index.html.erb @@ -25,9 +25,10 @@ <% unless task.executed_at? %> - <%= link_to t("admin.dashboard.administrator_tasks.index.solve"), - edit_admin_dashboard_administrator_task_path(task), - class: "button hollow" %> + <%= render Admin::TableActionsComponent.new(task, + actions: [:edit], + edit_text: t("admin.dashboard.administrator_tasks.index.solve") + ) %> <% end %> diff --git a/app/views/admin/milestones/_milestones.html.erb b/app/views/admin/milestones/_milestones.html.erb index 84f4a65ab..f3c1e1991 100644 --- a/app/views/admin/milestones/_milestones.html.erb +++ b/app/views/admin/milestones/_milestones.html.erb @@ -56,10 +56,10 @@ <% end %> - <%= link_to t("admin.milestones.index.delete"), - admin_polymorphic_path(milestone), - method: :delete, - class: "button hollow alert expanded" %> + <%= render Admin::TableActionsComponent.new(milestone, + actions: [:destroy], + destroy_text: t("admin.milestones.index.delete") + ) %> <% end %> diff --git a/app/views/admin/poll/booths/_booth.html.erb b/app/views/admin/poll/booths/_booth.html.erb index 6bef50aae..bca880e5d 100644 --- a/app/views/admin/poll/booths/_booth.html.erb +++ b/app/views/admin/poll/booths/_booth.html.erb @@ -11,9 +11,10 @@ new_admin_booth_shift_path(booth), class: "button hollow" %> <% else %> - <%= link_to t("admin.booths.booth.edit"), - edit_admin_booth_path(booth), - class: "button hollow" %> + <%= render Admin::TableActionsComponent.new(booth, + actions: [:edit], + edit_text: t("admin.booths.booth.edit") + ) %> <% end %> diff --git a/app/views/admin/poll/officers/_officer.html.erb b/app/views/admin/poll/officers/_officer.html.erb index 70fc18ec1..45e516594 100644 --- a/app/views/admin/poll/officers/_officer.html.erb +++ b/app/views/admin/poll/officers/_officer.html.erb @@ -16,10 +16,10 @@ <% if officer.persisted? %> - <%= link_to t("admin.poll_officers.officer.delete"), - admin_officer_path(officer), - method: :delete, - class: "button hollow alert expanded" %> + <%= render Admin::TableActionsComponent.new(officer, + actions: [:destroy], + destroy_text: t("admin.poll_officers.officer.delete") + ) %> <% else %> <%= link_to t("admin.poll_officers.officer.add"), { controller: "admin/poll/officers", action: :create, user_id: officer.user_id }, method: :post, diff --git a/app/views/admin/poll/officers/index.html.erb b/app/views/admin/poll/officers/index.html.erb index 640369feb..02b67492f 100644 --- a/app/views/admin/poll/officers/index.html.erb +++ b/app/views/admin/poll/officers/index.html.erb @@ -30,11 +30,10 @@ <% if officer.persisted? %> - <%= link_to t("admin.poll_officers.officer.delete"), - admin_officer_path(officer), - method: :delete, - class: "button hollow alert expanded" - %> + <%= render Admin::TableActionsComponent.new(officer, + actions: [:destroy], + destroy_text: t("admin.poll_officers.officer.delete") + ) %> <% else %> <%= link_to t("admin.poll_officers.officer.add"), { controller: "admin/poll/officers", action: :create, diff --git a/app/views/admin/poll/shifts/_shifts.html.erb b/app/views/admin/poll/shifts/_shifts.html.erb index 140ae43c9..af3c0e662 100644 --- a/app/views/admin/poll/shifts/_shifts.html.erb +++ b/app/views/admin/poll/shifts/_shifts.html.erb @@ -6,7 +6,7 @@ <%= t("admin.poll_shifts.new.officer") %> <%= t("admin.poll_shifts.new.table_email") %> <%= Poll::Shift.human_attribute_name(:task) %> - <%= t("admin.poll_shifts.new.shift") %> + <%= t("admin.poll_shifts.new.shift") %> @@ -17,10 +17,10 @@ <%= shift.officer_email %> <%= t("admin.poll_shifts.#{shift.task}") %> - <%= link_to t("admin.poll_shifts.new.remove_shift"), - admin_booth_shift_path(@booth, shift), - method: :delete, - class: "button hollow alert expanded" %> + <%= render Admin::TableActionsComponent.new(shift, + actions: [:destroy], + destroy_text: t("admin.poll_shifts.new.remove_shift") + ) %> <% end %> diff --git a/app/views/admin/site_customization/content_blocks/index.html.erb b/app/views/admin/site_customization/content_blocks/index.html.erb index 17328f8a2..33bdcf756 100644 --- a/app/views/admin/site_customization/content_blocks/index.html.erb +++ b/app/views/admin/site_customization/content_blocks/index.html.erb @@ -34,9 +34,10 @@ <%= link_to "#{content_block.name} (#{content_block.locale})", edit_admin_site_customization_content_block_path(content_block) %> <%= raw content_block.body %> - <%= link_to t("admin.site_customization.content_blocks.index.delete"), - admin_site_customization_content_block_path(content_block), - method: :delete, class: "button hollow alert" %> + <%= render Admin::TableActionsComponent.new(content_block, + actions: [:destroy], + destroy_text: t("admin.site_customization.content_blocks.index.delete") + ) %> <% end %> diff --git a/app/views/admin/site_customization/pages/index.html.erb b/app/views/admin/site_customization/pages/index.html.erb index d902086fc..d22efec9b 100644 --- a/app/views/admin/site_customization/pages/index.html.erb +++ b/app/views/admin/site_customization/pages/index.html.erb @@ -35,20 +35,17 @@ <%= I18n.l page.created_at, format: :short %> <%= t("admin.site_customization.pages.page.status_#{page.status}") %> -
- <% if page.status == "published" %> - <%= link_to t("admin.site_customization.pages.index.see_page"), - page.url, - target: "_blank", - class: "button hollow expanded" %> - <% end %> -
-
- <%= link_to t("admin.site_customization.pages.index.delete"), - admin_site_customization_page_path(page), - method: :delete, - class: "button hollow alert expanded" %> -
+ <% if page.status == "published" %> + <%= link_to t("admin.site_customization.pages.index.see_page"), + page.url, + target: "_blank", + class: "button hollow" %> + <% end %> + + <%= render Admin::TableActionsComponent.new(page, + actions: [:destroy], + destroy_text: t("admin.site_customization.pages.index.delete") + ) %> <% end %> diff --git a/app/views/admin/tags/index.html.erb b/app/views/admin/tags/index.html.erb index 26e58e040..d50d4283b 100644 --- a/app/views/admin/tags/index.html.erb +++ b/app/views/admin/tags/index.html.erb @@ -30,7 +30,7 @@ <% end %> - <%= link_to t("admin.tags.destroy"), admin_tag_path(tag), method: :delete, class: "button hollow alert" %> + <%= render Admin::TableActionsComponent.new(tag, actions: [:destroy], destroy_text: t("admin.tags.destroy")) %> <% end %> diff --git a/spec/components/admin/table_actions_component_spec.rb b/spec/components/admin/table_actions_component_spec.rb index d4161b2d2..b6d7c43cf 100644 --- a/spec/components/admin/table_actions_component_spec.rb +++ b/spec/components/admin/table_actions_component_spec.rb @@ -26,4 +26,13 @@ describe Admin::TableActionsComponent, type: :component do expect(page).not_to have_link "Edit" end end + + it "allows custom texts for actions" do + render_inline Admin::TableActionsComponent.new(record, edit_text: "change", destroy_text: "annihilate") + + expect(page).to have_link "annihilate" + expect(page).to have_link "change" + expect(page).not_to have_link "Delete" + expect(page).not_to have_link "Edit" + end end From b1f9ca4ad59c0898afaf7b3613914fbe2d26ef70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 9 Jun 2020 17:20:00 +0200 Subject: [PATCH 08/18] Allow custom URLs in links to actions There were a couple of cases where these links didn't point to the default actions. --- .../admin/table_actions_component.html.erb | 6 ++---- app/components/admin/table_actions_component.rb | 10 +++++++++- .../dashboard/actions/_default_actions.html.erb | 7 ++++--- app/views/admin/officials/index.html.erb | 7 +++++-- app/views/admin/officials/search.html.erb | 14 +++++--------- .../poll/questions/answers/documents.html.erb | 9 ++++----- .../poll/shifts/_search_officers_results.html.erb | 8 +++++--- .../admin/site_customization/cards/_card.html.erb | 12 +++--------- .../content_blocks/index.html.erb | 8 +++++--- .../site_customization/documents/index.html.erb | 9 ++++----- config/locales/en/admin.yml | 2 -- config/locales/es/admin.yml | 2 -- .../admin/table_actions_component_spec.rb | 7 +++++++ 13 files changed, 53 insertions(+), 48 deletions(-) diff --git a/app/components/admin/table_actions_component.html.erb b/app/components/admin/table_actions_component.html.erb index dac471bc8..dbb3a93df 100644 --- a/app/components/admin/table_actions_component.html.erb +++ b/app/components/admin/table_actions_component.html.erb @@ -1,12 +1,10 @@ <% if actions.include?(:edit) %> - <%= link_to edit_text, - admin_polymorphic_path(record, action: :edit), - class: "button hollow" %> + <%= link_to edit_text, edit_path, class: "button hollow" %> <% end %> <% if actions.include?(:destroy) %> <%= link_to destroy_text, - admin_polymorphic_path(record), + destroy_path, method: :delete, class: "button hollow alert", data: { confirm: t("admin.actions.confirm") } %> diff --git a/app/components/admin/table_actions_component.rb b/app/components/admin/table_actions_component.rb index b016cadc1..c2e078dee 100644 --- a/app/components/admin/table_actions_component.rb +++ b/app/components/admin/table_actions_component.rb @@ -1,7 +1,7 @@ class Admin::TableActionsComponent < ApplicationComponent attr_reader :record, :options - def initialize(record, **options) + def initialize(record = nil, **options) @record = record @options = options end @@ -16,7 +16,15 @@ class Admin::TableActionsComponent < ApplicationComponent options[:edit_text] || t("admin.actions.edit") end + def edit_path + options[:edit_path] || admin_polymorphic_path(record, action: :edit) + end + def destroy_text options[:destroy_text] || t("admin.actions.delete") end + + def destroy_path + options[:destroy_path] || admin_polymorphic_path(record) + end end diff --git a/app/views/admin/dashboard/actions/_default_actions.html.erb b/app/views/admin/dashboard/actions/_default_actions.html.erb index ea102bda5..05bff653e 100644 --- a/app/views/admin/dashboard/actions/_default_actions.html.erb +++ b/app/views/admin/dashboard/actions/_default_actions.html.erb @@ -5,9 +5,10 @@ <%= t("admin.dashboard.actions.index.active") %>   - <%= link_to t("admin.dashboard.actions.index.edit"), - admin_settings_path(anchor: "tab-proposals"), - class: "button hollow" %> + <%= render Admin::TableActionsComponent.new( + actions: [:edit], + edit_path: admin_settings_path(anchor: "tab-proposals"), + ) %> <% end %> diff --git a/app/views/admin/officials/index.html.erb b/app/views/admin/officials/index.html.erb index 3b1e2b7da..a9b76dcc1 100644 --- a/app/views/admin/officials/index.html.erb +++ b/app/views/admin/officials/index.html.erb @@ -28,8 +28,11 @@ <%= t("admin.officials.level_#{official.official_level}") %> - <%= link_to t("admin.officials.search.edit_official"), - edit_admin_official_path(official), class: "button hollow expanded" %> + <%= render Admin::TableActionsComponent.new( + actions: [:edit], + edit_path: edit_admin_official_path(official), + edit_text: t("admin.officials.search.edit_official") + ) %> <% end %> diff --git a/app/views/admin/officials/search.html.erb b/app/views/admin/officials/search.html.erb index 324c3f7fd..9aaf8c847 100644 --- a/app/views/admin/officials/search.html.erb +++ b/app/views/admin/officials/search.html.erb @@ -32,15 +32,11 @@ <%= t("admin.officials.level_#{user.official_level}") %> - <% if user.official? %> - <%= link_to t("admin.officials.search.edit_official"), - edit_admin_official_path(user), - class: "button hollow expanded" %> - <% else %> - <%= link_to t("admin.officials.search.make_official"), - edit_admin_official_path(user), - class: "button expanded" %> - <% end %> + <%= render Admin::TableActionsComponent.new( + actions: [:edit], + edit_path: edit_admin_official_path(user), + edit_text: user.official? ? t("admin.officials.search.edit_official") : t("admin.officials.search.make_official") + ) %> <% end %> diff --git a/app/views/admin/poll/questions/answers/documents.html.erb b/app/views/admin/poll/questions/answers/documents.html.erb index 6bef094c6..3f6ff5df7 100644 --- a/app/views/admin/poll/questions/answers/documents.html.erb +++ b/app/views/admin/poll/questions/answers/documents.html.erb @@ -42,11 +42,10 @@ rel: "nofollow", class: "button hollow" %> - <%= link_to t("admin.shared.delete"), - document_path(document), - method: :delete, - class: "button hollow alert", - data: { confirm: t("admin.actions.confirm") } %> + <%= render Admin::TableActionsComponent.new(document, + actions: [:destroy], + destroy_path: document_path(document) + ) %> <% end %> diff --git a/app/views/admin/poll/shifts/_search_officers_results.html.erb b/app/views/admin/poll/shifts/_search_officers_results.html.erb index b19db5e79..ec8cfc3bd 100644 --- a/app/views/admin/poll/shifts/_search_officers_results.html.erb +++ b/app/views/admin/poll/shifts/_search_officers_results.html.erb @@ -25,9 +25,11 @@ <%= user.email %> - <%= link_to t("admin.poll_shifts.new.edit_shifts"), - new_admin_booth_shift_path(officer_id: user.poll_officer.id), - class: "button hollow" %> + <%= render Admin::TableActionsComponent.new( + actions: [:edit], + edit_text: t("admin.poll_shifts.new.edit_shifts"), + edit_path: new_admin_booth_shift_path(officer_id: user.poll_officer.id) + ) %> <% end %> diff --git a/app/views/admin/site_customization/cards/_card.html.erb b/app/views/admin/site_customization/cards/_card.html.erb index 44a49f989..578b3c01a 100644 --- a/app/views/admin/site_customization/cards/_card.html.erb +++ b/app/views/admin/site_customization/cards/_card.html.erb @@ -17,14 +17,8 @@ <% end %> - <%= link_to t("admin.actions.edit"), - 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" %> + <%= render Admin::TableActionsComponent.new(card, + edit_path: edit_admin_widget_card_path(card, page_id: params[:page_id]) + ) %> diff --git a/app/views/admin/site_customization/content_blocks/index.html.erb b/app/views/admin/site_customization/content_blocks/index.html.erb index 33bdcf756..ef069e448 100644 --- a/app/views/admin/site_customization/content_blocks/index.html.erb +++ b/app/views/admin/site_customization/content_blocks/index.html.erb @@ -46,9 +46,11 @@ <%= link_to "#{content_block.heading.name} (#{content_block.locale})", admin_site_customization_edit_heading_content_block_path(content_block) %> <%= raw content_block.body %> - <%= link_to t("admin.site_customization.content_blocks.index.delete"), - admin_site_customization_delete_heading_content_block_path(content_block.id), - method: :delete, class: "button hollow alert" %> + <%= render Admin::TableActionsComponent.new( + actions: [:destroy], + destroy_text: t("admin.site_customization.content_blocks.index.delete"), + destroy_path: admin_site_customization_delete_heading_content_block_path(content_block) + ) %> <% end %> diff --git a/app/views/admin/site_customization/documents/index.html.erb b/app/views/admin/site_customization/documents/index.html.erb index a4bc3de65..c92462cb9 100644 --- a/app/views/admin/site_customization/documents/index.html.erb +++ b/app/views/admin/site_customization/documents/index.html.erb @@ -26,11 +26,10 @@ <%= link_to document.title, document.attachment.url, target: :blank %>
- <%= link_to t("admin.shared.delete"), - admin_site_customization_document_path(document), - method: :delete, - class: "button hollow alert", - data: { confirm: t("admin.actions.confirm") } %> + <%= render Admin::TableActionsComponent.new( + actions: [:destroy], + destroy_path: admin_site_customization_document_path(document) + ) %>
diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 6cbf33afe..cbe7f7a15 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -359,7 +359,6 @@ en: 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." create: Create resource or action - edit: Edit active: 'Yes' inactive: 'No' title: Resources and actions @@ -1289,7 +1288,6 @@ en: author: Author content: Content created_at: Created at - delete: Delete color_help: Hexadecimal format 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." diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 575518f56..d6d3d1563 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -359,7 +359,6 @@ es: 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." create: Crear recurso o acción - edit: Editar active: 'Si' inactive: 'No' title: Recursos y acciones @@ -1288,7 +1287,6 @@ es: author: Autor content: Contenido created_at: Fecha de creación - delete: Eliminar color_help: Formato hexadecimal 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." diff --git a/spec/components/admin/table_actions_component_spec.rb b/spec/components/admin/table_actions_component_spec.rb index b6d7c43cf..490b858ba 100644 --- a/spec/components/admin/table_actions_component_spec.rb +++ b/spec/components/admin/table_actions_component_spec.rb @@ -35,4 +35,11 @@ describe Admin::TableActionsComponent, type: :component do expect(page).not_to have_link "Delete" expect(page).not_to have_link "Edit" 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 From 497963817cf8323646bc9867cfc958e5d5797749 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 9 Jun 2020 17:32:32 +0200 Subject: [PATCH 09/18] Allow different confirmation texts in destroy link --- .../admin/table_actions_component.html.erb | 2 +- app/components/admin/table_actions_component.rb | 4 ++++ app/views/admin/poll/polls/_poll.html.erb | 13 +++---------- .../admin/table_actions_component_spec.rb | 6 ++++++ 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/app/components/admin/table_actions_component.html.erb b/app/components/admin/table_actions_component.html.erb index dbb3a93df..e2d859a9b 100644 --- a/app/components/admin/table_actions_component.html.erb +++ b/app/components/admin/table_actions_component.html.erb @@ -7,5 +7,5 @@ destroy_path, method: :delete, class: "button hollow alert", - data: { confirm: t("admin.actions.confirm") } %> + data: { confirm: destroy_confirmation } %> <% end %> diff --git a/app/components/admin/table_actions_component.rb b/app/components/admin/table_actions_component.rb index c2e078dee..740538ab0 100644 --- a/app/components/admin/table_actions_component.rb +++ b/app/components/admin/table_actions_component.rb @@ -27,4 +27,8 @@ class Admin::TableActionsComponent < ApplicationComponent def destroy_path options[:destroy_path] || admin_polymorphic_path(record) end + + def destroy_confirmation + options[:destroy_confirmation] || t("admin.actions.confirm") + end end diff --git a/app/views/admin/poll/polls/_poll.html.erb b/app/views/admin/poll/polls/_poll.html.erb index d112b671b..27f43affd 100644 --- a/app/views/admin/poll/polls/_poll.html.erb +++ b/app/views/admin/poll/polls/_poll.html.erb @@ -11,16 +11,9 @@ <%= l poll.ends_at.to_date %> - <%= link_to t("admin.actions.edit"), - edit_admin_poll_path(poll), - class: "button hollow" %> - - <%= link_to t("admin.actions.delete"), - admin_poll_path(poll), - method: :delete, - "data-confirm": t("admin.polls.destroy.alert"), - class: "button hollow alert" %> - + <%= render Admin::TableActionsComponent.new(poll, + destroy_confirmation: t("admin.polls.destroy.alert") + ) %> <%= link_to t("admin.actions.configure"), admin_poll_path(poll), class: "button hollow " %> diff --git a/spec/components/admin/table_actions_component_spec.rb b/spec/components/admin/table_actions_component_spec.rb index 490b858ba..7ccbf950f 100644 --- a/spec/components/admin/table_actions_component_spec.rb +++ b/spec/components/admin/table_actions_component_spec.rb @@ -42,4 +42,10 @@ describe Admin::TableActionsComponent, type: :component do expect(page).to have_link "Edit", href: "/myedit" expect(page).to have_link "Delete", href: "/mydestroy" end + + it "allows custom confirmation text" do + render_inline Admin::TableActionsComponent.new(record, destroy_confirmation: "Are you mad? Be careful!") + + expect(page).to have_css "a[data-confirm='Are you mad? Be careful!']" + end end From e3753b1ad9f8697242922da1414e3203ee81bec2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 11 Jun 2020 15:39:28 +0200 Subject: [PATCH 10/18] Allow custom options in links to actions Some links were using options like `remote: true`. --- .../admin/table_actions_component.html.erb | 8 ++------ app/components/admin/table_actions_component.rb | 12 ++++++++++++ .../booth_assignments/_booth_assignment.html.erb | 15 ++++++++------- .../admin/table_actions_component_spec.rb | 6 ++++++ 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/app/components/admin/table_actions_component.html.erb b/app/components/admin/table_actions_component.html.erb index e2d859a9b..2648f99dc 100644 --- a/app/components/admin/table_actions_component.html.erb +++ b/app/components/admin/table_actions_component.html.erb @@ -1,11 +1,7 @@ <% if actions.include?(:edit) %> - <%= link_to edit_text, edit_path, class: "button hollow" %> + <%= link_to edit_text, edit_path, edit_options %> <% end %> <% if actions.include?(:destroy) %> - <%= link_to destroy_text, - destroy_path, - method: :delete, - class: "button hollow alert", - data: { confirm: destroy_confirmation } %> + <%= link_to destroy_text, destroy_path, destroy_options %> <% end %> diff --git a/app/components/admin/table_actions_component.rb b/app/components/admin/table_actions_component.rb index 740538ab0..339dc4c6c 100644 --- a/app/components/admin/table_actions_component.rb +++ b/app/components/admin/table_actions_component.rb @@ -20,6 +20,10 @@ class Admin::TableActionsComponent < ApplicationComponent options[:edit_path] || admin_polymorphic_path(record, action: :edit) end + def edit_options + { class: "button hollow" }.merge(options[:edit_options] || {}) + end + def destroy_text options[:destroy_text] || t("admin.actions.delete") end @@ -28,6 +32,14 @@ class Admin::TableActionsComponent < ApplicationComponent options[:destroy_path] || admin_polymorphic_path(record) end + def destroy_options + { + method: :delete, + class: "button hollow alert", + data: { confirm: destroy_confirmation } + }.merge(options[:destroy_options] || {}) + end + def destroy_confirmation options[:destroy_confirmation] || t("admin.actions.confirm") end 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 8f159a264..1663ac00f 100644 --- a/app/views/admin/poll/booth_assignments/_booth_assignment.html.erb +++ b/app/views/admin/poll/booth_assignments/_booth_assignment.html.erb @@ -11,13 +11,14 @@ - <%= link_to t("admin.booth_assignments.manage.actions.unassign"), - admin_poll_booth_assignment_path(@poll, booth_assignment), - method: :delete, - remote: true, - title: t("admin.booth_assignments.manage.actions.unassign"), - class: "button hollow alert expanded", - data: (booth_assignment.shifts? ? { confirm: "#{t("admin.poll_booth_assignments.alert.shifts")}" } : nil) if !@poll.expired? %> + <% unless @poll.expired? %> + <%= render Admin::TableActionsComponent.new(booth_assignment, + actions: [:destroy], + destroy_text: t("admin.booth_assignments.manage.actions.unassign"), + destroy_confirmation: (booth_assignment.shifts? ? "#{t("admin.poll_booth_assignments.alert.shifts")}" : ""), + destroy_options: { remote: true } + ) %> + <% end %> <% else %> diff --git a/spec/components/admin/table_actions_component_spec.rb b/spec/components/admin/table_actions_component_spec.rb index 7ccbf950f..eba078a57 100644 --- a/spec/components/admin/table_actions_component_spec.rb +++ b/spec/components/admin/table_actions_component_spec.rb @@ -48,4 +48,10 @@ describe Admin::TableActionsComponent, type: :component do expect(page).to have_css "a[data-confirm='Are you mad? Be careful!']" end + + it "allows custom options" do + render_inline Admin::TableActionsComponent.new(record, edit_options: { id: "edit_me" }) + + expect(page).to have_css "a#edit_me" + end end From fb23df2e5be03ecbe2bf9199173c9ddf56e65aa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 12 Jun 2020 19:23:25 +0200 Subject: [PATCH 11/18] Allow additional links in table actions component This way we'll be able to make these links consistent. --- .../admin/table_actions_component.html.erb | 2 + .../admin/admin_notifications/index.html.erb | 17 ++++---- app/views/admin/audits/_audits.html.erb | 8 ++-- app/views/admin/budget_groups/index.html.erb | 8 ++-- app/views/admin/budgets/index.html.erb | 30 +++++--------- app/views/admin/newsletters/index.html.erb | 9 ++-- .../_booth_assignment.html.erb | 16 +++++--- app/views/admin/poll/booths/_booth.html.erb | 8 ++-- .../admin/poll/officers/_officer.html.erb | 8 ++-- app/views/admin/poll/officers/index.html.erb | 12 +++--- app/views/admin/poll/polls/_poll.html.erb | 9 ++-- .../admin/poll/polls/_questions.html.erb | 7 ++-- .../poll/polls/booth_assignments.html.erb | 12 +++--- .../questions/_successful_proposals.html.erb | 8 ++-- .../poll/questions/answers/documents.html.erb | 15 +++---- .../site_customization/pages/index.html.erb | 16 ++++---- app/views/admin/system_emails/index.html.erb | 41 +++++++++---------- config/locales/en/admin.yml | 5 --- config/locales/es/admin.yml | 5 --- .../admin/table_actions_component_spec.rb | 11 +++++ 20 files changed, 131 insertions(+), 116 deletions(-) diff --git a/app/components/admin/table_actions_component.html.erb b/app/components/admin/table_actions_component.html.erb index 2648f99dc..6a885a37a 100644 --- a/app/components/admin/table_actions_component.html.erb +++ b/app/components/admin/table_actions_component.html.erb @@ -1,3 +1,5 @@ +<%= content %> + <% if actions.include?(:edit) %> <%= link_to edit_text, edit_path, edit_options %> <% end %> diff --git a/app/views/admin/admin_notifications/index.html.erb b/app/views/admin/admin_notifications/index.html.erb index 48f132461..ad284ce11 100644 --- a/app/views/admin/admin_notifications/index.html.erb +++ b/app/views/admin/admin_notifications/index.html.erb @@ -30,14 +30,17 @@ <% if admin_notification.draft? %> - <%= render Admin::TableActionsComponent.new(admin_notification) %> - <%= link_to t("admin.admin_notifications.index.preview"), - admin_admin_notification_path(admin_notification), - class: "button" %> + <%= render Admin::TableActionsComponent.new(admin_notification) do |actions| %> + <%= actions.link_to t("admin.admin_notifications.index.preview"), + admin_admin_notification_path(admin_notification), + class: "button" %> + <% end %> <% else %> - <%= link_to t("admin.admin_notifications.index.view"), - admin_admin_notification_path(admin_notification), - class: "button" %> + <%= render Admin::TableActionsComponent.new(actions: []) do |actions| %> + <%= actions.link_to t("admin.admin_notifications.index.view"), + admin_admin_notification_path(admin_notification), + class: "button" %> + <% end %> <% end %> diff --git a/app/views/admin/audits/_audits.html.erb b/app/views/admin/audits/_audits.html.erb index ee1f3c030..684c246a3 100644 --- a/app/views/admin/audits/_audits.html.erb +++ b/app/views/admin/audits/_audits.html.erb @@ -34,9 +34,11 @@ <%= audit.user&.name %> - <%= link_to t("shared.show"), - admin_polymorphic_path(audit), - class: "button hollow primary" %> + <%= render Admin::TableActionsComponent.new(actions: []) do |actions| %> + <%= actions.link_to t("shared.show"), + admin_polymorphic_path(audit), + class: "button hollow primary" %> + <% end %> <% end %> diff --git a/app/views/admin/budget_groups/index.html.erb b/app/views/admin/budget_groups/index.html.erb index 3634e4bdc..023cdae4a 100644 --- a/app/views/admin/budget_groups/index.html.erb +++ b/app/views/admin/budget_groups/index.html.erb @@ -16,7 +16,6 @@ <%= t("admin.budget_groups.name") %> <%= Budget::Group.human_attribute_name(:max_votable_headings) %> <%= t("admin.budget_groups.headings_name") %> - <%= t("admin.budget_groups.headings_edit") %> <%= t("admin.actions.actions") %> @@ -26,10 +25,11 @@ <%= link_to group.name, edit_admin_budget_group_path(@budget, group) %> <%= group.max_votable_headings %> <%= group.headings.count %> - <%= link_to t("admin.budget_groups.headings_manage"), - admin_budget_group_headings_path(@budget, group) %> - <%= render Admin::TableActionsComponent.new(group) %> + <%= render Admin::TableActionsComponent.new(group) do |actions| %> + <%= actions.link_to t("admin.budget_groups.headings_manage"), + admin_budget_group_headings_path(@budget, group) %> + <% end %> <% end %> diff --git a/app/views/admin/budgets/index.html.erb b/app/views/admin/budgets/index.html.erb index c63ee4789..8f89a02bc 100644 --- a/app/views/admin/budgets/index.html.erb +++ b/app/views/admin/budgets/index.html.erb @@ -14,10 +14,7 @@ <%= t("admin.budgets.index.table_name") %> <%= t("admin.budgets.index.table_phase") %> - <%= t("admin.budgets.index.table_investments") %> - <%= t("admin.budgets.index.table_edit_groups") %> - <%= t("admin.budgets.index.table_edit_budget") %> - <%= t("admin.budgets.index.table_admin_ballots") %> + <%= t("admin.actions.actions") %> @@ -30,21 +27,16 @@ <%= t("budgets.phase.#{budget.phase}") %> - <%= link_to t("admin.budgets.index.budget_investments"), - admin_budget_budget_investments_path(budget_id: budget.id), - class: "button hollow medium" %> - - - <%= link_to t("admin.budgets.index.edit_groups"), admin_budget_groups_path(budget) %> - - - <%= link_to t("admin.budgets.index.edit_budget"), edit_admin_budget_path(budget) %> - - - <% if budget.poll.present? %> - <%= link_to t("admin.budgets.index.admin_ballots"), admin_poll_booth_assignments_path(budget.poll) %> - <% else %> - <%= link_to_create_budget_poll(budget) %> + <%= render Admin::TableActionsComponent.new(budget, actions: [:edit], edit_text: t("admin.budgets.index.edit_budget")) do |actions| %> + <%= actions.link_to t("admin.budgets.index.budget_investments"), + admin_budget_budget_investments_path(budget_id: budget.id), + class: "button hollow medium" %> + <%= actions.link_to t("admin.budgets.index.edit_groups"), admin_budget_groups_path(budget) %> + <% if budget.poll.present? %> + <%= actions.link_to t("admin.budgets.index.admin_ballots"), admin_poll_booth_assignments_path(budget.poll) %> + <% else %> + <%= link_to_create_budget_poll(budget) %> + <% end %> <% end %> diff --git a/app/views/admin/newsletters/index.html.erb b/app/views/admin/newsletters/index.html.erb index f9cf9b604..a86d704c3 100644 --- a/app/views/admin/newsletters/index.html.erb +++ b/app/views/admin/newsletters/index.html.erb @@ -29,10 +29,11 @@ <% end %> - <%= render Admin::TableActionsComponent.new(newsletter) %> - - <%= link_to t("admin.newsletters.index.preview"), admin_newsletter_path(newsletter), - class: "button" %> + <%= render Admin::TableActionsComponent.new(newsletter) do |actions| %> + <%= actions.link_to t("admin.newsletters.index.preview"), + admin_newsletter_path(newsletter), + class: "button" %> + <% end %> <% end %> 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 1663ac00f..acbddc7fa 100644 --- a/app/views/admin/poll/booth_assignments/_booth_assignment.html.erb +++ b/app/views/admin/poll/booth_assignments/_booth_assignment.html.erb @@ -25,11 +25,15 @@ <%= t("admin.booth_assignments.manage.status.unassigned") %> - <%= link_to t("admin.booth_assignments.manage.actions.assign"), - admin_poll_booth_assignments_path(@poll, booth_id: booth.id), - method: :post, - remote: true, - title: t("admin.booth_assignments.manage.actions.assign"), - class: "button hollow expanded" if !@poll.expired? %> + <% 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, + title: t("admin.booth_assignments.manage.actions.assign"), + class: "button hollow expanded" %> + <% end %> + <% end %> <% end %> diff --git a/app/views/admin/poll/booths/_booth.html.erb b/app/views/admin/poll/booths/_booth.html.erb index bca880e5d..0e02fa36d 100644 --- a/app/views/admin/poll/booths/_booth.html.erb +++ b/app/views/admin/poll/booths/_booth.html.erb @@ -7,9 +7,11 @@ <% if controller_name == "shifts" || controller_name == "booths" && action_name == "available" %> - <%= link_to t("admin.booths.booth.shifts"), - new_admin_booth_shift_path(booth), - class: "button hollow" %> + <%= render Admin::TableActionsComponent.new(actions: []) do |actions| %> + <%= actions.link_to t("admin.booths.booth.shifts"), + new_admin_booth_shift_path(booth), + class: "button hollow" %> + <% end %> <% else %> <%= render Admin::TableActionsComponent.new(booth, actions: [:edit], diff --git a/app/views/admin/poll/officers/_officer.html.erb b/app/views/admin/poll/officers/_officer.html.erb index 45e516594..dd3202e7d 100644 --- a/app/views/admin/poll/officers/_officer.html.erb +++ b/app/views/admin/poll/officers/_officer.html.erb @@ -21,9 +21,11 @@ destroy_text: t("admin.poll_officers.officer.delete") ) %> <% else %> - <%= link_to t("admin.poll_officers.officer.add"), { controller: "admin/poll/officers", action: :create, user_id: officer.user_id }, - method: :post, - class: "button success expanded" %> + <%= render Admin::TableActionsComponent.new(actions: []) do |actions| %> + <%= actions.link_to t("admin.poll_officers.officer.add"), { controller: "admin/poll/officers", action: :create, user_id: officer.user_id }, + method: :post, + class: "button success expanded" %> + <% end %> <% end %> diff --git a/app/views/admin/poll/officers/index.html.erb b/app/views/admin/poll/officers/index.html.erb index 02b67492f..1e2b4e144 100644 --- a/app/views/admin/poll/officers/index.html.erb +++ b/app/views/admin/poll/officers/index.html.erb @@ -35,11 +35,13 @@ destroy_text: t("admin.poll_officers.officer.delete") ) %> <% else %> - <%= link_to t("admin.poll_officers.officer.add"), - { controller: "admin/poll/officers", action: :create, - user_id: officer.user_id }, - method: :post, - class: "button success expanded" %> + <%= render Admin::TableActionsComponent.new(actions: []) do |actions| %> + <%= actions.link_to t("admin.poll_officers.officer.add"), + { controller: "admin/poll/officers", action: :create, + user_id: officer.user_id }, + method: :post, + class: "button success expanded" %> + <% end %> <% end %> diff --git a/app/views/admin/poll/polls/_poll.html.erb b/app/views/admin/poll/polls/_poll.html.erb index 27f43affd..33189750b 100644 --- a/app/views/admin/poll/polls/_poll.html.erb +++ b/app/views/admin/poll/polls/_poll.html.erb @@ -13,9 +13,10 @@ <%= render Admin::TableActionsComponent.new(poll, destroy_confirmation: t("admin.polls.destroy.alert") - ) %> - <%= link_to t("admin.actions.configure"), - admin_poll_path(poll), - class: "button hollow " %> + ) do |actions| %> + <%= actions.link_to t("admin.actions.configure"), + admin_poll_path(poll), + class: "button hollow " %> + <% end %> diff --git a/app/views/admin/poll/polls/_questions.html.erb b/app/views/admin/poll/polls/_questions.html.erb index 59964d6e6..79e57748a 100644 --- a/app/views/admin/poll/polls/_questions.html.erb +++ b/app/views/admin/poll/polls/_questions.html.erb @@ -30,9 +30,10 @@ <% end %> - <%= link_to t("admin.polls.show.edit_answers"), admin_question_path(question), - class: "button hollow" %> - <%= render Admin::TableActionsComponent.new(question) %> + <%= render Admin::TableActionsComponent.new(question) do |actions| %> + <%= actions.link_to t("admin.polls.show.edit_answers"), admin_question_path(question), + class: "button hollow" %> + <% end %> <% end %> diff --git a/app/views/admin/poll/polls/booth_assignments.html.erb b/app/views/admin/poll/polls/booth_assignments.html.erb index 66814cefc..0816de134 100644 --- a/app/views/admin/poll/polls/booth_assignments.html.erb +++ b/app/views/admin/poll/polls/booth_assignments.html.erb @@ -5,7 +5,7 @@ <%= t("admin.polls.index.name") %> <%= t("admin.polls.index.dates") %> - <%= t("admin.actions.actions") %> + <%= t("admin.actions.actions") %> <% @polls.each do |poll| %> @@ -16,10 +16,12 @@ <%= l poll.starts_at.to_date %> - <%= l poll.ends_at.to_date %> - - <%= link_to t("admin.booth_assignments.manage_assignments"), - manage_admin_poll_booth_assignments_path(poll), - class: "button hollow" %> + + <%= render Admin::TableActionsComponent.new(actions: []) do |actions| %> + <%= actions.link_to t("admin.booth_assignments.manage_assignments"), + manage_admin_poll_booth_assignments_path(poll), + class: "button hollow" %> + <% end %> <% end %> diff --git a/app/views/admin/poll/questions/_successful_proposals.html.erb b/app/views/admin/poll/questions/_successful_proposals.html.erb index f58c84d25..88bd6e477 100644 --- a/app/views/admin/poll/questions/_successful_proposals.html.erb +++ b/app/views/admin/poll/questions/_successful_proposals.html.erb @@ -15,9 +15,11 @@

- <%= link_to t("admin.questions.index.create_question"), - new_admin_question_path(proposal_id: proposal.id), - class: "button hollow" %> + <%= render Admin::TableActionsComponent.new(actions: []) do |actions| %> + <%= actions.link_to t("admin.questions.index.create_question"), + new_admin_question_path(proposal_id: proposal.id), + class: "button hollow" %> + <% end %> <% end %> diff --git a/app/views/admin/poll/questions/answers/documents.html.erb b/app/views/admin/poll/questions/answers/documents.html.erb index 3f6ff5df7..5ec767388 100644 --- a/app/views/admin/poll/questions/answers/documents.html.erb +++ b/app/views/admin/poll/questions/answers/documents.html.erb @@ -36,16 +36,17 @@ <%= link_to document.title, document.attachment.url %> - <%= link_to t("documents.buttons.download_document"), - document.attachment.url, - target: "_blank", - rel: "nofollow", - class: "button hollow" %> - <%= render Admin::TableActionsComponent.new(document, actions: [:destroy], destroy_path: document_path(document) - ) %> + ) do |actions| %> + <%= actions.link_to t("documents.buttons.download_document"), + document.attachment.url, + target: "_blank", + rel: "nofollow", + class: "button hollow" %> + + <% end %> <% end %> diff --git a/app/views/admin/site_customization/pages/index.html.erb b/app/views/admin/site_customization/pages/index.html.erb index d22efec9b..359ba932f 100644 --- a/app/views/admin/site_customization/pages/index.html.erb +++ b/app/views/admin/site_customization/pages/index.html.erb @@ -35,17 +35,17 @@ <%= I18n.l page.created_at, format: :short %> <%= t("admin.site_customization.pages.page.status_#{page.status}") %> - <% if page.status == "published" %> - <%= link_to t("admin.site_customization.pages.index.see_page"), - page.url, - target: "_blank", - class: "button hollow" %> - <% end %> - <%= render Admin::TableActionsComponent.new(page, actions: [:destroy], destroy_text: t("admin.site_customization.pages.index.delete") - ) %> + ) do |actions| %> + <% if page.status == "published" %> + <%= actions.link_to t("admin.site_customization.pages.index.see_page"), + page.url, + target: "_blank", + class: "button hollow" %> + <% end %> + <% end %> <% end %> diff --git a/app/views/admin/system_emails/index.html.erb b/app/views/admin/system_emails/index.html.erb index 3e8cabc3b..c70793954 100644 --- a/app/views/admin/system_emails/index.html.erb +++ b/app/views/admin/system_emails/index.html.erb @@ -18,32 +18,29 @@ <%= t("admin.system_emails.#{system_email_title}.description") %> - <% if system_email_actions.include?("view") %> -
- <%= link_to t("admin.shared.view"), admin_system_email_view_path(system_email_title), - class: "button hollow expanded" %> -
- <% end %> - <% if system_email_actions.include?("preview_pending") %> -
- <%= link_to t("admin.system_emails.preview_pending.action"), - admin_system_email_preview_pending_path(system_email_title), - class: "button expanded" %> -
-
- <%= link_to t("admin.system_emails.preview_pending.send_pending"), - admin_system_email_send_pending_path(system_email_title), - class: "button success expanded", - method: :put %> -
- <% end %> - <% if system_email_actions.include?("edit_info") %> -
+ <%= render Admin::TableActionsComponent.new(actions: []) do |actions| %> + <% if system_email_actions.include?("view") %> + <%= actions.link_to t("admin.shared.view"), + admin_system_email_view_path(system_email_title), + class: "button hollow" %> + <% end %> + + <% if system_email_actions.include?("preview_pending") %> + <%= actions.link_to t("admin.system_emails.preview_pending.action"), + admin_system_email_preview_pending_path(system_email_title), + class: "button" %> + <%= actions.link_to t("admin.system_emails.preview_pending.send_pending"), + admin_system_email_send_pending_path(system_email_title), + class: "button success", + method: :put %> + <% end %> + + <% if system_email_actions.include?("edit_info") %>

<%= t("admin.system_emails.edit_info") %>
<%= "app/views/mailer/#{system_email_title}.html.erb" %>

-
+ <% end %> <% end %> diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index cbe7f7a15..a7960eee4 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -72,10 +72,6 @@ en: budget_investments: Manage projects table_name: Name table_phase: Phase - table_investments: Investments - table_edit_groups: Headings groups - table_edit_budget: Edit - table_admin_ballots: Ballots edit_groups: Edit headings groups edit_budget: Edit budget admin_ballots: Admin ballots @@ -117,7 +113,6 @@ en: budget_groups: name: "Name" headings_name: "Headings" - headings_edit: "Edit Headings" headings_manage: "Manage headings" no_groups: "There are no groups." amount: diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index d6d3d1563..586cc1b70 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -72,10 +72,6 @@ es: budget_investments: Gestionar proyectos de gasto table_name: Nombre table_phase: Fase - table_investments: Proyectos de gasto - table_edit_groups: Grupos de partidas - table_edit_budget: Editar - table_admin_ballots: Urnas edit_groups: Editar grupos de partidas edit_budget: Editar presupuesto admin_ballots: Gestionar urnas @@ -117,7 +113,6 @@ es: budget_groups: name: "Nombre" headings_name: "Partidas" - headings_edit: "Editar Partidas" headings_manage: "Gestionar partidas" no_groups: "No hay grupos." amount: diff --git a/spec/components/admin/table_actions_component_spec.rb b/spec/components/admin/table_actions_component_spec.rb index eba078a57..c4630c645 100644 --- a/spec/components/admin/table_actions_component_spec.rb +++ b/spec/components/admin/table_actions_component_spec.rb @@ -54,4 +54,15 @@ describe Admin::TableActionsComponent, type: :component do expect(page).to have_css "a#edit_me" end + + it "allows custom content" do + render_inline Admin::TableActionsComponent.new(record) do + "Main".html_safe + end + + expect(page).to have_css "a", count: 3 + expect(page).to have_link "Main", href: "/" + expect(page).to have_link "Edit" + expect(page).to have_link "Delete" + end end From 64b0cc741b63b0496b87246ed437a7dc6a965d3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sun, 5 Jul 2020 12:11:38 +0200 Subject: [PATCH 12/18] Improve table actions layout In the past we were using some
tags surrounding table action links in order to guarantee these links wouldn't be wider that their cell's space and wouldn't expand over two lines. However, while these links didn't expand over two lines, at certain resolutions the width of their text exceeded the width of the links, causing part of the text to be outside their borders. This behavior was also inconsistent: some tables had these
tags, and some tables didn't. Since we've now introduced the table actions component, the code is more consistent and we're getting rid of these
tags. So now we're again facing the issue where links could expand over two lines. Using a flex layout solves this issue and considerably improves the layout at lower resolutions. --- app/assets/stylesheets/admin.scss | 12 ++---------- app/assets/stylesheets/admin/table_actions.scss | 12 ++++++++++++ app/assets/stylesheets/application.scss | 1 + .../admin/table_actions_component.html.erb | 16 +++++++++------- app/views/admin/administrators/search.html.erb | 2 +- .../dashboard/actions/_default_actions.html.erb | 2 +- app/views/admin/dashboard/actions/index.html.erb | 4 ++-- .../dashboard/administrator_tasks/index.html.erb | 4 ++-- app/views/admin/poll/booths/_booth.html.erb | 2 +- app/views/admin/poll/booths/index.html.erb | 2 +- .../poll/questions/answers/documents.html.erb | 4 ++-- .../poll/questions/answers/videos/index.html.erb | 6 ++---- .../shifts/_search_officers_results.html.erb | 6 ++---- 13 files changed, 38 insertions(+), 35 deletions(-) create mode 100644 app/assets/stylesheets/admin/table_actions.scss diff --git a/app/assets/stylesheets/admin.scss b/app/assets/stylesheets/admin.scss index 2803ccf86..fad0f439a 100644 --- a/app/assets/stylesheets/admin.scss +++ b/app/assets/stylesheets/admin.scss @@ -236,16 +236,8 @@ $sidebar-active: #f4fcd0; table-layout: fixed; } - [type="submit"] ~ a, - a ~ a { - margin-left: 0; - margin-right: 0; - margin-top: $line-height / 2; - - @include breakpoint(medium) { - margin-left: $line-height / 2; - margin-top: 0; - } + [type="submit"] ~ a { + margin-left: $line-height / 2; } } diff --git a/app/assets/stylesheets/admin/table_actions.scss b/app/assets/stylesheets/admin/table_actions.scss new file mode 100644 index 000000000..9d782a4be --- /dev/null +++ b/app/assets/stylesheets/admin/table_actions.scss @@ -0,0 +1,12 @@ +.admin .table-actions { + align-items: baseline; + display: flex; + + > :not(:first-child) { + margin-left: $line-height / 2; + } + + > p { + align-self: flex-start; + } +} diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 5158c724d..0e4d08318 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -27,3 +27,4 @@ @import "jquery-ui/sortable"; @import "leaflet"; @import "sticky_overrides"; +@import "admin/*"; diff --git a/app/components/admin/table_actions_component.html.erb b/app/components/admin/table_actions_component.html.erb index 6a885a37a..b5430cf8a 100644 --- a/app/components/admin/table_actions_component.html.erb +++ b/app/components/admin/table_actions_component.html.erb @@ -1,9 +1,11 @@ -<%= content %> +
+ <%= content %> -<% if actions.include?(:edit) %> - <%= link_to edit_text, edit_path, edit_options %> -<% end %> + <% if actions.include?(:edit) %> + <%= link_to edit_text, edit_path, edit_options %> + <% end %> -<% if actions.include?(:destroy) %> - <%= link_to destroy_text, destroy_path, destroy_options %> -<% end %> + <% if actions.include?(:destroy) %> + <%= link_to destroy_text, destroy_path, destroy_options %> + <% end %> +
diff --git a/app/views/admin/administrators/search.html.erb b/app/views/admin/administrators/search.html.erb index 671b6efb2..03591a1ce 100644 --- a/app/views/admin/administrators/search.html.erb +++ b/app/views/admin/administrators/search.html.erb @@ -17,7 +17,7 @@ <%= user.name %> <%= user.email %> - + <% if user.administrator? && user.administrator.persisted? %> <%= render Admin::TableActionsComponent.new(user.administrator, actions: [:destroy]) %> <% else %> diff --git a/app/views/admin/dashboard/actions/_default_actions.html.erb b/app/views/admin/dashboard/actions/_default_actions.html.erb index 05bff653e..896c02a7e 100644 --- a/app/views/admin/dashboard/actions/_default_actions.html.erb +++ b/app/views/admin/dashboard/actions/_default_actions.html.erb @@ -4,7 +4,7 @@ <%= Dashboard::Action.human_attribute_name("action_type_resource") %> <%= t("admin.dashboard.actions.index.active") %>   - + <%= render Admin::TableActionsComponent.new( actions: [:edit], edit_path: admin_settings_path(anchor: "tab-proposals"), diff --git a/app/views/admin/dashboard/actions/index.html.erb b/app/views/admin/dashboard/actions/index.html.erb index c6aee28f1..2e32b97d6 100644 --- a/app/views/admin/dashboard/actions/index.html.erb +++ b/app/views/admin/dashboard/actions/index.html.erb @@ -17,7 +17,7 @@ <%= t("admin.dashboard.actions.index.day_offset") %> <%= t("admin.dashboard.actions.index.required_supports") %> <%= t("admin.dashboard.actions.index.order") %> - <%= t("admin.actions.actions") %> + <%= t("admin.actions.actions") %> @@ -31,7 +31,7 @@ <%= number_with_delimiter(action.day_offset, delimiter: ".") %> <%= number_with_delimiter(action.required_supports, delimiter: ".") %> <%= action.order %> - + <%= render Admin::TableActionsComponent.new(action) %> diff --git a/app/views/admin/dashboard/administrator_tasks/index.html.erb b/app/views/admin/dashboard/administrator_tasks/index.html.erb index 93cebb001..ff30b6d37 100644 --- a/app/views/admin/dashboard/administrator_tasks/index.html.erb +++ b/app/views/admin/dashboard/administrator_tasks/index.html.erb @@ -10,7 +10,7 @@ <%= t("admin.dashboard.administrator_tasks.index.source") %> <%= t("admin.dashboard.administrator_tasks.index.resource") %> - <%= t("admin.actions.actions") %> + <%= t("admin.actions.actions") %> @@ -23,7 +23,7 @@ <%= task.source.action.title %> - + <% unless task.executed_at? %> <%= render Admin::TableActionsComponent.new(task, actions: [:edit], diff --git a/app/views/admin/poll/booths/_booth.html.erb b/app/views/admin/poll/booths/_booth.html.erb index 0e02fa36d..8814016ed 100644 --- a/app/views/admin/poll/booths/_booth.html.erb +++ b/app/views/admin/poll/booths/_booth.html.erb @@ -5,7 +5,7 @@ <%= booth.location %> - + <% 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"), diff --git a/app/views/admin/poll/booths/index.html.erb b/app/views/admin/poll/booths/index.html.erb index 23ad5667f..415515653 100644 --- a/app/views/admin/poll/booths/index.html.erb +++ b/app/views/admin/poll/booths/index.html.erb @@ -18,7 +18,7 @@ <%= t("admin.booths.index.name") %> <%= t("admin.booths.index.location") %> - <%= t("admin.actions.actions") %> + <%= t("admin.actions.actions") %> <% @booths.each do |booth| %> diff --git a/app/views/admin/poll/questions/answers/documents.html.erb b/app/views/admin/poll/questions/answers/documents.html.erb index 5ec767388..0a1d66573 100644 --- a/app/views/admin/poll/questions/answers/documents.html.erb +++ b/app/views/admin/poll/questions/answers/documents.html.erb @@ -27,7 +27,7 @@ - + <% @answer.documents.each do |document| %> @@ -35,7 +35,7 @@ - - + @@ -28,7 +26,7 @@ - diff --git a/app/views/admin/poll/shifts/_search_officers_results.html.erb b/app/views/admin/poll/shifts/_search_officers_results.html.erb index ec8cfc3bd..27280e2c9 100644 --- a/app/views/admin/poll/shifts/_search_officers_results.html.erb +++ b/app/views/admin/poll/shifts/_search_officers_results.html.erb @@ -10,9 +10,7 @@ - + @@ -24,7 +22,7 @@ - <% end %> diff --git a/app/views/admin/hidden_comments/index.html.erb b/app/views/admin/hidden_comments/index.html.erb index 0744661b0..d52f4f68a 100644 --- a/app/views/admin/hidden_comments/index.html.erb +++ b/app/views/admin/hidden_comments/index.html.erb @@ -23,17 +23,7 @@ <% end %> <% end %> diff --git a/app/views/admin/hidden_debates/index.html.erb b/app/views/admin/hidden_debates/index.html.erb index 27473db52..954ecf854 100644 --- a/app/views/admin/hidden_debates/index.html.erb +++ b/app/views/admin/hidden_debates/index.html.erb @@ -24,17 +24,7 @@ <% end %> diff --git a/app/views/admin/hidden_proposal_notifications/index.html.erb b/app/views/admin/hidden_proposal_notifications/index.html.erb index 61522cf88..5b17b7dce 100644 --- a/app/views/admin/hidden_proposal_notifications/index.html.erb +++ b/app/views/admin/hidden_proposal_notifications/index.html.erb @@ -24,17 +24,7 @@ <% end %> diff --git a/app/views/admin/hidden_proposals/index.html.erb b/app/views/admin/hidden_proposals/index.html.erb index bf8a2ff6a..b9502d7bc 100644 --- a/app/views/admin/hidden_proposals/index.html.erb +++ b/app/views/admin/hidden_proposals/index.html.erb @@ -28,17 +28,7 @@ <% end %> diff --git a/app/views/admin/hidden_users/index.html.erb b/app/views/admin/hidden_users/index.html.erb index d02a42e0b..bb2387e9f 100644 --- a/app/views/admin/hidden_users/index.html.erb +++ b/app/views/admin/hidden_users/index.html.erb @@ -19,17 +19,7 @@ <% end %> diff --git a/spec/components/admin/hidden_table_actions_component_spec.rb b/spec/components/admin/hidden_table_actions_component_spec.rb new file mode 100644 index 000000000..f439cf06c --- /dev/null +++ b/spec/components/admin/hidden_table_actions_component_spec.rb @@ -0,0 +1,14 @@ +require "rails_helper" + +describe Admin::HiddenTableActionsComponent, type: :component do + let(:record) { create(:user) } + let(:component) { Admin::HiddenTableActionsComponent.new(record) } + + it "renders links to restore and confirm hide" do + render_inline component + + expect(page).to have_css "a", count: 2 + expect(page).to have_css "a[href*='restore'][data-method='put']", text: "Restore" + expect(page).to have_css "a[href*='confirm_hide'][data-method='put']", text: "Confirm moderation" + end +end From 1537f25739ab89b4ccc83b9c0414d04bb6fece5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sun, 14 Jun 2020 22:01:13 +0200 Subject: [PATCH 14/18] Extract component for organization actions We remove duplication by doing so, and now we only need to add the call do render Admin::TableActionsComponent once. --- .../table_actions_component.html.erb | 13 ++++++ .../organizations/table_actions_component.rb | 18 ++++++++ app/views/admin/organizations/index.html.erb | 12 +---- app/views/admin/organizations/search.html.erb | 12 +---- .../table_actions_component_spec.rb | 46 +++++++++++++++++++ 5 files changed, 79 insertions(+), 22 deletions(-) create mode 100644 app/components/admin/organizations/table_actions_component.html.erb create mode 100644 app/components/admin/organizations/table_actions_component.rb create mode 100644 spec/components/admin/organizations/table_actions_component_spec.rb diff --git a/app/components/admin/organizations/table_actions_component.html.erb b/app/components/admin/organizations/table_actions_component.html.erb new file mode 100644 index 000000000..5c0b565ab --- /dev/null +++ b/app/components/admin/organizations/table_actions_component.html.erb @@ -0,0 +1,13 @@ +<%= render Admin::TableActionsComponent.new(actions: []) do %> + <% if can_verify? %> + <%= link_to t("admin.organizations.index.verify"), + verify_admin_organization_path(organization, request.query_parameters), + method: :put, class: "button success small-5" %> + <% end %> + + <% if can_reject? %> + <%= link_to t("admin.organizations.index.reject"), + reject_admin_organization_path(organization, request.query_parameters), + method: :put, class: "button hollow alert small-5" %> + <% end %> +<% end %> diff --git a/app/components/admin/organizations/table_actions_component.rb b/app/components/admin/organizations/table_actions_component.rb new file mode 100644 index 000000000..d0b29708f --- /dev/null +++ b/app/components/admin/organizations/table_actions_component.rb @@ -0,0 +1,18 @@ +class Admin::Organizations::TableActionsComponent < ApplicationComponent + delegate :can?, to: :controller + attr_reader :organization + + def initialize(organization) + @organization = organization + end + + private + + def can_verify? + can? :verify, organization + end + + def can_reject? + can? :reject, organization + end +end diff --git a/app/views/admin/organizations/index.html.erb b/app/views/admin/organizations/index.html.erb index 7970fde46..b1110488a 100644 --- a/app/views/admin/organizations/index.html.erb +++ b/app/views/admin/organizations/index.html.erb @@ -48,17 +48,7 @@ <% end %> <% end %> diff --git a/app/views/admin/organizations/search.html.erb b/app/views/admin/organizations/search.html.erb index e3d0564cf..2e534d052 100644 --- a/app/views/admin/organizations/search.html.erb +++ b/app/views/admin/organizations/search.html.erb @@ -44,17 +44,7 @@ <% end %> <% end %> diff --git a/spec/components/admin/organizations/table_actions_component_spec.rb b/spec/components/admin/organizations/table_actions_component_spec.rb new file mode 100644 index 000000000..66ab51cf2 --- /dev/null +++ b/spec/components/admin/organizations/table_actions_component_spec.rb @@ -0,0 +1,46 @@ +require "rails_helper" + +describe Admin::Organizations::TableActionsComponent, type: :component do + let(:organization) { create(:organization) } + let(:component) { Admin::Organizations::TableActionsComponent.new(organization) } + + it "renders links to verify and reject when it can" do + allow(component).to receive(:can_verify?).and_return(true) + allow(component).to receive(:can_reject?).and_return(true) + + render_inline component + + expect(page).to have_css "a", count: 2 + expect(page).to have_css "a[href*='verify'][data-method='put']", text: "Verify" + expect(page).to have_css "a[href*='reject'][data-method='put']", text: "Reject" + end + + it "renders link to verify when it cannot reject" do + allow(component).to receive(:can_verify?).and_return(true) + allow(component).to receive(:can_reject?).and_return(false) + + render_inline component + + expect(page).to have_css "a", count: 1 + expect(page).to have_link "Verify" + end + + it "renders link to reject when it cannot verify" do + allow(component).to receive(:can_verify?).and_return(false) + allow(component).to receive(:can_reject?).and_return(true) + + render_inline component + + expect(page).to have_css "a", count: 1 + expect(page).to have_link "Reject" + end + + it "does not render any actions when it cannot verify nor reject" do + allow(component).to receive(:can_verify?).and_return(false) + allow(component).to receive(:can_reject?).and_return(false) + + render_inline component + + expect(page).not_to have_css "a" + end +end From 02e27e13dcc561590effa95001aee503da2378c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 30 Jun 2020 19:08:12 +0200 Subject: [PATCH 15/18] Extract component for budget actions We can omit passing a parameter to the helper method thanks to that, and we group related code together. --- .../budgets/table_actions_component.html.erb | 11 +++++++ .../admin/budgets/table_actions_component.rb | 21 +++++++++++++ app/helpers/budgets_helper.rb | 12 -------- app/views/admin/budgets/index.html.erb | 12 +------- .../budgets/table_actions_component_spec.rb | 30 +++++++++++++++++++ 5 files changed, 63 insertions(+), 23 deletions(-) create mode 100644 app/components/admin/budgets/table_actions_component.html.erb create mode 100644 app/components/admin/budgets/table_actions_component.rb create mode 100644 spec/components/admin/budgets/table_actions_component_spec.rb diff --git a/app/components/admin/budgets/table_actions_component.html.erb b/app/components/admin/budgets/table_actions_component.html.erb new file mode 100644 index 000000000..9540163e0 --- /dev/null +++ b/app/components/admin/budgets/table_actions_component.html.erb @@ -0,0 +1,11 @@ +<%= render Admin::TableActionsComponent.new(budget, actions: [:edit], edit_text: t("admin.budgets.index.edit_budget")) do %> + <%= link_to t("admin.budgets.index.budget_investments"), + admin_budget_budget_investments_path(budget_id: budget.id), + class: "button hollow medium" %> + <%= link_to t("admin.budgets.index.edit_groups"), admin_budget_groups_path(budget) %> + <% if budget.poll.present? %> + <%= link_to t("admin.budgets.index.admin_ballots"), admin_poll_booth_assignments_path(budget.poll) %> + <% else %> + <%= link_to_create_budget_poll %> + <% end %> +<% end %> diff --git a/app/components/admin/budgets/table_actions_component.rb b/app/components/admin/budgets/table_actions_component.rb new file mode 100644 index 000000000..75dab1850 --- /dev/null +++ b/app/components/admin/budgets/table_actions_component.rb @@ -0,0 +1,21 @@ +class Admin::Budgets::TableActionsComponent < ApplicationComponent + attr_reader :budget + + def initialize(budget) + @budget = budget + end + + private + + def link_to_create_budget_poll + 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 }), + method: :post + end +end diff --git a/app/helpers/budgets_helper.rb b/app/helpers/budgets_helper.rb index d56d6de61..b3a01f7d5 100644 --- a/app/helpers/budgets_helper.rb +++ b/app/helpers/budgets_helper.rb @@ -97,18 +97,6 @@ module BudgetsHelper investment.group.headings.count > 1 end - def link_to_create_budget_poll(budget) - 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 }), - method: :post - end - def budget_subnav_items_for(budget) { results: t("budgets.results.link"), diff --git a/app/views/admin/budgets/index.html.erb b/app/views/admin/budgets/index.html.erb index 8f89a02bc..9140973af 100644 --- a/app/views/admin/budgets/index.html.erb +++ b/app/views/admin/budgets/index.html.erb @@ -27,17 +27,7 @@ <%= t("budgets.phase.#{budget.phase}") %> <% end %> diff --git a/spec/components/admin/budgets/table_actions_component_spec.rb b/spec/components/admin/budgets/table_actions_component_spec.rb new file mode 100644 index 000000000..05312853c --- /dev/null +++ b/spec/components/admin/budgets/table_actions_component_spec.rb @@ -0,0 +1,30 @@ +require "rails_helper" + +describe Admin::Budgets::TableActionsComponent, type: :component do + let(:budget) { create(:budget) } + let(:component) { Admin::Budgets::TableActionsComponent.new(budget) } + + it "renders links to edit budget, manage investments and edit groups and manage ballots" do + render_inline component + + expect(page).to have_css "a", count: 4 + expect(page).to have_link "Manage projects", href: /investments/ + expect(page).to have_link "Edit headings groups", href: /groups/ + expect(page).to have_link "Edit budget", href: /edit/ + expect(page).to have_link "Admin ballots" + end + + it "renders link to create new poll for budgets without polls" do + render_inline component + + expect(page).to have_css "a[href*='polls'][data-method='post']", text: "Admin ballots" + end + + it "renders link to manage ballots for budgets with polls" do + budget.poll = create(:poll, budget: budget) + + render_inline component + + expect(page).to have_link "Admin ballots", href: /booth_assignments/ + end +end From 08c2bfc25579d7384d8852674cce00ea3bf0a07e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 1 Jul 2020 19:01:06 +0200 Subject: [PATCH 16/18] Extract component to add/remove admin/mod/manager We remove some duplication by doing so. --- .../roles/table_actions_component.html.erb | 7 +++++ .../admin/roles/table_actions_component.rb | 30 +++++++++++++++++++ app/views/admin/administrators/index.html.erb | 5 +++- .../admin/administrators/search.html.erb | 11 +------ app/views/admin/managers/index.html.erb | 2 +- app/views/admin/managers/search.html.erb | 11 +------ app/views/admin/moderators/index.html.erb | 2 +- app/views/admin/moderators/search.html.erb | 11 +------ .../roles/table_actions_component_spec.rb | 17 +++++++++++ 9 files changed, 63 insertions(+), 33 deletions(-) create mode 100644 app/components/admin/roles/table_actions_component.html.erb create mode 100644 app/components/admin/roles/table_actions_component.rb create mode 100644 spec/components/admin/roles/table_actions_component_spec.rb diff --git a/app/components/admin/roles/table_actions_component.html.erb b/app/components/admin/roles/table_actions_component.html.erb new file mode 100644 index 000000000..0531450cc --- /dev/null +++ b/app/components/admin/roles/table_actions_component.html.erb @@ -0,0 +1,7 @@ +<% if already_has_role? %> + <%= render Admin::TableActionsComponent.new(record, actions: actions) %> +<% else %> + <%= render Admin::TableActionsComponent.new(actions: []) do %> + <%= link_to add_user_text, add_user_path, method: :post, class: "button success expanded" %> + <% end %> +<% end %> diff --git a/app/components/admin/roles/table_actions_component.rb b/app/components/admin/roles/table_actions_component.rb new file mode 100644 index 000000000..57d19f169 --- /dev/null +++ b/app/components/admin/roles/table_actions_component.rb @@ -0,0 +1,30 @@ +class Admin::Roles::TableActionsComponent < ApplicationComponent + attr_reader :record, :actions + + def initialize(record, actions: [:destroy]) + @record = record + @actions = actions + end + + private + + def role + record.class.name.tableize + end + + def already_has_role? + record.persisted? + end + + def add_user_text + t("admin.#{role}.#{role.singularize}.add") + end + + def add_user_path + { + controller: "admin/#{role}", + action: :create, + user_id: record.user + } + end +end diff --git a/app/views/admin/administrators/index.html.erb b/app/views/admin/administrators/index.html.erb index 4c5620b3a..90dc07e5d 100644 --- a/app/views/admin/administrators/index.html.erb +++ b/app/views/admin/administrators/index.html.erb @@ -29,7 +29,10 @@ <%= administrator.description %> <% end %> diff --git a/app/views/admin/administrators/search.html.erb b/app/views/admin/administrators/search.html.erb index 03591a1ce..d5ccddf38 100644 --- a/app/views/admin/administrators/search.html.erb +++ b/app/views/admin/administrators/search.html.erb @@ -18,16 +18,7 @@ <% end %> diff --git a/app/views/admin/managers/index.html.erb b/app/views/admin/managers/index.html.erb index 62ca1f189..86cfa88bc 100644 --- a/app/views/admin/managers/index.html.erb +++ b/app/views/admin/managers/index.html.erb @@ -22,7 +22,7 @@ <%= manager.email %> <% end %> diff --git a/app/views/admin/managers/search.html.erb b/app/views/admin/managers/search.html.erb index a834a9d80..442fe3194 100644 --- a/app/views/admin/managers/search.html.erb +++ b/app/views/admin/managers/search.html.erb @@ -18,16 +18,7 @@ <% end %> diff --git a/app/views/admin/moderators/index.html.erb b/app/views/admin/moderators/index.html.erb index 1c60e1d6d..beb22577c 100644 --- a/app/views/admin/moderators/index.html.erb +++ b/app/views/admin/moderators/index.html.erb @@ -24,7 +24,7 @@ <%= moderator.email %> <% end %> diff --git a/app/views/admin/moderators/search.html.erb b/app/views/admin/moderators/search.html.erb index 3cda8819e..d3b1d69d1 100644 --- a/app/views/admin/moderators/search.html.erb +++ b/app/views/admin/moderators/search.html.erb @@ -18,16 +18,7 @@ <% end %> diff --git a/spec/components/admin/roles/table_actions_component_spec.rb b/spec/components/admin/roles/table_actions_component_spec.rb new file mode 100644 index 000000000..42382cf8b --- /dev/null +++ b/spec/components/admin/roles/table_actions_component_spec.rb @@ -0,0 +1,17 @@ +require "rails_helper" + +describe Admin::Roles::TableActionsComponent, type: :component do + let(:user) { create(:user) } + + it "renders link to add the role for new records" do + render_inline Admin::Roles::TableActionsComponent.new(user.build_manager) + + expect(page).to have_css "a[data-method='post']", text: "Add" + end + + it "renders link to remove the role for existing records" do + render_inline Admin::Roles::TableActionsComponent.new(create(:manager, user: user)) + + expect(page).to have_css "a[data-method='delete']", text: "Delete" + end +end From 7cb0a4135b8d67acf71fb64badd4bff5de82ec55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Mon, 6 Jul 2020 19:53:24 +0200 Subject: [PATCH 17/18] Extract component for admin officers table This way we can remove duplication and simplify the code in the view. Note we're not using the "within" method in the tests to access a row, because it doesn't seem to work in components tests when passing the `text:` option. --- .../poll/officers/officers_component.html.erb | 36 ++++++++++++++++++ .../admin/poll/officers/officers_component.rb | 18 +++++++++ .../admin/poll/officers/_officer.html.erb | 34 +---------------- app/views/admin/poll/officers/index.html.erb | 38 +------------------ .../poll/officers/officers_component_spec.rb | 35 +++++++++++++++++ 5 files changed, 91 insertions(+), 70 deletions(-) create mode 100644 app/components/admin/poll/officers/officers_component.html.erb create mode 100644 app/components/admin/poll/officers/officers_component.rb create mode 100644 spec/components/admin/poll/officers/officers_component_spec.rb diff --git a/app/components/admin/poll/officers/officers_component.html.erb b/app/components/admin/poll/officers/officers_component.html.erb new file mode 100644 index 000000000..baf93a50f --- /dev/null +++ b/app/components/admin/poll/officers/officers_component.html.erb @@ -0,0 +1,36 @@ +<%= tag.table options do %> + + + + + + + + + <% officers.each do |officer| %> + + + + + + <% end %> + +<% end %> diff --git a/app/components/admin/poll/officers/officers_component.rb b/app/components/admin/poll/officers/officers_component.rb new file mode 100644 index 000000000..c9972a641 --- /dev/null +++ b/app/components/admin/poll/officers/officers_component.rb @@ -0,0 +1,18 @@ +class Admin::Poll::Officers::OfficersComponent < ApplicationComponent + attr_reader :officers, :options + + def initialize(officers, **options) + @officers = officers + @options = options + end + + private + + def add_user_path(officer) + { + controller: "admin/poll/officers", + action: :create, + user_id: officer.user_id + } + end +end diff --git a/app/views/admin/poll/officers/_officer.html.erb b/app/views/admin/poll/officers/_officer.html.erb index dd3202e7d..e026254b0 100644 --- a/app/views/admin/poll/officers/_officer.html.erb +++ b/app/views/admin/poll/officers/_officer.html.erb @@ -1,33 +1 @@ -
<%= t("admin.questions.show.answers.document_title") %><%= t("admin.questions.show.answers.document_actions") %><%= t("admin.questions.show.answers.document_actions") %>
<%= link_to document.title, document.attachment.url %> + <%= render Admin::TableActionsComponent.new(document, actions: [:destroy], destroy_path: document_path(document) diff --git a/app/views/admin/poll/questions/answers/videos/index.html.erb b/app/views/admin/poll/questions/answers/videos/index.html.erb index 1a7d41402..e2995d0e2 100644 --- a/app/views/admin/poll/questions/answers/videos/index.html.erb +++ b/app/views/admin/poll/questions/answers/videos/index.html.erb @@ -17,9 +17,7 @@
<%= t("admin.answers.videos.index.video_title") %> <%= t("admin.answers.videos.index.video_url") %> - <%= t("admin.actions.actions") %> - <%= t("admin.actions.actions") %>
<%= video.title %> <%= link_to "#{video.url}", video.url %> + <%= render Admin::TableActionsComponent.new(video) %>
<%= t("admin.poll_shifts.new.table_name") %> <%= t("admin.poll_shifts.new.table_email") %> - <%= t("admin.poll_shifts.new.table_shift") %> - <%= t("admin.poll_shifts.new.table_shift") %>
<%= user.email %> + <%= render Admin::TableActionsComponent.new( actions: [:edit], edit_text: t("admin.poll_shifts.new.edit_shifts"), From eb3f2bc2ca0fdec8abff5f9477fcca3e0e8fcd70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sun, 14 Jun 2020 18:32:21 +0200 Subject: [PATCH 13/18] Extract component for restore and hide actions By doing so, we remove a lot of duplication. --- .../hidden_table_actions_component.html.erb | 12 +++++++ .../admin/hidden_table_actions_component.rb | 34 +++++++++++++++++++ .../hidden_budget_investments/index.html.erb | 12 +------ .../admin/hidden_comments/index.html.erb | 12 +------ app/views/admin/hidden_debates/index.html.erb | 12 +------ .../index.html.erb | 12 +------ .../admin/hidden_proposals/index.html.erb | 12 +------ app/views/admin/hidden_users/index.html.erb | 12 +------ .../hidden_table_actions_component_spec.rb | 14 ++++++++ 9 files changed, 66 insertions(+), 66 deletions(-) create mode 100644 app/components/admin/hidden_table_actions_component.html.erb create mode 100644 app/components/admin/hidden_table_actions_component.rb create mode 100644 spec/components/admin/hidden_table_actions_component_spec.rb diff --git a/app/components/admin/hidden_table_actions_component.html.erb b/app/components/admin/hidden_table_actions_component.html.erb new file mode 100644 index 000000000..7cf58e888 --- /dev/null +++ b/app/components/admin/hidden_table_actions_component.html.erb @@ -0,0 +1,12 @@ +<%= render Admin::TableActionsComponent.new(actions: []) do %> + <%= link_to restore_text, restore_path, + method: :put, + data: { confirm: t("admin.actions.confirm") }, + class: "button hollow warning" %> + + <% unless record.confirmed_hide? %> + <%= link_to confirm_hide_text, confirm_hide_path, + method: :put, + class: "button" %> + <% end %> +<% end %> diff --git a/app/components/admin/hidden_table_actions_component.rb b/app/components/admin/hidden_table_actions_component.rb new file mode 100644 index 000000000..68647d130 --- /dev/null +++ b/app/components/admin/hidden_table_actions_component.rb @@ -0,0 +1,34 @@ +class Admin::HiddenTableActionsComponent < ApplicationComponent + attr_reader :record + + def initialize(record) + @record = record + end + + private + + def restore_text + t("admin.actions.restore") + end + + def restore_path + action_path(:restore) + end + + def confirm_hide_text + t("admin.actions.confirm_hide") + end + + def confirm_hide_path + action_path(:confirm_hide) + end + + def action_path(action) + url_for({ + controller: "admin/hidden_#{record.model_name.plural}", + action: action, + id: record, + only_path: true + }.merge(request.query_parameters)) + end +end diff --git a/app/views/admin/hidden_budget_investments/index.html.erb b/app/views/admin/hidden_budget_investments/index.html.erb index ed89d5cdc..90213a5ed 100644 --- a/app/views/admin/hidden_budget_investments/index.html.erb +++ b/app/views/admin/hidden_budget_investments/index.html.erb @@ -24,17 +24,7 @@ - <%= link_to t("admin.actions.restore"), - restore_admin_hidden_budget_investment_path(investment, request.query_parameters), - method: :put, - data: { confirm: t("admin.actions.confirm") }, - class: "button hollow warning" %> - <% unless investment.confirmed_hide? %> - <%= link_to t("admin.actions.confirm_hide"), - confirm_hide_admin_hidden_budget_investment_path(investment, request.query_parameters), - method: :put, - class: "button" %> - <% end %> + <%= render Admin::HiddenTableActionsComponent.new(investment) %>
- <%= link_to t("admin.actions.restore"), - restore_admin_hidden_comment_path(comment, request.query_parameters), - method: :put, - data: { confirm: t("admin.actions.confirm") }, - class: "button hollow warning" %> - <% unless comment.confirmed_hide? %> - <%= link_to t("admin.actions.confirm_hide"), - confirm_hide_admin_hidden_comment_path(comment, request.query_parameters), - method: :put, - class: "button" %> - <% end %> + <%= render Admin::HiddenTableActionsComponent.new(comment) %>
- <%= link_to t("admin.actions.restore"), - restore_admin_hidden_debate_path(debate, request.query_parameters), - method: :put, - data: { confirm: t("admin.actions.confirm") }, - class: "button hollow warning" %> - <% unless debate.confirmed_hide? %> - <%= link_to t("admin.actions.confirm_hide"), - confirm_hide_admin_hidden_debate_path(debate, request.query_parameters), - method: :put, - class: "button" %> - <% end %> + <%= render Admin::HiddenTableActionsComponent.new(debate) %>
- <%= link_to t("admin.actions.restore"), - restore_admin_hidden_proposal_notification_path(proposal_notification, request.query_parameters), - method: :put, - data: { confirm: t("admin.actions.confirm") }, - class: "button hollow warning" %> - <% unless proposal_notification.confirmed_hide? %> - <%= link_to t("admin.actions.confirm_hide"), - confirm_hide_admin_hidden_proposal_notification_path(proposal_notification, request.query_parameters), - method: :put, - class: "button" %> - <% end %> + <%= render Admin::HiddenTableActionsComponent.new(proposal_notification) %>
- <%= link_to t("admin.actions.restore"), - restore_admin_hidden_proposal_path(proposal, request.query_parameters), - method: :put, - data: { confirm: t("admin.actions.confirm") }, - class: "button hollow warning" %> - <% unless proposal.confirmed_hide? %> - <%= link_to t("admin.actions.confirm_hide"), - confirm_hide_admin_hidden_proposal_path(proposal, request.query_parameters), - method: :put, - class: "button" %> - <% end %> + <%= render Admin::HiddenTableActionsComponent.new(proposal) %>
- <%= link_to t("admin.actions.restore"), - restore_admin_hidden_user_path(user, request.query_parameters), - method: :put, - data: { confirm: t("admin.actions.confirm") }, - class: "button hollow warning" %> - <% unless user.confirmed_hide? %> - <%= link_to t("admin.actions.confirm_hide"), - confirm_hide_admin_hidden_user_path(user, request.query_parameters), - method: :put, - class: "button" %> - <% end %> + <%= render Admin::HiddenTableActionsComponent.new(user) %>
- <% if can? :verify, organization %> - <%= link_to t("admin.organizations.index.verify"), - verify_admin_organization_path(organization, request.query_parameters), - method: :put, class: "button success small-5" %> - <% end %> - - <% if can? :reject, organization %> - <%= link_to t("admin.organizations.index.reject"), - reject_admin_organization_path(organization, request.query_parameters), - method: :put, class: "button hollow alert small-5" %> - <% end %> + <%= render Admin::Organizations::TableActionsComponent.new(organization) %>
- <% if can? :verify, organization %> - <%= link_to t("admin.organizations.index.verify"), - verify_admin_organization_path(organization, request.query_parameters), - method: :put, class: "button success small-5" %> - <% end %> - - <% if can? :reject, organization %> - <%= link_to t("admin.organizations.index.reject"), - reject_admin_organization_path(organization, request.query_parameters), - method: :put, class: "button hollow alert small-5" %> - <% end %> + <%= render Admin::Organizations::TableActionsComponent.new(organization) %>
- <%= render Admin::TableActionsComponent.new(budget, actions: [:edit], edit_text: t("admin.budgets.index.edit_budget")) do |actions| %> - <%= actions.link_to t("admin.budgets.index.budget_investments"), - admin_budget_budget_investments_path(budget_id: budget.id), - class: "button hollow medium" %> - <%= actions.link_to t("admin.budgets.index.edit_groups"), admin_budget_groups_path(budget) %> - <% if budget.poll.present? %> - <%= actions.link_to t("admin.budgets.index.admin_ballots"), admin_poll_booth_assignments_path(budget.poll) %> - <% else %> - <%= link_to_create_budget_poll(budget) %> - <% end %> - <% end %> + <%= render Admin::Budgets::TableActionsComponent.new(budget) %>
- <%= render Admin::TableActionsComponent.new(administrator) %> + <%= render Admin::Roles::TableActionsComponent.new( + administrator, + actions: [:edit, :destroy] + ) %>
<%= user.name %> <%= user.email %> - <% if user.administrator? && user.administrator.persisted? %> - <%= render Admin::TableActionsComponent.new(user.administrator, actions: [:destroy]) %> - <% else %> - <%= link_to t("admin.administrators.administrator.add"), - { controller: "admin/administrators", - action: :create, - user_id: user }, - method: :post, - class: "button success expanded" %> - <% end %> + <%= render Admin::Roles::TableActionsComponent.new(user.administrator || user.build_administrator) %>
- <%= render Admin::TableActionsComponent.new(manager, actions: [:destroy]) %> + <%= render Admin::Roles::TableActionsComponent.new(manager) %>
<%= user.name %> <%= user.email %> - <% if user.manager? && user.manager.persisted? %> - <%= render Admin::TableActionsComponent.new(user.manager, actions: [:destroy]) %> - <% else %> - <%= link_to t("admin.managers.manager.add"), - { controller: "admin/managers", - action: :create, - user_id: user }, - method: :post, - class: "button success expanded" %> - <% end %> + <%= render Admin::Roles::TableActionsComponent.new(user.manager || user.build_manager) %>
- <%= render Admin::TableActionsComponent.new(moderator, actions: [:destroy]) %> + <%= render Admin::Roles::TableActionsComponent.new(moderator) %>
<%= user.name %> <%= user.email %> - <% if user.moderator? && user.moderator.persisted? %> - <%= render Admin::TableActionsComponent.new(user.moderator, actions: [:destroy]) %> - <% else %> - <%= link_to t("admin.moderators.moderator.add"), - { controller: "admin/moderators", - action: :create, - user_id: user }, - method: :post, - class: "button success expanded" %> - <% end %> + <%= render Admin::Roles::TableActionsComponent.new(user.moderator || user.build_moderator) %>
<%= t("admin.poll_officers.officer.name") %><%= t("admin.poll_officers.officer.email") %><%= t("admin.actions.actions") %>
+ <%= officer.name %> + + <%= officer.email %> + + <% if officer.persisted? %> + <%= render Admin::TableActionsComponent.new(officer, + actions: [:destroy], + destroy_text: t("admin.poll_officers.officer.delete") + ) %> + <% else %> + <%= render Admin::TableActionsComponent.new(actions: []) do |actions| %> + <%= actions.link_to t("admin.poll_officers.officer.add"), + add_user_path(officer), + method: :post, + class: "button success expanded" %> + <% end %> + <% end %> +
- - - - - - - - - - - - - - -
<%= t("admin.poll_officers.officer.name") %><%= t("admin.poll_officers.officer.email") %><%= t("admin.actions.actions") %>
- <%= officer.name %> - - <%= officer.email %> - - <% if officer.persisted? %> - <%= render Admin::TableActionsComponent.new(officer, - actions: [:destroy], - destroy_text: t("admin.poll_officers.officer.delete") - ) %> - <% else %> - <%= render Admin::TableActionsComponent.new(actions: []) do |actions| %> - <%= actions.link_to t("admin.poll_officers.officer.add"), { controller: "admin/poll/officers", action: :create, user_id: officer.user_id }, - method: :post, - class: "button success expanded" %> - <% end %> - <% end %> -
+<%= render Admin::Poll::Officers::OfficersComponent.new([officer]) %> diff --git a/app/views/admin/poll/officers/index.html.erb b/app/views/admin/poll/officers/index.html.erb index 1e2b4e144..c6b5caf74 100644 --- a/app/views/admin/poll/officers/index.html.erb +++ b/app/views/admin/poll/officers/index.html.erb @@ -11,43 +11,7 @@ <% if @officers.any? %> - - - - - - - - - - <% @officers.each do |officer| %> - - - - - - <% end %> - -
<%= t("admin.poll_officers.officer.name") %><%= t("admin.poll_officers.officer.email") %><%= t("admin.actions.actions") %>
- <%= officer.name %> - - <%= officer.email %> - - <% if officer.persisted? %> - <%= render Admin::TableActionsComponent.new(officer, - actions: [:destroy], - destroy_text: t("admin.poll_officers.officer.delete") - ) %> - <% else %> - <%= render Admin::TableActionsComponent.new(actions: []) do |actions| %> - <%= actions.link_to t("admin.poll_officers.officer.add"), - { controller: "admin/poll/officers", action: :create, - user_id: officer.user_id }, - method: :post, - class: "button success expanded" %> - <% end %> - <% end %> -
+ <%= render Admin::Poll::Officers::OfficersComponent.new(@officers, id: "officers") %> <%= paginate @officers %> <% end %> diff --git a/spec/components/admin/poll/officers/officers_component_spec.rb b/spec/components/admin/poll/officers/officers_component_spec.rb new file mode 100644 index 000000000..5d8e9a79a --- /dev/null +++ b/spec/components/admin/poll/officers/officers_component_spec.rb @@ -0,0 +1,35 @@ +require "rails_helper" + +describe Admin::Poll::Officers::OfficersComponent, type: :component do + let(:existing_officer) { create(:poll_officer, name: "Old officer") } + let(:new_officer) { build(:poll_officer, name: "New officer") } + let(:officers) { [existing_officer, new_officer] } + let(:component) { Admin::Poll::Officers::OfficersComponent.new(officers) } + + it "renders as many rows as officers" do + within "tbody" do + expect(page).to have_css "tr", count: 2 + expect(page).to have_css "a", count: 2 + end + end + + it "renders link to destroy for existing officers" do + render_inline component + row = page.find("tr", text: "Old officer") + + expect(row).to have_css "a[data-method='delete']", text: "Delete" + end + + it "renders link to add for new officers" do + render_inline component + row = page.find("tr", text: "New officer") + + expect(row).to have_css "a[data-method='post']", text: "Add" + end + + it "accepts table options" do + render_inline Admin::Poll::Officers::OfficersComponent.new(officers, class: "my-officers-table") + + expect(page).to have_css "table.my-officers-table" + end +end From 48db31cd6b5d8461751173a084e51edc6daa5f10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Mon, 6 Jul 2020 20:45:48 +0200 Subject: [PATCH 18/18] Remove redundant links in admin tables There were places where we had two links pointing to the same place; one link would be the name/title of a record, and one link would be under the "actions" column. This is confusing, since users would probably expect these links to point to different places (which is what happens in other tables in the admin section) and might try to click one of them and then the other one and be surprised when they found out both of them go to the same page. --- app/views/admin/budget_groups/index.html.erb | 2 +- app/views/admin/budget_headings/index.html.erb | 2 +- app/views/admin/officials/index.html.erb | 4 +--- app/views/admin/poll/polls/_poll.html.erb | 4 +--- app/views/admin/poll/polls/_questions.html.erb | 4 +--- app/views/admin/poll/polls/booth_assignments.html.erb | 4 +--- spec/system/admin/budget_groups_spec.rb | 2 +- spec/system/admin/budget_headings_spec.rb | 2 +- spec/system/admin/officials_spec.rb | 2 +- spec/system/admin/poll/booth_assigments_spec.rb | 2 +- spec/system/admin/poll/polls_spec.rb | 2 +- spec/system/admin/poll/questions_spec.rb | 2 +- 12 files changed, 12 insertions(+), 20 deletions(-) diff --git a/app/views/admin/budget_groups/index.html.erb b/app/views/admin/budget_groups/index.html.erb index 023cdae4a..293078dd3 100644 --- a/app/views/admin/budget_groups/index.html.erb +++ b/app/views/admin/budget_groups/index.html.erb @@ -22,7 +22,7 @@ <% @groups.each do |group| %> - <%= link_to group.name, edit_admin_budget_group_path(@budget, group) %> + <%= group.name %> <%= group.max_votable_headings %> <%= group.headings.count %> diff --git a/app/views/admin/budget_headings/index.html.erb b/app/views/admin/budget_headings/index.html.erb index bfb878ec9..7ffd37ff7 100644 --- a/app/views/admin/budget_headings/index.html.erb +++ b/app/views/admin/budget_headings/index.html.erb @@ -24,7 +24,7 @@ <% @headings.each do |heading| %> - <%= link_to heading.name, edit_admin_budget_group_heading_path(@budget, @group, heading) %> + <%= heading.name %> <%= @budget.formatted_heading_price(heading) %> <% if @budget.approval_voting? %> <%= heading.max_ballot_lines %> diff --git a/app/views/admin/officials/index.html.erb b/app/views/admin/officials/index.html.erb index a9b76dcc1..b62a450b6 100644 --- a/app/views/admin/officials/index.html.erb +++ b/app/views/admin/officials/index.html.erb @@ -16,9 +16,7 @@ <% @officials.each do |official| %> - - <%= link_to official.name, edit_admin_official_path(official) %> - + <%= official.name %> <%= official.official_position %> diff --git a/app/views/admin/poll/polls/_poll.html.erb b/app/views/admin/poll/polls/_poll.html.erb index 33189750b..2cad1f6cd 100644 --- a/app/views/admin/poll/polls/_poll.html.erb +++ b/app/views/admin/poll/polls/_poll.html.erb @@ -1,8 +1,6 @@ - - <%= link_to poll.name, admin_poll_path(poll) %> - + <%= poll.name %> <%= l poll.starts_at.to_date %> diff --git a/app/views/admin/poll/polls/_questions.html.erb b/app/views/admin/poll/polls/_questions.html.erb index 79e57748a..130f899c6 100644 --- a/app/views/admin/poll/polls/_questions.html.erb +++ b/app/views/admin/poll/polls/_questions.html.erb @@ -18,9 +18,7 @@ <% @poll.questions.each do |question| %> - - <%= link_to question.title, admin_question_path(question) %> - + <%= question.title %> <% if question.proposal.present? %> <%= link_to t("admin.polls.show.see_proposal"), diff --git a/app/views/admin/poll/polls/booth_assignments.html.erb b/app/views/admin/poll/polls/booth_assignments.html.erb index 0816de134..7fa9b2e01 100644 --- a/app/views/admin/poll/polls/booth_assignments.html.erb +++ b/app/views/admin/poll/polls/booth_assignments.html.erb @@ -10,9 +10,7 @@ <% @polls.each do |poll| %> - - <%= link_to poll.name, manage_admin_poll_booth_assignments_path(poll) %> - + <%= poll.name %> <%= l poll.starts_at.to_date %> - <%= l poll.ends_at.to_date %> diff --git a/spec/system/admin/budget_groups_spec.rb b/spec/system/admin/budget_groups_spec.rb index 6026ea187..75c05e1b9 100644 --- a/spec/system/admin/budget_groups_spec.rb +++ b/spec/system/admin/budget_groups_spec.rb @@ -128,7 +128,7 @@ describe "Admin budget groups" do click_button "Create new group" expect(page).to have_content "Group created successfully!" - expect(page).to have_link "All City" + expect(page).to have_content "All City" end scenario "Maximum number of headings in which a user can vote is set to 1 by default" do diff --git a/spec/system/admin/budget_headings_spec.rb b/spec/system/admin/budget_headings_spec.rb index b92d4ce6e..397b39968 100644 --- a/spec/system/admin/budget_headings_spec.rb +++ b/spec/system/admin/budget_headings_spec.rb @@ -148,7 +148,7 @@ describe "Admin budget headings" do click_button "Create new heading" expect(page).to have_content "Heading created successfully!" - expect(page).to have_link "All City" + expect(page).to have_content "All City" expect(page).to have_content "€1,000" expect(page).to have_content "10000" expect(page).to have_content "Yes" diff --git a/spec/system/admin/officials_spec.rb b/spec/system/admin/officials_spec.rb index 3c5abd448..a9eaab1f5 100644 --- a/spec/system/admin/officials_spec.rb +++ b/spec/system/admin/officials_spec.rb @@ -19,7 +19,7 @@ describe "Admin officials" do scenario "Edit an official" do visit admin_officials_path - click_link official.name + click_link "Edit official" expect(page).to have_current_path(edit_admin_official_path(official)) diff --git a/spec/system/admin/poll/booth_assigments_spec.rb b/spec/system/admin/poll/booth_assigments_spec.rb index 7ee942b05..ebfb38695 100644 --- a/spec/system/admin/poll/booth_assigments_spec.rb +++ b/spec/system/admin/poll/booth_assigments_spec.rb @@ -16,7 +16,7 @@ describe "Admin booths assignments" do visit booth_assignments_admin_polls_path - expect(page).to have_link(poll.name, href: manage_admin_poll_booth_assignments_path(poll)) + expect(page).to have_link("Manage assignments", href: manage_admin_poll_booth_assignments_path(poll)) expect(page).to have_content(second_poll.name) within("#poll_#{second_poll.id}") do diff --git a/spec/system/admin/poll/polls_spec.rb b/spec/system/admin/poll/polls_spec.rb index 8703dd4e2..d7a2fbc21 100644 --- a/spec/system/admin/poll/polls_spec.rb +++ b/spec/system/admin/poll/polls_spec.rb @@ -58,7 +58,7 @@ describe "Admin polls" do poll = create(:poll) visit admin_polls_path - click_link poll.name + click_link "Configure" expect(page).to have_content poll.name end diff --git a/spec/system/admin/poll/questions_spec.rb b/spec/system/admin/poll/questions_spec.rb index dde70b676..3863cf676 100644 --- a/spec/system/admin/poll/questions_spec.rb +++ b/spec/system/admin/poll/questions_spec.rb @@ -52,7 +52,7 @@ describe "Admin poll questions" do question = create(:poll_question, poll: poll) visit admin_poll_path(poll) - click_link question.title + click_link "Edit answers" expect(page).to have_content(question.title) expect(page).to have_content(question.author.name)