From aa3707aa560605d1807939599263ec59e14f379c Mon Sep 17 00:00:00 2001 From: Mark van der Wal Date: Mon, 22 Jun 2020 12:20:02 +0200 Subject: [PATCH 1/3] Added getSchema method to itemtypes service. --- projects/common/src/fm/models/item.type.ts | 1 + .../common/src/fm/services/itemtype.service.ts | 14 ++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/projects/common/src/fm/models/item.type.ts b/projects/common/src/fm/models/item.type.ts index 4c19e57..cf11313 100644 --- a/projects/common/src/fm/models/item.type.ts +++ b/projects/common/src/fm/models/item.type.ts @@ -4,5 +4,6 @@ export interface IItemType { editor?: string; isFolder?: boolean; iconColor?: string; + schema?: string; extraAttributes?: string; } diff --git a/projects/common/src/fm/services/itemtype.service.ts b/projects/common/src/fm/services/itemtype.service.ts index f81f1ad..96f04c5 100644 --- a/projects/common/src/fm/services/itemtype.service.ts +++ b/projects/common/src/fm/services/itemtype.service.ts @@ -9,9 +9,9 @@ export class ItemTypeService { public itemTypes: IItemTypes; private httpClient: HttpClient; - constructor(xhrBackend: HttpXhrBackend) { + constructor(xhrBackend: HttpXhrBackend) { this.httpClient = new HttpClient(xhrBackend); - } + } getIcon(itemType: string) { var icon = "fa fa-file-o"; @@ -31,6 +31,12 @@ export class ItemTypeService { return extraAttributes; } + getSchema(itemType: string): string { + let schema = null; + if (this.itemTypes[itemType]) schema = this.itemTypes[itemType].schema; + return schema; + } + hasViewer(item: IItem) { let itemType: string = item.itemType; if (this.itemTypes[itemType]) return this.itemTypes[itemType].viewer !== undefined; @@ -49,7 +55,7 @@ export class ItemTypeService { } public load(config:AppConfig): Promise { - + var url = `${ config.getConfig("apiEndPoint")}/api/v1/itemtypes/` return this.httpClient.get(url) .toPromise() @@ -59,4 +65,4 @@ export class ItemTypeService { }) .catch(error => this.itemTypes = null); }; -} \ No newline at end of file +} From 75015f6d226b3837a93b7d4b04a6519867f652f5 Mon Sep 17 00:00:00 2001 From: Mark van der Wal Date: Mon, 22 Jun 2020 13:12:02 +0200 Subject: [PATCH 2/3] Added schema service --- .../common/src/fm/common-service.module.ts | 6 ++-- .../common/src/fm/services/schema.service.ts | 30 +++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 projects/common/src/fm/services/schema.service.ts diff --git a/projects/common/src/fm/common-service.module.ts b/projects/common/src/fm/common-service.module.ts index cff3204..537a517 100644 --- a/projects/common/src/fm/common-service.module.ts +++ b/projects/common/src/fm/common-service.module.ts @@ -9,6 +9,7 @@ import { OAuthModule, OAuthService, OAuthStorage } from 'angular-oauth2-oidc'; //components import { ItemTypeService } from './services/itemtype.service'; +import { SchemaService } from './services/schema.service'; import { FolderService } from './services/folder.service'; import { TimespanService } from './services/timespan.service'; import { ItemService } from './services/item.service'; @@ -47,7 +48,8 @@ export { AuthCallbackGuard, ResumableFileUploadService, NgbDateNativeAdapter, - StateSerializerService + StateSerializerService, + SchemaService }; @NgModule({ @@ -71,7 +73,7 @@ export class AppCommonServiceModule { { provide: APP_INITIALIZER, useFactory: appConfigFactory, - deps: [Injector, AppConfig, OAuthService, AuthConfigFactory, OAuthStorage,ItemTypeService], + deps: [Injector, AppConfig, OAuthService, AuthConfigFactory, OAuthStorage, ItemTypeService], multi: true }, { diff --git a/projects/common/src/fm/services/schema.service.ts b/projects/common/src/fm/services/schema.service.ts new file mode 100644 index 0000000..354057e --- /dev/null +++ b/projects/common/src/fm/services/schema.service.ts @@ -0,0 +1,30 @@ +import {Injectable} from '@angular/core'; +import {HttpClient} from '@angular/common/http'; +import {AppConfig} from '../shared/app.config'; +import {Observable} from 'rxjs'; + +@Injectable() +export class SchemaService { + constructor(private httpClient: HttpClient, private appConfig: AppConfig) { + } + + ApiEndpoint() { + return this.appConfig.getConfig('apiEndPoint'); + } + + public getSchemaIdFromSchemaUrl(schemaUrl): string { + const url = new URL(schemaUrl); + const pathSplit = url.pathname.split('/'); + + return pathSplit[pathSplit.length - 1].replace('.json', ''); + } + + public getSchemaWithUrl(schemaUrl): Observable { + const id = this.getSchemaIdFromSchemaUrl(schemaUrl); + return this.httpClient.get(`${this.ApiEndpoint()}/api/v1/schema/${id}`); + } + + public getSchemaWithId(schemaId): Observable { + return this.httpClient.get(`${this.ApiEndpoint()}/api/v1/schema/${schemaId}`); + } +} From 0482aa7124c673b79922e65e9070b2ee17ec9ab5 Mon Sep 17 00:00:00 2001 From: Mark van der Wal Date: Mon, 22 Jun 2020 13:37:38 +0200 Subject: [PATCH 3/3] Added provided in root for schema service --- projects/common/src/fm/services/schema.service.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/projects/common/src/fm/services/schema.service.ts b/projects/common/src/fm/services/schema.service.ts index 354057e..acdfae6 100644 --- a/projects/common/src/fm/services/schema.service.ts +++ b/projects/common/src/fm/services/schema.service.ts @@ -3,7 +3,9 @@ import {HttpClient} from '@angular/common/http'; import {AppConfig} from '../shared/app.config'; import {Observable} from 'rxjs'; -@Injectable() +@Injectable({ + providedIn: 'root', +}) export class SchemaService { constructor(private httpClient: HttpClient, private appConfig: AppConfig) { }