59 lines
1.7 KiB
TypeScript
59 lines
1.7 KiB
TypeScript
import {Component, OnInit} from '@angular/core';
|
|
import {OaipmhValidatorService} from "../../../services/oaipmh-validator.service";
|
|
import {JobResult, Progress, Status} from "../../entities/JobResult";
|
|
import {ActivatedRoute} from "@angular/router";
|
|
import {Subscriber} from "rxjs";
|
|
import {Breadcrumb} from "../../../openaire-library/utils/breadcrumbs/breadcrumbs.component";
|
|
import {filter, repeat, take} from "rxjs/operators";
|
|
|
|
@Component({
|
|
selector: 'app-oaipmh-history',
|
|
templateUrl: './oaipmh-history.component.html',
|
|
styleUrls: ['./oaipmh-history.component.less']
|
|
})
|
|
export class OaipmhHistoryComponent implements OnInit {
|
|
public result: JobResult;
|
|
public jobId: string = "";
|
|
public breadcrumbs: Breadcrumb[] = [{name: 'home', route: '/'}, {name: 'Validator\'s History'}];
|
|
protected readonly Progress = Progress;
|
|
|
|
subscriptions = [];
|
|
|
|
constructor(private route: ActivatedRoute, private validator: OaipmhValidatorService) {}
|
|
|
|
ngOnInit(): void {
|
|
this.subscriptions.push(this.route.queryParams.subscribe(params => {
|
|
this.jobId = params['jobId'];
|
|
this.result = null;
|
|
if(!this.jobId) {
|
|
this.jobId = "825";
|
|
}
|
|
this.getJobResult();
|
|
}));
|
|
}
|
|
|
|
ngOnDestroy() {
|
|
this.subscriptions.forEach(subscription => {
|
|
if (subscription instanceof Subscriber) {
|
|
subscription.unsubscribe();
|
|
}
|
|
});
|
|
}
|
|
|
|
public getJobResult() {
|
|
this.subscriptions.push(this.validator.getJobResult(this.jobId)
|
|
.pipe(
|
|
repeat({ delay: 5000 }),
|
|
filter((result: JobResult) => {
|
|
this.result = result;
|
|
return result.progress !== Progress.IN_PROGRESS
|
|
}),
|
|
take(1)
|
|
)
|
|
.subscribe()
|
|
);
|
|
}
|
|
|
|
protected readonly Status = Status;
|
|
}
|