1
|
import {Component, Input} from '@angular/core';
|
2
|
import {ErrorCodes} from './properties/openaireProperties';
|
3
|
|
4
|
@Component({
|
5
|
selector: 'errorMessages',
|
6
|
template: `
|
7
|
<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>
|
8
|
<div *ngIf="status.every(checkErroCode(errorCodes.NONE))" class="uk-animation-fade uk-alert uk-alert-primary" role="alert">No {{type}} available</div>
|
9
|
<div *ngIf="status.every(checkErroCode(errorCodes.ERROR)) ||
|
10
|
(status.some(checkErroCode(errorCodes.ERROR)) && (!status.every(checkErroCode(errorCodes.DONE)) || !status.every(checkErroCode(errorCodes.LOADING))))"
|
11
|
class="uk-animation-fade uk-alert uk-alert-warning" role="alert">
|
12
|
An Error Occured
|
13
|
</div>
|
14
|
<div *ngIf="status.every(checkErroCode(errorCodes.NOT_AVAILABLE)) ||
|
15
|
(status.some(checkErroCode(errorCodes.NOT_AVAILABLE)) && (!status.every(checkErroCode(errorCodes.DONE)) || !status.every(checkErroCode(errorCodes.LOADING))))"
|
16
|
class="uk-animation-fade uk-alert uk-alert-warning" role="alert">
|
17
|
Service temprorarily unavailable. Please try again later.
|
18
|
</div>
|
19
|
<div *ngIf="status.every(checkErroCode(errorCodes.NOT_FOUND)) ||
|
20
|
(status.some(checkErroCode(errorCodes.NOT_FOUND)) && (!status.every(checkErroCode(errorCodes.DONE)) || !status.every(checkErroCode(errorCodes.LOADING))))"
|
21
|
class="uk-animation-fade uk-alert uk-alert-warning" role="alert">
|
22
|
No {{type}} found
|
23
|
</div>
|
24
|
<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>
|
25
|
`
|
26
|
})
|
27
|
|
28
|
export class ErrorMessagesComponent {
|
29
|
@Input() status: Array<number>;
|
30
|
@Input() type: string;
|
31
|
|
32
|
public errorCodes:ErrorCodes;
|
33
|
|
34
|
constructor () {}
|
35
|
|
36
|
ngOnInit() {
|
37
|
this.errorCodes = new ErrorCodes();
|
38
|
console.info("ngOnInit");
|
39
|
if(!this.status) {
|
40
|
this.status = [this.errorCodes.LOADING];
|
41
|
}
|
42
|
}
|
43
|
|
44
|
ngOnDestroy() {}
|
45
|
|
46
|
public checkErroCode(code: number) {
|
47
|
return function(status: number) {
|
48
|
return (status == code);
|
49
|
}
|
50
|
}
|
51
|
}
|