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 { 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();

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

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

25
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<Snapshot> {
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<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