From 3352bfd805c77dab15c549712fd5f9ea6ab70f91 Mon Sep 17 00:00:00 2001 From: Mark van der Wal Date: Thu, 9 Jul 2020 13:45:24 +0200 Subject: [PATCH] Added schema layout api to schemaService --- .../common/src/fm/services/schema.service.ts | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/projects/common/src/fm/services/schema.service.ts b/projects/common/src/fm/services/schema.service.ts index f6fce31..6985dd1 100644 --- a/projects/common/src/fm/services/schema.service.ts +++ b/projects/common/src/fm/services/schema.service.ts @@ -1,13 +1,15 @@ -import {Injectable} from '@angular/core'; +import {Inject, Injectable, LOCALE_ID} from '@angular/core'; import {HttpClient} from '@angular/common/http'; import {AppConfig} from '../shared/app.config'; -import {Observable} from 'rxjs'; +import {Observable, of} from 'rxjs'; +import {catchError, switchMap} from 'rxjs/operators'; @Injectable({ providedIn: 'root', }) export class SchemaService { - constructor(private httpClient: HttpClient, private appConfig: AppConfig) { + constructor(private httpClient: HttpClient, private appConfig: AppConfig, + @Inject(LOCALE_ID) private locale) { } ApiEndpoint() { @@ -19,4 +21,23 @@ export class SchemaService { const encodedId = encodeURIComponent(id); return this.httpClient.get(`${this.ApiEndpoint()}/api/v1/schema/${encodedId}`); } + + public getSchemaLayout(schemaUrl: string, locale: string): Observable { + const encodedId = encodeURIComponent(schemaUrl); + return this.httpClient.get(`${this.ApiEndpoint()}/api/v1/schema/${encodedId}/layout/${locale}`); + } + + public getSchemaAndLayout(schemaUrl: string, locale: string = this.locale): + Observable<{schemaJson: any, schemaLayout: any}> { + return this.getSchema(schemaUrl).pipe( + switchMap( + schemaJson => this.getSchemaLayout(schemaUrl, locale) + .pipe(catchError(err => { + return of(undefined); + })), + (schemaJson, schemaLayout) => { + return ({schemaJson, schemaLayout}); + } + )); + } }