openaire-library/utils/errorMessages.component.ts

52 lines
2.3 KiB
TypeScript
Raw Normal View History

import {Component, Input} from '@angular/core';
import {ErrorCodes} from './properties/errorCodes';
@Component({
selector: 'errorMessages',
template: `
<div *ngIf="status.some(checkErroCode(errorCodes.LOADING))" class="uk-animation-fade uk-margin-top uk-width-1-1" role="alert"><img src="./assets/loading.gif" class="uk-align-center" alt="Loading"></div>
<div *ngIf="status.every(checkErroCode(errorCodes.NONE))" class="uk-animation-fade uk-alert uk-alert-primary" role="alert">No {{type}} available</div>
<div *ngIf="status.every(checkErroCode(errorCodes.ERROR)) ||
(status.some(checkErroCode(errorCodes.ERROR)) && (!status.every(checkErroCode(errorCodes.DONE)) || !status.every(checkErroCode(errorCodes.LOADING))))"
class="uk-animation-fade uk-alert uk-alert-warning" role="alert">
An Error Occured
</div>
<div *ngIf="status.every(checkErroCode(errorCodes.NOT_AVAILABLE)) ||
(status.some(checkErroCode(errorCodes.NOT_AVAILABLE)) && (!status.every(checkErroCode(errorCodes.DONE)) || !status.every(checkErroCode(errorCodes.LOADING))))"
class="uk-animation-fade uk-alert uk-alert-warning" role="alert">
Service temprorarily unavailable. Please try again later.
</div>
<div *ngIf="status.every(checkErroCode(errorCodes.NOT_FOUND)) ||
(status.some(checkErroCode(errorCodes.NOT_FOUND)) && (!status.every(checkErroCode(errorCodes.DONE)) || !status.every(checkErroCode(errorCodes.LOADING))))"
class="uk-animation-fade uk-alert uk-alert-warning" role="alert">
No {{type}} found
</div>
<div *ngIf="status.every(checkErroCode(errorCodes.OUT_OF_BOUND))" class="uk-animation-fade uk-alert uk-alert-warning" role="alert">Requested page out of bounds</div>
`
})
export class ErrorMessagesComponent {
@Input() status: Array<number>;
@Input() type: string;
public errorCodes:ErrorCodes;
constructor () {}
ngOnInit() {
this.errorCodes = new ErrorCodes();
console.info("ngOnInit");
if(!this.status) {
this.status = [this.errorCodes.LOADING];
}
}
ngOnDestroy() {}
public checkErroCode(code: number) {
return function(status: number) {
return (status == code);
}
}
}