argos/dmp-frontend/src/app/core/services/help-content/help-content.service.ts

58 lines
2.1 KiB
TypeScript
Raw Normal View History

2019-09-23 10:17:03 +02:00
import { HttpClient } from '@angular/common/http';
2018-02-16 08:45:18 +01:00
/**
* Created by stefania on 7/17/17.
*/
import { Injectable } from '@angular/core';
2019-09-23 10:17:03 +02:00
import { Observable, throwError as observableThrowError } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
2019-01-18 18:03:45 +01:00
import { environment } from '../../../../environments/environment';
import { PageHelpContent } from '../../model/help-content/page-help-content';
import { CachedContentItem } from './cached-content-item';
2018-11-27 15:13:56 +01:00
2019-09-23 10:17:03 +02:00
2018-02-16 08:45:18 +01:00
@Injectable()
export class HelpContentService {
2018-11-27 15:13:56 +01:00
private _helpServiceUrl = environment.HelpService.Url;
2018-10-05 17:00:54 +02:00
cache = new Map<String, CachedContentItem>();
2018-02-16 11:34:02 +01:00
2019-09-23 10:17:03 +02:00
constructor(private http: HttpClient) {
2018-10-05 17:00:54 +02:00
}
2018-02-16 11:34:02 +01:00
2019-09-23 10:17:03 +02:00
// getActivePageContent(route: string) {
// if (!this.cache.get(route) || !this.isValidCachedItem(route)) {
// return this.http.get(this._helpServiceUrl + '/page/route?q=' + route).pipe(
// map((res: Response) => {
// this.cache.set(route, { timestamp: Date.now(), content: res.json() as PageHelpContent });
// return res.json();
// }),
// catchError(this.handleError));
// }
// return Observable.create(observer => observer.next(this.cache.get(route).content));
// }
// private extractData(res: Response) {
// const body = res.json();
// return body. || {};
// }
// private handleError(error: Response | any) {
// // In a real world app, we might use a remote logging infrastructure
// // We'd also dig deeper into the error to get a better message
// let errMsg = '';
// if (error instanceof Response) {
// const body = error.text() || '';
// //const err = body.error || JSON.stringify(body);
// errMsg = `${error.status} - ${error.statusText || ''} ${body}`;
// } else {
// errMsg = (error.message) ? error.message :
// error.status ? `${error.status} - ${error.statusText}` : 'Server error';
// console.error(errMsg); // log to console instead
// }
// return observableThrowError(errMsg);
// }
2018-02-16 11:34:02 +01:00
2019-09-23 10:17:03 +02:00
// isValidCachedItem(route) {
// const cachedTimestamp = this.cache.get(route).timestamp;
// const currentTimestamp = Date.now();
// if (currentTimestamp - cachedTimestamp > 30000) { return false; } else { return true; }
// }
2018-06-05 10:18:01 +02:00
}