From cb5992f52542891da41fc0117cb1b98d2b3ff6da Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 18 Nov 2019 20:12:13 +0100 Subject: [PATCH] Keep ordering. --- .../pages/contents/contents-page.component.ts | 2 +- frontend/app/shared/state/apps.state.ts | 16 ++++++------- frontend/app/shared/state/contents.state.ts | 24 +++++++++++-------- frontend/app/shared/state/schemas.state.ts | 12 ++++++---- 4 files changed, 31 insertions(+), 23 deletions(-) diff --git a/frontend/app/features/content/pages/contents/contents-page.component.ts b/frontend/app/features/content/pages/contents/contents-page.component.ts index 488e55e1d..56b4f5128 100644 --- a/frontend/app/features/content/pages/contents/contents-page.component.ts +++ b/frontend/app/features/content/pages/contents/contents-page.component.ts @@ -154,7 +154,7 @@ export class ContentsPageComponent extends ResourceOwner implements OnInit { } public isItemSelected(content: ContentDto): boolean { - return !!this.selectedItems[content.id]; + return this.selectedItems[content.id] === true; } private selectItems(predicate?: (content: ContentDto) => boolean) { diff --git a/frontend/app/shared/state/apps.state.ts b/frontend/app/shared/state/apps.state.ts index 58725ca63..5b9b9a958 100644 --- a/frontend/app/shared/state/apps.state.ts +++ b/frontend/app/shared/state/apps.state.ts @@ -34,14 +34,6 @@ interface Snapshot { @Injectable() export class AppsState extends State { - public get appName() { - return this.snapshot.selectedApp ? this.snapshot.selectedApp.name : ''; - } - - public get appDisplayName() { - return this.snapshot.selectedApp ? this.snapshot.selectedApp.displayName : ''; - } - public apps = this.project(s => s.apps); @@ -51,6 +43,14 @@ export class AppsState extends State { public selectedApp = this.selectedAppOrNull.pipe(defined()); + public get appName() { + return this.snapshot.selectedApp ? this.snapshot.selectedApp.name : ''; + } + + public get appDisplayName() { + return this.snapshot.selectedApp ? this.snapshot.selectedApp.displayName : ''; + } + constructor( private readonly appsService: AppsService, private readonly dialogs: DialogService diff --git a/frontend/app/shared/state/contents.state.ts b/frontend/app/shared/state/contents.state.ts index a154b51de..e38db3b7e 100644 --- a/frontend/app/shared/state/contents.state.ts +++ b/frontend/app/shared/state/contents.state.ts @@ -60,6 +60,8 @@ function sameContent(lhs: ContentDto, rhs?: ContentDto): boolean { } export abstract class ContentsStateBase extends State { + private previousId: string; + public selectedContent = this.project(x => x.selectedContent, sameContent); @@ -115,7 +117,7 @@ export abstract class ContentsStateBase extends State { of(this.snapshot.contents.find(x => x.id === id)).pipe( switchMap(content => { if (!content) { - return this.contentsService.getContent(this.appName, this.schemaName, id).pipe(catchError(() => of(null))); + return this.contentsService.getContent(this.appName, this.schemaId, id).pipe(catchError(() => of(null))); } else { return of(content); } @@ -123,7 +125,7 @@ export abstract class ContentsStateBase extends State { } public load(isReload = false): Observable { - if (!isReload) { + if (this.schemaId !== this.previousId) { this.resetState(); } @@ -143,11 +145,13 @@ export abstract class ContentsStateBase extends State { } private loadInternalCore(isReload = false) { - if (!this.appName) { + if (!this.appName || !this.schemaId) { return empty(); } - return this.contentsService.getContents(this.appName, this.schemaName, + this.previousId = this.schemaId; + + return this.contentsService.getContents(this.appName, this.schemaId, this.snapshot.contentsPager.pageSize, this.snapshot.contentsPager.skip, this.snapshot.contentsQuery, undefined).pipe( @@ -181,12 +185,12 @@ export abstract class ContentsStateBase extends State { } public loadVersion(content: ContentDto, version: Version): Observable> { - return this.contentsService.getVersionData(this.appName, this.schemaName, content.id, version).pipe( + return this.contentsService.getVersionData(this.appName, this.schemaId, content.id, version).pipe( shareSubscribed(this.dialogs)); } public create(request: any, publish: boolean): Observable { - return this.contentsService.postContent(this.appName, this.schemaName, request, publish).pipe( + return this.contentsService.postContent(this.appName, this.schemaId, request, publish).pipe( tap(payload => { this.dialogs.notifyInfo('Content created successfully.'); @@ -338,7 +342,7 @@ export abstract class ContentsStateBase extends State { } } - protected abstract get schemaName(): string; + protected abstract get schemaId(): string; } @Injectable() @@ -349,8 +353,8 @@ export class ContentsState extends ContentsStateBase { super(appsState, contentsService, dialogs); } - protected get schemaName() { - return this.schemasState.schemaName; + protected get schemaId() { + return this.schemasState.schemaId; } } @@ -364,7 +368,7 @@ export class ManualContentsState extends ContentsStateBase { super(appsState, contentsService, dialogs); } - protected get schemaName() { + protected get schemaId() { return this.schema.name; } } diff --git a/frontend/app/shared/state/schemas.state.ts b/frontend/app/shared/state/schemas.state.ts index ffe89fa9d..0aab1c720 100644 --- a/frontend/app/shared/state/schemas.state.ts +++ b/frontend/app/shared/state/schemas.state.ts @@ -63,10 +63,6 @@ function sameSchema(lhs: SchemaDetailsDto | null, rhs?: SchemaDetailsDto | null) @Injectable() export class SchemasState extends State { - public get schemaName() { - return this.snapshot.selectedSchema ? this.snapshot.selectedSchema.name : ''; - } - public categoriesPlain = this.project(x => x.categories); @@ -91,6 +87,14 @@ export class SchemasState extends State { public categories = this.projectFrom2(this.schemas, this.categoriesPlain, (s, c) => buildCategories(c, s)); + public get schemaId() { + return this.snapshot.selectedSchema ? this.snapshot.selectedSchema.id : ''; + } + + public get schemaName() { + return this.snapshot.selectedSchema ? this.snapshot.selectedSchema.name : ''; + } + constructor( private readonly appsState: AppsState, private readonly dialogs: DialogService,