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

Turbo dialog stream

Oliver Günther2dc244a8278a
diff --git a/config/initializers/turbo_stream_actions.rb b/config/initializers/turbo_stream_actions.rb
new file mode 100644
index 00000000000..22f8bacc9c7
--- /dev/null
+++ b/config/initializers/turbo_stream_actions.rb
@@ -0,0 +1,5 @@
+ActiveSupport.on_load :turbo_streams_tag_builder do
+ def dialog(&)
+ action(:dialog, nil, &)
+ end
+end
diff --git a/frontend/src/turbo/dialog-stream-action.ts b/frontend/src/turbo/dialog-stream-action.ts
new file mode 100644
index 00000000000..5dc75ceaff9
--- /dev/null
+++ b/frontend/src/turbo/dialog-stream-action.ts
@@ -0,0 +1,16 @@
+import { StreamActions, StreamElement } from '@hotwired/turbo';
+
+export function registerDialogStreamAction() {
+ StreamActions.dialog = function dialogStreamAction(this:StreamElement) {
+ const content = this.templateElement.content;
+ const parent = content.firstElementChild as HTMLElement;
+ const dialog = content.querySelector('dialog') as HTMLDialogElement;
+ document.body.append(content);
+
+ // Auto-show the modal
+ dialog.showModal();
+
+ // Remove the element on close
+ dialog.addEventListener('close', () => parent.remove());
+ };
+}
diff --git a/frontend/src/turbo/setup.ts b/frontend/src/turbo/setup.ts
index 9906f7dc4ce..08d6dd9e038 100644
--- a/frontend/src/turbo/setup.ts
+++ b/frontend/src/turbo/setup.ts
@@ -1,6 +1,7 @@
import "../typings/shims.d.ts"
import * as Turbo from '@hotwired/turbo';
import { ModalDialogElement } from '@openproject/primer-view-components/app/components/primer/alpha/modal_dialog';
+import { registerDialogStreamAction } from './dialog-stream-action';
// Disable default turbo-drive for now as we don't need it for now AND it breaks angular routing
Turbo.session.drive = false;
@@ -25,3 +26,5 @@ document.addEventListener('turbo:submit-end', (event:CustomEvent) => {
dialog && dialog.close(true);
}
});
+
+registerDialogStreamAction();
diff --git a/modules/meeting/app/components/meetings/header_component.html.erb b/modules/meeting/app/components/meetings/header_component.html.erb
index c99e3c3e8d9..3aa3628647d 100644
--- a/modules/meeting/app/components/meetings/header_component.html.erb
+++ b/modules/meeting/app/components/meetings/header_component.html.erb
@@ -44,8 +44,12 @@
end
menu.with_item(label: t(:label_history),
- tag: :button,
- content_arguments: { "data-show-dialog-id": "meetings-history-dialog" },
+ tag: :a,
+ href: history_meeting_path(@meeting),
+ content_arguments: {
+ "data-show-dialog-id": "meetings-history-dialog",
+ "data-turbo-stream": true
+ },
value: ""
) do |item|
item.with_leading_visual_icon(icon: :clock) # or :check TBD
@@ -64,17 +68,6 @@
end
end
- show_header.with_row do
- render(OpTurbo::OpPrimer::AsyncDialogComponent.new(
- id: "meetings-history-dialog",
- src: history_meeting_path(@meeting),
- size: :xlarge,
- header_variant: :large,
- title: I18n.t(:label_history),
- hide_button: true
- ))
- end
-
show_header.with_row do
render(Meetings::HeaderInfolineComponent.new(@meeting))
end
diff --git a/modules/meeting/app/controllers/meetings_controller.rb b/modules/meeting/app/controllers/meetings_controller.rb
index c52505a2d10..0766b381656 100644
--- a/modules/meeting/app/controllers/meetings_controller.rb
+++ b/modules/meeting/app/controllers/meetings_controller.rb
@@ -138,8 +138,6 @@ class MeetingsController < ApplicationController
def history
@events = get_events
-
- render :history
rescue ActiveRecord::RecordNotFound => e
op_handle_warning "Failed to find all resources in activities: #{e.message}"
render_404 I18n.t(:error_can_not_find_all_resources)
diff --git a/modules/meeting/app/views/meetings/history.turbo_stream.erb b/modules/meeting/app/views/meetings/history.turbo_stream.erb
new file mode 100644
index 00000000000..dd3b518b3f1
--- /dev/null
+++ b/modules/meeting/app/views/meetings/history.turbo_stream.erb
@@ -0,0 +1,11 @@
+<%=
+ turbo_stream.dialog do
+ render(Primer::Alpha::Dialog.new(title: t(:label_history),
+ id: 'meeting-history-dialog')) do |d|
+ d.with_header(variant: :large)
+ d.with_body do
+ render(Activities::DaysComponent.new(events: @events, current_project: @project, activity_page: @activity_page))
+ end
+ end
+ end
+%>