Skip to content

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

hand over additional data on dialog close

Klaus Zandersefc271160430
diff --git a/app/controllers/concerns/op_turbo/component_stream.rb b/app/controllers/concerns/op_turbo/component_stream.rb
index ed75e2d0113..4d7dce56d6d 100644
--- a/app/controllers/concerns/op_turbo/component_stream.rb
+++ b/app/controllers/concerns/op_turbo/component_stream.rb
@@ -100,8 +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)
+ def close_dialog_via_turbo_stream(target, additional: nil)
+ turbo_streams << OpTurbo::StreamComponent
+ .new(action: :closeDialog, target:, additional: additional.to_json)
+ .render_in(view_context)
end
def turbo_streams
diff --git a/frontend/src/stimulus/controllers/dynamic/my/time-tracking.controller.ts b/frontend/src/stimulus/controllers/dynamic/my/time-tracking.controller.ts
index eee431cf0aa..e5241f1319a 100644
--- a/frontend/src/stimulus/controllers/dynamic/my/time-tracking.controller.ts
+++ b/frontend/src/stimulus/controllers/dynamic/my/time-tracking.controller.ts
@@ -41,7 +41,6 @@ export default class MyTimeTrackingController extends Controller {
private calendar:Calendar;
private DEFAULT_TIMED_EVENT_DURATION = '01:00';
- private updatingDate:string|null = null;
private boundListener = this.dialogCloseListener.bind(this);
async connect() {
@@ -386,7 +385,6 @@ export default class MyTimeTrackingController extends Controller {
newTimeEntry(event:ActionEvent) {
const dialogParams = `onlyMe=true&date=${event.params.date}`;
- this.updatingDate = event.params.date as string;
void this.turboRequests.request(
`${this.pathHelper.timeEntryDialog()}?${dialogParams}`,
@@ -395,7 +393,10 @@ export default class MyTimeTrackingController extends Controller {
}
dialogCloseListener(event:CustomEvent):void {
- const { detail: { dialog, submitted } } = event as { detail:{ dialog:HTMLDialogElement; submitted:boolean } };
+ interface AdditionalDialogCloseData {
+ spent_on?:string;
+ }
+ const { detail: { dialog, additional, submitted } } = event as { detail:{ dialog:HTMLDialogElement; additional:AdditionalDialogCloseData|undefined; submitted:boolean } };
if (dialog.id !== 'time-entry-dialog' || !submitted) { return; }
// we simply refresh the calendar page
@@ -407,9 +408,8 @@ export default class MyTimeTrackingController extends Controller {
// list view replaces only the updated date
if (this.viewModeValue === 'list') {
// we don't know what date we clicked, so we need to reload the whole page
- if (this.updatingDate) {
- void this.turboRequests.request(this.pathHelper.myTimeTrackingRefresh(this.updatingDate, this.viewModeValue, this.modeValue), { method: 'GET' });
- this.updatingDate = null;
+ if (additional && additional.spent_on) {
+ void this.turboRequests.request(this.pathHelper.myTimeTrackingRefresh(additional.spent_on, this.viewModeValue, this.modeValue), { method: 'GET' });
} else {
window.location.reload();
}
diff --git a/frontend/src/turbo/dialog-stream-action.ts b/frontend/src/turbo/dialog-stream-action.ts
index 326cf0efb57..0ba00c9fa92 100644
--- a/frontend/src/turbo/dialog-stream-action.ts
+++ b/frontend/src/turbo/dialog-stream-action.ts
@@ -3,9 +3,11 @@ 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
+ const additionalData = JSON.parse(this.getAttribute('additional') || '{}') as unknown;
+
+ // dispatching 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 } }));
+ document.dispatchEvent(new CustomEvent('dialog:close', { detail: { dialog, submitted: true, additional: additionalData } }));
dialog.close('close-event-already-dispatched');
};
diff --git a/frontend/src/turbo/turbo-event-listeners.ts b/frontend/src/turbo/turbo-event-listeners.ts
index 00bd871abc8..18fc192fd33 100644
--- a/frontend/src/turbo/turbo-event-listeners.ts
+++ b/frontend/src/turbo/turbo-event-listeners.ts
@@ -19,9 +19,8 @@ export function addTurboEventListeners() {
if (dialog) {
if (dialog.dataset.keepOpenOnSubmit !== 'true') {
dialog.close('close-event-already-dispatched');
+ document.dispatchEvent(new CustomEvent('dialog:close', { detail: { dialog, submitted: true } }));
}
-
- document.dispatchEvent(new CustomEvent('dialog:close', { detail: { dialog, submitted: true } }));
}
}
});
diff --git a/modules/costs/app/components/time_entries/entry_dialog_component.html.erb b/modules/costs/app/components/time_entries/entry_dialog_component.html.erb
index 6dbcc8c26b9..a41ef049ae8 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
@@ -1,4 +1,4 @@
-<%= render(Primer::Alpha::Dialog.new(title: t("caption_log_time_dialog"), size: :medium_portrait, id: MODAL_ID, data: { "controller" => "time-entry", "application-target" => "dynamic", "time-entry-id" => time_entry.id, "ongoing" => time_entry.ongoing? })) do |d| %>
+<%= render(Primer::Alpha::Dialog.new(title: t("caption_log_time_dialog"), size: :medium_portrait, id: MODAL_ID, data: { "keep-open-on-submit": true, "controller" => "time-entry", "application-target" => "dynamic", "time-entry-id" => time_entry.id, "ongoing" => time_entry.ongoing? })) do |d| %>
<% d.with_header(variant: :large) %>
<% d.with_body do %>
<%= render(
diff --git a/modules/costs/app/controllers/time_entries_controller.rb b/modules/costs/app/controllers/time_entries_controller.rb
index 9dfce83a6c8..2865e586c05 100644
--- a/modules/costs/app/controllers/time_entries_controller.rb
+++ b/modules/costs/app/controllers/time_entries_controller.rb
@@ -89,12 +89,14 @@ class TimeEntriesController < ApplicationController
@time_entry = call.result
- unless call.success?
+ if call.success?
+ close_dialog_via_turbo_stream("#time-entry-dialog", additional: { spent_on: @time_entry.spent_on })
+ else
form_component = TimeEntries::TimeEntryFormComponent.new(time_entry: @time_entry, **form_config_options)
update_via_turbo_stream(component: form_component, status: :bad_request)
- respond_with_turbo_streams
end
+ respond_with_turbo_streams
end
def update # rubocop:disable Metrics/AbcSize
@@ -104,14 +106,14 @@ class TimeEntriesController < ApplicationController
@time_entry = call.result
- if call.failure?
- if params[:no_dialog]
- render_error_flash_message_via_turbo_stream(message: t("notice_time_entry_update_failed",
- errors: call.errors.full_messages.join(", ")))
- else
- form_component = TimeEntries::TimeEntryFormComponent.new(time_entry: @time_entry, **form_config_options)
- update_via_turbo_stream(component: form_component, status: :bad_request)
- end
+ if call.success?
+ close_dialog_via_turbo_stream("#time-entry-dialog", additional: { spent_on: @time_entry.spent_on })
+ elsif params[:no_dialog]
+ render_error_flash_message_via_turbo_stream(message: t("notice_time_entry_update_failed",
+ errors: call.errors.full_messages.join(", ")))
+ else
+ form_component = TimeEntries::TimeEntryFormComponent.new(time_entry: @time_entry, **form_config_options)
+ update_via_turbo_stream(component: form_component, status: :bad_request)
end
respond_with_turbo_streams(status: call.success? ? :ok : :bad_request)