Skip to content

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

handle switching from automatic to manual

ulferts4dc11b72404b
diff --git a/config/locales/js-en.yml b/config/locales/js-en.yml
index 0ae5ef373c1..aa5c8b4b867 100644
--- a/config/locales/js-en.yml
+++ b/config/locales/js-en.yml
@@ -864,6 +864,8 @@ en:
not_found: "There is no such view"
duplicate_query_title: "Name of this view already exists. Change anyway?"
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."
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.html
index bf2852d50b3..f365be9dc60 100644
--- a/frontend/src/app/components/datepicker/datepicker.modal.html
+++ b/frontend/src/app/components/datepicker/datepicker.modal.html
@@ -48,9 +48,11 @@
[ngClass]="{'-current' : datepickerHelper.isStateOfCurrentActivatedField('start')}"
[ngModel]="dates.start"
(ngModelChange)="updateDate('start', $event)"
+ [disabled]="!isSchedulable"
(click)="setCurrentActivatedField('start')">
</div>
<a class="form--field-inline-action"
+ *ngIf="isSchedulable"
[title]="text.clear"
(click)="clear('start')">
<span class="icon2 icon-small icon-cancel"></span>
@@ -75,9 +77,11 @@
[ngClass]="{'-current' : datepickerHelper.isStateOfCurrentActivatedField('end')}"
[ngModel]="dates.end"
(ngModelChange)="updateDate('end', $event)"
+ [disabled]="!isSchedulable"
(click)="setCurrentActivatedField('end')">
</div>
<a class="form--field-inline-action"
+ *ngIf="isSchedulable"
[title]="text.clear"
(click)="clear('end')">
<span class="icon2 icon-small icon-cancel"></span>
@@ -108,8 +112,17 @@
</div>
</form>
- <input id="flatpickr-input"
- hidden>
+ <ng-container *ngIf="!isSchedulable">
+ <div class="notification-box -info">
+ <div class="notification-box--content">
+ <p [textContent]="text.isParent"></p>
+ </div>
+ </div>
+ </ng-container>
+ <ng-container *ngIf="isSchedulable">
+ <input id="flatpickr-input"
+ hidden>
+ </ng-container>
<div class="datepicker-modal--actions-container">
<a (click)="cancel()"
diff --git a/frontend/src/app/components/datepicker/datepicker.modal.ts b/frontend/src/app/components/datepicker/datepicker.modal.ts
index 51a8893cafb..794330a8b9c 100644
--- a/frontend/src/app/components/datepicker/datepicker.modal.ts
+++ b/frontend/src/app/components/datepicker/datepicker.modal.ts
@@ -73,7 +73,8 @@ export class DatePickerModal extends OpModalComponent implements AfterViewInit {
startDate: this.I18n.t('js.work_packages.properties.startDate'),
endDate: this.I18n.t('js.work_packages.properties.dueDate'),
placeholder: this.I18n.t('js.placeholders.default'),
- today: this.I18n.t('js.label_today')
+ today: this.I18n.t('js.label_today'),
+ isParent: this.I18n.t('js.work_packages.scheduling.is_parent')
};
public onDataUpdated = new EventEmitter<string>();
@@ -115,9 +116,9 @@ export class DatePickerModal extends OpModalComponent implements AfterViewInit {
}
ngAfterViewInit():void {
- this.initializeDatepicker();
- this.datepickerHelper.setDatepickerRestrictions(this.dates, this.datePickerInstance);
- this.datepickerHelper.setRangeClasses(this.dates);
+ if (this.isSchedulable) {
+ this.showDateSelection();
+ }
this.onDataChange();
}
@@ -125,6 +126,12 @@ export class DatePickerModal extends OpModalComponent implements AfterViewInit {
changeSchedulingMode() {
this.scheduleManually = !this.scheduleManually;
this.cdRef.detectChanges();
+
+ if (this.scheduleManually) {
+ this.showDateSelection();
+ } else {
+ this.removeDateSelection();
+ }
}
save():void {
@@ -181,7 +188,7 @@ export class DatePickerModal extends OpModalComponent implements AfterViewInit {
}
showTodayLink(key:DateKeys):boolean {
- if (!this.datepickerHelper.isStateOfCurrentActivatedField(key)) {
+ if (!this.datepickerHelper.isStateOfCurrentActivatedField(key) && !this.isSchedulable) {
return false;
}
@@ -192,6 +199,24 @@ 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.
+ */
+ get isSchedulable():boolean {
+ return !this.isParent || this.scheduleManually;
+ }
+
+ private showDateSelection() {
+ this.initializeDatepicker();
+ this.datepickerHelper.setDatepickerRestrictions(this.dates, this.datePickerInstance);
+ this.datepickerHelper.setRangeClasses(this.dates);
+ }
+
+ private removeDateSelection() {
+ this.datePickerInstance.destroy();
+ }
+
private initializeDatepicker() {
this.datePickerInstance = new DatePicker(
'#flatpickr-input',
@@ -331,4 +356,12 @@ export class DatePickerModal extends OpModalComponent implements AfterViewInit {
private initialActivatedField():DateKeys {
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/modules/fields/changeset/resource-changeset.ts b/frontend/src/app/modules/fields/changeset/resource-changeset.ts
index 2e14556e772..790a5551a3d 100644
--- a/frontend/src/app/modules/fields/changeset/resource-changeset.ts
+++ b/frontend/src/app/modules/fields/changeset/resource-changeset.ts
@@ -345,12 +345,12 @@ export class ResourceChangeset<T extends HalResource = HalResource> {
}
_.each(this.changeset.all, (val:ChangeItem, key:string) => {
- const fieldSchema:IFieldSchema|null = this.schema.ofProperty(key);
- if (fieldSchema && !fieldSchema.writable) {
+ if (!this.schema.isAttributeEditable(key)) {
debugLog(`Trying to write ${key} but is not writable in schema`);
return;
}
+ const fieldSchema:IFieldSchema|null = this.schema.ofProperty(key);
// Override in _links if it is a linked property
if (fieldSchema && reference._links[key]) {
plainPayload._links[key] = this.getLinkedValue(val.to, fieldSchema);
diff --git a/frontend/src/app/modules/hal/schemas/work-package-schema-proxy.ts b/frontend/src/app/modules/hal/schemas/work-package-schema-proxy.ts
index 3e5a919f6f6..f9949eb06d3 100644
--- a/frontend/src/app/modules/hal/schemas/work-package-schema-proxy.ts
+++ b/frontend/src/app/modules/hal/schemas/work-package-schema-proxy.ts
@@ -83,8 +83,15 @@ export class WorkPackageSchemaProxy extends SchemaProxy {
* @param property
*/
public isAttributeEditable(property:string):boolean {
- return super.isAttributeEditable(property) &&
- (!this.isReadonly || property === 'status');
+ if (this.isReadonly && property !== 'status') {
+ return false;
+ } else if (['startDate', 'dueDate', 'date'].includes(property) &&
+ this.resource.scheduleManually) {
+ // This is a blatant shortcut but should be adequate.
+ return super.isAttributeEditable('scheduleManually');
+ } else {
+ return super.isAttributeEditable(property);
+ }
}
public get isMilestone():boolean {
diff --git a/spec/features/work_packages/scheduling/scheduling_mode_spec.rb b/spec/features/work_packages/scheduling/scheduling_mode_spec.rb
index deac05aa0ca..26c5d0cc54b 100644
--- a/spec/features/work_packages/scheduling/scheduling_mode_spec.rb
+++ b/spec/features/work_packages/scheduling/scheduling_mode_spec.rb
@@ -86,6 +86,12 @@ describe 'scheduling mode',
let(:combined_field) { work_packages_page.edit_field(:combinedDate) }
+ def expect_dates(work_package, start_date, due_date)
+ work_package.reload
+ expect(work_package.start_date).to eql Date.parse(start_date)
+ expect(work_package.due_date).to eql Date.parse(due_date)
+ end
+
before do
login_as(user)
@@ -101,14 +107,29 @@ describe 'scheduling mode',
# Editing the start/due dates of a parent work package is possible if the
# work package is manually scheduled
combined_field.expect_scheduling_mode manually: false
+ combined_field.expect_parent_notification
combined_field.toggle_scheduling_mode
combined_field.update(%w[2016-01-05 2016-01-10])
work_packages_page.expect_and_dismiss_notification message: 'Successful update.'
- wp.reload
+ expect_dates(wp, '2016-01-05', '2016-01-10')
expect(wp.schedule_manually).to be_truthy
- expect(wp.start_date).to eql Date.parse('2016-01-05')
- expect(wp.due_date).to eql Date.parse('2016-01-10')
+
+ # is not moved because it is a child
+ expect_dates(wp_child, '2016-01-01', '2016-01-05')
+
+ # The due date is moved backwards because its child was moved
+ # but the start date remains unchanged as its grandchild stays put.
+ expect_dates(wp_parent, '2016-01-01', '2016-01-10')
+
+ # is moved backwards because of the follows relationship
+ expect_dates(wp_suc, '2016-01-11', '2016-01-15')
+
+ # is moved backwards because it is the parent of the successor
+ expect_dates(wp_suc_parent, '2016-01-11', '2016-01-15')
+
+ # is moved backwards as the whole hierarchy is moved backwards
+ expect_dates(wp_suc_child, '2016-01-11', '2016-01-15')
end
end
diff --git a/spec/support/edit_fields/date_edit_field.rb b/spec/support/edit_fields/date_edit_field.rb
index 5894984f81f..3fc8479df06 100644
--- a/spec/support/edit_fields/date_edit_field.rb
+++ b/spec/support/edit_fields/date_edit_field.rb
@@ -42,6 +42,12 @@ class DateEditField < EditField
end
end
+ def expect_parent_notification
+ within_modal do
+ expect(page).to have_content(I18n.t('js.work_packages.scheduling.is_parent'))
+ end
+ end
+
def toggle_scheduling_mode
within_modal do
find('.datepicker-modal--scheduling-action').click