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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Simplify inheritance of activities tab stimulus controllers (#19669)
Kabiru Mwenja9269f8077bf2
diff --git a/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/auto-scrolling.controller.ts b/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/auto-scrolling.controller.tsindex b69f98c7ccf..2c4a23f595d 100644--- a/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/auto-scrolling.controller.ts+++ b/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/auto-scrolling.controller.ts@@ -28,8 +28,7 @@* ++*/-import { Controller } from '@hotwired/stimulus';-import { withIndexOutletMixin } from './mixins/with-index-outlet';+import BaseController from './base.controller';enum AnchorType {Comment = 'comment',@@ -43,8 +42,10 @@ interface CustomEventWithIdParam extends Event {};}-export default class AutoScrollingController extends withIndexOutletMixin(Controller) {+export default class AutoScrollingController extends BaseController {connect() {+ super.connect();+this.handleInitialScroll();}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/base.controller.tssimilarity index 53%rename from frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/mixins/with-index-outlet.tsrename to frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/base.controller.tsindex ee9aafb1254..35378e55a36 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/base.controller.ts@@ -30,32 +30,31 @@import { Controller } from '@hotwired/stimulus';import { useMeta } from 'stimulus-use';-import IndexController from '../index.controller';+import IndexController from './index.controller';-export const withIndexOutletMixin = (BaseController:typeof Controller) => {- return class extends BaseController {- static metaNames = ['csrf-token'];- declare readonly csrfToken:string;+export default class BaseController extends Controller {+ static metaNames = ['csrf-token'];+ declare readonly csrfToken:string;- static outlets = [- ...(BaseController.outlets || []),- 'work-packages--activities-tab--index',- ];+ indexOutlet:IndexController;- declare readonly workPackagesActivitiesTabIndexOutlet:IndexController;+ connect() {+ useMeta(this, { suffix: false });+ this.indexOutlet = this.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(); }- // 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; }- get scrollableContainer() { return this.indexOutlet.viewPortService.scrollableContainer; }+ private get indexController() {+ const identifier = 'work-packages--activities-tab--index';+ const target = document.getElementById(identifier)!;- initializeUseMeta() {- useMeta(this as unknown as Controller<HTMLElement>, { suffix: false });- }- };-};+ return this.application.getControllerForElementAndIdentifier(target, identifier) as IndexController;+ }+}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.tsindex b31631f3941..0af8f354821 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@@ -28,16 +28,15 @@* ++*/-import { Controller } from '@hotwired/stimulus';import {ICKEditorInstance,} from 'core-app/shared/components/editor/components/ckeditor/ckeditor.types';import { retrieveCkEditorInstance } from 'core-app/shared/helpers/ckeditor-helpers';import AutoScrollingController from './auto-scrolling.controller';import StemsController from './stems.controller';-import { withIndexOutletMixin } from './mixins/with-index-outlet';+import BaseController from './base.controller';-export default class EditorController extends withIndexOutletMixin(Controller) {+export default class EditorController extends BaseController {static outlets = ['work-packages--activities-tab--auto-scrolling','work-packages--activities-tab--stems',@@ -58,6 +57,8 @@ export default class EditorController extends withIndexOutletMixin(Controller) {private ckEditorAbortController = new AbortController();connect() {+ super.connect();+this.setupEventListeners();this.setLocalStorageKeys();this.populateRescuedEditorContent();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.tsindex e06122e932a..39f88eff383 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@@ -28,12 +28,11 @@* ++*/-import { Controller } from '@hotwired/stimulus';import { renderStreamMessage } from '@hotwired/turbo';import type EditorController from './editor.controller';-import { withIndexOutletMixin } from './mixins/with-index-outlet';+import BaseController from './base.controller';-export default class InternalCommentController extends withIndexOutletMixin(Controller) {+export default class InternalCommentController extends BaseController {static outlets = ['work-packages--activities-tab--editor'];declare readonly workPackagesActivitiesTabEditorOutlet:EditorController;private get editorOutlet() { return this.workPackagesActivitiesTabEditorOutlet; }@@ -55,10 +54,6 @@ export default class InternalCommentController extends withIndexOutletMixin(Contdeclare isInternalValue:boolean;- connect() {- this.initializeUseMeta();- }-onSubmitEnd(_event:CustomEvent):void {if (this.hasInternalCheckboxTarget) {this.toggleInternal();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.tsindex 58673371ced..efb096d72a2 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@@ -28,14 +28,13 @@* ++*/-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 type AutoScrollingController from './auto-scrolling.controller';import StemsController from './stems.controller';-import { withIndexOutletMixin } from './mixins/with-index-outlet';+import BaseController from './base.controller';-export default class PollingController extends withIndexOutletMixin(Controller) {+export default class PollingController extends BaseController {static outlets = ['work-packages--activities-tab--auto-scrolling', 'work-packages--activities-tab--stems'];declare readonly workPackagesActivitiesTabAutoScrollingOutlet:AutoScrollingController;declare readonly workPackagesActivitiesTabStemsOutlet:StemsController;@@ -53,7 +52,7 @@ export default class PollingController extends withIndexOutletMixin(Controller)private abortController = new AbortController();async connect() {- this.initializeUseMeta();+ super.connect();const context = await window.OpenProject.getPluginContext();this.turboRequests = context.services.turboRequests;diff --git a/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/stems.controller.ts b/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/stems.controller.tsindex 31184559c98..18d012d51e0 100644--- a/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/stems.controller.ts+++ b/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/stems.controller.ts@@ -28,11 +28,12 @@* ++*/-import { Controller } from '@hotwired/stimulus';-import { withIndexOutletMixin } from './mixins/with-index-outlet';+import BaseController from './base.controller';-export default class StemsController extends withIndexOutletMixin(Controller) {+export default class StemsController extends BaseController {connect() {+ super.connect();+this.handleStemVisibility();}