Browse Source

Update schemas for reference field.

pull/118/head
Sebastian Stehle 8 years ago
parent
commit
13a64d6de8
  1. 7
      src/Squidex/app/features/schemas/pages/messages.ts
  2. 39
      src/Squidex/app/features/schemas/pages/schema/schema-page.component.ts
  3. 15
      src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.ts

7
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 { export class SchemaDeleted {
constructor( constructor(
public readonly schema: SchemaDto public readonly schema: SchemaDto

39
src/Squidex/app/features/schemas/pages/schema/schema-page.component.ts

@ -5,9 +5,10 @@
* Copyright (c) Sebastian Stehle. All rights reserved * 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 { FormBuilder, Validators } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router'; import { ActivatedRoute, Router } from '@angular/router';
import { Subscription } from 'rxjs';
import { import {
AddFieldDto, AddFieldDto,
@ -20,6 +21,7 @@ import {
FieldDto, FieldDto,
fieldTypes, fieldTypes,
HistoryChannelUpdated, HistoryChannelUpdated,
ImmutableArray,
MessageBus, MessageBus,
ModalView, ModalView,
SchemaDetailsDto, SchemaDetailsDto,
@ -31,7 +33,11 @@ import {
ValidatorsEx ValidatorsEx
} from 'shared'; } from 'shared';
import { SchemaDeleted, SchemaUpdated } from './../messages'; import {
SchemaCreated,
SchemaDeleted,
SchemaUpdated
} from './../messages';
@Component({ @Component({
selector: 'sqx-schema-page', selector: 'sqx-schema-page',
@ -41,12 +47,14 @@ import { SchemaDeleted, SchemaUpdated } from './../messages';
fadeAnimation fadeAnimation
] ]
}) })
export class SchemaPageComponent extends AppComponentBase implements OnInit { export class SchemaPageComponent extends AppComponentBase implements OnDestroy, OnInit {
private schemaCreatedSubscription: Subscription;
public fieldTypes = fieldTypes; public fieldTypes = fieldTypes;
public schemaExport: any; public schemaExport: any;
public schema: SchemaDetailsDto; public schema: SchemaDetailsDto;
public schemas: SchemaDto[]; public schemas: ImmutableArray<SchemaDto>;
public exportSchemaDialog = new ModalView(); public exportSchemaDialog = new ModalView();
@ -85,7 +93,19 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit {
super(dialogs, apps); super(dialogs, apps);
} }
public ngOnDestroy() {
this.schemaCreatedSubscription.unsubscribe();
}
public ngOnInit() { 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']) this.route.data.map(p => p['schema'])
.subscribe((schema: SchemaDetailsDto) => { .subscribe((schema: SchemaDetailsDto) => {
this.schema = schema; this.schema = schema;
@ -100,7 +120,7 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit {
this.appNameOnce() this.appNameOnce()
.switchMap(app => this.schemasService.getSchemas(app)) .switchMap(app => this.schemasService.getSchemas(app))
.subscribe(dtos => { .subscribe(dtos => {
this.schemas = dtos; this.schemas = ImmutableArray.of(dtos);
}, error => { }, error => {
this.notifyError(error); this.notifyError(error);
}); });
@ -212,7 +232,7 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit {
this.appNameOnce() this.appNameOnce()
.switchMap(app => this.schemasService.deleteSchema(app, this.schema.name, this.schema.version)).retry(2) .switchMap(app => this.schemasService.deleteSchema(app, this.schema.name, this.schema.version)).retry(2)
.subscribe(() => { .subscribe(() => {
this.emitSchemaDeleted(this.schema); this.onSchemaRemoved(this.schema);
this.back(); this.back();
}, error => { }, error => {
this.notifyError(error); this.notifyError(error);
@ -258,6 +278,12 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit {
this.configureScriptsDialog.hide(); this.configureScriptsDialog.hide();
} }
private onSchemaRemoved(schema: SchemaDto) {
this.schemas = this.schemas.removeAll(s => s.id === schema.id);
this.emitSchemaDeleted(schema);
}
private resetFieldForm() { private resetFieldForm() {
this.addFieldForm.enable(); this.addFieldForm.enable();
this.addFieldForm.reset({ type: 'String' }); this.addFieldForm.reset({ type: 'String' });
@ -266,6 +292,7 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit {
private updateSchema(schema: SchemaDetailsDto) { private updateSchema(schema: SchemaDetailsDto) {
this.schema = schema; this.schema = schema;
this.schemas = this.schemas.replaceBy('id', schema);
this.emitSchemaUpdated(schema); this.emitSchemaUpdated(schema);
this.notify(); this.notify();

15
src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.ts

@ -22,7 +22,11 @@ import {
SchemasService SchemasService
} from 'shared'; } from 'shared';
import { SchemaDeleted, SchemaUpdated } from './../messages'; import {
SchemaCreated,
SchemaDeleted,
SchemaUpdated
} from './../messages';
@Component({ @Component({
selector: 'sqx-schemas-page', selector: 'sqx-schemas-page',
@ -96,12 +100,17 @@ export class SchemasPageComponent extends AppComponentBase implements OnDestroy,
}); });
} }
public onSchemaCreated(dto: SchemaDto) { public onSchemaCreated(schema: SchemaDto) {
this.updateSchemas(this.schemas.push(dto), this.schemaQuery); this.updateSchemas(this.schemas.push(schema), this.schemaQuery);
this.emitSchemaCreated(schema);
this.addSchemaDialog.hide(); this.addSchemaDialog.hide();
} }
private emitSchemaCreated(schema: SchemaDto) {
this.messageBus.emit(new SchemaCreated(schema));
}
private updateSchemas(schemas: ImmutableArray<SchemaDto>, query?: string) { private updateSchemas(schemas: ImmutableArray<SchemaDto>, query?: string) {
this.schemas = schemas; this.schemas = schemas;

Loading…
Cancel
Save