diff --git a/src/Squidex/app/features/content/pages/content/content-field.component.ts b/src/Squidex/app/features/content/pages/content/content-field.component.ts index cd7c145a4..b03bede89 100644 --- a/src/Squidex/app/features/content/pages/content/content-field.component.ts +++ b/src/Squidex/app/features/content/pages/content/content-field.component.ts @@ -5,7 +5,7 @@ * Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved. */ -import { ChangeDetectionStrategy, Component, EventEmitter, Input, OnChanges, Output } from '@angular/core'; +import { Component, EventEmitter, Input, OnChanges, Output, SimpleChanges } from '@angular/core'; import { AbstractControl, FormGroup } from '@angular/forms'; import { @@ -18,8 +18,7 @@ import { @Component({ selector: 'sqx-content-field', styleUrls: ['./content-field.component.scss'], - templateUrl: './content-field.component.html', - changeDetection: ChangeDetectionStrategy.OnPush + templateUrl: './content-field.component.html' }) export class ContentFieldComponent implements OnChanges { @Input() @@ -42,13 +41,16 @@ export class ContentFieldComponent implements OnChanges { public selectedFormControl: AbstractControl; - public ngOnChanges() { + public ngOnChanges(changes: SimpleChanges) { if (this.field.isLocalizable) { this.selectedFormControl = this.fieldForm.controls[this.language.iso2Code]; - this.selectedFormControl['_clearChangeFns'](); } else { this.selectedFormControl = this.fieldForm.controls[fieldInvariant]; } + + if (changes['language']) { + this.selectedFormControl['_clearChangeFns'](); + } } } diff --git a/src/Squidex/app/features/content/pages/content/content-page.component.html b/src/Squidex/app/features/content/pages/content/content-page.component.html index d769d7584..8aa3b56ae 100644 --- a/src/Squidex/app/features/content/pages/content/content-page.component.html +++ b/src/Squidex/app/features/content/pages/content/content-page.component.html @@ -27,23 +27,27 @@ + + - - + + - + + + -
+
- Viewing version {{contentVersion.value. + Viewing version {{version.value}}.
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 b36496422..645713ba9 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 @@ -75,19 +75,19 @@ export class ContentPageComponent implements CanComponentDeactivate, OnDestroy, }); this.selectedSchemaSubscription = - this.schemasState.selectedSchema.filter(s => !!s) + this.schemasState.selectedSchema.filter(s => !!s).map(s => s!) .subscribe(schema => { - this.schema = schema!; + this.schema = schema; this.contentForm = new EditContentForm(this.schema, this.languages); }); this.contentSubscription = - this.contentsState.selectedContent.filter(c => !!c) + this.contentsState.selectedContent.filter(c => !!c).map(c => c!) .subscribe(content => { - this.content = content!; + this.content = content; - this.loadContent(content!.data); + this.loadContent(content.data); }); this.contentVersionSelectedSubscription = @@ -114,20 +114,24 @@ export class ContentPageComponent implements CanComponentDeactivate, OnDestroy, } private saveContent(publish: boolean) { + if (this.content && this.content.status === 'Archived') { + return; + } + const value = this.contentForm.submit(); if (value) { - if (!this.content) { - this.contentsState.create(value, publish) + if (this.content) { + this.contentsState.update(this.content, value) .subscribe(dto => { - this.back(); + this.contentForm.submitCompleted(); }, error => { this.contentForm.submitFailed(error); }); } else { this.contentsState.create(value, publish) .subscribe(dto => { - this.contentForm.submitCompleted(); + this.back(); }, error => { this.contentForm.submitFailed(error); }); @@ -142,7 +146,7 @@ export class ContentPageComponent implements CanComponentDeactivate, OnDestroy, } private loadContent(data: any) { - this.contentForm.load(data); + this.contentForm.loadData(data, this.content && this.content.status === 'Archived'); } private loadVersion(version: Version) { @@ -155,8 +159,6 @@ export class ContentPageComponent implements CanComponentDeactivate, OnDestroy, this.contentVersion = null; } - this.dialogs.notifyInfo('Content version loaded successfully.'); - this.loadContent(dto); }); } diff --git a/src/Squidex/app/features/content/pages/contents/contents-page.component.html b/src/Squidex/app/features/content/pages/contents/contents-page.component.html index ac4cc36c7..0b4090779 100644 --- a/src/Squidex/app/features/content/pages/contents/contents-page.component.html +++ b/src/Squidex/app/features/content/pages/contents/contents-page.component.html @@ -144,7 +144,7 @@ - + diff --git a/src/Squidex/app/features/content/shared/content-item.component.html b/src/Squidex/app/features/content/shared/content-item.component.html index 910973d98..b95d7c688 100644 --- a/src/Squidex/app/features/content/shared/content-item.component.html +++ b/src/Squidex/app/features/content/shared/content-item.component.html @@ -81,7 +81,7 @@ - diff --git a/src/Squidex/app/features/content/shared/content-item.component.ts b/src/Squidex/app/features/content/shared/content-item.component.ts index 118835909..a5eb2909b 100644 --- a/src/Squidex/app/features/content/shared/content-item.component.ts +++ b/src/Squidex/app/features/content/shared/content-item.component.ts @@ -5,7 +5,7 @@ * Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved. */ -import { Component, EventEmitter, Input, OnChanges, Output } from '@angular/core'; +import { Component, EventEmitter, Input, OnChanges, Output, SimpleChanges } from '@angular/core'; import { AppLanguageDto, @@ -78,10 +78,14 @@ export class ContentItemComponent implements OnChanges { ) { } - public ngOnChanges() { - this.patchForm = new PatchContentForm(this.schema, this.language); + public ngOnChanges(changes: SimpleChanges) { + if (changes['schema'] || changes['language']) { + this.patchForm = new PatchContentForm(this.schema, this.language); + } - this.updateValues(); + if (changes['content'] || changes['language']) { + this.updateValues(); + } } public shouldStop(event: Event) { @@ -104,6 +108,12 @@ export class ContentItemComponent implements OnChanges { } } + public cancel() { + this.patchForm.submitCompleted(); + + this.updateValues(); + } + private updateValues() { this.values = []; diff --git a/src/Squidex/app/features/schemas/pages/schema/forms/field-form-validation.component.html b/src/Squidex/app/features/schemas/pages/schema/forms/field-form-validation.component.html index 1ddcefca7..1dd91c0cc 100644 --- a/src/Squidex/app/features/schemas/pages/schema/forms/field-form-validation.component.html +++ b/src/Squidex/app/features/schemas/pages/schema/forms/field-form-validation.component.html @@ -3,7 +3,7 @@
- +
diff --git a/src/Squidex/app/features/schemas/pages/schema/forms/field-form-validation.component.ts b/src/Squidex/app/features/schemas/pages/schema/forms/field-form-validation.component.ts index 7ffe5d41e..7f72ab83e 100644 --- a/src/Squidex/app/features/schemas/pages/schema/forms/field-form-validation.component.ts +++ b/src/Squidex/app/features/schemas/pages/schema/forms/field-form-validation.component.ts @@ -8,7 +8,11 @@ import { ChangeDetectionStrategy, Component, Input } from '@angular/core'; import { FormGroup } from '@angular/forms'; -import { AppPatternDto, FieldDto } from '@app/shared'; +import { + AppPatternDto, + FieldDto, + ImmutableArray +} from '@app/shared'; @Component({ selector: 'sqx-field-form-validation', @@ -24,5 +28,5 @@ export class FieldFormValidationComponent { public field: FieldDto; @Input() - public patterns: AppPatternDto[]; + public patterns: ImmutableArray; } \ No newline at end of file diff --git a/src/Squidex/app/features/schemas/pages/schema/schema-page.component.ts b/src/Squidex/app/features/schemas/pages/schema/schema-page.component.ts index e041d69d7..42fc4c753 100644 --- a/src/Squidex/app/features/schemas/pages/schema/schema-page.component.ts +++ b/src/Squidex/app/features/schemas/pages/schema/schema-page.component.ts @@ -68,9 +68,9 @@ export class SchemaPageComponent implements OnDestroy, OnInit { this.patternsState.load().onErrorResumeNext().subscribe(); this.selectedSchemaSubscription = - this.schemasState.selectedSchema + this.schemasState.selectedSchema.filter(s => !!s).map(s => s!) .subscribe(schema => { - this.schema = schema!; + this.schema = schema; this.export(); }); diff --git a/src/Squidex/app/framework/angular/forms/focus-on-init.directive.ts b/src/Squidex/app/framework/angular/forms/focus-on-init.directive.ts index e7ae2fef8..1a3cbcc3a 100644 --- a/src/Squidex/app/framework/angular/forms/focus-on-init.directive.ts +++ b/src/Squidex/app/framework/angular/forms/focus-on-init.directive.ts @@ -21,10 +21,12 @@ export class FocusOnInitDirective implements AfterViewInit { } public ngAfterViewInit() { - this.renderer.invokeElementMethod(this.element.nativeElement, 'focus', []); + setTimeout(() => { + this.renderer.invokeElementMethod(this.element.nativeElement, 'focus', []); - if (this.select) { - this.renderer.invokeElementMethod(this.element.nativeElement, 'select', []); - } + if (this.select) { + this.renderer.invokeElementMethod(this.element.nativeElement, 'select', []); + } + }, 100); } } \ No newline at end of file diff --git a/src/Squidex/app/framework/angular/modals/dialog-renderer.component.html b/src/Squidex/app/framework/angular/modals/dialog-renderer.component.html index 1b6621cdc..f39ac71d5 100644 --- a/src/Squidex/app/framework/angular/modals/dialog-renderer.component.html +++ b/src/Squidex/app/framework/angular/modals/dialog-renderer.component.html @@ -11,7 +11,7 @@ - + diff --git a/src/Squidex/app/framework/state.ts b/src/Squidex/app/framework/state.ts index ca543b357..e7e42c6ae 100644 --- a/src/Squidex/app/framework/state.ts +++ b/src/Squidex/app/framework/state.ts @@ -57,6 +57,8 @@ export class Form { if (newValue) { this.form.reset(newValue); + } else { + this.form.markAsPristine(); } } diff --git a/src/Squidex/app/shared/state/contents.state.ts b/src/Squidex/app/shared/state/contents.state.ts index 4dd78c43f..56d2fcce8 100644 --- a/src/Squidex/app/shared/state/contents.state.ts +++ b/src/Squidex/app/shared/state/contents.state.ts @@ -72,6 +72,16 @@ export class EditContentForm extends Form { this.enableContentForm(); } + public loadData(value: any, isArchive: boolean) { + super.load(value); + + if (isArchive) { + this.form.disable(); + } else { + this.enableContentForm(); + } + } + private enableContentForm() { if (this.schema.fields.length === 0) { this.form.enable(); @@ -277,7 +287,7 @@ export abstract class ContentsStateBase extends State { .do(dto => { this.dialogs.notifyInfo('Contents updated successfully.'); - this.replaceContent(updateData(content, request, this.user, dto.version, now)); + this.replaceContent(updateData(content, dto.payload, this.user, dto.version, now)); }) .notify(this.dialogs); } @@ -287,7 +297,7 @@ export abstract class ContentsStateBase extends State { .do(dto => { this.dialogs.notifyInfo('Contents updated successfully.'); - this.replaceContent(updateData(content, request, this.user, dto.version, now)); + this.replaceContent(updateData(content, dto.payload, this.user, dto.version, now)); }) .notify(this.dialogs); }