1
|
import {Component} from '@angular/core';
|
2
|
import {ElementRef, Input} from '@angular/core';
|
3
|
import {ActivatedRoute, Router} from '@angular/router';
|
4
|
|
5
|
import {EnvProperties} from '../../../utils/properties/env-properties';
|
6
|
import {OrganizationInfo} from '../../../utils/entities/organizationInfo';
|
7
|
import {RouterHelper} from '../../../utils/routerHelper.class';
|
8
|
import {ErrorCodes} from '../../../utils/properties/errorCodes';
|
9
|
|
10
|
import {OrganizationsDeletedByInferenceService} from './deletedByInference.service';
|
11
|
import {ResultPreview} from "../../../utils/result-preview/result-preview";
|
12
|
import {AlertModal} from "../../../utils/modal/alert";
|
13
|
import {Subscriber} from "rxjs";
|
14
|
import {properties} from "../../../../../environments/environment";
|
15
|
|
16
|
@Component({
|
17
|
selector: 'organizationsDeletedByInference',
|
18
|
template: `
|
19
|
<errorMessages [status]="[status]" [type]="type" tab_error_class=true></errorMessages>
|
20
|
<no-load-paging *ngIf="results.length > pageSize" [type]="type"
|
21
|
(pageChange)="updatePage($event)"
|
22
|
[page]="page" [pageSize]="pageSize"
|
23
|
[totalResults]="results.length">
|
24
|
</no-load-paging>
|
25
|
<ul class="uk-list uk-list-divider uk-margin">
|
26
|
<li *ngFor="let result of results.slice((page-1)*pageSize, page*pageSize)">
|
27
|
<result-preview [modal]="modal" [properties]="properties" [hasLink]="false" [result]="getResultPreview(result)"></result-preview>
|
28
|
</li>
|
29
|
</ul>
|
30
|
<no-load-paging *ngIf="results.length > pageSize" [type]="type"
|
31
|
(pageChange)="updatePage($event)"
|
32
|
[page]="page" [pageSize]="pageSize"
|
33
|
[totalResults]="results.length">
|
34
|
</no-load-paging>
|
35
|
`
|
36
|
})
|
37
|
export class OrganizationsDeletedByInferenceComponent {
|
38
|
public results: OrganizationInfo[] = [];
|
39
|
@Input() id: string;
|
40
|
@Input() ids: string[] = [];
|
41
|
@Input() type: string;
|
42
|
@Input() modal: AlertModal;
|
43
|
|
44
|
// Custom tab paging variables
|
45
|
public page: number = 1;
|
46
|
public pageSize: number = 5;
|
47
|
|
48
|
public status: number;
|
49
|
public routerHelper:RouterHelper = new RouterHelper();
|
50
|
public errorCodes:ErrorCodes = new ErrorCodes();
|
51
|
|
52
|
subscriptions = [];
|
53
|
properties:EnvProperties;
|
54
|
|
55
|
constructor ( private element: ElementRef,
|
56
|
private _deletedByInferenceService: OrganizationsDeletedByInferenceService,
|
57
|
private route: ActivatedRoute) {
|
58
|
}
|
59
|
|
60
|
ngOnInit() {
|
61
|
|
62
|
this.properties = properties;
|
63
|
|
64
|
this.subscriptions.push(this.route.queryParams.subscribe(data => {
|
65
|
this.errorCodes = new ErrorCodes();
|
66
|
this.status = this.errorCodes.LOADING;
|
67
|
|
68
|
this.getDeletedByInference();
|
69
|
}));
|
70
|
}
|
71
|
|
72
|
ngOnDestroy() {
|
73
|
this.subscriptions.forEach(subscription => {
|
74
|
if (subscription instanceof Subscriber) {
|
75
|
subscription.unsubscribe();
|
76
|
}
|
77
|
});
|
78
|
}
|
79
|
getDeletedByInference() {
|
80
|
this.results = [];
|
81
|
this.status = this.errorCodes.LOADING;
|
82
|
|
83
|
this.subscriptions.push(this._deletedByInferenceService.getDeletedByInferenceResults(this.id, String(this.ids.length), this.properties).subscribe(
|
84
|
data => {
|
85
|
this.results = data;
|
86
|
this.status = this.errorCodes.DONE;
|
87
|
},
|
88
|
error => {
|
89
|
if(error.status == '404') {
|
90
|
this.status = this.errorCodes.NOT_FOUND;
|
91
|
} else if(error.status == '500') {
|
92
|
this.status = this.errorCodes.ERROR;
|
93
|
} else {
|
94
|
this.status = this.errorCodes.NOT_AVAILABLE;
|
95
|
}
|
96
|
}
|
97
|
));
|
98
|
}
|
99
|
|
100
|
public getResultPreview(result: OrganizationInfo): ResultPreview {
|
101
|
return ResultPreview.organizationInfoConvert(result);
|
102
|
}
|
103
|
|
104
|
public totalPages(totalResults: number): number {
|
105
|
let totalPages:any = totalResults/this.pageSize;
|
106
|
if(!(Number.isInteger(totalPages))) {
|
107
|
totalPages = (parseInt(totalPages, this.pageSize) + 1);
|
108
|
}
|
109
|
return totalPages;
|
110
|
}
|
111
|
|
112
|
public updatePage($event) {
|
113
|
this.page = $event.value;
|
114
|
}
|
115
|
}
|