angular update to version 8
parent
4f507eddf3
commit
e6891861e5
@ -0,0 +1,12 @@
|
||||
# This file is used by the build system to adjust CSS and JS output to support the specified browsers below.
|
||||
# For additional information regarding the format and rule options, please see:
|
||||
# https://github.com/browserslist/browserslist#queries
|
||||
|
||||
# You can see what browsers were selected by your queries by running:
|
||||
# npx browserslist
|
||||
|
||||
> 0.5%
|
||||
last 2 versions
|
||||
Firefox ESR
|
||||
not dead
|
||||
not IE 9-11 # For IE 9-11 support, remove 'not'.
|
@ -1,55 +1,57 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
/**
|
||||
* Created by stefania on 7/17/17.
|
||||
*/
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Http, Response } from '@angular/http';
|
||||
import { Observable } from 'rxjs/Rx';
|
||||
import { Observable, throwError as observableThrowError } from 'rxjs';
|
||||
import { catchError, map } from 'rxjs/operators';
|
||||
import { environment } from '../../../../environments/environment';
|
||||
import { PageHelpContent } from '../../model/help-content/page-help-content';
|
||||
import { CachedContentItem } from './cached-content-item';
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class HelpContentService {
|
||||
private _helpServiceUrl = environment.HelpService.Url;
|
||||
cache = new Map<String, CachedContentItem>();
|
||||
|
||||
constructor(private http: Http) {
|
||||
constructor(private http: HttpClient) {
|
||||
}
|
||||
|
||||
getActivePageContent(route: string) {
|
||||
if (!this.cache.get(route) || !this.isValidCachedItem(route)) {
|
||||
return this.http.get(this._helpServiceUrl + '/page/route?q=' + route)
|
||||
.map(res => {
|
||||
this.cache.set(route, { timestamp: Date.now(), content: <PageHelpContent>res.json() });
|
||||
return res.json();
|
||||
})
|
||||
.catch(this.handleError);
|
||||
}
|
||||
return Observable.create(observer => observer.next(this.cache.get(route).content));
|
||||
}
|
||||
private extractData(res: Response) {
|
||||
const body = res.json();
|
||||
return body.data || {};
|
||||
}
|
||||
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 Observable.throw(errMsg);
|
||||
}
|
||||
// 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);
|
||||
// }
|
||||
|
||||
isValidCachedItem(route) {
|
||||
const cachedTimestamp = this.cache.get(route).timestamp;
|
||||
const currentTimestamp = Date.now();
|
||||
if (currentTimestamp - cachedTimestamp > 30000) { return false; } else { return true; }
|
||||
}
|
||||
// isValidCachedItem(route) {
|
||||
// const cachedTimestamp = this.cache.get(route).timestamp;
|
||||
// const currentTimestamp = Date.now();
|
||||
// if (currentTimestamp - cachedTimestamp > 30000) { return false; } else { return true; }
|
||||
// }
|
||||
}
|
||||
|
Loading…
Reference in New Issue