Browse Source

Keep ordering.

pull/448/head
Sebastian 6 years ago
parent
commit
cb5992f525
  1. 2
      frontend/app/features/content/pages/contents/contents-page.component.ts
  2. 16
      frontend/app/shared/state/apps.state.ts
  3. 24
      frontend/app/shared/state/contents.state.ts
  4. 12
      frontend/app/shared/state/schemas.state.ts

2
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) {

16
frontend/app/shared/state/apps.state.ts

@ -34,14 +34,6 @@ interface Snapshot {
@Injectable()
export class AppsState extends State<Snapshot> {
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<Snapshot> {
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

24
frontend/app/shared/state/contents.state.ts

@ -60,6 +60,8 @@ function sameContent(lhs: ContentDto, rhs?: ContentDto): boolean {
}
export abstract class ContentsStateBase extends State<Snapshot> {
private previousId: string;
public selectedContent =
this.project(x => x.selectedContent, sameContent);
@ -115,7 +117,7 @@ export abstract class ContentsStateBase extends State<Snapshot> {
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<Snapshot> {
}
public load(isReload = false): Observable<any> {
if (!isReload) {
if (this.schemaId !== this.previousId) {
this.resetState();
}
@ -143,11 +145,13 @@ export abstract class ContentsStateBase extends State<Snapshot> {
}
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<Snapshot> {
}
public loadVersion(content: ContentDto, version: Version): Observable<Versioned<any>> {
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<ContentDto> {
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<Snapshot> {
}
}
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;
}
}

12
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<Snapshot> {
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<Snapshot> {
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,

Loading…
Cancel
Save