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

Improve typing and DRY up activities tab controller mixin

Kabiru Mwenja7b604518cddd
diff --git a/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/editor.controller.ts b/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/editor.controller.ts
index 0657f829e74..b31631f3941 100644
--- a/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/editor.controller.ts
+++ b/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/editor.controller.ts
@@ -262,6 +262,6 @@ export default class EditorController extends withIndexOutletMixin(Controller) {
}
get ckEditorInstance():ICKEditorInstance | undefined {
- return retrieveCkEditorInstance(this.element);
+ return retrieveCkEditorInstance(this.element as HTMLElement);
}
}
diff --git a/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/internal-comment.controller.ts b/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/internal-comment.controller.ts
index 41420086095..e06122e932a 100644
--- a/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/internal-comment.controller.ts
+++ b/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/internal-comment.controller.ts
@@ -30,7 +30,6 @@
import { Controller } from '@hotwired/stimulus';
import { renderStreamMessage } from '@hotwired/turbo';
-import { useMeta } from 'stimulus-use';
import type EditorController from './editor.controller';
import { withIndexOutletMixin } from './mixins/with-index-outlet';
@@ -56,12 +55,8 @@ export default class InternalCommentController extends withIndexOutletMixin(Cont
declare isInternalValue:boolean;
- static metaNames = ['csrf-token'];
- declare readonly csrfToken:string;
-
connect() {
- // FIXME: Cast to the proper Controller type for useMeta
- useMeta(this as unknown as Controller<HTMLElement>, { suffix: false });
+ this.initializeUseMeta();
}
onSubmitEnd(_event:CustomEvent):void {
diff --git a/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/mixins/with-index-outlet.ts b/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/mixins/with-index-outlet.ts
index c17c1314aaa..ee9aafb1254 100644
--- a/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/mixins/with-index-outlet.ts
+++ b/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/mixins/with-index-outlet.ts
@@ -29,23 +29,33 @@
*/
import { Controller } from '@hotwired/stimulus';
+import { useMeta } from 'stimulus-use';
import IndexController from '../index.controller';
export const withIndexOutletMixin = (BaseController:typeof Controller) => {
- return class extends BaseController<HTMLElement> {
+ return class extends BaseController {
+ static metaNames = ['csrf-token'];
+ declare readonly csrfToken:string;
+
static outlets = [
...(BaseController.outlets || []),
'work-packages--activities-tab--index',
];
declare readonly workPackagesActivitiesTabIndexOutlet:IndexController;
+
get indexOutlet() { return this.workPackagesActivitiesTabIndexOutlet; }
+ // Viewport service convenience methods
isMobile() { return this.indexOutlet.viewPortService.isMobile(); }
isWithinNotificationCenter() { return this.indexOutlet.viewPortService.isWithinNotificationCenter(); }
isWithinSplitScreen() { return this.indexOutlet.viewPortService.isWithinSplitScreen(); }
isJournalsContainerScrolledToBottom() { return this.indexOutlet.viewPortService.isJournalsContainerScrolledToBottom(); }
get scrollableContainer() { return this.indexOutlet.viewPortService.scrollableContainer; }
+
+ initializeUseMeta() {
+ useMeta(this as unknown as Controller<HTMLElement>, { suffix: false });
+ }
};
};
diff --git a/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/polling.controller.ts b/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/polling.controller.ts
index 7e683bfc48c..58673371ced 100644
--- a/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/polling.controller.ts
+++ b/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/polling.controller.ts
@@ -31,7 +31,6 @@
import { Controller } from '@hotwired/stimulus';
import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
import { TurboRequestsService } from 'core-app/core/turbo/turbo-requests.service';
-import { useMeta } from 'stimulus-use';
import type AutoScrollingController from './auto-scrolling.controller';
import StemsController from './stems.controller';
import { withIndexOutletMixin } from './mixins/with-index-outlet';
@@ -47,9 +46,6 @@ export default class PollingController extends withIndexOutletMixin(Controller)
declare readonly editFormTargets:HTMLFormElement[];
declare readonly reactionButtonTargets:HTMLElement[];
- static metaNames = ['csrf-token'];
- declare readonly csrfToken:string;
-
private updateInProgress:boolean = false;
private intervallId:number;
private turboRequests:TurboRequestsService;
@@ -57,8 +53,7 @@ export default class PollingController extends withIndexOutletMixin(Controller)
private abortController = new AbortController();
async connect() {
- // FIXME: Cast to the proper Controller type for useMeta
- useMeta(this as unknown as Controller<HTMLElement>, { suffix: false });
+ this.initializeUseMeta();
const context = await window.OpenProject.getPluginContext();
this.turboRequests = context.services.turboRequests;