49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
import { Injectable } from '@angular/core';
|
|
import { HttpClient } from '@angular/common/http';
|
|
import { Observable, of } from 'rxjs';
|
|
import { catchError, tap } from 'rxjs/operators';
|
|
import { ISType } from './ISType';
|
|
import { types } from './types';
|
|
|
|
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class IsService {
|
|
|
|
constructor(private httpClient: HttpClient) { }
|
|
|
|
/* NextNext Token */
|
|
private token = '';
|
|
|
|
/**
|
|
* Handle Http operation that failed.
|
|
* Let the app continue.
|
|
* @param operation - name of the operation that failed
|
|
* @param result - optional value to return as the observable result
|
|
*/
|
|
private handleError<T>(operation = 'operation', result?: T) {
|
|
return (error: any): Observable<T> => {
|
|
console.error(error);
|
|
console.error(`${operation} failed: ${error.message}`); // log to console instead
|
|
// Let the app keep running by returning an empty result.
|
|
return of(result as T);
|
|
};
|
|
}
|
|
|
|
public getResourceTypes(): Observable<ISType[]> {
|
|
|
|
const url = 'http://pc-frosini.isti.cnr.it:8080/resource-registry/types/Resource?polymorphic=true&gcube-token=' + this.token;
|
|
// const observable: Observable<ISType[]> = of(types);
|
|
const observable: Observable<ISType[]> = this.httpClient.get<ISType[]>(url);
|
|
/*
|
|
observable.pipe(
|
|
tap(_ => console.info('Fetched Resource Types')),
|
|
catchError(this.handleError<ISType[]>('getResourceTypes()', types))
|
|
);
|
|
*/
|
|
return observable
|
|
}
|
|
|
|
}
|