Merge branch 'develop' of https://git.akkerweb.nl/FarmMaps/FarmMapsLib into develop
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good Details

2022.01
Willem Dantuma 2020-06-23 13:36:29 +02:00
commit 4130e0a796
4 changed files with 47 additions and 6 deletions

View File

@ -9,6 +9,7 @@ import { OAuthModule, OAuthService, OAuthStorage } from 'angular-oauth2-oidc';
//components //components
import { ItemTypeService } from './services/itemtype.service'; import { ItemTypeService } from './services/itemtype.service';
import { SchemaService } from './services/schema.service';
import { FolderService } from './services/folder.service'; import { FolderService } from './services/folder.service';
import { TimespanService } from './services/timespan.service'; import { TimespanService } from './services/timespan.service';
import { ItemService } from './services/item.service'; import { ItemService } from './services/item.service';
@ -47,7 +48,8 @@ export {
AuthCallbackGuard, AuthCallbackGuard,
ResumableFileUploadService, ResumableFileUploadService,
NgbDateNativeAdapter, NgbDateNativeAdapter,
StateSerializerService StateSerializerService,
SchemaService
}; };
@NgModule({ @NgModule({
@ -71,7 +73,7 @@ export class AppCommonServiceModule {
{ {
provide: APP_INITIALIZER, provide: APP_INITIALIZER,
useFactory: appConfigFactory, useFactory: appConfigFactory,
deps: [Injector, AppConfig, OAuthService, AuthConfigFactory, OAuthStorage,ItemTypeService], deps: [Injector, AppConfig, OAuthService, AuthConfigFactory, OAuthStorage, ItemTypeService],
multi: true multi: true
}, },
{ {

View File

@ -4,5 +4,6 @@ export interface IItemType {
editor?: string; editor?: string;
isFolder?: boolean; isFolder?: boolean;
iconColor?: string; iconColor?: string;
schema?: string;
extraAttributes?: string; extraAttributes?: string;
} }

View File

@ -9,9 +9,9 @@ export class ItemTypeService {
public itemTypes: IItemTypes; public itemTypes: IItemTypes;
private httpClient: HttpClient; private httpClient: HttpClient;
constructor(xhrBackend: HttpXhrBackend) { constructor(xhrBackend: HttpXhrBackend) {
this.httpClient = new HttpClient(xhrBackend); this.httpClient = new HttpClient(xhrBackend);
} }
getIcon(itemType: string) { getIcon(itemType: string) {
var icon = "fa fa-file-o"; var icon = "fa fa-file-o";
@ -31,6 +31,12 @@ export class ItemTypeService {
return extraAttributes; return extraAttributes;
} }
getSchema(itemType: string): string {
let schema = null;
if (this.itemTypes[itemType]) schema = this.itemTypes[itemType].schema;
return schema;
}
hasViewer(item: IItem) { hasViewer(item: IItem) {
let itemType: string = item.itemType; let itemType: string = item.itemType;
if (this.itemTypes[itemType]) return this.itemTypes[itemType].viewer !== undefined; if (this.itemTypes[itemType]) return this.itemTypes[itemType].viewer !== undefined;
@ -49,7 +55,7 @@ export class ItemTypeService {
} }
public load(config:AppConfig): Promise<any> { public load(config:AppConfig): Promise<any> {
var url = `${ config.getConfig("apiEndPoint")}/api/v1/itemtypes/` var url = `${ config.getConfig("apiEndPoint")}/api/v1/itemtypes/`
return this.httpClient.get(url) return this.httpClient.get(url)
.toPromise() .toPromise()
@ -59,4 +65,4 @@ export class ItemTypeService {
}) })
.catch(error => this.itemTypes = null); .catch(error => this.itemTypes = null);
}; };
} }

View File

@ -0,0 +1,32 @@
import {Injectable} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {AppConfig} from '../shared/app.config';
import {Observable} from 'rxjs';
@Injectable({
providedIn: 'root',
})
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<string> {
const id = this.getSchemaIdFromSchemaUrl(schemaUrl);
return this.httpClient.get<any>(`${this.ApiEndpoint()}/api/v1/schema/${id}`);
}
public getSchemaWithId(schemaId): Observable<string> {
return this.httpClient.get<any>(`${this.ApiEndpoint()}/api/v1/schema/${schemaId}`);
}
}