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

Ensure the create service opens a new changeset

Oliver Günther4af97f6b9d02
diff --git a/frontend/src/app/components/wp-edit-form/work-package-editing-service.ts b/frontend/src/app/components/wp-edit-form/work-package-editing-service.ts
index e36cba1d5ff..d181a27ec41 100644
--- a/frontend/src/app/components/wp-edit-form/work-package-editing-service.ts
+++ b/frontend/src/app/components/wp-edit-form/work-package-editing-service.ts
@@ -154,6 +154,18 @@ export class WorkPackageEditingService extends StateCacheService<WorkPackageChan
this.clearSome(change.workPackageId);
}
+ /**
+ * Create a new changeset for the given work package, discarding any previous changeset that might exist
+ * @param workPackage
+ * @param form
+ */
+ public edit(workPackage:WorkPackageResource, form?:FormResource):WorkPackageChangeset {
+ const state = this.multiState.get(workPackage.id!);
+ const changeset = new WorkPackageChangeset(workPackage, state, form);
+
+ state.putValue(changeset);
+ return changeset;
+ }
/**
* Start or continue editing the work package with a given edit context
@@ -161,7 +173,7 @@ export class WorkPackageEditingService extends StateCacheService<WorkPackageChan
* @param {form:FormResource} Initialize with an existing form
* @return {WorkPackageChangeset} Change object to work on
*/
- public changeFor(fallback:WorkPackageResource, form?:FormResource):WorkPackageChangeset {
+ public changeFor(fallback:WorkPackageResource):WorkPackageChangeset {
const state = this.multiState.get(fallback.id!);
const workPackage = this.wpCacheService.state(fallback.id!).getValueOr(fallback);
let changeset = state.value;
@@ -170,9 +182,7 @@ export class WorkPackageEditingService extends StateCacheService<WorkPackageChan
// If there is an empty one for a older work package reference
// build a new changeset
if (!changeset || (changeset.isEmpty() && changeset.pristineResource.lockVersion < workPackage.lockVersion)) {
- changeset = new WorkPackageChangeset(workPackage, state, form)
- state.putValue(changeset);
- return changeset;
+ return this.edit(workPackage);
}
const change = state.value!;
diff --git a/frontend/src/app/components/wp-new/wp-create.service.ts b/frontend/src/app/components/wp-new/wp-create.service.ts
index ed0706c8a3b..e782d346e5c 100644
--- a/frontend/src/app/components/wp-new/wp-create.service.ts
+++ b/frontend/src/app/components/wp-new/wp-create.service.ts
@@ -97,7 +97,7 @@ export class WorkPackageCreateService implements OnDestroy {
let wp = this.halResourceService.createHalResourceOfType<WorkPackageResource>('WorkPackage', form.payload.$plain());
wp.initializeNewResource(form);
- const change = this.wpEditing.changeFor(wp, form);
+ const change = this.wpEditing.edit(wp, form);
// Call work package initialization hook
this.hooks.call('workPackageNewInitialization', change);
@@ -128,7 +128,7 @@ export class WorkPackageCreateService implements OnDestroy {
wp.initializeNewResource(form);
- return this.wpEditing.changeFor(wp, form);
+ return this.wpEditing.edit(wp, form);
}
diff --git a/frontend/src/app/modules/fields/changeset/resource-changeset.ts b/frontend/src/app/modules/fields/changeset/resource-changeset.ts
index a9f8cf56cf9..5aea5e8ba31 100644
--- a/frontend/src/app/modules/fields/changeset/resource-changeset.ts
+++ b/frontend/src/app/modules/fields/changeset/resource-changeset.ts
@@ -74,14 +74,14 @@ export abstract class ResourceChangeset<T extends HalResource|{ [key:string]:unk
*/
public value(key:string) {
if (this.isOverridden(key)) {
- return this.changes[key];
+ return this.changeset.get(key);
} else {
return this.pristineResource[key];
}
}
public setValue(key:string, val:any) {
- this.changes[key] = val;
+ this.changeset.set(key, val);
}
public getSchemaName(attribute:string):string {