import {Component, ViewChild} from '@angular/core';
import {ElementRef, Input} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import {Observable} from 'rxjs';
import {EnvProperties} from '../../../utils/properties/env-properties';
import {DeletedByInferenceResult} from '../../../utils/entities/deletedByInferenceResult';
import {RouterHelper} from '../../../utils/routerHelper.class';
import {ErrorCodes} from '../../../utils/properties/errorCodes';
import {DeletedByInferenceService} from './deletedByInference.service';
import {zip} from 'rxjs';
@Component({
selector: 'deletedByInference',
template: `
pageSize" class="uk-margin-bottom">
{{results.length | number}} {{type}}, page {{page | number}} of {{totalPages(results.length) | number}}
-
[no title available]
0"class="uk-label custom-label label-blue label-publication" title="Type">{{result.types.join(", ")}}{{" "}}
0" class="uk-label custom-label label-language " title="Language">{{result.languages.join(", ")}}{{" "}}
0" class="uk-label custom-label label-country " title="Country">{{result.countries.join(", ")}}{{" "}}
{{result.accessMode}}{{" "}}
({{result.date}})
0">
Project:
{{project['funderShortname']?project['funderShortname']:project['funderName']}}
| {{ project['acronym']?project['acronym']:(project['title'].length>25?project['title'].substring(0,25)+'...':project['title'])}} ({{project.code}}){{project['funderShortname']?project['funderShortname']:project['funderName']}} | {{ project['acronym']?project['acronym']:(project['title'].length>25?project['title'].substring(0,25)+'...':project['title'])}}({{project.code}}),
15">...
{{result.description}}
`
})
export class DeletedByInferenceComponent {
public results: DeletedByInferenceResult[] = [];
@Input() id: string;
@Input() ids: string[] = [];
@Input() type: string;
// Custom tab paging variables
public page: number = 1;
public pageSize: number = 10;
public status: number;
public routerHelper:RouterHelper = new RouterHelper();
public errorCodes:ErrorCodes = new ErrorCodes();
sub: any;
properties:EnvProperties;
constructor ( private element: ElementRef,
private _deletedByInferenceService: DeletedByInferenceService,
private route: ActivatedRoute,
private _router: Router) {
}
ngOnInit() {
this.route.data
.subscribe((data: { envSpecific: EnvProperties }) => {
this.properties = data.envSpecific;
});
this.sub = this.route.queryParams.subscribe(data => {
this.errorCodes = new ErrorCodes();
this.status = this.errorCodes.LOADING;
this.getDeletedByInference();
});
}
ngOnDestroy() {}
getDeletedByInference() {
this.results = [];
this.status = this.errorCodes.LOADING;
if(this.ids) {
var allRequests = [];
for(let id of this.ids) {
allRequests.push(this._deletedByInferenceService.getDeletedByInferencePublications(id, this.properties));
}
zip.apply(null, allRequests).subscribe(
// this._deletedByInferenceService.getDeletedByInferencePublications(id, this.properties).subscribe(
data => {
this.results = data;
this.status = this.errorCodes.DONE;
},
error => {
if(error.status == '404') {
this.status = this.errorCodes.NOT_FOUND;
} else if(error.status == '500') {
this.status = this.errorCodes.ERROR;
} else {
this.status = this.errorCodes.NOT_AVAILABLE;
}
}
);
}
}
public totalPages(totalResults: number): number {
let totalPages:any = totalResults/this.pageSize;
if(!(Number.isInteger(totalPages))) {
totalPages = (parseInt(totalPages, this.pageSize) + 1);
}
return totalPages;
}
public updatePage($event) {
this.page = $event.value;
}
}