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
js refactoring as requested by @oliverguenther
Jonas Jabarifc45e41df6ee
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 e2176862308..e94cf1f744d 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@@ -359,6 +359,16 @@ export default class IndexController extends Controller {async onSubmit(event:Event | null = null) {event?.preventDefault();++ const formData = this.prepareFormData();+ const response = await this.submitForm(formData);++ if (!response.ok) return;++ await this.handleSuccessfulSubmission(response);+ }++ private prepareFormData():FormData {const ckEditorInstance = this.getCkEditorInstance();const data = ckEditorInstance ? ckEditorInstance.getData({ trim: false }) : '';@@ -367,37 +377,50 @@ export default class IndexController extends Controller {formData.append('filter', this.filterValue);formData.append('journal[notes]', data);- const response = await this.fetchWithCSRF(this.formTarget.action, 'POST', formData);+ return formData;+ }- if (response.ok) {- this.setLastUpdateTimestamp();- const text = await response.text();- Turbo.renderStreamMessage(text);+ private async submitForm(formData:FormData):Promise<Response> {+ return this.fetchWithCSRF(this.formTarget.action, 'POST', formData);+ }- if (this.journalsContainerTarget) {- this.clearEditor();- if (this.isMobile()) {- this.hideEditorIfEmpty();- } else {- this.focusEditor();- }- if (this.journalsContainerTarget) {- this.journalsContainerTarget.style.marginBottom = '';- this.journalsContainerTarget.classList.add('work-packages-activities-tab-index-component--journals-container_with-input-compensation');- }- setTimeout(() => {- this.scrollJournalContainer(- this.journalsContainerTarget,- this.sortingValue === 'asc',- );- if (this.isMobile()) {- this.scrollInputContainerIntoView(300);- }- }, 10);+ private async handleSuccessfulSubmission(response:Response):Promise<void> {+ this.setLastUpdateTimestamp();+ const text = await response.text();+ Turbo.renderStreamMessage(text);++ if (!this.journalsContainerTarget) return;++ this.clearEditor();+ this.handleEditorVisibility();+ this.adjustJournalsContainer();++ setTimeout(() => {+ this.scrollJournalContainer(+ this.journalsContainerTarget,+ this.sortingValue === 'asc',+ );+ if (this.isMobile()) {+ this.scrollInputContainerIntoView(300);}+ }, 10);+ }++ private handleEditorVisibility():void {+ if (this.isMobile()) {+ this.hideEditorIfEmpty();+ } else {+ this.focusEditor();}}+ private adjustJournalsContainer():void {+ if (!this.journalsContainerTarget) return;++ this.journalsContainerTarget.style.marginBottom = '';+ this.journalsContainerTarget.classList.add('work-packages-activities-tab-index-component--journals-container_with-input-compensation');+ }+private async fetchWithCSRF(url:string | URL, method:string, body?:FormData) {return fetch(url, {method,