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
Extract polling and editor stimulus values from the index controller (#19735)
Kabiru Mwenja4003b0e30a4a
diff --git a/app/components/work_packages/activities_tab/index_component.rb b/app/components/work_packages/activities_tab/index_component.rbindex 04dcce4b307..c1bd41061ef 100644--- a/app/components/work_packages/activities_tab/index_component.rb+++ b/app/components/work_packages/activities_tab/index_component.rb@@ -66,19 +66,20 @@ module WorkPackages].join(" ")}stimulus_controller_values = {+ editor_stimulus_controller("-unsaved-changes-confirmation-message-value") => unsaved_changes_confirmation_message,index_stimulus_controller("-notification-center-path-name-value") => notifications_path,- index_stimulus_controller("-update-streams-path-value") => update_streams_work_package_activities_path(work_package),index_stimulus_controller("-sorting-value") => journal_sorting,index_stimulus_controller("-filter-value") => filter,index_stimulus_controller("-user-id-value") => User.current.id,index_stimulus_controller("-work-package-id-value") => work_package.id,- index_stimulus_controller("-polling-interval-in-ms-value") => polling_interval,- index_stimulus_controller("-show-conflict-flash-message-url-value") => show_conflict_flash_message_work_packages_path,- index_stimulus_controller("-last-server-timestamp-value") => last_server_timestamp,- index_stimulus_controller("-unsaved-changes-confirmation-message-value") => unsaved_changes_confirmation_message+ polling_stimulus_controller("-last-server-timestamp-value") => last_server_timestamp,+ polling_stimulus_controller("-polling-interval-in-ms-value") => polling_interval,+ polling_stimulus_controller("-show-conflict-flash-message-url-value") => show_conflict_flash_message_work_packages_path,+ polling_stimulus_controller("-update-streams-path-value") => update_streams_work_package_activities_path(work_package)}stimulus_controller_outlets = {editor_stimulus_controller("-#{auto_scrolling_stimulus_controller}-outlet") => index_component_dom_selector,+ editor_stimulus_controller("-#{polling_stimulus_controller}-outlet") => index_component_dom_selector,editor_stimulus_controller("-#{stems_stimulus_controller}-outlet") => index_component_dom_selector,polling_stimulus_controller("-#{auto_scrolling_stimulus_controller}-outlet") => index_component_dom_selector,polling_stimulus_controller("-#{stems_stimulus_controller}-outlet") => index_component_dom_selectordiff --git a/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/base.controller.ts b/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/base.controller.tsindex 5c284fed338..cf8eef1a9c0 100644--- a/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/base.controller.ts+++ b/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/base.controller.ts@@ -31,7 +31,7 @@import { Controller } from '@hotwired/stimulus';import { useMeta } from 'stimulus-use';import { ViewPortServiceInterface } from './services/view-port-service';-import IndexController from './index.controller';+import type IndexController from './index.controller';export default class BaseController extends Controller implements ViewPortServiceInterface {static metaNames = ['csrf-token'];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 08d18018860..592410244aa 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@@ -32,21 +32,31 @@ 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 type AutoScrollingController from './auto-scrolling.controller';import BaseController from './base.controller';+import type PollingController from './polling.controller';+import type StemsController from './stems.controller';export default class EditorController extends BaseController {static outlets = ['work-packages--activities-tab--auto-scrolling',+ 'work-packages--activities-tab--polling','work-packages--activities-tab--stems',];declare readonly workPackagesActivitiesTabAutoScrollingOutlet:AutoScrollingController;+ declare readonly workPackagesActivitiesTabPollingOutlet:PollingController;declare readonly workPackagesActivitiesTabStemsOutlet:StemsController;private get autoScrollingOutlet() { return this.workPackagesActivitiesTabAutoScrollingOutlet; }+ private get pollingOutlet() { return this.workPackagesActivitiesTabPollingOutlet; }private get stemsOutlet() { return this.workPackagesActivitiesTabStemsOutlet; }+ static values = {+ unsavedChangesConfirmationMessage: String,+ };++ declare unsavedChangesConfirmationMessageValue:string;+static targets = ['buttonRow', 'formRow', 'form'];declare readonly buttonRowTarget:HTMLInputElement;declare readonly formRowTarget:HTMLElement;@@ -127,7 +137,7 @@ export default class EditorController extends BaseController {this.closeForm();} else {// eslint-disable-next-line no-alert- const shouldClose = window.confirm(this.indexOutlet.unsavedChangesConfirmationMessageValue);+ const shouldClose = window.confirm(this.unsavedChangesConfirmationMessageValue);if (shouldClose) { this.closeForm(); }}}@@ -219,7 +229,7 @@ export default class EditorController extends BaseController {if (formSubmitResponse.succeeded) {// extract server timestamp from response headers in order to be in sync with the server- this.indexOutlet.setLastServerTimestampViaHeaders(formSubmitResponse.response.headers);+ this.pollingOutlet.setLastServerTimestampViaHeaders(formSubmitResponse.response.headers);if (!this.indexOutlet.hasJournalsContainerTarget) return;diff --git a/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/index.controller.ts b/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/index.controller.tsindex 0da3117c524..ab234aae8dd 100644--- a/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/index.controller.ts+++ b/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/index.controller.ts@@ -33,28 +33,18 @@ import { ViewPortService } from './services/view-port-service';export default class IndexController extends Controller<HTMLElement> {static values = {- updateStreamsPath: String,- sorting: String,- pollingIntervalInMs: Number,filter: String,+ notificationCenterPathName: String,+ sorting: String,userId: Number,workPackageId: Number,- notificationCenterPathName: String,- lastServerTimestamp: String,- showConflictFlashMessageUrl: String,- unsavedChangesConfirmationMessage: String,};- declare updateStreamsPathValue:string;- declare sortingValue:string;- declare lastServerTimestampValue:string;- declare pollingIntervalInMsValue:number;- declare notificationCenterPathNameValue:string;declare filterValue:string;+ declare notificationCenterPathNameValue:string;+ declare sortingValue:string;declare userIdValue:number;declare workPackageIdValue:number;- declare showConflictFlashMessageUrlValue:string;- declare unsavedChangesConfirmationMessageValue:string;static targets = ['journalsContainer'];declare readonly journalsContainerTarget:HTMLElement;@@ -90,12 +80,6 @@ export default class IndexController extends Controller<HTMLElement> {this.journalsContainerTarget.classList.add('work-packages-activities-tab-index-component--journals-container_with-initial-input-compensation');}- setLastServerTimestampViaHeaders(headers:Headers) {- if (headers.has('X-Server-Timestamp')) {- this.lastServerTimestampValue = headers.get('X-Server-Timestamp') as string;- }- }-showJournalsContainerInput() {if (!this.hasJournalsContainerTarget) return;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 efb096d72a2..1fa214b845c 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,8 +31,8 @@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 BaseController from './base.controller';+import type StemsController from './stems.controller';export default class PollingController extends BaseController {static outlets = ['work-packages--activities-tab--auto-scrolling', 'work-packages--activities-tab--stems'];@@ -41,6 +41,18 @@ export default class PollingController extends BaseController {private get autoScrollingOutlet() { return this.workPackagesActivitiesTabAutoScrollingOutlet; }private get stemsOutlet() { return this.workPackagesActivitiesTabStemsOutlet; }+ static values = {+ lastServerTimestamp: String,+ pollingIntervalInMs: { type: Number, default: 10000 },+ showConflictFlashMessageUrl: String,+ updateStreamsPath: String,+ };++ declare lastServerTimestampValue:string;+ declare pollingIntervalInMsValue:number;+ declare showConflictFlashMessageUrlValue:string;+ declare updateStreamsPathValue:string;+static targets = ['editForm', 'reactionButton'];declare readonly editFormTargets:HTMLFormElement[];declare readonly reactionButtonTargets:HTMLElement[];@@ -97,12 +109,18 @@ export default class PollingController extends BaseController {});}+ setLastServerTimestampViaHeaders(headers:Headers) {+ if (headers.has('X-Server-Timestamp')) {+ this.lastServerTimestampValue = headers.get('X-Server-Timestamp') as string;+ }+ }+private startPolling() {if (this.intervallId) {this.stopPolling();}- this.intervallId = window.setInterval(() => this.updateActivitiesList(), this.indexOutlet.pollingIntervalInMsValue);+ this.intervallId = window.setInterval(() => this.updateActivitiesList(), this.pollingIntervalInMsValue);}private stopPolling() {@@ -166,11 +184,11 @@ export default class PollingController extends BaseController {private prepareUpdateStreamsUrl(editingJournals:Set<string>):string {const baseUrl = window.location.origin;- const url = new URL(this.indexOutlet.updateStreamsPathValue, baseUrl);+ const url = new URL(this.updateStreamsPathValue, baseUrl);url.searchParams.set('sortBy', this.indexOutlet.sortingValue);url.searchParams.set('filter', this.indexOutlet.filterValue);- url.searchParams.set('last_update_timestamp', this.indexOutlet.lastServerTimestampValue);+ url.searchParams.set('last_update_timestamp', this.lastServerTimestampValue);if (editingJournals.size > 0) {url.searchParams.set('editing_journals', Array.from(editingJournals).join(','));@@ -185,7 +203,7 @@ export default class PollingController extends BaseController {// a specific signal would be way better than a static timeout, but I couldn't find a suitable onesetTimeout(() => {this.stemsOutlet.handleStemVisibility();- this.indexOutlet.setLastServerTimestampViaHeaders(headers);+ this.setLastServerTimestampViaHeaders(headers);this.checkForAndHandleWorkPackageUpdate(html);this.checkForNewNotifications(html);this.performAutoScrolling(html, journalsContainerAtBottom);@@ -249,7 +267,7 @@ export default class PollingController extends BaseController {// currently we do not have a programmatic way to show the primer flash messages// so we just do a request to the server to show it// should be refactored once we have a programmatic way to show the primer flash messages!- const url = `${this.indexOutlet.showConflictFlashMessageUrlValue}?scheme=warning`;+ const url = `${this.showConflictFlashMessageUrlValue}?scheme=warning`;void this.turboRequests.request(url, { method: 'GET' });}