diff --git a/frontend/src/app/features/content/pages/contents/contents-page.component.ts b/frontend/src/app/features/content/pages/contents/contents-page.component.ts index 605e315a1..96335bc0f 100644 --- a/frontend/src/app/features/content/pages/contents/contents-page.component.ts +++ b/frontend/src/app/features/content/pages/contents/contents-page.component.ts @@ -10,8 +10,8 @@ import { Component, OnInit, ViewChild } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; import { Observable } from 'rxjs'; -import { distinctUntilChanged, map, shareReplay, switchMap, take, tap, withLatestFrom } from 'rxjs/operators'; -import { AppLanguageDto, AppsState, ContentDto, ContentsService, ContentsState, contentsTranslationStatus, ContributorsState, defined, getTableFields, LanguagesState, LocalStoreService, ModalModel, Queries, Query, QuerySynchronizer, ResourceOwner, Router2State, SchemaDto, SchemasService, SchemasState, Settings, switchSafe, TableSettings, TempService, TranslationStatus, UIState } from '@app/shared'; +import { distinctUntilChanged, map, shareReplay, switchMap, take, tap } from 'rxjs/operators'; +import { AppLanguageDto, AppsState, ContentDto, ContentsService, ContentsState, contentsTranslationStatus, ContributorsState, defined, getTableConfig, LanguagesState, LocalStoreService, ModalModel, Queries, Query, QuerySynchronizer, ResourceOwner, Router2State, SchemaDto, SchemasService, SchemasState, Settings, switchSafe, TableSettings, TempService, TranslationStatus, UIState } from '@app/shared'; import { DueTimeSelectorComponent } from './../../shared/due-time-selector.component'; @Component({ @@ -95,16 +95,16 @@ export class ContentsPageComponent extends ResourceOwner implements OnInit { getSchemaName(this.route).pipe(switchMap(() => this.schemasState.selectedSchema.pipe(defined(), take(1), shareReplay(1)))); const tableSetting$ = - schema$.pipe(map(s => new TableSettings(this.uiState, s)), shareReplay(1)); + schema$.pipe(map(schema => new TableSettings(this.uiState, schema)), shareReplay(1)); - const tableName$ = - tableSetting$.pipe(switchMap(s => s.listFields), map(s => getTableFields(s))); + const tableConfig$ = + tableSetting$.pipe(switchMap(getTableConfig)); this.tableSettings = tableSetting$; this.own( - tableName$.pipe(withLatestFrom(schema$)) - .subscribe(([fieldNames, schema]) => { + tableConfig$ + .subscribe(({ fieldNames, schema }) => { if (this.schema?.id !== schema.id) { this.resetSelection(); diff --git a/frontend/src/app/shared/services/schemas.service.ts b/frontend/src/app/shared/services/schemas.service.ts index 597e3a3ca..056a86fb3 100644 --- a/frontend/src/app/shared/services/schemas.service.ts +++ b/frontend/src/app/shared/services/schemas.service.ts @@ -101,7 +101,7 @@ export function getTableFields(fields: ReadonlyArray) { } result.sort(); - + return result; } diff --git a/frontend/src/app/shared/state/table-settings.ts b/frontend/src/app/shared/state/table-settings.ts index 6dfad2d53..838233715 100644 --- a/frontend/src/app/shared/state/table-settings.ts +++ b/frontend/src/app/shared/state/table-settings.ts @@ -5,7 +5,7 @@ * Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved. */ -import { take } from 'rxjs/operators'; +import { map, take } from 'rxjs/operators'; import { State, Types } from '@app/framework'; import { META_FIELDS, SchemaDto, TableField } from './../services/schemas.service'; import { UIState } from './ui.state'; @@ -45,8 +45,8 @@ export class TableSettings extends State { this.projectFrom(this.fields, x => x.length > 0 ? x : this.schemaDefaults); constructor( - private readonly uiState: UIState, - private readonly schema: SchemaDto, + public readonly uiState: UIState, + public readonly schema: SchemaDto, ) { super({ fields: [], sizes: {}, wrappings: {} }); @@ -143,3 +143,22 @@ export class TableSettings extends State { } } } + +export function getTableConfig(source: TableSettings) { + function sortedTableFields(fields: ReadonlyArray) { + const result: string[] = []; + + for (const field of fields) { + if (field.name && field.name.indexOf('meta') < 0) { + result.push(field.name); + } + } + + result.sort(); + return result; + } + + return source.listFields.pipe( + map(fields => sortedTableFields(fields)), + map(fields => ({ fieldNames: fields, schema: source.schema }))); +} \ No newline at end of file