Revision 61263
Added by Konstantinos Triantafyllou over 2 years ago
modules/uoa-services-library/branches/angular-11/ng-openaire-library/src/app/services/reports.service.ts | ||
---|---|---|
4 | 4 |
|
5 | 5 |
|
6 | 6 |
|
7 |
import {map, tap} from "rxjs/operators"; |
|
7 |
import {map, tap, timeout} from "rxjs/operators";
|
|
8 | 8 |
|
9 | 9 |
@Injectable() |
10 | 10 |
export class ReportsService { |
... | ... | |
16 | 16 |
//var headers = new Headers(); |
17 | 17 |
//headers.append('responseType', 'arraybuffer'); |
18 | 18 |
return this.http.get(url, {responseType: 'text'}) |
19 |
.pipe(map(res => new Blob([res], { type: 'text/csv' }))); |
|
19 |
.pipe( |
|
20 |
timeout(10000), |
|
21 |
map(res => new Blob([res], { type: 'text/csv' }))); |
|
20 | 22 |
} |
21 | 23 |
getCSVResponse(url: string){ |
22 | 24 |
//var headers = new Headers(); |
23 | 25 |
//headers.append('responseType', 'arraybuffer'); |
24 |
return this.http.get(url, {responseType: 'text'}); |
|
26 |
return this.http.get(url, {responseType: 'text'}) |
|
27 |
.pipe(timeout(10000)); |
|
25 | 28 |
//.pipe(map(res => res)); |
26 | 29 |
} |
27 | 30 |
|
modules/uoa-services-library/branches/angular-11/ng-openaire-library/src/app/landingPages/organization/organization.component.ts | ||
---|---|---|
92 | 92 |
private funderId: string; |
93 | 93 |
private funderCount: number; |
94 | 94 |
subscriptions = []; |
95 |
innerReportSubscriptions = []; |
|
95 | 96 |
properties: EnvProperties; |
96 | 97 |
public indexUpdateDate: Date; |
97 | 98 |
public showFeedback: boolean = false; |
... | ... | |
188 | 189 |
subscription.unsubscribe(); |
189 | 190 |
} |
190 | 191 |
}); |
192 |
this.innerReportSubscriptions.forEach(subscription => { |
|
193 |
if(subscription instanceof Subscriber) { |
|
194 |
subscription.unsubscribe(); |
|
195 |
} |
|
196 |
}); |
|
197 |
|
|
191 | 198 |
this.fetchDatasets.clearSubscriptions(); |
192 | 199 |
this.fetchPublications.clearSubscriptions(); |
193 | 200 |
this.fetchSoftware.clearSubscriptions(); |
... | ... | |
390 | 397 |
data => { |
391 | 398 |
projects = data[1]; |
392 | 399 |
for (let index = 0; index < projects.length; index++) { |
393 |
this.subscriptions.push(this._searchResearchResultsService.numOfEntityResults(this.funderContentType, projects[index].id, "project", this.properties).subscribe(
|
|
400 |
this.innerReportSubscriptions.push(this._searchResearchResultsService.numOfEntityResults(this.funderContentType, projects[index].id, "project", this.properties).subscribe(
|
|
394 | 401 |
data => { |
395 | 402 |
//if(data == 0 && title) { // if no publications for this project |
396 | 403 |
if (data == 0 && (counter > 1 || title)) { // if no publications for this project |
... | ... | |
435 | 442 |
} |
436 | 443 |
title = true; |
437 | 444 |
|
438 |
this.subscriptions.push(this._reportsService.getCSVResponse(url).subscribe(
|
|
445 |
this.innerReportSubscriptions.push(this._reportsService.getCSVResponse(url).subscribe(
|
|
439 | 446 |
data => { |
440 | 447 |
counter--; |
441 | 448 |
response[index] = data; |
... | ... | |
473 | 480 |
|
474 | 481 |
this.closeLoading(); |
475 | 482 |
this.confirmOpenCsvError(); |
483 |
this.innerReportSubscriptions.forEach(subscription => subscription.unsubscribe()); |
|
476 | 484 |
}/*, |
477 | 485 |
() => console.log('Completed file download.')*/ |
478 | 486 |
) ); |
... | ... | |
481 | 489 |
err => { |
482 | 490 |
this.handleError("Error getting number of publications for project with id: " + projects[index].id, err); |
483 | 491 |
this.closeLoading(); |
492 |
this.confirmOpenCsvError(); |
|
493 |
this.innerReportSubscriptions.forEach(subscription => subscription.unsubscribe()); |
|
484 | 494 |
})); |
485 | 495 |
} |
486 | 496 |
}, |
modules/uoa-services-library/branches/angular-11/ng-openaire-library/src/app/landingPages/htmlProjectReport/htmlProjectReport.service.ts | ||
---|---|---|
1 | 1 |
import {Injectable} from '@angular/core'; |
2 | 2 |
import {HttpClient} from "@angular/common/http"; |
3 |
import {timeout} from "rxjs/operators"; |
|
3 | 4 |
|
4 | 5 |
@Injectable() |
5 | 6 |
export class HtmlProjectReportService { |
... | ... | |
12 | 13 |
//'((oaftype exact result) and (resulttypeid exact "'+resultTypeId+'")) and |
13 | 14 |
'(relprojectid exact "'+id+'"))'; |
14 | 15 |
|
15 |
return this.http.get(url,{responseType: 'text'}); |
|
16 |
return this.http.get(url,{responseType: 'text'}).pipe(timeout(10000));
|
|
16 | 17 |
} |
17 | 18 |
} |
modules/uoa-services-library/branches/angular-11/ng-openaire-library/src/app/timeout-interceptor.service.ts | ||
---|---|---|
3 | 3 |
import { Observable } from 'rxjs'; |
4 | 4 |
import { timeout } from 'rxjs/operators'; |
5 | 5 |
import {isPlatformServer} from "@angular/common"; |
6 |
import {properties} from "../../environments/environment"; |
|
7 |
import {isArray} from "util"; |
|
6 | 8 |
|
7 | 9 |
export const DEFAULT_TIMEOUT = new InjectionToken<number>('defaultTimeout'); |
8 | 10 |
|
9 | 11 |
@Injectable() |
10 | 12 |
export class TimeoutInterceptor implements HttpInterceptor { |
13 |
private static TIMEOUT_WHITELIST = [properties.csvAPIURL]; |
|
14 |
|
|
11 | 15 |
constructor(@Inject(DEFAULT_TIMEOUT) protected defaultTimeout: number, @Inject(PLATFORM_ID) private platformId: any) { |
12 | 16 |
} |
13 | 17 |
|
14 | 18 |
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { |
15 |
if (req.method !== 'GET') { |
|
19 |
if (req.method !== 'GET' || this.isService(req, TimeoutInterceptor.TIMEOUT_WHITELIST)) {
|
|
16 | 20 |
return next.handle(req); |
17 | 21 |
} |
18 | 22 |
|
... | ... | |
20 | 24 |
const timeoutValueNumeric = Number(timeoutValue); |
21 | 25 |
return next.handle(req).pipe(timeout(timeoutValueNumeric)); |
22 | 26 |
} |
27 |
|
|
28 |
isService(req: HttpRequest<any>, service: string | string[]):boolean { |
|
29 |
if(isArray(service)) { |
|
30 |
return !!service.find(element => req.url.indexOf(element) !== -1); |
|
31 |
} else { |
|
32 |
return req.url.indexOf(service) !== -1; |
|
33 |
} |
|
34 |
} |
|
23 | 35 |
} |
Also available in: Unified diff
[Library | Angular 11]: Merge changes from trunk