Skip to content

Commit

Permalink
Generic report page added
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoumpierre committed Apr 30, 2018
1 parent 98e441c commit 8cf1a16
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 11 deletions.
15 changes: 12 additions & 3 deletions src/components/report-popover/report-popover.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
<!-- Generated template for the ReportPopoverComponent component -->
<div>
<ion-list no-lines>
<ion-list-header>Período</ion-list-header>
<ion-list>
<ion-item-divider>
Período
</ion-item-divider>

<ion-item>
<ion-label>De</ion-label>
<ion-datetime displayFormat="DDD DD/MM/YYYY" pickerFormat="DD MM YYYY" [(ngModel)]="from"></ion-datetime>
</ion-item>

<ion-item>
<ion-label>Até</ion-label>
<ion-datetime displayFormat="DDD DD/MM/YYYY" pickerFormat="DD MM YYYY" [(ngModel)]="to"></ion-datetime>
</ion-item>

<ion-item-divider>
Opções
</ion-item-divider>

<button ion-item (click)="clear()">Limpar filtro</button>
<button ion-item (click)="save()">Salvar</button>
<button ion-item (click)="save()">Aplicar filtro</button>
</ion-list>
</div>
24 changes: 20 additions & 4 deletions src/pages/reports/detail/reports-detail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ export class ReportsDetailPage {
categoryName = 'produto';
this.listTitle = 'Lista de pedidos';
break;
case 'customers':
categoryName = 'cliente';
this.listTitle = 'Lista de pedidos';
break;
default:
this.listTitle = 'Listagem';
}
Expand All @@ -63,7 +67,7 @@ export class ReportsDetailPage {
*/
presentPopover(myEvent) {
let popover = this.popoverCtrl.create(ReportPopoverComponent, {period: this.period});
popover.present();
popover.present({ev: myEvent});
popover.onDidDismiss(data => {
if (data) {
this.updatePeriod([data.from, data.to]);
Expand All @@ -76,11 +80,15 @@ export class ReportsDetailPage {
*/
updatePeriod(period) {
if (period && period[0] && period[1]) {
this.period = [period[0], period[1]];
this.period = period = [
this.toIso(period[0]),
this.toIso(period[1])
];

this.periodTitle = moment(period[0]).format('DD/MM/YYYY') + ' - ' + moment(period[1]).format('DD/MM/YYYY');

this.apiProvider.builder('reports/' + this.category + '/' + this.id + '/' + period[0] + '/' + period[1]).loader().get()
.subscribe((res) => this.updateListDate(res));
this.apiProvider.builder('reports/' + this.category + '/' + this.id + '/' + moment(period[0]).format('YYYY-MM-DD') + '/' + moment(period[1]).format('YYYY-MM-DD'))
.loader().get().subscribe((res) => this.updateListDate(res));
} else {
this.period = [];
this.periodTitle = 'Sempre';
Expand All @@ -105,4 +113,12 @@ export class ReportsDetailPage {

this.report = res;
}

/**
* @param date
* @returns {string}
*/
toIso(date) {
return new Date(date).toISOString();
}
}
5 changes: 5 additions & 0 deletions src/pages/reports/index/reports.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
</ion-header>

<ion-content>
<button ion-button (click)="goToReportView('customers')" full clear icon-left large>
<ion-icon name="people"></ion-icon>
Clientes
</button>

<button ion-button (click)="goToReportView('products')" full clear icon-left large>
<ion-icon name="alarm"></ion-icon>
Produtos
Expand Down
24 changes: 20 additions & 4 deletions src/pages/reports/view/reports-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ export class ReportsViewPage {
case 'products':
categoryName = 'produtos';
break;
case 'customers':
categoryName = 'clientes';
break;
}

this.pageTitle = 'Relatório de ' + categoryName;
Expand All @@ -63,7 +66,7 @@ export class ReportsViewPage {
*/
presentPopover(myEvent) {
let popover = this.popoverCtrl.create(ReportPopoverComponent, {period: this.period});
popover.present();
popover.present({ev: myEvent});
popover.onDidDismiss(data => {
if (data) {
this.updatePeriod([data.from, data.to]);
Expand All @@ -76,11 +79,16 @@ export class ReportsViewPage {
*/
updatePeriod(period) {
if (period && period[0] && period[1]) {
this.period = [period[0], period[1]];
this.period = period = [
this.toIso(period[0]),
this.toIso(period[1])
];

this.periodTitle = moment(period[0]).format('DD/MM/YYYY') + ' - ' + moment(period[1]).format('DD/MM/YYYY');

this.apiProvider.builder('reports/' + this.category + '/' + period[0] + '/' + period[1]).loader().get()
.subscribe((res) => {
this.apiProvider
.builder('reports/' + this.category + '/' + moment(period[0]).format('YYYY-MM-DD') + '/' + moment(period[1]).format('YYYY-MM-DD'))
.loader().get().subscribe((res) => {
this.reports = res;
this.loaded = true;
});
Expand All @@ -95,4 +103,12 @@ export class ReportsViewPage {
});
}
}

/**
* @param date
* @returns {string}
*/
toIso(date) {
return new Date(date).toISOString();
}
}

0 comments on commit 8cf1a16

Please sign in to comment.