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
Add special behaviour when clearing a date and setting the duration afterwards
Henriette Dargefbc3f2f8660c
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 342f77c205d..6be97e64c8f 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@@ -233,7 +233,7 @@ export default class PreviewController extends DialogPreviewController {if (this.currentDueDate) {this.highlightField(this.dueDateField);}- this.keepFieldValueWithPriority('start_date', 'due_date', 'duration');+ this.keepFieldValue();}changeDueDate(selectedDate:Date) {@@ -251,7 +251,7 @@ export default class PreviewController extends DialogPreviewController {if (this.currentStartDate) {this.highlightField(this.startDateField);}- this.keepFieldValueWithPriority('start_date', 'due_date', 'duration');+ this.keepFieldValue();}private updateFlatpickrCalendar() {@@ -306,7 +306,7 @@ export default class PreviewController extends DialogPreviewController {doMarkFieldAsTouched(fieldName:string) {super.doMarkFieldAsTouched(fieldName);- this.keepFieldValueWithPriority('start_date', 'due_date', 'duration');+ this.keepFieldValue();}setIgnoreNonWorkingDays(event:{ target:HTMLInputElement }) {@@ -445,4 +445,64 @@ export default class PreviewController extends DialogPreviewController {}return null;}++ /*+ * I am aware, that the following methods look pretty similar to the logic on the progress/preview controller.+ * There are however slight differences. That could still be abstracted into the shared parent controller.+ * However, this comes at the cost of heavily reduced readability which is why it was agreed to keep it duplicated like this.+ * Further, in the future, is is likely that the datepicker and the progress will further diverge in their behavior.+ */+ private keepFieldValue() {+ if (this.isInitialValueEmpty('start_date') && !this.isTouched('start_date')) {+ // let start date be derived+ return;+ }++ if (this.isBeingEdited('start_date')) {+ this.untouchFieldsWhenStartDateIsEdited();+ } else if (this.isBeingEdited('due_date')) {+ this.untouchFieldsWhenDueDateIsEdited();+ } else if (this.isBeingEdited('duration')) {+ this.untouchFieldsWhenDurationIsEdited();+ }+ }++ private untouchFieldsWhenStartDateIsEdited() {+ if (this.areBothTouched('due_date', 'duration')) {+ if (this.isValueEmpty('duration') && this.isValueEmpty('due_date')) {+ return;+ }+ if (this.isValueEmpty('duration')) {+ this.markUntouched('duration');+ } else {+ this.markUntouched('due_date');+ }+ } else if (this.isTouchedAndEmpty('due_date') && this.isValueSet('duration')) {+ // force due date derivation+ this.markUntouched('due_date');+ this.markTouched('duration');+ } else if (this.isTouchedAndEmpty('duration') && this.isValueSet('due_date')) {+ // force duration derivation+ this.markUntouched('duration');+ this.markTouched('due_date');+ }+ }++ private untouchFieldsWhenDueDateIsEdited():void {+ if (this.isTouchedAndEmpty('start_date') && this.isValueSet('duration')) {+ // force start date derivation+ this.markUntouched('start_date');+ this.markTouched('duration');+ } else if (this.isValueSet('start_date')) {+ this.markUntouched('duration');+ }+ }++ private untouchFieldsWhenDurationIsEdited():void {+ if (this.isValueSet('start_date')) {+ this.markUntouched('due_date');+ } else if (this.isValueSet('due_date')) {+ this.markUntouched('start_date');+ }+ }}diff --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 9d4f5ca535d..fbd464f4ad5 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@@ -228,56 +228,4 @@ 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 c4d6e491eeb..95220dcc34d 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@@ -107,11 +107,63 @@ export default class PreviewController extends DialogPreviewController {this.markTouched(this.targetFieldName);if (this.isWorkBasedMode()) {- this.keepFieldValueWithPriority('estimated_hours', 'remaining_hours', 'done_ratio');+ this.keepWorkValue();}}private isWorkBasedMode() {return this.findValueInput('done_ratio') !== undefined;}++ private keepWorkValue() {+ if (this.isInitialValueEmpty('estimated_hours') && !this.isTouched('estimated_hours')) {+ // let work be derived+ return;+ }++ if (this.isBeingEdited('estimated_hours')) {+ this.untouchFieldsWhenWorkIsEdited();+ } else if (this.isBeingEdited('remaining_hours')) {+ this.untouchFieldsWhenRemainingWorkIsEdited();+ } else if (this.isBeingEdited('done_ratio')) {+ this.untouchFieldsWhenPercentCompleteIsEdited();+ }+ }++ private untouchFieldsWhenWorkIsEdited() {+ if (this.areBothTouched('remaining_hours', 'done_ratio')) {+ if (this.isValueEmpty('done_ratio') && this.isValueEmpty('remaining_hours')) {+ return;+ }+ if (this.isValueEmpty('done_ratio')) {+ this.markUntouched('done_ratio');+ } else {+ this.markUntouched('remaining_hours');+ }+ } else if (this.isTouchedAndEmpty('remaining_hours') && this.isValueSet('done_ratio')) {+ // force remaining work derivation+ this.markUntouched('remaining_hours');+ this.markTouched('done_ratio');+ } else if (this.isTouchedAndEmpty('done_ratio') && this.isValueSet('remaining_hours')) {+ // force % complete derivation+ this.markUntouched('done_ratio');+ this.markTouched('remaining_hours');+ }+ }++ private untouchFieldsWhenRemainingWorkIsEdited() {+ if (this.isTouchedAndEmpty('estimated_hours') && this.isValueSet('done_ratio')) {+ // force work derivation+ this.markUntouched('estimated_hours');+ this.markTouched('done_ratio');+ } else if (this.isValueSet('estimated_hours')) {+ this.markUntouched('done_ratio');+ }+ }++ private untouchFieldsWhenPercentCompleteIsEdited() {+ if (this.isValueSet('estimated_hours')) {+ this.markUntouched('remaining_hours');+ }+ }}diff --git a/spec/features/work_packages/datepicker/datepicker_single_date_mode_logic_spec.rb b/spec/features/work_packages/datepicker/datepicker_single_date_mode_logic_spec.rbindex 105e9593d03..d5dbf966c66 100644--- a/spec/features/work_packages/datepicker/datepicker_single_date_mode_logic_spec.rb+++ b/spec/features/work_packages/datepicker/datepicker_single_date_mode_logic_spec.rb@@ -748,5 +748,41 @@ RSpec.describe "Datepicker: Single-date mode logic test cases (WP #61146)", :js,datepicker.expect_due_highlightedendend++ context "and start date is cleared and a duration is set (scenario 23a)" do+ it "preserves the start date" do+ datepicker.expect_start_date "2025-02-12"+ datepicker.expect_due_date "2025-02-14"+ datepicker.expect_duration "3"++ datepicker.set_start_date ""+ datepicker.focus_duration+ datepicker.set_duration "3"++ datepicker.expect_start_date "2025-02-12"+ datepicker.expect_due_date "2025-02-14"+ datepicker.expect_duration "3"++ datepicker.expect_duration_highlighted+ end+ end++ context "and finish date is cleared and a duration is set (scenario 23b)" do+ it "preserves the finish date" do+ datepicker.expect_start_date "2025-02-12"+ datepicker.expect_due_date "2025-02-14"+ datepicker.expect_duration "3"++ datepicker.set_due_date ""+ datepicker.focus_duration+ datepicker.set_duration "3"++ datepicker.expect_start_date "2025-02-12"+ datepicker.expect_due_date "2025-02-14"+ datepicker.expect_duration "3"++ datepicker.expect_duration_highlighted+ end+ endendend