Browse Source

Yet another fix to autosave.

pull/462/head
Sebastian 6 years ago
parent
commit
25ffad6ebc
  1. 64
      frontend/app/features/content/pages/content/content-page.component.ts

64
frontend/app/features/content/pages/content/content-page.component.ts

@ -52,7 +52,7 @@ export class ContentPageComponent extends ResourceOwner implements CanComponentD
public formContext: any; public formContext: any;
public content: ContentDto; public content?: ContentDto | null;
public contentVersion: Version | null; public contentVersion: Version | null;
public contentForm: EditContentForm; public contentForm: EditContentForm;
public contentFormCompare: EditContentForm | null = null; public contentFormCompare: EditContentForm | null = null;
@ -118,9 +118,7 @@ export class ContentPageComponent extends ResourceOwner implements CanComponentD
const autosaved = this.autoSaveService.get(this.autoSaveKey); const autosaved = this.autoSaveService.get(this.autoSaveKey);
if (content) { if (content) {
this.content = content; this.loadContent(content.dataDraft, true);
this.loadContent(this.content.dataDraft, true);
} }
if (autosaved && this.isOtherContent(content) && this.contentForm.hasChanges(autosaved)) { if (autosaved && this.isOtherContent(content) && this.contentForm.hasChanges(autosaved)) {
@ -133,6 +131,8 @@ export class ContentPageComponent extends ResourceOwner implements CanComponentD
} }
}); });
} }
this.content = content;
})); }));
this.own( this.own(
@ -237,32 +237,44 @@ export class ContentPageComponent extends ResourceOwner implements CanComponentD
} }
public discardChanges() { public discardChanges() {
this.contentsState.discardDraft(this.content); if (this.content) {
this.contentsState.discardDraft(this.content);
}
} }
public delete() { public delete() {
this.contentsState.deleteMany([this.content]).pipe(onErrorResumeNext()) if (this.content) {
.subscribe(() => { this.contentsState.deleteMany([this.content]).pipe(onErrorResumeNext())
this.back(); .subscribe(() => {
}); this.back();
});
}
} }
public publishChanges() { public publishChanges() {
this.checkPendingChanges('publish your changes').pipe( const content = this.content;
filter(x => !!x),
switchMap(_ => this.dueTimeSelector.selectDueTime(status)), if (content) {
switchMap(d => this.contentsState.publishDraft(this.content, d)), this.checkPendingChanges('publish your changes').pipe(
onErrorResumeNext()) filter(x => !!x),
.subscribe(); switchMap(_ => this.dueTimeSelector.selectDueTime(status)),
switchMap(d => this.contentsState.publishDraft(content, d)),
onErrorResumeNext())
.subscribe();
}
} }
public changeStatus(status: string) { public changeStatus(status: string) {
this.checkPendingChanges('change the status').pipe( const content = this.content;
filter(x => !!x),
switchMap(_ => this.dueTimeSelector.selectDueTime(status)), if (content) {
switchMap(d => this.contentsState.changeStatus(this.content, status, d)), this.checkPendingChanges('change the status').pipe(
onErrorResumeNext()) filter(x => !!x),
.subscribe(); switchMap(_ => this.dueTimeSelector.selectDueTime(status)),
switchMap(d => this.contentsState.changeStatus(content, status, d)),
onErrorResumeNext())
.subscribe();
}
} }
private checkPendingChanges(action: string) { private checkPendingChanges(action: string) {
@ -276,12 +288,14 @@ export class ContentPageComponent extends ResourceOwner implements CanComponentD
} }
private loadVersion(version: Version | null, compare: boolean) { private loadVersion(version: Version | null, compare: boolean) {
if (!this.content || version === null || version.eq(this.content.version)) { const content = this.content;
if (!content || version === null || version.eq(content.version)) {
this.contentFormCompare = null; this.contentFormCompare = null;
this.contentVersion = null; this.contentVersion = null;
this.loadContent(this.content.dataDraft, true); this.loadContent(content ? content.dataDraft : {}, true);
} else { } else {
this.contentsState.loadVersion(this.content, version) this.contentsState.loadVersion(content, version)
.subscribe(dto => { .subscribe(dto => {
if (compare) { if (compare) {
this.contentFormCompare = new EditContentForm(this.languages, this.schema); this.contentFormCompare = new EditContentForm(this.languages, this.schema);
@ -289,7 +303,7 @@ export class ContentPageComponent extends ResourceOwner implements CanComponentD
this.contentFormCompare.load(dto.payload); this.contentFormCompare.load(dto.payload);
this.contentFormCompare.setEnabled(false); this.contentFormCompare.setEnabled(false);
this.loadContent(this.content.dataDraft, false); this.loadContent(content.dataDraft, false);
} else { } else {
this.contentFormCompare = null; this.contentFormCompare = null;

Loading…
Cancel
Save