FarmMapsLib/projects/common/src/fm/services/itemtype.service.ts

75 lines
2.6 KiB
TypeScript
Raw Normal View History

2020-01-08 10:37:37 +00:00
import { Injectable } from '@angular/core';
import {IItemTypes} from '../models/item.types'
import {IItem} from '../models/item'
2020-02-11 17:55:43 +00:00
import {AppConfig} from '../shared/app.config';
import {HttpClient, HttpXhrBackend} from '@angular/common/http';
2020-01-08 10:37:37 +00:00
2020-02-12 19:38:14 +00:00
@Injectable()
2020-01-08 10:37:37 +00:00
export class ItemTypeService {
public itemTypes: IItemTypes;
2020-02-11 17:55:43 +00:00
private httpClient: HttpClient;
2020-01-08 10:37:37 +00:00
constructor(xhrBackend: HttpXhrBackend) {
2020-02-11 17:55:43 +00:00
this.httpClient = new HttpClient(xhrBackend);
}
2020-01-08 10:37:37 +00:00
getIcon(itemType: string) {
2023-03-06 13:04:14 +00:00
let icon = "fal fa-file";
if (this.itemTypes && this.itemTypes[itemType]) icon = this.itemTypes[itemType].icon;
2020-01-08 10:37:37 +00:00
return icon;
}
getColor(itemType: string) {
2023-03-06 13:04:14 +00:00
let color = "#000000";
if (this.itemTypes && this.itemTypes[itemType]) color = this.itemTypes[itemType].iconColor;
2020-01-08 10:37:37 +00:00
return color;
}
2020-02-11 17:55:43 +00:00
getExtraAttributes(itemType: string) {
2023-03-06 13:04:14 +00:00
let extraAttributes = null;
if (this.itemTypes && this.itemTypes[itemType] && this.itemTypes[itemType].extraAttributes) extraAttributes = this.itemTypes[itemType].extraAttributes;
2020-02-11 17:55:43 +00:00
return extraAttributes;
}
getSchema(itemType: string): string {
let schema = null;
if (this.itemTypes && this.itemTypes[itemType]) schema = this.itemTypes[itemType].schema;
return schema;
}
2020-01-08 10:37:37 +00:00
hasViewer(item: IItem) {
2023-03-06 13:04:14 +00:00
const itemType: string = item.itemType;
if (this.itemTypes && this.itemTypes[itemType]) return this.itemTypes[itemType].viewer !== undefined;
2020-01-08 10:37:37 +00:00
return false;
}
hasEditor(item: IItem) {
2023-03-06 13:04:14 +00:00
const itemType: string = item.itemType;
if (this.itemTypes && this.itemTypes[itemType]) return this.itemTypes[itemType].editor !== undefined;
2020-01-08 10:37:37 +00:00
return false;
}
isLayer(item: IItem) {
2023-03-06 13:04:14 +00:00
const itemType: string = item.itemType;
2020-01-08 10:37:37 +00:00
return itemType == "vnd.farmmaps.itemtype.geotiff.processed" || itemType == "vnd.farmmaps.itemtype.layer" || itemType == "vnd.farmmaps.itemtype.shape.processed";
}
2020-02-11 17:55:43 +00:00
public load(config:AppConfig): Promise<any> {
2020-10-30 07:22:58 +00:00
if(this.itemTypes==null) {
2023-03-06 13:04:14 +00:00
const url = `${ config.getConfig("apiEndPoint")}/api/v1/itemtypes/`
2020-10-30 07:22:58 +00:00
return this.httpClient.get(url)
.toPromise()
.then((itemTypes:IItemTypes) => {
this.itemTypes = itemTypes;
//return data;
})
2024-04-15 13:03:05 +00:00
.catch((error) => {
console.log(error);
this.itemTypes = null
});
2020-10-30 07:22:58 +00:00
} else {
return new Promise<void>((resolve) => {resolve()});
2020-10-30 07:22:58 +00:00
}
2023-03-06 13:04:14 +00:00
}
}