1
|
import {Component, Input} from '@angular/core';
|
2
|
import {ErrorCodes} from './properties/errorCodes';
|
3
|
import {properties} from "../../../environments/environment";
|
4
|
|
5
|
@Component({
|
6
|
selector: 'errorMessages',
|
7
|
template: `
|
8
|
<div *ngIf="status.some(checkErrorCode(errorCodes.LOADING))"
|
9
|
[class]="(tab_error_class ? '' : 'uk-animation-fade') + ' uk-margin-top uk-width-1-1'" role="alert">
|
10
|
<span *ngIf="!dashboard" class="loading-gif uk-align-center"></span>
|
11
|
<loading *ngIf="dashboard"></loading>
|
12
|
</div>
|
13
|
<div *ngIf="status.every(checkErrorCode(errorCodes.NONE))"
|
14
|
[class]="(tab_error_class ? 'uk-margin-top' : 'uk-animation-fade') + ' uk-alert uk-alert-primary'" role="alert">No {{type}} available</div>
|
15
|
<div *ngIf="status.every(checkErrorCode(errorCodes.ERROR)) ||
|
16
|
(status.some(checkErrorCode(errorCodes.ERROR)) && (!status.every(checkErrorCode(errorCodes.DONE)) || !status.every(checkErrorCode(errorCodes.LOADING))))"
|
17
|
[class]="(tab_error_class ? 'uk-margin-top' : 'uk-animation-fade') + ' uk-alert uk-alert-warning'" role="alert">
|
18
|
An Error Occurred
|
19
|
</div>
|
20
|
<div *ngIf="status.every(checkErrorCode(errorCodes.NOT_AVAILABLE)) ||
|
21
|
(status.some(checkErrorCode(errorCodes.NOT_AVAILABLE)) && (!status.every(checkErrorCode(errorCodes.DONE)) || !status.every(checkErrorCode(errorCodes.LOADING))))"
|
22
|
[class]="(tab_error_class ? 'uk-margin-top' : 'uk-animation-fade') + ' uk-alert uk-alert-warning'" role="alert">
|
23
|
Service temporarily unavailable. Please try again later.
|
24
|
</div>
|
25
|
<div *ngIf="status.every(checkErrorCode(errorCodes.NOT_FOUND)) ||
|
26
|
(status.some(checkErrorCode(errorCodes.NOT_FOUND)) && (!status.every(checkErrorCode(errorCodes.DONE)) || !status.every(checkErrorCode(errorCodes.LOADING))))"
|
27
|
[class]="(tab_error_class ? 'uk-margin-top' : 'uk-animation-fade') + ' uk-alert uk-alert-warning'" role="alert">
|
28
|
No {{type}} found
|
29
|
</div>
|
30
|
<div *ngIf="status.every(checkErrorCode(errorCodes.OUT_OF_BOUND))"
|
31
|
[class]="(tab_error_class ? 'uk-margin-top' : 'uk-animation-fade') + ' uk-alert uk-alert-warning'" role="alert">Requested page out of bounds
|
32
|
</div>
|
33
|
<div *ngIf="status.some(checkErrorCode(errorCodes.NOT_SAVED))"
|
34
|
[class]="(tab_error_class ? 'uk-margin-top' : 'uk-animation-fade') + ' uk-alert uk-alert-warning'" role="alert">Changes could not be saved
|
35
|
</div>
|
36
|
<div *ngIf="status.some(checkErrorCode(errorCodes.FORBIDDEN))"
|
37
|
[class]="(tab_error_class ? 'uk-margin-top' : 'uk-animation-fade') + ' uk-alert uk-alert-danger'" role="alert">You are not allowed to access this page
|
38
|
</div>
|
39
|
`
|
40
|
})
|
41
|
|
42
|
export class ErrorMessagesComponent {
|
43
|
@Input() status: Array<number>;
|
44
|
@Input() type: string;
|
45
|
@Input() tab_error_class: boolean = false;
|
46
|
dashboard = properties.isDashboard;
|
47
|
|
48
|
public errorCodes:ErrorCodes;
|
49
|
|
50
|
constructor () {
|
51
|
this.errorCodes = new ErrorCodes();
|
52
|
}
|
53
|
|
54
|
ngOnInit() {
|
55
|
if(!this.status) {
|
56
|
this.status = [this.errorCodes.LOADING];
|
57
|
}
|
58
|
}
|
59
|
|
60
|
ngOnDestroy() {}
|
61
|
|
62
|
public checkErrorCode(code: number) {
|
63
|
return function(status: number) {
|
64
|
return (status == code);
|
65
|
}
|
66
|
}
|
67
|
|
68
|
public getErrorCode(status: any) {
|
69
|
if(status == '401' || status == 401) {
|
70
|
return this.errorCodes.FORBIDDEN;
|
71
|
} else if(status == "403" || status == 403) {
|
72
|
return this.errorCodes.FORBIDDEN;
|
73
|
} else if(status == "204" || status == 204) {
|
74
|
return this.errorCodes.NONE;
|
75
|
} else if(status == '404' || status == 404) {
|
76
|
return this.errorCodes.NOT_FOUND;
|
77
|
} else if(status == '500'|| status == 500) {
|
78
|
return this.errorCodes.ERROR;
|
79
|
} else {
|
80
|
return this.errorCodes.NOT_AVAILABLE;
|
81
|
}
|
82
|
}
|
83
|
}
|