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

Adapt action in frontend

Oliver Günther1f7bc56c9850
diff --git a/frontend/src/stimulus/controllers/poll-for-changes.controller.ts b/frontend/src/stimulus/controllers/poll-for-changes.controller.ts
new file mode 100644
index 00000000000..3640468db3b
--- /dev/null
+++ b/frontend/src/stimulus/controllers/poll-for-changes.controller.ts
@@ -0,0 +1,51 @@
+/*
+ * -- copyright
+ * OpenProject is an open source project management software.
+ * Copyright (C) 2023 the OpenProject GmbH
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version 3.
+ *
+ * OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+ * Copyright (C) 2006-2013 Jean-Philippe Lang
+ * Copyright (C) 2010-2013 the ChiliProject Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * See COPYRIGHT and LICENSE files for more details.
+ * ++
+ */
+
+import { ApplicationController } from 'stimulus-use';
+import { renderStreamMessage } from '@hotwired/turbo';
+
+export default class PollForChangesController extends ApplicationController {
+ connect() {
+ super.connect();
+ setTimeout(() => {
+ console.log("Checking");
+ this.triggerTurboStream();
+ }, 2000);
+ }
+
+ async triggerTurboStream():Promise<void> {
+ await fetch(`/meetings/2512/check_for_updates`, {
+ headers: {
+ Accept: 'text/vnd.turbo-stream.html',
+ },
+ }).then((r) => r.text())
+ .then((html) => renderStreamMessage(html));
+ }
+}
diff --git a/frontend/src/stimulus/setup.ts b/frontend/src/stimulus/setup.ts
index 48382bd3b44..2c39321f936 100644
--- a/frontend/src/stimulus/setup.ts
+++ b/frontend/src/stimulus/setup.ts
@@ -6,6 +6,7 @@ import OpDisableWhenCheckedController from './controllers/disable-when-checked.c
import PrintController from './controllers/print.controller';
import RefreshOnFormChangesController from './controllers/refresh-on-form-changes.controller';
import AsyncDialogController from './controllers/async-dialog.controller';
+import PollForChangesController from './controllers/poll-for-changes.controller';
declare global {
interface Window {
@@ -28,3 +29,4 @@ instance.register('disable-when-checked', OpDisableWhenCheckedController);
instance.register('print', PrintController);
instance.register('refresh-on-form-changes', RefreshOnFormChangesController);
instance.register('async-dialog', AsyncDialogController);
+instance.register('poll-for-changes', PollForChangesController);
diff --git a/frontend/src/turbo/flash-stream-action.ts b/frontend/src/turbo/flash-stream-action.ts
new file mode 100644
index 00000000000..0105e0c9786
--- /dev/null
+++ b/frontend/src/turbo/flash-stream-action.ts
@@ -0,0 +1,9 @@
+import { StreamActions, StreamElement } from '@hotwired/turbo';
+
+export function registerFlashStreamAction() {
+ StreamActions.flash = function dialogStreamAction(this:StreamElement) {
+ const content = this.templateElement.content;
+
+ document.body.append(content);
+ };
+}
diff --git a/frontend/src/turbo/setup.ts b/frontend/src/turbo/setup.ts
index 9bd905bbb9a..50747fa5a7c 100644
--- a/frontend/src/turbo/setup.ts
+++ b/frontend/src/turbo/setup.ts
@@ -2,6 +2,7 @@ import '../typings/shims.d.ts';
import * as Turbo from '@hotwired/turbo';
import { registerDialogStreamAction } from './dialog-stream-action';
import { addTurboEventListeners } from './turbo-event-listeners';
+import { registerFlashStreamAction } from './flash-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;
@@ -10,6 +11,7 @@ Turbo.start();
addTurboEventListeners();
registerDialogStreamAction();
+registerFlashStreamAction();
// Error handling when "Content missing" returned
document.addEventListener('turbo:frame-missing', (event:CustomEvent) => {
diff --git a/modules/meeting/app/components/meetings/show_component.html.erb b/modules/meeting/app/components/meetings/show_component.html.erb
index 38e4240339e..1f95ddd844a 100644
--- a/modules/meeting/app/components/meetings/show_component.html.erb
+++ b/modules/meeting/app/components/meetings/show_component.html.erb
@@ -1,5 +1,5 @@
<%=
- flex_layout(data: { turbo: true }) do |show_page|
+ flex_layout(data: { controller: "poll-for-changes", turbo: true }) do |show_page|
show_page.with_row do
# prototyical usage of Primer's flash message component wrapped in a component which can be updated via turbo stream
# empty initially