1
|
import {Component, Input} from '@angular/core';
|
2
|
import {ErrorCodes} from './properties/errorCodes';
|
3
|
|
4
|
@Component({
|
5
|
selector: 'errorMessages',
|
6
|
template: `
|
7
|
<div *ngIf="status.some(checkErroCode(errorCodes.LOADING))"
|
8
|
[class]="(tab_error_class ? '' : 'uk-animation-fade') + ' uk-margin-top uk-width-1-1'" role="alert"><span class="loading-gif uk-align-center" ></span></div>
|
9
|
<div *ngIf="status.every(checkErroCode(errorCodes.NONE))"
|
10
|
[class]="(tab_error_class ? 'uk-margin-top' : 'uk-animation-fade') + ' uk-alert uk-alert-primary'" role="alert">No {{type}} available</div>
|
11
|
<div *ngIf="status.every(checkErroCode(errorCodes.ERROR)) ||
|
12
|
(status.some(checkErroCode(errorCodes.ERROR)) && (!status.every(checkErroCode(errorCodes.DONE)) || !status.every(checkErroCode(errorCodes.LOADING))))"
|
13
|
[class]="(tab_error_class ? 'uk-margin-top' : 'uk-animation-fade') + ' uk-alert uk-alert-warning'" role="alert">
|
14
|
An Error Occured
|
15
|
</div>
|
16
|
<div *ngIf="status.every(checkErroCode(errorCodes.NOT_AVAILABLE)) ||
|
17
|
(status.some(checkErroCode(errorCodes.NOT_AVAILABLE)) && (!status.every(checkErroCode(errorCodes.DONE)) || !status.every(checkErroCode(errorCodes.LOADING))))"
|
18
|
[class]="(tab_error_class ? 'uk-margin-top' : 'uk-animation-fade') + ' uk-alert uk-alert-warning'" role="alert">
|
19
|
Service temprorarily unavailable. Please try again later.
|
20
|
</div>
|
21
|
<div *ngIf="status.every(checkErroCode(errorCodes.NOT_FOUND)) ||
|
22
|
(status.some(checkErroCode(errorCodes.NOT_FOUND)) && (!status.every(checkErroCode(errorCodes.DONE)) || !status.every(checkErroCode(errorCodes.LOADING))))"
|
23
|
[class]="(tab_error_class ? 'uk-margin-top' : 'uk-animation-fade') + ' uk-alert uk-alert-warning'" role="alert">
|
24
|
No {{type}} found
|
25
|
</div>
|
26
|
<div *ngIf="status.every(checkErroCode(errorCodes.OUT_OF_BOUND))"
|
27
|
[class]="(tab_error_class ? 'uk-margin-top' : 'uk-animation-fade') + ' uk-alert uk-alert-warning'" role="alert">Requested page out of bounds
|
28
|
</div>
|
29
|
<div *ngIf="status.some(checkErroCode(errorCodes.NOT_SAVED))"
|
30
|
[class]="(tab_error_class ? 'uk-margin-top' : 'uk-animation-fade') + ' uk-alert uk-alert-warning'" role="alert">Changes could not be saved
|
31
|
</div>
|
32
|
<div *ngIf="status.some(checkErroCode(errorCodes.FORBIDDEN))"
|
33
|
[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
|
34
|
</div>
|
35
|
`
|
36
|
})
|
37
|
|
38
|
export class ErrorMessagesComponent {
|
39
|
@Input() status: Array<number>;
|
40
|
@Input() type: string;
|
41
|
@Input() tab_error_class: boolean = false;
|
42
|
|
43
|
public errorCodes:ErrorCodes;
|
44
|
|
45
|
constructor () {}
|
46
|
|
47
|
ngOnInit() {
|
48
|
this.errorCodes = new ErrorCodes();
|
49
|
console.info("ngOnInit");
|
50
|
if(!this.status) {
|
51
|
this.status = [this.errorCodes.LOADING];
|
52
|
}
|
53
|
}
|
54
|
|
55
|
ngOnDestroy() {}
|
56
|
|
57
|
public checkErroCode(code: number) {
|
58
|
return function(status: number) {
|
59
|
return (status == code);
|
60
|
}
|
61
|
}
|
62
|
}
|