information-system-gui/src/main/webapp/app/facet-composer/facet-composer.service.ts

62 lines
2.2 KiB
TypeScript

import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import { ApplicationConfigService } from 'app/core/config/application-config.service';
import { IFacetComposer } from './i-facet-composer';
export interface ITypeSpecification{
name:string, //nome tipo
description:string; //descrizione tipo
facetSpecs: IFacetComposer[];
}
@Injectable({
providedIn: 'root'
})
export class FacetComposerService {
httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
};
constructor(private http: HttpClient, private applicationConfigService: ApplicationConfigService) { }
//TODO: paginate (when pagination APIs will be ready)
//resourcespecification
getFormStructure(ctxPath:string, type:string): Observable<ITypeSpecification> {
const serviceUrl = this.applicationConfigService.getEndpointFor('api/is/facetspecifications');
let queryParams = new HttpParams();
queryParams = queryParams.append("typeName",type).append("currentContext",ctxPath);
return this.http.get<ITypeSpecification>(serviceUrl,{params:queryParams});
}
getRelationOptions(ctxPath:string, type:string): Observable<string> {
const serviceUrl = this.applicationConfigService.getEndpointFor('api/is/resourcetypejson');
let queryParams = new HttpParams();
queryParams = queryParams.append("typeName",type).append("currentContext",ctxPath);
return this.http.get<string>(serviceUrl,{params:queryParams});
}
createResource(type:string, data:string): Observable<string> {
//alert('create?');
const serviceUrl = this.applicationConfigService.getEndpointFor('api/is/createresource');
let queryParams = new HttpParams();
queryParams = queryParams.append("typeName",type).append("data",data);
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
let res : Observable<string>|undefined;
try{ alert('prima')
res = this.http.post<string>(serviceUrl, {params:queryParams});
}catch(error){
alert('errore')
console.error('---------------------');
console.error(error);
return new Observable<string>();
};
return new Observable<string>();
}
}