Ensure the create service opens a new changeset

pull/7677/head
Oliver Günther 5 years ago
parent 5083396cc6
commit 4af97f6b9d
No known key found for this signature in database
GPG Key ID: A3A8BDAD7C0C552C
  1. 18
      frontend/src/app/components/wp-edit-form/work-package-editing-service.ts
  2. 4
      frontend/src/app/components/wp-new/wp-create.service.ts
  3. 4
      frontend/src/app/modules/fields/changeset/resource-changeset.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!;

@ -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);
}

@ -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 {

Loading…
Cancel
Save