2020-03-16 14:09:46 +01:00
|
|
|
import {Component, ViewChild} from '@angular/core';
|
|
|
|
import {ElementRef, Input} from '@angular/core';
|
|
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
2019-03-05 10:45:42 +01:00
|
|
|
|
2020-03-16 14:09:46 +01:00
|
|
|
import {EnvProperties} from '../../../utils/properties/env-properties';
|
|
|
|
import {ResultLandingInfo} from '../../../utils/entities/resultLandingInfo';
|
|
|
|
import {RouterHelper} from '../../../utils/routerHelper.class';
|
|
|
|
import {ErrorCodes} from '../../../utils/properties/errorCodes';
|
2019-03-05 10:45:42 +01:00
|
|
|
|
2020-03-16 14:09:46 +01:00
|
|
|
import {DeletedByInferenceService} from './deletedByInference.service';
|
|
|
|
import {SearchResult} from "../../../utils/entities/searchResult";
|
|
|
|
import {ResultPreview} from "../../../utils/result-preview/result-preview";
|
|
|
|
import {AlertModal} from "../../../utils/modal/alert";
|
2019-03-05 10:45:42 +01:00
|
|
|
|
|
|
|
@Component({
|
2020-03-16 14:09:46 +01:00
|
|
|
selector: 'deletedByInference',
|
|
|
|
template: `
|
2019-03-05 10:45:42 +01:00
|
|
|
<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-03-05 10:45:42 +01:00
|
|
|
})
|
|
|
|
export class DeletedByInferenceComponent {
|
2019-09-30 13:02:06 +02:00
|
|
|
public results: ResultLandingInfo[] = [];
|
2019-03-05 10:45:42 +01:00
|
|
|
@Input() id: string;
|
|
|
|
@Input() ids: string[] = [];
|
|
|
|
@Input() type: string;
|
2020-03-16 14:09:46 +01:00
|
|
|
@Input() resultType: string;
|
|
|
|
@Input() modal: AlertModal;
|
|
|
|
|
2019-03-05 10:45:42 +01:00
|
|
|
// Custom tab paging variables
|
|
|
|
public page: number = 1;
|
2019-09-05 10:49:33 +02:00
|
|
|
public pageSize: number = 5;
|
2020-03-16 14:09:46 +01:00
|
|
|
|
2019-03-05 10:45:42 +01:00
|
|
|
public status: number;
|
2020-03-16 14:09:46 +01:00
|
|
|
public routerHelper: RouterHelper = new RouterHelper();
|
|
|
|
public errorCodes: ErrorCodes = new ErrorCodes();
|
|
|
|
|
2019-03-05 10:45:42 +01:00
|
|
|
sub: any;
|
2020-03-16 14:09:46 +01:00
|
|
|
properties: EnvProperties;
|
|
|
|
|
|
|
|
constructor(private element: ElementRef,
|
|
|
|
private _deletedByInferenceService: DeletedByInferenceService,
|
|
|
|
private route: ActivatedRoute,
|
|
|
|
private _router: Router) {
|
2019-03-05 10:45:42 +01:00
|
|
|
}
|
2020-03-16 14:09:46 +01:00
|
|
|
|
2019-03-05 10:45:42 +01:00
|
|
|
ngOnInit() {
|
|
|
|
this.route.data
|
|
|
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
2020-03-16 14:09:46 +01:00
|
|
|
this.properties = data.envSpecific;
|
|
|
|
|
2019-03-05 10:45:42 +01:00
|
|
|
});
|
2020-03-16 14:09:46 +01:00
|
|
|
this.sub = this.route.queryParams.subscribe(data => {
|
|
|
|
this.errorCodes = new ErrorCodes();
|
|
|
|
this.status = this.errorCodes.LOADING;
|
|
|
|
|
|
|
|
this.getDeletedByInference();
|
2019-03-05 10:45:42 +01:00
|
|
|
});
|
|
|
|
}
|
2020-03-16 14:09:46 +01:00
|
|
|
|
|
|
|
ngOnDestroy() {
|
|
|
|
}
|
|
|
|
|
2019-03-05 10:45:42 +01:00
|
|
|
getDeletedByInference() {
|
|
|
|
this.results = [];
|
|
|
|
this.status = this.errorCodes.LOADING;
|
2019-07-17 21:48:19 +02:00
|
|
|
this._deletedByInferenceService.getDeletedByInferenceResults(this.id, String(this.ids.length), this.properties).subscribe(
|
|
|
|
data => {
|
|
|
|
this.results = data;
|
|
|
|
this.status = this.errorCodes.DONE;
|
|
|
|
},
|
|
|
|
error => {
|
2020-03-16 14:09:46 +01:00
|
|
|
if (error.status == '404') {
|
2019-07-17 21:48:19 +02:00
|
|
|
this.status = this.errorCodes.NOT_FOUND;
|
2020-03-16 14:09:46 +01:00
|
|
|
} else if (error.status == '500') {
|
2019-07-17 21:48:19 +02:00
|
|
|
this.status = this.errorCodes.ERROR;
|
|
|
|
} else {
|
|
|
|
this.status = this.errorCodes.NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2019-03-05 10:45:42 +01:00
|
|
|
}
|
2020-03-16 14:09:46 +01:00
|
|
|
|
|
|
|
public getResultPreview(result: ResultLandingInfo): ResultPreview {
|
|
|
|
return ResultPreview.resultLandingInfoConvert(result, this.resultType);
|
|
|
|
}
|
|
|
|
|
2019-03-05 10:45:42 +01:00
|
|
|
public totalPages(totalResults: number): number {
|
2020-03-16 14:09:46 +01:00
|
|
|
let totalPages: any = totalResults / this.pageSize;
|
|
|
|
if (!(Number.isInteger(totalPages))) {
|
|
|
|
totalPages = (parseInt(totalPages, this.pageSize) + 1);
|
2019-03-05 10:45:42 +01:00
|
|
|
}
|
|
|
|
return totalPages;
|
|
|
|
}
|
2020-03-16 14:09:46 +01:00
|
|
|
|
2019-03-05 10:45:42 +01:00
|
|
|
public updatePage($event) {
|
|
|
|
this.page = $event.value;
|
|
|
|
}
|
|
|
|
}
|