From cdfed1430aaaf2b385c3d022588fd4080d784863 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Sat, 5 Oct 2019 11:00:39 +0200 Subject: [PATCH] Only show selected schema. --- .../shared/content-selector-item.component.ts | 2 +- .../shared/contents-selector.component.html | 2 +- .../shared/contents-selector.component.ts | 52 ++++++++++++------- .../shared/references-editor.component.html | 1 + src/Squidex/app/shared/state/schemas.state.ts | 2 +- 5 files changed, 36 insertions(+), 23 deletions(-) diff --git a/src/Squidex/app/features/content/shared/content-selector-item.component.ts b/src/Squidex/app/features/content/shared/content-selector-item.component.ts index c12213f1e..7bfc69ad4 100644 --- a/src/Squidex/app/features/content/shared/content-selector-item.component.ts +++ b/src/Squidex/app/features/content/shared/content-selector-item.component.ts @@ -20,7 +20,7 @@ import { selector: '[sqxContentSelectorItem]', template: ` - + - diff --git a/src/Squidex/app/features/content/shared/contents-selector.component.ts b/src/Squidex/app/features/content/shared/contents-selector.component.ts index b3e3e45e2..b6025a183 100644 --- a/src/Squidex/app/features/content/shared/contents-selector.component.ts +++ b/src/Squidex/app/features/content/shared/contents-selector.component.ts @@ -5,7 +5,7 @@ * Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved. */ -import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; +import { ChangeDetectorRef, Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; import { ContentDto, @@ -26,14 +26,16 @@ import { styleUrls: ['./contents-selector.component.scss'], templateUrl: './contents-selector.component.html', providers: [ - ManualContentsState, - SchemasState + ManualContentsState ] }) export class ContentsSelectorComponent extends ResourceOwner implements OnInit { @Output() public select = new EventEmitter(); + @Input() + public schemaIds: string[]; + @Input() public language: LanguageDto; @@ -47,6 +49,7 @@ export class ContentsSelectorComponent extends ResourceOwner implements OnInit { public alreadySelected: ContentDto[]; public schema: SchemaDetailsDto; + public schemas: SchemaDto[] = []; public queryModel: QueryModel; @@ -58,7 +61,8 @@ export class ContentsSelectorComponent extends ResourceOwner implements OnInit { constructor( public readonly contentsState: ManualContentsState, - public readonly schemasState: SchemasState + public readonly schemasState: SchemasState, + private readonly changeDetector: ChangeDetectorRef ) { super(); } @@ -70,9 +74,25 @@ export class ContentsSelectorComponent extends ResourceOwner implements OnInit { this.updateModel(); })); - this.own( - this.schemasState.selectedSchema - .subscribe(schema => { + this.schemas = this.schemasState.snapshot.schemas.values; + + if (this.schemaIds && this.schemaIds.length > 0) { + this.schemas = this.schemas.filter(x => this.schemaIds.indexOf(x.id) >= 0); + } + + this.selectSchema(this.schemas[0]); + + this.changeDetector.detectChanges(); + } + + public selectSchema(selected: string | SchemaDto) { + if (Types.is(selected, SchemaDto)) { + selected = selected.id; + } + + this.schemasState.loadSchema(selected) + .subscribe(schema => { + if (schema) { this.schema = schema; this.minWidth = `${200 + (200 * schema.referenceFields.length)}px`; @@ -81,22 +101,12 @@ export class ContentsSelectorComponent extends ResourceOwner implements OnInit { this.contentsState.load(); this.updateModel(); - })); - this.schemasState.load() - .subscribe(() => { - this.selectSchema(this.schemasState.snapshot.schemas.at(0)); + this.changeDetector.detectChanges(); + } }); } - public selectSchema(selected: string | SchemaDto) { - if (Types.is(selected, SchemaDto)) { - this.schemasState.select(selected.id).subscribe(); - } else { - this.schemasState.select(selected).subscribe(); - } - } - public reload() { this.contentsState.load(true); } @@ -138,7 +148,9 @@ export class ContentsSelectorComponent extends ResourceOwner implements OnInit { if (isSelected) { for (let content of this.contentsState.snapshot.contents.values) { - this.selectedItems[content.id] = content; + if (!this.isItemAlreadySelected(content)) { + this.selectedItems[content.id] = content; + } } } diff --git a/src/Squidex/app/features/content/shared/references-editor.component.html b/src/Squidex/app/features/content/shared/references-editor.component.html index 2c333f9b1..488e1166a 100644 --- a/src/Squidex/app/features/content/shared/references-editor.component.html +++ b/src/Squidex/app/features/content/shared/references-editor.component.html @@ -26,6 +26,7 @@ [alreadySelected]="snapshot.contentItems" [language]="language" [languages]="languages" + [schemaIds]="schemaIds" (select)="select($event)"> \ No newline at end of file diff --git a/src/Squidex/app/shared/state/schemas.state.ts b/src/Squidex/app/shared/state/schemas.state.ts index 0da3fad96..384bb0cd2 100644 --- a/src/Squidex/app/shared/state/schemas.state.ts +++ b/src/Squidex/app/shared/state/schemas.state.ts @@ -110,7 +110,7 @@ export class SchemasState extends State { })); } - private loadSchema(idOrName: string | null) { + public loadSchema(idOrName: string | null) { return !idOrName ? of(null) : this.schemasService.getSchema(this.appName, idOrName).pipe( catchError(() => of(null)));