2019-10-02 16:15:08 +02:00
|
|
|
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';
|
2020-03-16 14:09:46 +01:00
|
|
|
import {ResultLandingInfo} from "../../../utils/entities/resultLandingInfo";
|
|
|
|
import {ResultPreview} from "../../../utils/result-preview/result-preview";
|
|
|
|
import {AlertModal} from "../../../utils/modal/alert";
|
2019-10-02 16:15:08 +02:00
|
|
|
|
|
|
|
@Component({
|
2020-03-16 14:09:46 +01:00
|
|
|
selector: 'organizationsDeletedByInference',
|
2019-10-02 16:15:08 +02:00
|
|
|
template: `
|
|
|
|
<errorMessages [status]="[status]" [type]="type" tab_error_class=true></errorMessages>
|
2020-03-16 14:09:46 +01:00
|
|
|
<no-load-paging *ngIf="results.length > pageSize" [type]="type"
|
|
|
|
(pageChange)="updatePage($event)"
|
|
|
|
[page]="page" [pageSize]="pageSize"
|
|
|
|
[totalResults]="results.length">
|
|
|
|
</no-load-paging>
|
|
|
|
<ul class="uk-list uk-list-divider uk-margin">
|
|
|
|
<li *ngFor="let result of results.slice((page-1)*pageSize, page*pageSize)">
|
|
|
|
<result-preview [modal]="modal" [properties]="properties" [result]="getResultPreview(result)"></result-preview>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
<no-load-paging *ngIf="results.length > pageSize" [type]="type"
|
|
|
|
(pageChange)="updatePage($event)"
|
|
|
|
[page]="page" [pageSize]="pageSize"
|
|
|
|
[totalResults]="results.length">
|
|
|
|
</no-load-paging>
|
2019-10-02 16:15:08 +02:00
|
|
|
`
|
|
|
|
})
|
|
|
|
export class OrganizationsDeletedByInferenceComponent {
|
|
|
|
public results: OrganizationInfo[] = [];
|
|
|
|
@Input() id: string;
|
|
|
|
@Input() ids: string[] = [];
|
|
|
|
@Input() type: string;
|
2020-03-16 14:09:46 +01:00
|
|
|
@Input() modal: AlertModal;
|
2019-10-02 16:15:08 +02:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2020-03-16 14:09:46 +01:00
|
|
|
|
|
|
|
public getResultPreview(result: OrganizationInfo): ResultPreview {
|
|
|
|
return ResultPreview.organizationInfoConvert(result);
|
|
|
|
}
|
2019-10-02 16:15:08 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|