OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[OP#65610] Add a delete button in the list view
Klaus Zandersb4f4ac156a9f
diff --git a/app/controllers/concerns/op_turbo/component_stream.rb b/app/controllers/concerns/op_turbo/component_stream.rbindex ccec531c515..d631fc59c2c 100644--- a/app/controllers/concerns/op_turbo/component_stream.rb+++ b/app/controllers/concerns/op_turbo/component_stream.rb@@ -118,6 +118,10 @@ module OpTurbo.render_in(view_context)end+ def reload_page_via_turbo_stream+ turbo_streams << OpTurbo::StreamComponent.new(action: :reloadPage, target: nil).render_in(view_context)+ end+def turbo_streams@turbo_streams ||= []enddiff --git a/frontend/src/turbo/setup.ts b/frontend/src/turbo/setup.tsindex cfffcd07076..b6bf8c27b0f 100644--- a/frontend/src/turbo/setup.ts+++ b/frontend/src/turbo/setup.ts@@ -10,6 +10,7 @@ import { addTurboGlobalListeners } from './turbo-global-listeners';import { applyTurboNavigationPatch } from './turbo-navigation-patch';import { debugLog, whenDebugging } from 'core-app/shared/helpers/debug_output';import { TURBO_EVENTS } from './constants';+import { StreamActions } from '@hotwired/turbo';Turbo.session.drive = true;Turbo.setProgressBarDelay(100);@@ -34,6 +35,10 @@ registerFlashStreamAction();registerLiveRegionStreamAction();registerInputCaptionStreamAction();+StreamActions.reloadPage = function reloadPage() {+ window.location.reload();+};+// Apply navigational patch// https://github.com/hotwired/turbo/issues/1300applyTurboNavigationPatch();diff --git a/modules/costs/app/components/my/time_tracking/time_entry_row.rb b/modules/costs/app/components/my/time_tracking/time_entry_row.rbindex a5e604343a5..d9908b38968 100644--- a/modules/costs/app/components/my/time_tracking/time_entry_row.rb+++ b/modules/costs/app/components/my/time_tracking/time_entry_row.rb@@ -54,6 +54,25 @@ module My) do |item|item.with_leading_visual_icon(icon: :pencil)end++ if can_delete_time_entry?++ menu.with_item(+ scheme: :danger,+ content_arguments: {+ data: {+ "turbo" => true,+ "turbo-method" => :delete,+ "turbo-confirm" => t("js.text_are_you_sure")+ }+ },+ href: time_entry_path(time_entry, no_dialog: true),+ label: t("label_delete"),+ tag: :a+ ) do |item|+ item.with_leading_visual_icon(icon: :trash)+ end+ endendend@@ -103,6 +122,10 @@ module Mydef time_entrymodelend++ def can_delete_time_entry?+ TimeEntries::DeleteContract.new(time_entry, User.current).valid?+ endendendenddiff --git a/modules/costs/app/components/time_entries/entry_dialog_component.html.erb b/modules/costs/app/components/time_entries/entry_dialog_component.html.erbindex 6483c044f19..9ee3dce66e8 100644--- a/modules/costs/app/components/time_entries/entry_dialog_component.html.erb+++ b/modules/costs/app/components/time_entries/entry_dialog_component.html.erb@@ -12,7 +12,7 @@<% end %><% d.with_footer(variant: :large) do %><% flex_layout(justify_content: :flex_end, classes: "time-entry-dialog-footer-buttons") do |flex| %>- <% if time_entry.persisted? %>+ <% if can_delete_time_entry? %><% flex.with_column do %><%= render(Primer::Beta::Button.new(diff --git a/modules/costs/app/components/time_entries/entry_dialog_component.rb b/modules/costs/app/components/time_entries/entry_dialog_component.rbindex 0cae2ce12a6..c4347461022 100644--- a/modules/costs/app/components/time_entries/entry_dialog_component.rb+++ b/modules/costs/app/components/time_entries/entry_dialog_component.rb@@ -45,7 +45,7 @@ module TimeEntriesdef can_delete_time_entry?return false if time_entry.new_record?- DeleteContract.deletion_allowed?(time_entry, User.current)+ TimeEntries::DeleteContract.new(time_entry, User.current).valid?endendenddiff --git a/modules/costs/app/controllers/time_entries_controller.rb b/modules/costs/app/controllers/time_entries_controller.rbindex 9f8f81cdb65..3ddd507b201 100644--- a/modules/costs/app/controllers/time_entries_controller.rb+++ b/modules/costs/app/controllers/time_entries_controller.rb@@ -108,6 +108,8 @@ class TimeEntriesController < ApplicationControllerif call.success?if request_from_dialog?close_dialog_via_turbo_stream("#time-entry-dialog", additional: { spent_on: @time_entry.spent_on })+ else+ reload_page_via_turbo_streamendelsif call.failure? && request_from_dialog?form_component = TimeEntries::TimeEntryFormComponent.new(time_entry: @time_entry, **form_config_options)@@ -125,11 +127,18 @@ class TimeEntriesController < ApplicationController@time_entry = call.result- if call.success?- close_dialog_via_turbo_stream("#time-entry-dialog")+ if request_from_dialog?+ if call.success?+ close_dialog_via_turbo_stream("#time-entry-dialog")+ else+ form_component = TimeEntries::TimeEntryFormComponent.new(time_entry: @time_entry, **form_config_options)+ update_via_turbo_stream(component: form_component, status: :bad_request)+ end+ elsif call.success?+ reload_page_via_turbo_streamelse- form_component = TimeEntries::TimeEntryFormComponent.new(time_entry: @time_entry, **form_config_options)- update_via_turbo_stream(component: form_component, status: :bad_request)+ render_error_flash_message_via_turbo_stream(message: t("notice_time_entry_delete_failed",+ errors: call.errors.full_messages.join(", ")))endrespond_with_turbo_streams(status: call.success? ? :ok : :bad_request)diff --git a/modules/costs/config/locales/en.yml b/modules/costs/config/locales/en.ymlindex 707aef6fae1..8e2af4fcb92 100644--- a/modules/costs/config/locales/en.yml+++ b/modules/costs/config/locales/en.yml@@ -196,6 +196,7 @@ en:notice_cost_logged_successfully: "Unit cost logged successfully."notice_different_time_zones: "This user has a different time zone (%{tz}). Time will be logged using their time zone."notice_time_entry_update_failed: "Failed to update time entry. Errors: %{errors}"+ notice_time_entry_delete_failed: "Failed to delete time entry. Errors: %{errors}"permission_edit_cost_entries: "Edit booked unit costs"permission_edit_own_cost_entries: "Edit own booked unit costs"