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
handle switching from manual to automatic
ulferts74fe1919970c
diff --git a/app/services/work_packages/set_attributes_service.rb b/app/services/work_packages/set_attributes_service.rbindex 95bfe647db2..6fc42e53c0b 100644--- a/app/services/work_packages/set_attributes_service.rb+++ b/app/services/work_packages/set_attributes_service.rb@@ -143,16 +143,15 @@ class WorkPackages::SetAttributesService < ::BaseServices::SetAttributesmin_start = new_start_date- if min_start- work_package.due_date = min_start + work_package.duration - 1- work_package.start_date = min_start- end+ return unless min_start++ work_package.due_date = new_due_date(min_start)+ work_package.start_date = min_startenddef set_version_to_nilif work_package.version &&- !(work_package.project &&- work_package.project.shared_versions.include?(work_package.version))+ !work_package.project&.shared_versions.include?(work_package.version)work_package.version = nilendend@@ -201,17 +200,32 @@ class WorkPackages::SetAttributesService < ::BaseServices::SetAttributesdef new_start_datecurrent_start_date = work_package.start_date || work_package.due_date- return unless work_package.parent_id_changed? &&- work_package.parent_id &&- current_start_date+ return unless current_start_date && work_package.schedule_automatically?- min_start = work_package.parent.soonest_start+ min_start = new_start_date_from_parent || new_start_date_from_self- if min_start && (min_start > current_start_date)+ if min_start && (min_start > current_start_date || work_package.schedule_manually_changed?)min_startendend+ def new_start_date_from_parent+ return unless work_package.parent_id_changed? &&+ work_package.parent_id++ work_package.parent.soonest_start+ end++ def new_start_date_from_self+ return unless work_package.schedule_manually_changed?++ [min_child_date, work_package.soonest_start].compact.max+ end++ def new_due_date(min_start)+ min_start + (children_duration || work_package.duration) - 1+ end+def work_packagemodelend@@ -219,4 +233,20 @@ class WorkPackages::SetAttributesService < ::BaseServices::SetAttributesdef assignable_statusesinstantiate_contract(work_package, user).assignable_statuses(true)end++ def min_child_date+ (work_package.children.map(&:start_date) + work_package.children.map(&:due_date)).compact.min+ end++ def children_duration+ max = max_child_date++ return unless max++ max - min_child_date + 1+ end++ def max_child_date+ (work_package.children.map(&:start_date) + work_package.children.map(&:due_date)).compact.max+ endenddiff --git a/config/locales/js-en.yml b/config/locales/js-en.ymlindex aa5c8b4b867..173f1cf1a5a 100644--- a/config/locales/js-en.yml+++ b/config/locales/js-en.yml@@ -866,6 +866,7 @@ en:text_no_results: "No matching views were found."scheduling:is_parent: "The dates of this work package are automatically deduced from its children. Activate 'Manual scheduling' to set the dates."+ is_switched_from_manual_to_automatic: "The dates of this work package will need to be recalculated after switching from manual to automatic scheduling."table:configure_button: 'Configure work package table'summary: "Table with rows of work package and columns of work package attributes."diff --git a/frontend/src/app/components/datepicker/datepicker.modal.html b/frontend/src/app/components/datepicker/datepicker.modal.htmlindex f365be9dc60..671602b4056 100644--- a/frontend/src/app/components/datepicker/datepicker.modal.html+++ b/frontend/src/app/components/datepicker/datepicker.modal.html@@ -115,7 +115,12 @@<ng-container *ngIf="!isSchedulable"><div class="notification-box -info"><div class="notification-box--content">- <p [textContent]="text.isParent"></p>+ <ng-container *ngIf="isParent">+ <p [textContent]="text.isParent"></p>+ </ng-container>+ <ng-container *ngIf="isSwitchedFromManualToAutomatic && !isParent">+ <p [textContent]="text.isSwitchedFromManualToAutomatic"></p>+ </ng-container></div></div></ng-container>diff --git a/frontend/src/app/components/datepicker/datepicker.modal.ts b/frontend/src/app/components/datepicker/datepicker.modal.tsindex 794330a8b9c..e101da4a2eb 100644--- a/frontend/src/app/components/datepicker/datepicker.modal.ts+++ b/frontend/src/app/components/datepicker/datepicker.modal.ts@@ -74,7 +74,8 @@ export class DatePickerModal extends OpModalComponent implements AfterViewInit {endDate: this.I18n.t('js.work_packages.properties.dueDate'),placeholder: this.I18n.t('js.placeholders.default'),today: this.I18n.t('js.label_today'),- isParent: this.I18n.t('js.work_packages.scheduling.is_parent')+ isParent: this.I18n.t('js.work_packages.scheduling.is_parent'),+ isSwitchedFromManualToAutomatic: this.I18n.t('js.work_packages.scheduling.is_switched_from_manual_to_automatic')};public onDataUpdated = new EventEmitter<string>();@@ -129,7 +130,7 @@ export class DatePickerModal extends OpModalComponent implements AfterViewInit {if (this.scheduleManually) {this.showDateSelection();- } else {+ } else if (this.isParent) {this.removeDateSelection();}}@@ -200,11 +201,26 @@ export class DatePickerModal extends OpModalComponent implements AfterViewInit {}/**- * Retuns whether the user can alter the dates of the work package.- * The work package is schedulable if the work package is a not a parent or if manual scheduling is enabled.+ * Returns whether the user can alter the dates of the work package.+ * The work package is always schedulable if the work package scheduled manually.+ * But it might also be altered in automatic scheduling mode if it does not have children and if there was+ * no switch from manual to automatic scheduling.+ * The later is necessary as we cannot correctly calculate the resulting dates in the frontend.*/get isSchedulable():boolean {- return !this.isParent || this.scheduleManually;+ return this.scheduleManually || (!this.isParent && !this.isSwitchedFromManualToAutomatic);+ }++ /**+ * Determines whether the work package is a parent. It does so+ * by checking the children links.+ */+ get isParent():boolean {+ return this.changeset.projectedResource.$links.children && this.changeset.projectedResource.$links.children.length > 0;+ }++ get isSwitchedFromManualToAutomatic():boolean {+ return !this.scheduleManually && this.changeset.value('scheduleManually');}private showDateSelection() {@@ -357,11 +373,4 @@ export class DatePickerModal extends OpModalComponent implements AfterViewInit {return this.locals.fieldName === 'dueDate' || (this.dates.start && !this.dates.end) ? 'end' : 'start';}- /**- * Determines whether the work package is a parent. It does so- * by checking the children links.- */- private get isParent():boolean {- return this.changeset.projectedResource.$links.children.length > 0;- }}diff --git a/frontend/src/app/components/wp-edit-form/display-field-renderer.ts b/frontend/src/app/components/wp-edit-form/display-field-renderer.tsindex cb031d7b03b..1855f931bde 100644--- a/frontend/src/app/components/wp-edit-form/display-field-renderer.ts+++ b/frontend/src/app/components/wp-edit-form/display-field-renderer.ts@@ -110,11 +110,6 @@ export class DisplayFieldRenderer<T extends HalResource = HalResource> {return new MultipleLinesUserFieldModule(name, context) as DisplayField;}- // In the single view, start and end date are shown in a combined date field- if (this.container === 'single-view' && (name === 'combinedDate')) {- return new CombinedDateDisplayField(name, context) as DisplayField;- }-// We handle progress differently in the timelineif (this.container === 'timeline' && name === 'percentageDone') {return new ProgressTextDisplayField(name, context);diff --git a/frontend/src/app/modules/fields/display/display-field.initializer.ts b/frontend/src/app/modules/fields/display/display-field.initializer.tsindex 150d981d32d..099bc42786b 100644--- a/frontend/src/app/modules/fields/display/display-field.initializer.ts+++ b/frontend/src/app/modules/fields/display/display-field.initializer.ts@@ -49,6 +49,7 @@ import {WorkPackageIdDisplayField} from "core-app/modules/fields/display/field-timport {ProjectStatusDisplayField} from "core-app/modules/fields/display/field-types/project-status-display-field.module";import {PlainFormattableDisplayField} from "core-app/modules/fields/display/field-types/plain-formattable-display-field.module";import {LinkedWorkPackageDisplayField} from "core-app/modules/fields/display/field-types/linked-work-package-display-field.module";+import {CombinedDateDisplayField} from "core-app/modules/fields/display/field-types/combined-date-display.field";export function initializeCoreDisplayFields(displayFieldService:DisplayFieldService) {return () => {@@ -84,6 +85,7 @@ export function initializeCoreDisplayFields(displayFieldService:DisplayFieldServdisplayFieldService.addSpecificFieldType('WorkPackage', WorkPackageIdDisplayField, 'id', ['id']).addSpecificFieldType('WorkPackage', WorkPackageSpentTimeDisplayField, 'spentTime', ['spentTime'])+ .addSpecificFieldType('WorkPackage', CombinedDateDisplayField, 'combinedDate', ['combinedDate']).addSpecificFieldType('TimeEntry', PlainFormattableDisplayField, 'comment', ['comment']).addSpecificFieldType('TimeEntry', WorkPackageDisplayField, 'work_package', ['workPackage']);};diff --git a/frontend/src/app/modules/fields/edit/field/editable-attribute-field.component.ts b/frontend/src/app/modules/fields/edit/field/editable-attribute-field.component.tsindex f63015acdfc..c5b07699467 100644--- a/frontend/src/app/modules/fields/edit/field/editable-attribute-field.component.ts+++ b/frontend/src/app/modules/fields/edit/field/editable-attribute-field.component.ts@@ -53,7 +53,6 @@ import {ConfigurationService} from 'core-app/modules/common/config/configurationimport {OPContextMenuService} from "core-components/op-context-menu/op-context-menu.service";import {NotificationsService} from 'core-app/modules/common/notifications/notifications.service';import {I18nService} from 'core-app/modules/common/i18n/i18n.service';-import {IFieldSchema} from "core-app/modules/fields/field.base";import {ClickPositionMapper} from "core-app/modules/common/set-click-position/set-click-position";import {EditFormComponent} from "core-app/modules/fields/edit/edit-form/edit-form.component";import {HalResource} from "core-app/modules/hal/resources/hal-resource";diff --git a/spec/features/work_packages/scheduling/scheduling_mode_spec.rb b/spec/features/work_packages/scheduling/scheduling_mode_spec.rbindex 26c5d0cc54b..cc3d5ffc589 100644--- a/spec/features/work_packages/scheduling/scheduling_mode_spec.rb+++ b/spec/features/work_packages/scheduling/scheduling_mode_spec.rb@@ -62,7 +62,7 @@ describe 'scheduling mode',endendlet!(:wp_pre) do- FactoryBot.create(:work_package, project: project, start_date: '2016-01-06', due_date: '2016-01-10').tap do |pre|+ FactoryBot.create(:work_package, project: project, start_date: '2015-12-15', due_date: '2015-12-31').tap do |pre|FactoryBot.create(:follows_relation, from: wp, to: pre)endend@@ -101,11 +101,11 @@ describe 'scheduling mode',it 'can toggle the scheduling mode through the date modal' doexpect(wp.schedule_manually).to eq false- combined_field.activate!(expect_open: false)- combined_field.expect_active!# Editing the start/due dates of a parent work package is possible if the# work package is manually scheduled+ combined_field.activate!(expect_open: false)+ combined_field.expect_active!combined_field.expect_scheduling_mode manually: falsecombined_field.expect_parent_notificationcombined_field.toggle_scheduling_mode@@ -131,5 +131,98 @@ describe 'scheduling mode',# is moved backwards as the whole hierarchy is moved backwardsexpect_dates(wp_suc_child, '2016-01-11', '2016-01-15')++ # Switching back to automatic scheduling will lead to the work package+ # and all work packages that are dependent to be rescheduled again.+ combined_field.activate!(expect_open: false)+ combined_field.expect_active!+ combined_field.expect_scheduling_mode manually: true+ combined_field.toggle_scheduling_mode+ combined_field.expect_parent_notification+ combined_field.save!++ work_packages_page.expect_and_dismiss_notification message: 'Successful update.'++ # Moved forward again as the child determines the dates again+ expect_dates(wp, '2016-01-01', '2016-01-05')+ expect(wp.schedule_manually).to be_falsey++ # Had not been moved in the first place+ expect_dates(wp_child, '2016-01-01', '2016-01-05')++ # As the child now again takes up the same time interval as the grandchild,+ # the interval is shortened again.+ expect_dates(wp_parent, '2016-01-01', '2016-01-05')++ # is moved forward again because of the follows relationship+ expect_dates(wp_suc, '2016-01-06', '2016-01-10')++ # is moved forward again because its child is also moved forward+ expect_dates(wp_suc_parent, '2016-01-06', '2016-01-10')++ # is moved forward again because its parent is also moved forward+ expect_dates(wp_suc_child, '2016-01-06', '2016-01-10')++ # Switching back to manual scheduling but this time forward will lead to the work package+ # and all work packages that are dependent to be rescheduled again.+ combined_field.activate!(expect_open: false)+ combined_field.expect_active!+ combined_field.expect_scheduling_mode manually: false+ combined_field.expect_parent_notification+ combined_field.toggle_scheduling_mode+ # Increasing the duration while at it+ combined_field.update(%w[2015-12-20 2015-12-31])++ work_packages_page.expect_and_dismiss_notification message: 'Successful update.'++ expect_dates(wp, '2015-12-20', '2015-12-31')+ expect(wp.schedule_manually).to be_truthy++ # is not moved because it is a child+ expect_dates(wp_child, '2016-01-01', '2016-01-05')++ # The start date is moved forward because its child was moved+ # but the due date remains unchanged as its grandchild stays put.+ expect_dates(wp_parent, '2015-12-20', '2016-01-05')++ # is moved forward because of the follows relationship+ expect_dates(wp_suc, '2016-01-01', '2016-01-05')++ # is moved forward because it is the parent of the successor+ expect_dates(wp_suc_parent, '2016-01-01', '2016-01-05')++ # is moved forward as the whole hierarchy is moved backwards+ expect_dates(wp_suc_child, '2016-01-01', '2016-01-05')++ # Switching back to automatic scheduling will lead to the work package+ # and all work packages that are dependent to be rescheduled again.+ combined_field.activate!(expect_open: false)+ combined_field.expect_active!+ combined_field.expect_scheduling_mode manually: true+ combined_field.toggle_scheduling_mode+ combined_field.expect_parent_notification+ combined_field.save!++ work_packages_page.expect_and_dismiss_notification message: 'Successful update.'++ # Moved backwards again as the child determines the dates again+ expect_dates(wp, '2016-01-01', '2016-01-05')+ expect(wp.schedule_manually).to be_falsey++ # Had not been moved in the first place+ expect_dates(wp_child, '2016-01-01', '2016-01-05')++ # As the child now again takes up the same time interval as the grandchild,+ # the interval is shortened again.+ expect_dates(wp_parent, '2016-01-01', '2016-01-05')++ # is moved backwards again because of the follows relationship+ expect_dates(wp_suc, '2016-01-06', '2016-01-10')++ # is moved backwards again because its child is also moved forward+ expect_dates(wp_suc_parent, '2016-01-06', '2016-01-10')++ # is moved backwards again because its parent is also moved forward+ expect_dates(wp_suc_child, '2016-01-06', '2016-01-10')endenddiff --git a/spec/services/work_packages/set_attributes_service_spec.rb b/spec/services/work_packages/set_attributes_service_spec.rbindex 2c1cd4ab3d7..5e95be86404 100644--- a/spec/services/work_packages/set_attributes_service_spec.rb+++ b/spec/services/work_packages/set_attributes_service_spec.rb@@ -633,5 +633,105 @@ describe WorkPackages::SetAttributesService, type: :model doendendend++ context 'when switching back to automatic scheduling' do+ let(:work_package) do+ wp = FactoryBot.build_stubbed(:work_package,+ project: project,+ schedule_manually: true,+ start_date: Date.today,+ due_date: Date.today + 5.days)+ wp.type = FactoryBot.build_stubbed(:type)+ wp.send(:clear_changes_information)++ allow(wp)+ .to receive(:soonest_start)+ .and_return(soonest_start)++ wp+ end+ let(:call_attributes) { { schedule_manually: false } }+ let(:attributes) { {} }+ let(:soonest_start) { Date.today + 1.day }++ context 'when the soonest start date is later than the current start date' do+ let(:soonest_start) { Date.today + 3.days }++ it_behaves_like 'service call' do+ it 'sets the start date to the soonest possible start date' do+ subject++ expect(work_package.start_date).to eql(Date.today + 3.days)+ expect(work_package.due_date).to eql(Date.today + 8.days)+ end+ end+ end++ context 'when the soonest start date is before the current start date' do+ let(:soonest_start) { Date.today - 3.days }++ it_behaves_like 'service call' do+ it 'sets the start date to the soonest possible start date' do+ subject++ expect(work_package.start_date).to eql(Date.today)+ expect(work_package.due_date).to eql(Date.today + 5.days)+ end+ end+ end++ context 'when the soonest start date is nil' do+ let(:soonest_start) { nil }++ it_behaves_like 'service call' do+ it 'sets the start date to the soonest possible start date' do+ subject++ expect(work_package.start_date).to eql(Date.today)+ expect(work_package.due_date).to eql(Date.today + 5.days)+ end+ end+ end++ context 'when the work package also has a child' do+ let(:child) do+ FactoryBot.build_stubbed(:stubbed_work_package,+ start_date: child_start_date,+ due_date: child_due_date)+ end+ let(:child_start_date) { Date.today + 2.days }+ let(:child_due_date) { Date.today + 10.days }++ before do+ allow(work_package)+ .to receive(:children)+ .and_return([child])+ end++ context 'when the child`s start date is after soonest_start' do+ it_behaves_like 'service call' do+ it 'sets the dates to the child dates' do+ subject++ expect(work_package.start_date).to eql(Date.today + 2.days)+ expect(work_package.due_date).to eql(Date.today + 10.days)+ end+ end+ end++ context 'when the child`s start date is before soonest_start' do+ let(:soonest_start) { Date.today + 3.days }++ it_behaves_like 'service call' do+ it 'sets the dates to soonest date and to the duration of the child' do+ subject++ expect(work_package.start_date).to eql(Date.today + 3.days)+ expect(work_package.due_date).to eql(Date.today + 11.days)+ end+ end+ end+ end+ endendend