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
optimized polling approach in order to avoid unnecessary requests
Jonas Jabariec8367cfb859
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 0ff411fe5c1..5cd753d2aee 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@@ -32,40 +32,48 @@ export default class IndexController extends Controller {this.setLastUpdateTimestamp();this.setupEventListeners();this.handleInitialScroll();- this.intervallId = this.pollForUpdates();+ this.startPolling();}disconnect() {- document.removeEventListener('work-package-updated', this.handleWorkPackageUpdate);- window.clearInterval(this.intervallId);+ this.removeEventListeners();+ this.stopPolling();}private setupEventListeners() {this.handleWorkPackageUpdate = this.handleWorkPackageUpdate.bind(this);+ this.handleVisibilityChange = this.handleVisibilityChange.bind(this);document.addEventListener('work-package-updated', this.handleWorkPackageUpdate);+ document.addEventListener('visibilitychange', this.handleVisibilityChange);}- private handleInitialScroll() {- if (window.location.hash.includes('#activity-')) {- this.scrollToActivity();- } else if (this.sortingValue === 'asc') {- this.scrollToBottom();+ private removeEventListeners() {+ this.handleWorkPackageUpdate = this.handleWorkPackageUpdate.bind(this);+ this.handleVisibilityChange = this.handleVisibilityChange.bind(this);+ document.removeEventListener('work-package-updated', this.handleWorkPackageUpdate);+ document.removeEventListener('visibilitychange', this.handleVisibilityChange);+ }++ private handleVisibilityChange() {+ if (document.hidden) {+ this.stopPolling();+ } else {+ this.updateActivitiesList();+ this.startPolling();}}- private scrollToActivity() {- const activityId = window.location.hash.replace('#activity-', '');- const activityElement = document.getElementById(`activity-${activityId}`);- activityElement?.scrollIntoView({ behavior: 'smooth' });+ private startPolling() {+ if (this.intervallId) window.clearInterval(this.intervallId);+ this.intervallId = this.pollForUpdates();}- private scrollToBottom() {- const scrollableContainer = jQuery(this.element).scrollParent()[0];- if (scrollableContainer) {- setTimeout(() => {- scrollableContainer.scrollTop = scrollableContainer.scrollHeight;- }, 400);- }+ private stopPolling() {+ window.clearInterval(this.intervallId);+ }++ private pollForUpdates() {+ return window.setInterval(() => this.updateActivitiesList(), this.pollingIntervalInMsValue);}async handleWorkPackageUpdate(event:Event) {@@ -86,8 +94,27 @@ export default class IndexController extends Controller {}}- private pollForUpdates() {- return window.setInterval(() => this.updateActivitiesList(), this.pollingIntervalInMsValue);+ private handleInitialScroll() {+ if (window.location.hash.includes('#activity-')) {+ this.scrollToActivity();+ } else if (this.sortingValue === 'asc') {+ this.scrollToBottom();+ }+ }++ private scrollToActivity() {+ const activityId = window.location.hash.replace('#activity-', '');+ const activityElement = document.getElementById(`activity-${activityId}`);+ activityElement?.scrollIntoView({ behavior: 'smooth' });+ }++ private scrollToBottom() {+ const scrollableContainer = jQuery(this.element).scrollParent()[0];+ if (scrollableContainer) {+ setTimeout(() => {+ scrollableContainer.scrollTop = scrollableContainer.scrollHeight;+ }, 400);+ }}setFilterToOnlyComments() { this.filterValue = 'only_comments'; }@@ -177,6 +204,13 @@ export default class IndexController extends Controller {}}+ focusEditor() {+ const ckEditorInstance = this.getCkEditorInstance();+ if (ckEditorInstance) {+ setTimeout(() => ckEditorInstance.editing.view.focus(), 10);+ }+ }+quote(event:Event) {event.preventDefault();const target = event.currentTarget as HTMLElement;@@ -239,6 +273,7 @@ export default class IndexController extends Controller {if (this.journalsContainerTarget) {this.clearEditor();+ this.focusEditor();if (this.journalsContainerTarget) {this.journalsContainerTarget.style.marginBottom = '';this.journalsContainerTarget.classList.add('with-input-compensation');