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
better handling of edit and delete cases
Klaus Zanders1f9c4fc00c73
diff --git a/app/controllers/concerns/op_turbo/component_stream.rb b/app/controllers/concerns/op_turbo/component_stream.rbindex a84351f22cd..ed75e2d0113 100644--- a/app/controllers/concerns/op_turbo/component_stream.rb+++ b/app/controllers/concerns/op_turbo/component_stream.rb@@ -100,6 +100,10 @@ module OpTurbo.render_in(view_context)end+ def close_dialog_via_turbo_stream(target)+ turbo_streams << OpTurbo::StreamComponent.new(action: :closeDialog, target:).render_in(view_context)+ end+def turbo_streams@turbo_streams ||= []enddiff --git a/frontend/src/app/core/path-helper/path-helper.service.ts b/frontend/src/app/core/path-helper/path-helper.service.tsindex 1cb5e378435..12680902000 100644--- a/frontend/src/app/core/path-helper/path-helper.service.ts+++ b/frontend/src/app/core/path-helper/path-helper.service.ts@@ -343,7 +343,7 @@ export class PathHelperService {}public timeEntryEditDialog(timeEntryId:string) {- return `${this.timeEntryDialog()}?time_entry_id=${timeEntryId}`;+ return `${this.staticBase}/time_entries/${timeEntryId}/dialog`;}public timeEntryWorkPackageDialog(workPackageId:string) {diff --git a/frontend/src/turbo/dialog-stream-action.ts b/frontend/src/turbo/dialog-stream-action.tsindex bd086ae67a3..72f4b7361b1 100644--- a/frontend/src/turbo/dialog-stream-action.ts+++ b/frontend/src/turbo/dialog-stream-action.ts@@ -1,6 +1,14 @@import { StreamActions, StreamElement } from '@hotwired/turbo';export function registerDialogStreamAction() {+ StreamActions.closeDialog = function closeDialogStreamAction(this:StreamElement) {+ const dialog = document.querySelector(this.target) as HTMLDialogElement;+ // distpatching with submitted: true to indicate that the behavior of a successful submission should+ // be triggered (i.e. reloading the ui)+ document.dispatchEvent(new CustomEvent('dialog:close', { detail: { dialog, submitted: true } }));+ dialog.close('close-event-already-dispatched');+ };+StreamActions.dialog = function dialogStreamAction(this:StreamElement) {const content = this.templateElement.content;const dialog = content.querySelector('dialog') as HTMLDialogElement;diff --git a/modules/costs/app/controllers/time_entries_controller.rb b/modules/costs/app/controllers/time_entries_controller.rbindex 94badab870a..cfb0d802f3d 100644--- a/modules/costs/app/controllers/time_entries_controller.rb+++ b/modules/costs/app/controllers/time_entries_controller.rb@@ -37,9 +37,10 @@ class TimeEntriesController < ApplicationControllerwith_options only: [:dialog] dobefore_action :load_and_authorize_optional_projectbefore_action :load_and_authorize_optional_work_package- before_action :load_or_build_and_authorize_time_entryend+ before_action :load_or_build_and_authorize_time_entry, only: %i[dialog update destroy]+authorization_checked! :dialog, :create, :update, :user_tz_caption, :refresh_form, :destroydef dialog@@ -76,8 +77,6 @@ class TimeEntriesController < ApplicationControllertime_entry = call.result- # TODO Some logic to figure out what fields we want to show (user, etc)-replace_via_turbo_stream(component: TimeEntries::TimeEntryFormComponent.new(time_entry: time_entry, **form_config_options))@@ -101,10 +100,8 @@ class TimeEntriesController < ApplicationControllerenddef update- time_entry = TimeEntry.find_by(id: params[:id])-call = TimeEntries::UpdateService- .new(user: current_user, model: time_entry)+ .new(user: current_user, model: @time_entry).call(permitted_params.time_entries)@time_entry = call.result@@ -118,14 +115,12 @@ class TimeEntriesController < ApplicationControllerenddef destroy- time_entry = TimeEntry.find_by(id: params[:id])-- call = TimeEntries::DeleteService.new(user: current_user, model: time_entry).call+ call = TimeEntries::DeleteService.new(user: current_user, model: @time_entry).call@time_entry = call.resultif call.success?- # TODO: Render soimething that closes our dialog+ close_dialog_via_turbo_stream("#time-entry-dialog")elseform_component = TimeEntries::TimeEntryFormComponent.new(time_entry: @time_entry, **form_config_options)update_via_turbo_stream(component: form_component, status: :bad_request)@@ -172,8 +167,8 @@ class TimeEntriesController < ApplicationControllerenddef load_or_build_and_authorize_time_entry- @time_entry = if params[:time_entry_id]- TimeEntry.find_by(id: params[:time_entry_id]).tap do |entry|+ @time_entry = if params[:id]+ TimeEntry.visible.find_by(id: params[:id]).tap do |entry|if entry && !TimeEntries::UpdateContract.new(entry, current_user).user_allowed_to_update?deny_access(not_found: true)enddiff --git a/modules/costs/config/routes.rb b/modules/costs/config/routes.rbindex 4dd18a1f3b7..bf5540981ee 100644--- a/modules/costs/config/routes.rb+++ b/modules/costs/config/routes.rb@@ -31,6 +31,7 @@Rails.application.routes.draw doresources :time_entries, only: %i[create update destroy] doget :dialog, on: :collection+ get :dialog, on: :memberget "/users/:user_id/tz_caption", action: :user_tz_caption, on: :collectionpost :refresh_form, on: :collectionend