Browse Source

Autosave fix.

pull/430/head
Sebastian Stehle 6 years ago
parent
commit
7798444cc5
  1. 57
      src/Squidex/app/features/content/pages/content/content-page.component.ts
  2. 23
      src/Squidex/app/shared/components/references-dropdown.component.ts

57
src/Squidex/app/features/content/pages/content/content-page.component.ts

@ -156,10 +156,12 @@ export class ContentPageComponent extends ResourceOwner implements CanComponentD
}
public canDeactivate(): Observable<boolean> {
if (!this.contentForm.hasChanged()) {
return of(true);
} else {
return this.dialogs.confirm('Unsaved changes', 'You have unsaved changes, do you want to close the current content view and discard your changes?').pipe(
const observable =
this.contentForm.hasChanged() ?
this.dialogs.confirm('Unsaved changes', 'You have unsaved changes, do you want to close the current content view and discard your changes?') :
of(true);
return observable.pipe(
tap(confirmed => {
if (confirmed) {
this.autoSaveService.remove(this.autoSaveKey);
@ -167,7 +169,6 @@ export class ContentPageComponent extends ResourceOwner implements CanComponentD
})
);
}
}
public saveAndPublish() {
this.saveContent(true, false);
@ -185,11 +186,9 @@ export class ContentPageComponent extends ResourceOwner implements CanComponentD
const value = this.contentForm.submit();
if (value) {
this.autoSaveService.remove(this.autoSaveKey);
if (this.content) {
if (asDraft) {
if (this.content && !this.content.canDraftPropose) {
if (!this.content.canDraftPropose) {
return;
}
@ -200,7 +199,7 @@ export class ContentPageComponent extends ResourceOwner implements CanComponentD
this.contentForm.submitFailed(error);
});
} else {
if (this.content && !this.content.canUpdateAny) {
if (!this.content.canUpdate) {
return;
}
@ -212,7 +211,7 @@ export class ContentPageComponent extends ResourceOwner implements CanComponentD
});
}
} else {
if ((publish && !this.contentsState.snapshot.canCreate) || (!publish && !this.contentsState.snapshot.canCreateAndPublish)) {
if (!this.canCreate(publish)) {
return;
}
@ -230,21 +229,16 @@ export class ContentPageComponent extends ResourceOwner implements CanComponentD
}
}
public back() {
this.router.navigate([this.schema.name], { relativeTo: this.route.parent!.parent, replaceUrl: true });
private canCreate(publish: boolean) {
if (publish) {
return this.contentsState.snapshot.canCreateAndPublish;
} else {
return this.contentsState.snapshot.canCreate;
}
private loadContent(data: any, isInitial: boolean) {
this.isLoadingContent = true;
this.autoSaveService.remove(this.autoSaveKey);
try {
this.contentForm.load(data, isInitial);
this.contentForm.setEnabled(!this.content || this.content.canUpdateAny);
} finally {
this.isLoadingContent = false;
}
public back() {
this.router.navigate([this.schema.name], { relativeTo: this.route.parent!.parent, replaceUrl: true });
}
public discardChanges() {
@ -270,6 +264,10 @@ export class ContentPageComponent extends ResourceOwner implements CanComponentD
.subscribe();
}
public showLatest() {
this.loadVersion(null, false);
}
private loadVersion(version: Version | null, compare: boolean) {
if (!this.content || version === null || version.eq(this.content.version)) {
this.contentFormCompare = null;
@ -296,8 +294,17 @@ export class ContentPageComponent extends ResourceOwner implements CanComponentD
}
}
public showLatest() {
this.loadVersion(null, false);
private loadContent(data: any, isInitial: boolean) {
this.isLoadingContent = true;
this.autoSaveService.remove(this.autoSaveKey);
try {
this.contentForm.load(data, isInitial);
this.contentForm.setEnabled(!this.content || this.content.canUpdateAny);
} finally {
this.isLoadingContent = false;
}
}
public trackByField(index: number, field: FieldDto) {

23
src/Squidex/app/shared/components/references-dropdown.component.ts

@ -5,7 +5,7 @@
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
*/
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, forwardRef, Input, OnChanges } from '@angular/core';
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, forwardRef, Input, OnChanges, SimpleChanges } from '@angular/core';
import { FormControl, NG_VALUE_ACCESSOR } from '@angular/forms';
import {
@ -59,10 +59,6 @@ export class ReferencesDropdownComponent extends StatefulControlComponent<State,
@Input()
public mode: 'Array' | 'Single';
public get isValid() {
return !!this.schemaId && !!this.languageField;
}
@Input()
public set language(value: LanguageDto) {
this.languageField = value;
@ -70,6 +66,10 @@ export class ReferencesDropdownComponent extends StatefulControlComponent<State,
this.next(s => ({ ...s, contentNames: this.createContentNames(s.contents) }));
}
public get isValid() {
return !!this.schemaId && !!this.languageField;
}
public selectionControl = new FormControl('');
constructor(changeDetector: ChangeDetectorRef, uiOptions: UIOptions,
@ -106,12 +106,11 @@ export class ReferencesDropdownComponent extends StatefulControlComponent<State,
}));
}
public ngOnChanges() {
if (!this.isValid) {
this.selectionControl.disable();
return;
}
public ngOnChanges(changes: SimpleChanges) {
if (changes['schemaId']) {
this.resetState();
if (this.isValid) {
this.contentsService.getContents(this.appsState.appName, this.schemaId, this.itemCount, 0)
.subscribe(contents => {
const contentItems = contents.items;
@ -123,6 +122,10 @@ export class ReferencesDropdownComponent extends StatefulControlComponent<State,
}, () => {
this.selectionControl.disable();
});
} else {
this.selectionControl.disable();
}
}
}
public setDisabledState(isDisabled: boolean) {

Loading…
Cancel
Save