2017-12-19 13:53:46 +01:00
|
|
|
import {Component, Input} from '@angular/core';
|
2018-02-15 11:36:12 +01:00
|
|
|
import {ErrorCodes} from './properties/errorCodes';
|
2020-07-10 10:37:17 +02:00
|
|
|
import {properties} from "../../../environments/environment";
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'errorMessages',
|
|
|
|
template: `
|
2019-04-12 16:17:12 +02:00
|
|
|
<div *ngIf="status.some(checkErrorCode(errorCodes.LOADING))"
|
2020-07-10 10:37:17 +02:00
|
|
|
[class]="(tab_error_class ? '' : 'uk-animation-fade') + ' uk-margin-top uk-width-1-1'" role="alert">
|
2022-03-02 22:48:21 +01:00
|
|
|
<loading></loading>
|
2020-07-10 10:37:17 +02:00
|
|
|
</div>
|
2019-04-12 16:17:12 +02:00
|
|
|
<div *ngIf="status.every(checkErrorCode(errorCodes.NONE))"
|
2018-06-08 13:21:42 +02:00
|
|
|
[class]="(tab_error_class ? 'uk-margin-top' : 'uk-animation-fade') + ' uk-alert uk-alert-primary'" role="alert">No {{type}} available</div>
|
2019-04-12 16:17:12 +02:00
|
|
|
<div *ngIf="status.every(checkErrorCode(errorCodes.ERROR)) ||
|
|
|
|
(status.some(checkErrorCode(errorCodes.ERROR)) && (!status.every(checkErrorCode(errorCodes.DONE)) || !status.every(checkErrorCode(errorCodes.LOADING))))"
|
2018-06-08 13:21:42 +02:00
|
|
|
[class]="(tab_error_class ? 'uk-margin-top' : 'uk-animation-fade') + ' uk-alert uk-alert-warning'" role="alert">
|
2019-04-12 16:17:12 +02:00
|
|
|
An Error Occurred
|
2017-12-19 13:53:46 +01:00
|
|
|
</div>
|
2019-04-12 16:17:12 +02:00
|
|
|
<div *ngIf="status.every(checkErrorCode(errorCodes.NOT_AVAILABLE)) ||
|
|
|
|
(status.some(checkErrorCode(errorCodes.NOT_AVAILABLE)) && (!status.every(checkErrorCode(errorCodes.DONE)) || !status.every(checkErrorCode(errorCodes.LOADING))))"
|
2018-06-08 13:21:42 +02:00
|
|
|
[class]="(tab_error_class ? 'uk-margin-top' : 'uk-animation-fade') + ' uk-alert uk-alert-warning'" role="alert">
|
2019-04-12 16:17:12 +02:00
|
|
|
Service temporarily unavailable. Please try again later.
|
2017-12-19 13:53:46 +01:00
|
|
|
</div>
|
2019-04-12 16:17:12 +02:00
|
|
|
<div *ngIf="status.every(checkErrorCode(errorCodes.NOT_FOUND)) ||
|
|
|
|
(status.some(checkErrorCode(errorCodes.NOT_FOUND)) && (!status.every(checkErrorCode(errorCodes.DONE)) || !status.every(checkErrorCode(errorCodes.LOADING))))"
|
2018-06-08 13:21:42 +02:00
|
|
|
[class]="(tab_error_class ? 'uk-margin-top' : 'uk-animation-fade') + ' uk-alert uk-alert-warning'" role="alert">
|
2017-12-19 13:53:46 +01:00
|
|
|
No {{type}} found
|
|
|
|
</div>
|
2019-04-12 16:17:12 +02:00
|
|
|
<div *ngIf="status.every(checkErrorCode(errorCodes.OUT_OF_BOUND))"
|
2018-06-29 15:24:49 +02:00
|
|
|
[class]="(tab_error_class ? 'uk-margin-top' : 'uk-animation-fade') + ' uk-alert uk-alert-warning'" role="alert">Requested page out of bounds
|
|
|
|
</div>
|
2019-04-12 16:17:12 +02:00
|
|
|
<div *ngIf="status.some(checkErrorCode(errorCodes.NOT_SAVED))"
|
2018-06-29 15:24:49 +02:00
|
|
|
[class]="(tab_error_class ? 'uk-margin-top' : 'uk-animation-fade') + ' uk-alert uk-alert-warning'" role="alert">Changes could not be saved
|
|
|
|
</div>
|
2019-04-12 16:17:12 +02:00
|
|
|
<div *ngIf="status.some(checkErrorCode(errorCodes.FORBIDDEN))"
|
2019-01-16 21:43:44 +01:00
|
|
|
[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
|
2018-09-24 12:08:33 +02:00
|
|
|
</div>
|
2017-12-19 13:53:46 +01:00
|
|
|
`
|
|
|
|
})
|
|
|
|
|
|
|
|
export class ErrorMessagesComponent {
|
|
|
|
@Input() status: Array<number>;
|
|
|
|
@Input() type: string;
|
2018-06-08 13:21:42 +02:00
|
|
|
@Input() tab_error_class: boolean = false;
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
public errorCodes:ErrorCodes;
|
|
|
|
|
2019-02-15 13:50:24 +01:00
|
|
|
constructor () {
|
|
|
|
this.errorCodes = new ErrorCodes();
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
if(!this.status) {
|
|
|
|
this.status = [this.errorCodes.LOADING];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy() {}
|
|
|
|
|
2019-04-12 16:17:12 +02:00
|
|
|
public checkErrorCode(code: number) {
|
2017-12-19 13:53:46 +01:00
|
|
|
return function(status: number) {
|
|
|
|
return (status == code);
|
|
|
|
}
|
|
|
|
}
|
2019-02-15 13:50:24 +01:00
|
|
|
|
2019-04-09 20:40:45 +02:00
|
|
|
public getErrorCode(status: any) {
|
|
|
|
if(status == '401' || status == 401) {
|
2019-02-19 13:18:46 +01:00
|
|
|
return this.errorCodes.FORBIDDEN;
|
2019-04-09 20:40:45 +02:00
|
|
|
} else if(status == "403" || status == 403) {
|
2019-02-18 15:00:43 +01:00
|
|
|
return this.errorCodes.FORBIDDEN;
|
2019-04-09 20:40:45 +02:00
|
|
|
} else if(status == "204" || status == 204) {
|
2019-02-18 15:00:43 +01:00
|
|
|
return this.errorCodes.NONE;
|
2019-04-09 20:40:45 +02:00
|
|
|
} else if(status == '404' || status == 404) {
|
2019-02-15 13:50:24 +01:00
|
|
|
return this.errorCodes.NOT_FOUND;
|
2019-04-09 20:40:45 +02:00
|
|
|
} else if(status == '500'|| status == 500) {
|
2019-02-15 13:50:24 +01:00
|
|
|
return this.errorCodes.ERROR;
|
|
|
|
} else {
|
|
|
|
return this.errorCodes.NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|