diff --git a/src/Squidex/app/features/content/pages/content/content-page.component.ts b/src/Squidex/app/features/content/pages/content/content-page.component.ts index e00c1203c..519bd5fbf 100644 --- a/src/Squidex/app/features/content/pages/content/content-page.component.ts +++ b/src/Squidex/app/features/content/pages/content/content-page.component.ts @@ -156,17 +156,18 @@ export class ContentPageComponent extends ResourceOwner implements CanComponentD } public canDeactivate(): Observable { - 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( - tap(confirmed => { - if (confirmed) { - this.autoSaveService.remove(this.autoSaveKey); - } - }) - ); - } + 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); + } + }) + ); } public saveAndPublish() { @@ -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) { diff --git a/src/Squidex/app/shared/components/references-dropdown.component.ts b/src/Squidex/app/shared/components/references-dropdown.component.ts index 16dd9b26d..dd06a151f 100644 --- a/src/Squidex/app/shared/components/references-dropdown.component.ts +++ b/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 ({ ...s, contentNames: this.createContentNames(s.contents) })); } + public get isValid() { + return !!this.schemaId && !!this.languageField; + } + public selectionControl = new FormControl(''); constructor(changeDetector: ChangeDetectorRef, uiOptions: UIOptions, @@ -106,23 +106,26 @@ export class ReferencesDropdownComponent extends StatefulControlComponent { - const contentItems = contents.items; - const contentNames = this.createContentNames(contentItems); + if (this.isValid) { + this.contentsService.getContents(this.appsState.appName, this.schemaId, this.itemCount, 0) + .subscribe(contents => { + const contentItems = contents.items; + const contentNames = this.createContentNames(contentItems); - this.next(s => ({ ...s, contents: contentItems, contentNames })); + this.next(s => ({ ...s, contents: contentItems, contentNames })); - this.selectContent(); - }, () => { + this.selectContent(); + }, () => { + this.selectionControl.disable(); + }); + } else { this.selectionControl.disable(); - }); + } + } } public setDisabledState(isDisabled: boolean) {