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
Ensure that only two fields at most are send to the backend, otherwise we can easily create errorneous data. Therefore the logic of the progress controller was moved to the parent controller and abstracted as it is doing the exact same thing.
Henriette Dargefcbc424851c2
diff --git a/frontend/src/stimulus/controllers/dynamic/work-packages/date-picker/preview.controller.ts b/frontend/src/stimulus/controllers/dynamic/work-packages/date-picker/preview.controller.tsindex 9ca48678975..034b71aea58 100644--- a/frontend/src/stimulus/controllers/dynamic/work-packages/date-picker/preview.controller.ts+++ b/frontend/src/stimulus/controllers/dynamic/work-packages/date-picker/preview.controller.ts@@ -43,6 +43,8 @@ export default class PreviewController extends DialogPreviewController {markFieldAsTouched(event:{ target:HTMLInputElement }) {super.markFieldAsTouched(event);++ this.keepFieldValueWithPriority('start_date', 'due_date', 'duration');}// Ensures that on create forms, there is an "id" for the un-persisteddiff --git a/frontend/src/stimulus/controllers/dynamic/work-packages/dialog/preview.controller.ts b/frontend/src/stimulus/controllers/dynamic/work-packages/dialog/preview.controller.tsindex 707f9618635..ffe366be893 100644--- a/frontend/src/stimulus/controllers/dynamic/work-packages/dialog/preview.controller.ts+++ b/frontend/src/stimulus/controllers/dynamic/work-packages/dialog/preview.controller.ts@@ -212,6 +212,10 @@ export abstract class DialogPreviewController extends Controller {return this.touchedFields.has(fieldName);}+ protected areBothTouched(fieldName1:string, fieldName2:string):boolean {+ return this.isTouched(fieldName1) && this.isTouched(fieldName2);+ }+protected isInitialValueEmpty(fieldName:string):boolean {const valueInput = this.findInitialValueInput(fieldName);return valueInput?.value === '';@@ -245,4 +249,56 @@ export abstract class DialogPreviewController extends Controller {}});}++ protected keepFieldValueWithPriority(priority1:string, priority2:string, priority3:string) {+ if (this.isInitialValueEmpty(priority1) && !this.isTouched(priority1)) {+ // let priority field be derived+ return;+ }++ if (this.isBeingEdited(priority1)) {+ this.untouchFieldsWhenPriority1IsEdited(priority2, priority3);+ } else if (this.isBeingEdited(priority2)) {+ this.untouchFieldsWhenPriority2IsEdited(priority1, priority3);+ } else if (this.isBeingEdited(priority3)) {+ this.untouchFieldsWhenPriority3IsEdited(priority1, priority2);+ }+ }++ private untouchFieldsWhenPriority1IsEdited(priority2:string, priority3:string) {+ if (this.areBothTouched(priority2, priority3)) {+ if (this.isValueEmpty(priority3) && this.isValueEmpty(priority2)) {+ return;+ }+ if (this.isValueEmpty(priority3)) {+ this.markUntouched(priority3);+ } else {+ this.markUntouched(priority2);+ }+ } else if (this.isTouchedAndEmpty(priority2) && this.isValueSet(priority3)) {+ // force priority 2 derivation+ this.markUntouched(priority2);+ this.markTouched(priority3);+ } else if (this.isTouchedAndEmpty(priority3) && this.isValueSet(priority2)) {+ // force priority 3 derivation+ this.markUntouched(priority3);+ this.markTouched(priority2);+ }+ }++ private untouchFieldsWhenPriority2IsEdited(priority1:string, priority3:string):void {+ if (this.isTouchedAndEmpty(priority1) && this.isValueSet(priority3)) {+ // force priority 1 derivation+ this.markUntouched(priority1);+ this.markTouched(priority3);+ } else if (this.isValueSet(priority1)) {+ this.markUntouched(priority3);+ }+ }++ private untouchFieldsWhenPriority3IsEdited(priority1:string, priority2:string):void {+ if (this.isValueSet(priority1)) {+ this.markUntouched(priority2);+ }+ }}diff --git a/frontend/src/stimulus/controllers/dynamic/work-packages/progress/preview.controller.ts b/frontend/src/stimulus/controllers/dynamic/work-packages/progress/preview.controller.tsindex 32c4e625e25..d067724b849 100644--- a/frontend/src/stimulus/controllers/dynamic/work-packages/progress/preview.controller.ts+++ b/frontend/src/stimulus/controllers/dynamic/work-packages/progress/preview.controller.ts@@ -35,7 +35,7 @@ export default class PreviewController extends DialogPreviewController {super.markFieldAsTouched(event);if (this.isWorkBasedMode()) {- this.keepWorkValue();+ this.keepFieldValueWithPriority('estimated_hours', 'remaining_hours', 'done_ratio');}}@@ -62,60 +62,4 @@ export default class PreviewController extends DialogPreviewController {private isWorkBasedMode() {return super.findValueInput('done_ratio') !== undefined;}-- private keepWorkValue() {- if (super.isInitialValueEmpty('estimated_hours') && !super.isTouched('estimated_hours')) {- // let work be derived- return;- }-- if (super.isBeingEdited('estimated_hours')) {- this.untouchFieldsWhenWorkIsEdited();- } else if (super.isBeingEdited('remaining_hours')) {- this.untouchFieldsWhenRemainingWorkIsEdited();- } else if (super.isBeingEdited('done_ratio')) {- this.untouchFieldsWhenPercentCompleteIsEdited();- }- }-- private untouchFieldsWhenWorkIsEdited() {- if (this.areBothTouched('remaining_hours', 'done_ratio')) {- if (super.isValueEmpty('done_ratio') && super.isValueEmpty('remaining_hours')) {- return;- }- if (super.isValueEmpty('done_ratio')) {- super.markUntouched('done_ratio');- } else {- super.markUntouched('remaining_hours');- }- } else if (super.isTouchedAndEmpty('remaining_hours') && super.isValueSet('done_ratio')) {- // force remaining work derivation- super.markUntouched('remaining_hours');- super.markTouched('done_ratio');- } else if (super.isTouchedAndEmpty('done_ratio') && super.isValueSet('remaining_hours')) {- // force % complete derivation- super.markUntouched('done_ratio');- super.markTouched('remaining_hours');- }- }-- private untouchFieldsWhenRemainingWorkIsEdited():void {- if (super.isTouchedAndEmpty('estimated_hours') && super.isValueSet('done_ratio')) {- // force work derivation- super.markUntouched('estimated_hours');- super.markTouched('done_ratio');- } else if (super.isValueSet('estimated_hours')) {- super.markUntouched('done_ratio');- }- }-- private untouchFieldsWhenPercentCompleteIsEdited():void {- if (super.isValueSet('estimated_hours')) {- super.markUntouched('remaining_hours');- }- }-- private areBothTouched(fieldName1:string, fieldName2:string):boolean {- return super.isTouched(fieldName1) && super.isTouched(fieldName2);- }}