Added alert when error ocurrs listing catalog products, orders and campaigns in SPA app

This commit is contained in:
Ramón Tomás 2017-07-11 13:48:07 +02:00
parent 96c55b8682
commit 84a2d500a7
10 changed files with 74 additions and 26 deletions

View File

@ -1,5 +1,8 @@
<esh-header url="/catalog">Back to catalog</esh-header> <esh-header url="/catalog">Back to catalog</esh-header>
<div class="container"> <div class="container">
<div class="alert alert-warning esh-campaign-alert" role="alert" [hidden]="!errorReceived">
Error requesting campaigns list, please try later on
</div>
<div *ngIf="campaigns?.data?.length > 0"> <div *ngIf="campaigns?.data?.length > 0">
<esh-pager [model]="paginationInfo" (changed)="onPageChanged($event)"></esh-pager> <esh-pager [model]="paginationInfo" (changed)="onPageChanged($event)"></esh-pager>
<div class="card-group esh-campaign-items row"> <div class="card-group esh-campaign-items row">

View File

@ -62,4 +62,8 @@
text-align: center; text-align: center;
text-transform: uppercase; text-transform: uppercase;
} }
&-alert {
margin-top: 10px;
}
} }

View File

@ -3,6 +3,7 @@ import { CampaignsService } from './campaigns.service';
import { ICampaign } from '../shared/models/campaign.model'; import { ICampaign } from '../shared/models/campaign.model';
import { IPager } from '../shared/models/pager.model'; import { IPager } from '../shared/models/pager.model';
import { ConfigurationService } from '../shared/services/configuration.service'; import { ConfigurationService } from '../shared/services/configuration.service';
import { Observable } from 'rxjs/Observable';
@Component({ @Component({
selector: 'esh-campaigns', selector: 'esh-campaigns',
@ -14,6 +15,7 @@ export class CampaignsComponent implements OnInit {
paginationInfo: IPager; paginationInfo: IPager;
campaigns: ICampaign; campaigns: ICampaign;
isCampaignDetailFunctionEnabled: boolean = false; isCampaignDetailFunctionEnabled: boolean = false;
errorReceived: boolean;
constructor(private service: CampaignsService, private configurationService: ConfigurationService) { } constructor(private service: CampaignsService, private configurationService: ConfigurationService) { }
@ -37,20 +39,28 @@ export class CampaignsComponent implements OnInit {
} }
getCampaigns(pageSize: number, pageIndex: number) { getCampaigns(pageSize: number, pageIndex: number) {
this.service.getCampaigns(pageIndex, pageSize).subscribe(campaigns => { this.errorReceived = false;
this.campaigns = campaigns; this.service.getCampaigns(pageIndex, pageSize)
this.paginationInfo = { .catch((err) => this.handleError(err))
actualPage : campaigns.pageIndex, .subscribe(campaigns => {
itemsPage : campaigns.pageSize, this.campaigns = campaigns;
totalItems : campaigns.count, this.paginationInfo = {
totalPages: Math.ceil(campaigns.count / campaigns.pageSize), actualPage : campaigns.pageIndex,
items: campaigns.pageSize itemsPage : campaigns.pageSize,
}; totalItems : campaigns.count,
totalPages: Math.ceil(campaigns.count / campaigns.pageSize),
items: campaigns.pageSize
};
}); });
} }
onNavigateToDetails(uri: string) { onNavigateToDetails(uri: string) {
window.open(uri, "_blank"); window.open(uri, "_blank");
} }
private handleError(error: any) {
this.errorReceived = true;
return Observable.throw(error);
}
} }

View File

@ -6,6 +6,9 @@
<section class="esh-catalog-filters"> <section class="esh-catalog-filters">
<div class="container"> <div class="container">
<div class="alert alert-warning esh-catalog-alert" role="alert" [hidden]="!errorReceived">
Error requesting catalog products, please try later on
</div>
<label class="esh-catalog-label" data-title="brand"> <label class="esh-catalog-label" data-title="brand">
<select class="esh-catalog-filter" (change)="onBrandFilterChanged($event, $event.target.value)"> <select class="esh-catalog-filter" (change)="onBrandFilterChanged($event, $event.target.value)">
<option *ngFor="let brand of brands" [value]="brand.id">{{brand.brand}}</option> <option *ngFor="let brand of brands" [value]="brand.id">{{brand.brand}}</option>

View File

@ -151,4 +151,8 @@
content: '$'; content: '$';
} }
} }
&-alert {
margin-top: 10px;
}
} }

View File

@ -10,6 +10,7 @@ import { ICatalogBrand } from '../shared/models/catalogBrand.model';
import { IPager } from '../shared/models/pager.model'; import { IPager } from '../shared/models/pager.model';
import { BasketWrapperService} from '../shared/services/basket.wrapper.service'; import { BasketWrapperService} from '../shared/services/basket.wrapper.service';
import { SecurityService } from '../shared/services/security.service'; import { SecurityService } from '../shared/services/security.service';
import { Observable } from 'rxjs/Observable';
@Component({ @Component({
selector: 'esh-catalog .esh-catalog', selector: 'esh-catalog .esh-catalog',
@ -25,6 +26,7 @@ export class CatalogComponent implements OnInit {
paginationInfo: IPager; paginationInfo: IPager;
authenticated: boolean = false; authenticated: boolean = false;
authSubscription: Subscription; authSubscription: Subscription;
errorReceived: boolean;
constructor(private service: CatalogService, private basketService: BasketWrapperService, private configurationService: ConfigurationService, private securityService: SecurityService) { constructor(private service: CatalogService, private basketService: BasketWrapperService, private configurationService: ConfigurationService, private securityService: SecurityService) {
this.authenticated = securityService.IsAuthorized; this.authenticated = securityService.IsAuthorized;
@ -79,17 +81,18 @@ export class CatalogComponent implements OnInit {
} }
getCatalog(pageSize: number, pageIndex: number, brand?: number, type?: number) { getCatalog(pageSize: number, pageIndex: number, brand?: number, type?: number) {
this.service.getCatalog(pageIndex, pageSize, brand, type).subscribe(catalog => { this.errorReceived = false;
this.catalog = catalog; this.service.getCatalog(pageIndex, pageSize, brand, type)
.catch((err) => this.handleError(err))
this.paginationInfo = { .subscribe(catalog => {
actualPage : catalog.pageIndex, this.catalog = catalog;
itemsPage : catalog.pageSize, this.paginationInfo = {
totalItems : catalog.count, actualPage : catalog.pageIndex,
totalPages: Math.ceil(catalog.count / catalog.pageSize), itemsPage : catalog.pageSize,
items: catalog.pageSize totalItems : catalog.count,
}; totalPages: Math.ceil(catalog.count / catalog.pageSize),
items: catalog.pageSize
};
}); });
} }
@ -108,5 +111,10 @@ export class CatalogComponent implements OnInit {
this.brands.unshift(allBrands); this.brands.unshift(allBrands);
}); });
} }
private handleError(error: any) {
this.errorReceived = true;
return Observable.throw(error);
}
} }

View File

@ -2,6 +2,9 @@
<esh-header url="/catalog">Back to catalog</esh-header> <esh-header url="/catalog">Back to catalog</esh-header>
<div class="container"> <div class="container">
<div class="alert alert-warning esh-orders-alert" role="alert" [hidden]="!errorReceived">
Error requesting order list, please try later on
</div>
<article class="esh-orders-titles row"> <article class="esh-orders-titles row">
<section class="esh-orders-title col-xs-2">Order number</section> <section class="esh-orders-title col-xs-2">Order number</section>
<section class="esh-orders-title col-xs-4">Date</section> <section class="esh-orders-title col-xs-4">Date</section>

View File

@ -78,4 +78,8 @@
transition: color $animation-speed-default; transition: color $animation-speed-default;
} }
} }
&-alert {
margin-top: 10px;
}
} }

View File

@ -2,6 +2,7 @@ import { Component, OnInit } from '@angular/core';
import { OrdersService } from './orders.service'; import { OrdersService } from './orders.service';
import { IOrder } from '../shared/models/order.model'; import { IOrder } from '../shared/models/order.model';
import { ConfigurationService } from '../shared/services/configuration.service'; import { ConfigurationService } from '../shared/services/configuration.service';
import { Observable } from 'rxjs/Observable';
@Component({ @Component({
selector: 'esh-orders', selector: 'esh-orders',
@ -11,6 +12,7 @@ import { ConfigurationService } from '../shared/services/configuration.service';
export class OrdersComponent implements OnInit { export class OrdersComponent implements OnInit {
private oldOrders: IOrder[]; private oldOrders: IOrder[];
private interval = null; private interval = null;
errorReceived: boolean;
orders: IOrder[]; orders: IOrder[];
@ -36,13 +38,20 @@ export class OrdersComponent implements OnInit {
}, 1000); }, 1000);
} }
getOrders() { getOrders() {
this.service.getOrders().subscribe(orders => { this.errorReceived = false;
this.orders = orders; this.service.getOrders()
this.oldOrders = this.orders; .catch((err) => this.handleError(err))
console.log('orders items retrieved: ' + orders.length); .subscribe(orders => {
this.orders = orders;
this.oldOrders = this.orders;
console.log('orders items retrieved: ' + orders.length);
}); });
} }
private handleError(error: any) {
this.errorReceived = true;
return Observable.throw(error);
}
} }

View File

@ -31,7 +31,7 @@
height: 0; height: 0;
min-width: 14rem; min-width: 14rem;
overflow: hidden; overflow: hidden;
padding: .5rem; padding: .3rem;
position: absolute; position: absolute;
right: 0; right: 0;
top: 2.5rem; top: 2.5rem;