openaire-library/landingPages/organization/deletedByInference/deletedByInference.componen...

131 lines
4.9 KiB
TypeScript
Raw Normal View History

import {Component, ViewChild} from '@angular/core';
import {ElementRef, Input} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import {EnvProperties} from '../../../utils/properties/env-properties';
import {OrganizationInfo} from '../../../utils/entities/organizationInfo';
import {RouterHelper} from '../../../utils/routerHelper.class';
import {ErrorCodes} from '../../../utils/properties/errorCodes';
import {OrganizationsDeletedByInferenceService} from './deletedByInference.service';
@Component({
selector: 'deletedByInference',
template: `
<errorMessages [status]="[status]" [type]="type" tab_error_class=true></errorMessages>
<div>
<div *ngIf="results.length > pageSize" class="uk-margin-bottom">
<span class="uk-h6">{{results.length | number}} {{type}}, page {{page | number}} of {{totalPages(results.length) | number}}</span>
<paging-no-load class="uk-float-right" [currentPage]="page" [totalResults]="results.length" [size]="pageSize" (pageChange)="updatePage($event)"></paging-no-load>
</div>
<ul class="uk-list uk-list-divider uk-margin">
<li *ngFor="let result of results.slice((page-1)*pageSize, page*pageSize)" class="uk-margin-bottom">
<h5 *ngIf="result.title['url'] != undefined && result.title['url'] != null && result.title['url'] != ''"
class="custom-external uk-margin-remove-bottom">
<a *ngIf="result.title['name'] != undefined && result.title['name'] != ''"
href="{{result.title['url']}}" target="_blank"
[innerHTML]="result.title['name']">
</a>
<a *ngIf="result.title['name'] == undefined || result.title['name'] == ''"
href="{{result.title['url']}}" target="_blank">
[no title available]
</a>
</h5>
<h5 *ngIf="(result.title['name'] != undefined && result.title['name'] != '') &&
(result.title['url'] == undefined || result.title['url'] == null || result.title['url'] == '')"
class="uk-margin-remove-bottom"
[innerHTML]="result.title['name']">
</h5>
<h5 *ngIf="(result.title['name'] == undefined || result.title['name'] == '') &&
(result.title['url'] == undefined || result.title['url'] == null || result.title['url'] == '')"
class="uk-margin-remove-bottom">
[no title available]
</h5>
<div *ngIf="result.title.name && result.title.name != result.name ">{{result.name}}</div>
<span class="uk-label custom-label label-blue label-organization" title="Type">Organization</span>{{" "}}
<span *ngIf="result.country" class="uk-label custom-label label-country "
title="Country">{{result.country}}</span>{{" "}}
</li>
</ul>
</div>
`
})
export class OrganizationsDeletedByInferenceComponent {
public results: OrganizationInfo[] = [];
@Input() id: string;
@Input() ids: string[] = [];
@Input() type: string;
// Custom tab paging variables
public page: number = 1;
public pageSize: number = 5;
public status: number;
public routerHelper:RouterHelper = new RouterHelper();
public errorCodes:ErrorCodes = new ErrorCodes();
sub: any;
properties:EnvProperties;
constructor ( private element: ElementRef,
private _deletedByInferenceService: OrganizationsDeletedByInferenceService,
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;
this._deletedByInferenceService.getDeletedByInferenceResults(this.id, String(this.ids.length), 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;
}
}