Browse Source

Projection improved.

pull/414/head
Sebastian Stehle 6 years ago
parent
commit
2e680e28f7
  1. 2
      src/Squidex/app/features/administration/state/event-consumers.state.ts
  2. 4
      src/Squidex/app/features/administration/state/users.state.ts
  3. 20
      src/Squidex/app/framework/state.ts
  4. 16
      src/Squidex/app/shared/state/assets.state.ts
  5. 6
      src/Squidex/app/shared/state/backups.state.ts
  6. 4
      src/Squidex/app/shared/state/clients.state.ts
  7. 2
      src/Squidex/app/shared/state/comments.state.ts
  8. 10
      src/Squidex/app/shared/state/contents.state.ts
  9. 14
      src/Squidex/app/shared/state/contributors.state.ts
  10. 4
      src/Squidex/app/shared/state/languages.state.ts
  11. 4
      src/Squidex/app/shared/state/patterns.state.ts
  12. 4
      src/Squidex/app/shared/state/plans.state.ts
  13. 4
      src/Squidex/app/shared/state/roles.state.ts
  14. 2
      src/Squidex/app/shared/state/rule-events.state.ts
  15. 6
      src/Squidex/app/shared/state/rules.state.ts
  16. 17
      src/Squidex/app/shared/state/schemas.state.ts
  17. 8
      src/Squidex/app/shared/state/ui.state.ts
  18. 4
      src/Squidex/app/shared/state/workflows.state.ts

2
src/Squidex/app/features/administration/state/event-consumers.state.ts

@ -34,7 +34,7 @@ export class EventConsumersState extends State<Snapshot> {
this.project(x => x.eventConsumers); this.project(x => x.eventConsumers);
public isLoaded = public isLoaded =
this.project(x => !!x.isLoaded); this.project(x => x.isLoaded === true);
constructor( constructor(
private readonly dialogs: DialogService, private readonly dialogs: DialogService,

4
src/Squidex/app/features/administration/state/users.state.ts

@ -61,10 +61,10 @@ export class UsersState extends State<Snapshot> {
this.project(x => x.selectedUser); this.project(x => x.selectedUser);
public isLoaded = public isLoaded =
this.project(x => !!x.isLoaded); this.project(x => x.isLoaded === true);
public canCreate = public canCreate =
this.project(x => !!x.canCreate); this.project(x => x.canCreate === true);
constructor( constructor(
private readonly dialogs: DialogService, private readonly dialogs: DialogService,

20
src/Squidex/app/framework/state.ts

@ -6,8 +6,8 @@
*/ */
import { AbstractControl } from '@angular/forms'; import { AbstractControl } from '@angular/forms';
import { BehaviorSubject, Observable } from 'rxjs'; import { BehaviorSubject, combineLatest, Observable } from 'rxjs';
import { distinctUntilChanged, map } from 'rxjs/operators'; import { distinctUntilChanged, map, shareReplay } from 'rxjs/operators';
import { ErrorDto, getDisplayMessage } from './utils/error'; import { ErrorDto, getDisplayMessage } from './utils/error';
@ -167,15 +167,19 @@ export class State<T extends {}> {
return this.state.value; return this.state.value;
} }
public project<R1>(project1: (value: T) => R1, compare?: (x: R1, y: R1) => boolean) { public project<M>(project1: (value: T) => M, compare?: (x: M, y: M) => boolean) {
return this.changes.pipe( return this.changes.pipe(
map(x => project1(x)), distinctUntilChanged(compare)); map(x => project1(x)), distinctUntilChanged(compare), shareReplay());
} }
public project2<R1, R2>(project1: (value: T) => R1, project2: (value: R1) => R2, compare?: (x: R2, y: R2) => boolean) { public projectFrom<M, N>(source: Observable<M>, project: (value: M) => N, compare?: (x: N, y: N) => boolean) {
return this.changes.pipe( return source.pipe(
map(x => project1(x)), distinctUntilChanged(), map(x => project(x)), distinctUntilChanged(compare), shareReplay());
map(x => project2(x)), distinctUntilChanged(compare)); }
public projectFrom2<M, N, O>(lhs: Observable<M>, rhs: Observable<N>, project: (l: M, r: N) => O, compare?: (x: O, y: O) => boolean) {
return combineLatest(lhs, rhs, (x, y) => project(x, y)).pipe(
distinctUntilChanged(compare), shareReplay());
} }
constructor(state: Readonly<T>) { constructor(state: Readonly<T>) {

16
src/Squidex/app/shared/state/assets.state.ts

@ -51,14 +51,20 @@ interface Snapshot {
@Injectable() @Injectable()
export class AssetsState extends State<Snapshot> { export class AssetsState extends State<Snapshot> {
public tagsUnsorted =
this.project(x => x.tags);
public tagsSelected =
this.project(x => x.tags);
public tags = public tags =
this.project2(x => x.tags, x => sort(x)); this.projectFrom(this.tagsUnsorted, x => sort(x));
public tagsNames = public tagsNames =
this.project2(x => x.tags, x => Object.keys(x)); this.projectFrom(this.tagsUnsorted, x => Object.keys(x));
public selectedTagNames = public selectedTagNames =
this.project2(x => x.tagsSelected, x => Object.keys(x)); this.projectFrom(this.tagsSelected, x => Object.keys(x));
public assets = public assets =
this.project(x => x.assets); this.project(x => x.assets);
@ -70,10 +76,10 @@ export class AssetsState extends State<Snapshot> {
this.project(x => x.assetsPager); this.project(x => x.assetsPager);
public isLoaded = public isLoaded =
this.project(x => !!x.isLoaded); this.project(x => x.isLoaded === true);
public canCreate = public canCreate =
this.project(x => !!x.canCreate); this.project(x => x.canCreate === true);
constructor( constructor(
private readonly appsState: AppsState, private readonly appsState: AppsState,

6
src/Squidex/app/shared/state/backups.state.ts

@ -39,13 +39,13 @@ export class BackupsState extends State<Snapshot> {
this.project(x => x.backups); this.project(x => x.backups);
public maxBackupsReached = public maxBackupsReached =
this.project(x => x.backups.length >= 10); this.projectFrom(this.backups, x => x.length >= 10);
public isLoaded = public isLoaded =
this.project(x => !!x.isLoaded); this.project(x => x.isLoaded === true);
public canCreate = public canCreate =
this.project(x => !!x.canCreate); this.project(x => x.canCreate === true);
constructor( constructor(
private readonly appsState: AppsState, private readonly appsState: AppsState,

4
src/Squidex/app/shared/state/clients.state.ts

@ -51,10 +51,10 @@ export class ClientsState extends State<Snapshot> {
this.project(x => x.clients); this.project(x => x.clients);
public isLoaded = public isLoaded =
this.project(x => !!x.isLoaded); this.project(x => x.isLoaded === true);
public canCreate = public canCreate =
this.project(x => !!x.canCreate); this.project(x => x.canCreate === true);
constructor( constructor(
private readonly clientsService: ClientsService, private readonly clientsService: ClientsService,

2
src/Squidex/app/shared/state/comments.state.ts

@ -38,7 +38,7 @@ export class CommentsState extends State<Snapshot> {
this.project(x => x.comments); this.project(x => x.comments);
public isLoaded = public isLoaded =
this.project(x => !!x.isLoaded); this.project(x => x.isLoaded === true);
constructor( constructor(
private readonly appsState: AppsState, private readonly appsState: AppsState,

10
src/Squidex/app/shared/state/contents.state.ts

@ -74,22 +74,22 @@ export abstract class ContentsStateBase extends State<Snapshot> {
this.project(x => x.contentsQuery); this.project(x => x.contentsQuery);
public isLoaded = public isLoaded =
this.project(x => !!x.isLoaded); this.project(x => x.isLoaded === true);
public canCreate = public canCreate =
this.project(x => !!x.canCreate); this.project(x => x.canCreate === true);
public canCreateAndPublish = public canCreateAndPublish =
this.project(x => !!x.canCreateAndPublish); this.project(x => x.canCreateAndPublish === true);
public canCreateAny = public canCreateAny =
this.project(x => !!x.canCreate || !!x.canCreateAndPublish); this.project(x => x.canCreate === true || x.canCreateAndPublish === true);
public statuses = public statuses =
this.project(x => x.statuses); this.project(x => x.statuses);
public statusQueries = public statusQueries =
this.project2(x => x.statuses, x => buildQueries(x)); this.projectFrom(this.statuses, x => buildQueries(x));
constructor( constructor(
private readonly appsState: AppsState, private readonly appsState: AppsState,

14
src/Squidex/app/shared/state/contributors.state.ts

@ -6,8 +6,8 @@
*/ */
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { combineLatest, Observable, throwError } from 'rxjs'; import { Observable, throwError } from 'rxjs';
import { catchError, shareReplay, tap } from 'rxjs/operators'; import { catchError, tap } from 'rxjs/operators';
import { import {
DialogService, DialogService,
@ -76,19 +76,19 @@ export class ContributorsState extends State<Snapshot> {
this.project(x => x.maxContributors); this.project(x => x.maxContributors);
public isLoaded = public isLoaded =
this.project(x => !!x.isLoaded); this.project(x => x.isLoaded === true);
public canCreate = public canCreate =
this.project(x => !!x.canCreate); this.project(x => x.canCreate === true);
public filtered = public filtered =
combineLatest(this.queryRegex, this.contributors, (q, c) => getFilteredContributors(c, q)).pipe(shareReplay()); this.projectFrom2(this.queryRegex, this.contributors, (q, c) => getFilteredContributors(c, q));
public contributorsPaged = public contributorsPaged =
combineLatest(this.page, this.filtered, (p, c) => getPagedContributors(c, p)); this.projectFrom2(this.page, this.filtered, (p, c) => getPagedContributors(c, p));
public contributorsPager = public contributorsPager =
combineLatest(this.page, this.filtered, (p, c) => new Pager(c.length, p, PAGE_SIZE)); this.projectFrom2(this.page, this.filtered, (p, c) => new Pager(c.length, p, PAGE_SIZE));
constructor( constructor(
private readonly contributorsService: ContributorsService, private readonly contributorsService: ContributorsService,

4
src/Squidex/app/shared/state/languages.state.ts

@ -74,10 +74,10 @@ export class LanguagesState extends State<Snapshot> {
this.project(x => x.allLanguagesNew); this.project(x => x.allLanguagesNew);
public isLoaded = public isLoaded =
this.project(x => !!x.isLoaded); this.project(x => x.isLoaded === true);
public canCreate = public canCreate =
this.project(x => !!x.canCreate); this.project(x => x.canCreate === true);
constructor( constructor(
private readonly appLanguagesService: AppLanguagesService, private readonly appLanguagesService: AppLanguagesService,

4
src/Squidex/app/shared/state/patterns.state.ts

@ -49,10 +49,10 @@ export class PatternsState extends State<Snapshot> {
this.project(x => x.patterns); this.project(x => x.patterns);
public isLoaded = public isLoaded =
this.project(x => !!x.isLoaded); this.project(x => x.isLoaded === true);
public canCreate = public canCreate =
this.project(x => !!x.canCreate); this.project(x => x.canCreate === true);
constructor( constructor(
private readonly patternsService: PatternsService, private readonly patternsService: PatternsService,

4
src/Squidex/app/shared/state/plans.state.ts

@ -55,10 +55,10 @@ export class PlansState extends State<Snapshot> {
this.project(x => x.plans); this.project(x => x.plans);
public isOwner = public isOwner =
this.project(x => !!x.isOwner); this.project(x => x.isOwner === true);
public isLoaded = public isLoaded =
this.project(x => !!x.isLoaded); this.project(x => x.isLoaded === true);
public isDisabled = public isDisabled =
this.project(x => !x.isOwner); this.project(x => !x.isOwner);

4
src/Squidex/app/shared/state/roles.state.ts

@ -49,10 +49,10 @@ export class RolesState extends State<Snapshot> {
this.project(x => x.roles); this.project(x => x.roles);
public isLoaded = public isLoaded =
this.project(x => !!x.isLoaded); this.project(x => x.isLoaded === true);
public canCreate = public canCreate =
this.project(x => !!x.canCreate); this.project(x => x.canCreate === true);
constructor( constructor(
private readonly rolesService: RolesService, private readonly rolesService: RolesService,

2
src/Squidex/app/shared/state/rule-events.state.ts

@ -41,7 +41,7 @@ export class RuleEventsState extends State<Snapshot> {
this.project(x => x.ruleEventsPager); this.project(x => x.ruleEventsPager);
public isLoaded = public isLoaded =
this.project(x => !!x.isLoaded); this.project(x => x.isLoaded === true);
constructor( constructor(
private readonly appsState: AppsState, private readonly appsState: AppsState,

6
src/Squidex/app/shared/state/rules.state.ts

@ -46,13 +46,13 @@ export class RulesState extends State<Snapshot> {
this.project(x => x.rules); this.project(x => x.rules);
public isLoaded = public isLoaded =
this.project(x => !!x.isLoaded); this.project(x => x.isLoaded === true);
public canCreate = public canCreate =
this.project(x => !!x.canCreate); this.project(x => x.canCreate === true);
public canReadEvents = public canReadEvents =
this.project(x => !!x.canReadEvents); this.project(x => x.canReadEvents === true);
constructor( constructor(
private readonly appsState: AppsState, private readonly appsState: AppsState,

17
src/Squidex/app/shared/state/schemas.state.ts

@ -66,8 +66,8 @@ export class SchemasState extends State<Snapshot> {
return this.snapshot.selectedSchema ? this.snapshot.selectedSchema.name : ''; return this.snapshot.selectedSchema ? this.snapshot.selectedSchema.name : '';
} }
public categories = public categoriesPlain =
this.project2(x => x, x => buildCategories(x.categories, x.schemas)); this.project(x => x.categories);
public selectedSchema = public selectedSchema =
this.project(x => x.selectedSchema, sameSchema); this.project(x => x.selectedSchema, sameSchema);
@ -75,14 +75,17 @@ export class SchemasState extends State<Snapshot> {
public schemas = public schemas =
this.project(x => x.schemas); this.project(x => x.schemas);
public publishedSchemas =
this.project2(x => x.schemas, x => x.filter(s => s.isPublished));
public isLoaded = public isLoaded =
this.project(x => !!x.isLoaded); this.project(x => x.isLoaded === true);
public canCreate = public canCreate =
this.project(x => !!x.canCreate); this.project(x => x.canCreate === true);
public publishedSchemas =
this.projectFrom(this.schemas, x => x.filter(s => s.isPublished));
public categories =
this.projectFrom2(this.schemas, this.categoriesPlain, (s, c) => buildCategories(c, s));
constructor( constructor(
private readonly appsState: AppsState, private readonly appsState: AppsState,

8
src/Squidex/app/shared/state/ui.state.ts

@ -49,16 +49,16 @@ export class UIState extends State<Snapshot> {
this.project(x => x.settings); this.project(x => x.settings);
public canReadEvents = public canReadEvents =
this.project(x => !!x.canReadEvents); this.project(x => x.canReadEvents === true);
public canReadUsers = public canReadUsers =
this.project(x => !!x.canReadUsers); this.project(x => x.canReadUsers === true);
public canRestore = public canRestore =
this.project(x => !!x.canRestore); this.project(x => x.canRestore === true);
public canUserAdminResource = public canUserAdminResource =
this.project(x => !!x.canRestore || !!x.canReadUsers || !!x.canReadEvents); this.project(x => x.canRestore === true || x.canReadUsers === true || x.canReadEvents === true);
public get<T>(path: string, defaultValue: T) { public get<T>(path: string, defaultValue: T) {
return this.settings.pipe(map(x => this.getValue(x, path, defaultValue)), return this.settings.pipe(map(x => this.getValue(x, path, defaultValue)),

4
src/Squidex/app/shared/state/workflows.state.ts

@ -53,10 +53,10 @@ export class WorkflowsState extends State<Snapshot> {
this.project(x => x.errors); this.project(x => x.errors);
public isLoaded = public isLoaded =
this.project(x => !!x.isLoaded); this.project(x => x.isLoaded === true);
public canCreate = public canCreate =
this.project(x => !!x.canCreate); this.project(x => x.canCreate === true);
constructor( constructor(
private readonly workflowsService: WorkflowsService, private readonly workflowsService: WorkflowsService,

Loading…
Cancel
Save