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