Browse Source

Cleaner code.

pull/1029/head
Sebastian 3 years ago
parent
commit
869177d979
  1. 14
      frontend/src/app/features/content/pages/contents/contents-page.component.ts
  2. 2
      frontend/src/app/shared/services/schemas.service.ts
  3. 25
      frontend/src/app/shared/state/table-settings.ts

14
frontend/src/app/features/content/pages/contents/contents-page.component.ts

@ -10,8 +10,8 @@
import { Component, OnInit, ViewChild } from '@angular/core'; import { Component, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router'; import { ActivatedRoute, Router } from '@angular/router';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { distinctUntilChanged, map, shareReplay, switchMap, take, tap, withLatestFrom } from 'rxjs/operators'; import { distinctUntilChanged, map, shareReplay, switchMap, take, tap } 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 { 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'; import { DueTimeSelectorComponent } from './../../shared/due-time-selector.component';
@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)))); getSchemaName(this.route).pipe(switchMap(() => this.schemasState.selectedSchema.pipe(defined(), take(1), shareReplay(1))));
const tableSetting$ = 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$ = const tableConfig$ =
tableSetting$.pipe(switchMap(s => s.listFields), map(s => getTableFields(s))); tableSetting$.pipe(switchMap(getTableConfig));
this.tableSettings = tableSetting$; this.tableSettings = tableSetting$;
this.own( this.own(
tableName$.pipe(withLatestFrom(schema$)) tableConfig$
.subscribe(([fieldNames, schema]) => { .subscribe(({ fieldNames, schema }) => {
if (this.schema?.id !== schema.id) { if (this.schema?.id !== schema.id) {
this.resetSelection(); this.resetSelection();

2
frontend/src/app/shared/services/schemas.service.ts

@ -101,7 +101,7 @@ export function getTableFields(fields: ReadonlyArray<TableField>) {
} }
result.sort(); result.sort();
return result; return result;
} }

25
frontend/src/app/shared/state/table-settings.ts

@ -5,7 +5,7 @@
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved. * 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 { State, Types } from '@app/framework';
import { META_FIELDS, SchemaDto, TableField } from './../services/schemas.service'; import { META_FIELDS, SchemaDto, TableField } from './../services/schemas.service';
import { UIState } from './ui.state'; import { UIState } from './ui.state';
@ -45,8 +45,8 @@ export class TableSettings extends State<Snapshot> {
this.projectFrom(this.fields, x => x.length > 0 ? x : this.schemaDefaults); this.projectFrom(this.fields, x => x.length > 0 ? x : this.schemaDefaults);
constructor( constructor(
private readonly uiState: UIState, public readonly uiState: UIState,
private readonly schema: SchemaDto, public readonly schema: SchemaDto,
) { ) {
super({ fields: [], sizes: {}, wrappings: {} }); super({ fields: [], sizes: {}, wrappings: {} });
@ -143,3 +143,22 @@ export class TableSettings extends State<Snapshot> {
} }
} }
} }
export function getTableConfig(source: TableSettings) {
function sortedTableFields(fields: ReadonlyArray<TableField>) {
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 })));
}
Loading…
Cancel
Save