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

Add stimulus.js

Oliver Günther2ada9dcd0f08
diff --git a/app/views/layouts/base.html.erb b/app/views/layouts/base.html.erb
index 0d656ceb87a..0865af0fe20 100644
--- a/app/views/layouts/base.html.erb
+++ b/app/views/layouts/base.html.erb
@@ -44,6 +44,7 @@ See COPYRIGHT and LICENSE files for more details.
data-relative_url_root="<%= root_path %>"
data-overflowing-identifier=".__overflowing_body"
data-rendered-at="<%= Time.zone.now.iso8601 %>"
+ data-controller="application"
>
<%= render partial: 'warning_bar/warning_bar' %>
<noscript>
diff --git a/frontend/package-lock.json b/frontend/package-lock.json
index 8be50591675..acb9c7498d0 100644
--- a/frontend/package-lock.json
+++ b/frontend/package-lock.json
@@ -35,6 +35,7 @@
"@fullcalendar/resource-common": "^6.0.0-beta.1",
"@fullcalendar/resource-timeline": "^6.1.7",
"@fullcalendar/timegrid": "^6.1.7",
+ "@hotwired/stimulus": "^3.2.1",
"@kolkov/ngx-gallery": "^1.0.11",
"@ng-select/ng-option-highlight": "0.0.5",
"@ng-select/ng-select": "^4.0.4",
@@ -85,6 +86,7 @@
"reflect-metadata": "^0.1.13",
"rxjs": "^7.8.0",
"screenfull": "^4.2.1",
+ "stimulus-use": "^0.52.0",
"swagger-ui": "^4.16.1",
"tablesorter": "^2.31.3",
"ts-action": "^11.0.0",
@@ -4578,6 +4580,11 @@
"version": "1.1.3",
"license": "MIT"
},
+ "node_modules/@hotwired/stimulus": {
+ "version": "3.2.1",
+ "resolved": "https://registry.npmjs.org/@hotwired/stimulus/-/stimulus-3.2.1.tgz",
+ "integrity": "sha512-HGlzDcf9vv/EQrMJ5ZG6VWNs8Z/xMN+1o2OhV1gKiSG6CqZt5MCBB1gRg5ILiN3U0jEAxuDTNPRfBcnZBDmupQ=="
+ },
"node_modules/@html-eslint/eslint-plugin": {
"version": "0.15.0",
"dev": true,
@@ -30904,6 +30911,15 @@
"node": ">= 0.6"
}
},
+ "node_modules/stimulus-use": {
+ "version": "0.52.0",
+ "resolved": "https://registry.npmjs.org/stimulus-use/-/stimulus-use-0.52.0.tgz",
+ "integrity": "sha512-b2Z2krSSIqKvG9ncrjMlxbX3SYg9mgL0g/1Zc25jTZjTr0//wgg7szUi9G67amBs/yLqO12GAEnudybZgYNnjA==",
+ "peerDependencies": {
+ "@hotwired/stimulus": ">= 3",
+ "hotkeys-js": ">= 3"
+ }
+ },
"node_modules/store2": {
"version": "2.14.2",
"dev": true,
@@ -36555,6 +36571,11 @@
"@gar/promisify": {
"version": "1.1.3"
},
+ "@hotwired/stimulus": {
+ "version": "3.2.1",
+ "resolved": "https://registry.npmjs.org/@hotwired/stimulus/-/stimulus-3.2.1.tgz",
+ "integrity": "sha512-HGlzDcf9vv/EQrMJ5ZG6VWNs8Z/xMN+1o2OhV1gKiSG6CqZt5MCBB1gRg5ILiN3U0jEAxuDTNPRfBcnZBDmupQ=="
+ },
"@html-eslint/eslint-plugin": {
"version": "0.15.0",
"dev": true
@@ -54174,6 +54195,11 @@
"version": "1.5.0",
"dev": true
},
+ "stimulus-use": {
+ "version": "0.52.0",
+ "resolved": "https://registry.npmjs.org/stimulus-use/-/stimulus-use-0.52.0.tgz",
+ "integrity": "sha512-b2Z2krSSIqKvG9ncrjMlxbX3SYg9mgL0g/1Zc25jTZjTr0//wgg7szUi9G67amBs/yLqO12GAEnudybZgYNnjA=="
+ },
"store2": {
"version": "2.14.2",
"dev": true
diff --git a/frontend/package.json b/frontend/package.json
index fb95440e1ad..27ea0b77f01 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -108,6 +108,7 @@
"@fullcalendar/resource-common": "^6.0.0-beta.1",
"@fullcalendar/resource-timeline": "^6.1.7",
"@fullcalendar/timegrid": "^6.1.7",
+ "@hotwired/stimulus": "^3.2.1",
"@kolkov/ngx-gallery": "^1.0.11",
"@ng-select/ng-option-highlight": "0.0.5",
"@ng-select/ng-select": "^4.0.4",
@@ -158,6 +159,7 @@
"reflect-metadata": "^0.1.13",
"rxjs": "^7.8.0",
"screenfull": "^4.2.1",
+ "stimulus-use": "^0.52.0",
"swagger-ui": "^4.16.1",
"tablesorter": "^2.31.3",
"ts-action": "^11.0.0",
diff --git a/frontend/src/main.ts b/frontend/src/main.ts
index 520c25b3288..e0fac9de965 100644
--- a/frontend/src/main.ts
+++ b/frontend/src/main.ts
@@ -2,7 +2,6 @@ import { OpenProjectModule } from 'core-app/app.module';
import { enableProdMode } from '@angular/core';
import * as jQuery from 'jquery';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
-import { whenDebugging } from 'core-app/shared/helpers/debug_output';
import { initializeLocale } from 'core-app/core/setup/init-locale';
import { environment } from './environments/environment';
import { configureErrorReporter } from 'core-app/core/errors/configure-reporter';
@@ -30,6 +29,7 @@ window.ErrorReporter = configureErrorReporter();
require('core-app/core/setup/init-vendors');
require('core-app/core/setup/init-globals');
+require('stimulus/setup');
if (environment.production) {
enableProdMode();
diff --git a/frontend/src/stimulus/controllers/op-application.controller.ts b/frontend/src/stimulus/controllers/op-application.controller.ts
new file mode 100644
index 00000000000..c987ad44fd3
--- /dev/null
+++ b/frontend/src/stimulus/controllers/op-application.controller.ts
@@ -0,0 +1,21 @@
+import { ControllerConstructor } from '@hotwired/stimulus/dist/types/core/controller';
+import { ApplicationController } from 'stimulus-use';
+
+export class OpApplicationController extends ApplicationController {
+ static targets = ['dynamic'];
+
+ private loaded = new Set<string>();
+
+ dynamicTargetConnected(target:HTMLElement) {
+ const controller = target.dataset.controller as string;
+
+ if (!this.loaded.has(controller)) {
+ this.loaded.add(controller);
+ void import(/* webpackChunkName: "[request]" */`./dynamic/${controller}.controller`)
+ .then((imported:{ default:ControllerConstructor }) => this.application.register(controller, imported.default))
+ .catch((err:unknown) => {
+ console.error('Failed to load dyanmic controller chunk %O: %O', controller, err);
+ });
+ }
+ }
+}
diff --git a/frontend/src/stimulus/setup.ts b/frontend/src/stimulus/setup.ts
new file mode 100644
index 00000000000..5a52d646213
--- /dev/null
+++ b/frontend/src/stimulus/setup.ts
@@ -0,0 +1,19 @@
+import { Application } from '@hotwired/stimulus';
+import { environment } from '../environments/environment';
+import { OpApplicationController } from './controllers/op-application.controller';
+
+declare global {
+ interface Window {
+ Stimulus:Application;
+ }
+}
+
+const instance = Application.start();
+window.Stimulus = instance;
+
+instance.debug = !environment.production;
+instance.handleError = (error, message, detail) => {
+ console.warn(message, detail);
+};
+
+instance.register('application', OpApplicationController);
diff --git a/frontend/src/tsconfig.app.json b/frontend/src/tsconfig.app.json
index dd7433d77f8..8d84483da06 100644
--- a/frontend/src/tsconfig.app.json
+++ b/frontend/src/tsconfig.app.json
@@ -9,10 +9,12 @@
"main.ts",
"polyfills.ts",
"app/core/setup/init-globals.ts",
- "app/core/setup/init-vendors.ts"
+ "app/core/setup/init-vendors.ts",
+ "stimulus/setup.ts"
],
"include": [
"src/**/*.ts",
+ "stimulus/**/*.ts",
"**/*.d.ts",
"app/core/augmenting/dynamic-scripts/*.ts"
],