2019-10-11 18:16:14 +02:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
import { HttpClient } from '@angular/common/http';
|
|
|
|
import { Observable, of } from 'rxjs';
|
|
|
|
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);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-10-14 15:42:34 +02:00
|
|
|
public getResourceTypes(callback: (isTypes: ISType[]) => void): void {
|
2019-10-11 18:16:14 +02:00
|
|
|
|
|
|
|
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))
|
|
|
|
);
|
|
|
|
*/
|
2019-10-14 15:42:34 +02:00
|
|
|
observable.subscribe(data => callback(data));
|
2019-10-11 18:16:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|