diff --git a/src/Squidex/app/features/schemas/pages/messages.ts b/src/Squidex/app/features/schemas/pages/messages.ts index 4b59f0725..3702b2933 100644 --- a/src/Squidex/app/features/schemas/pages/messages.ts +++ b/src/Squidex/app/features/schemas/pages/messages.ts @@ -14,6 +14,13 @@ export class SchemaUpdated { } } +export class SchemaCreated { + constructor( + public readonly schema: SchemaDto + ) { + } +} + export class SchemaDeleted { constructor( public readonly schema: SchemaDto 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 44affcfc2..974e4989a 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 @@ -5,9 +5,10 @@ * Copyright (c) Sebastian Stehle. All rights reserved */ -import { Component, OnInit } from '@angular/core'; +import { Component, OnDestroy, OnInit } from '@angular/core'; import { FormBuilder, Validators } from '@angular/forms'; import { ActivatedRoute, Router } from '@angular/router'; +import { Subscription } from 'rxjs'; import { AddFieldDto, @@ -20,6 +21,7 @@ import { FieldDto, fieldTypes, HistoryChannelUpdated, + ImmutableArray, MessageBus, ModalView, SchemaDetailsDto, @@ -31,7 +33,11 @@ import { ValidatorsEx } from 'shared'; -import { SchemaDeleted, SchemaUpdated } from './../messages'; +import { + SchemaCreated, + SchemaDeleted, + SchemaUpdated +} from './../messages'; @Component({ selector: 'sqx-schema-page', @@ -41,12 +47,14 @@ import { SchemaDeleted, SchemaUpdated } from './../messages'; fadeAnimation ] }) -export class SchemaPageComponent extends AppComponentBase implements OnInit { +export class SchemaPageComponent extends AppComponentBase implements OnDestroy, OnInit { + private schemaCreatedSubscription: Subscription; + public fieldTypes = fieldTypes; public schemaExport: any; public schema: SchemaDetailsDto; - public schemas: SchemaDto[]; + public schemas: ImmutableArray; public exportSchemaDialog = new ModalView(); @@ -85,7 +93,19 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit { super(dialogs, apps); } + public ngOnDestroy() { + this.schemaCreatedSubscription.unsubscribe(); + } + public ngOnInit() { + this.schemaCreatedSubscription = + this.messageBus.of(SchemaCreated) + .subscribe(message => { + if (this.schemas) { + this.schemas = this.schemas.push(message.schema); + } + }); + this.route.data.map(p => p['schema']) .subscribe((schema: SchemaDetailsDto) => { this.schema = schema; @@ -100,7 +120,7 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit { this.appNameOnce() .switchMap(app => this.schemasService.getSchemas(app)) .subscribe(dtos => { - this.schemas = dtos; + this.schemas = ImmutableArray.of(dtos); }, error => { this.notifyError(error); }); @@ -212,7 +232,7 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit { this.appNameOnce() .switchMap(app => this.schemasService.deleteSchema(app, this.schema.name, this.schema.version)).retry(2) .subscribe(() => { - this.emitSchemaDeleted(this.schema); + this.onSchemaRemoved(this.schema); this.back(); }, error => { this.notifyError(error); @@ -258,6 +278,12 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit { this.configureScriptsDialog.hide(); } + private onSchemaRemoved(schema: SchemaDto) { + this.schemas = this.schemas.removeAll(s => s.id === schema.id); + + this.emitSchemaDeleted(schema); + } + private resetFieldForm() { this.addFieldForm.enable(); this.addFieldForm.reset({ type: 'String' }); @@ -266,6 +292,7 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit { private updateSchema(schema: SchemaDetailsDto) { this.schema = schema; + this.schemas = this.schemas.replaceBy('id', schema); this.emitSchemaUpdated(schema); this.notify(); diff --git a/src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.ts b/src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.ts index e529e8dc1..a5a60875e 100644 --- a/src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.ts +++ b/src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.ts @@ -22,7 +22,11 @@ import { SchemasService } from 'shared'; -import { SchemaDeleted, SchemaUpdated } from './../messages'; +import { + SchemaCreated, + SchemaDeleted, + SchemaUpdated +} from './../messages'; @Component({ selector: 'sqx-schemas-page', @@ -96,12 +100,17 @@ export class SchemasPageComponent extends AppComponentBase implements OnDestroy, }); } - public onSchemaCreated(dto: SchemaDto) { - this.updateSchemas(this.schemas.push(dto), this.schemaQuery); + public onSchemaCreated(schema: SchemaDto) { + this.updateSchemas(this.schemas.push(schema), this.schemaQuery); + this.emitSchemaCreated(schema); this.addSchemaDialog.hide(); } + private emitSchemaCreated(schema: SchemaDto) { + this.messageBus.emit(new SchemaCreated(schema)); + } + private updateSchemas(schemas: ImmutableArray, query?: string) { this.schemas = schemas;