From 3fb04ae0c974cc1f4eec6590b33447d6b9c0a87d Mon Sep 17 00:00:00 2001 From: Mahmut Gundogdu Date: Tue, 26 Apr 2022 18:35:19 +0300 Subject: [PATCH] Fix implement Dashboard charts and data table. --- .../ordering/src/ordering-routing.module.ts | 7 +++- .../projects/ordering/src/ordering.module.ts | 7 +--- .../order-status-chart.component.html | 18 +++++++++ .../order-status-chart.component.spec.ts | 25 ++++++++++++ .../order-status-chart.component.ts | 25 ++++++++++++ .../payments-chart.component.html | 19 ++++++++++ .../payments-chart.component.spec.ts | 25 ++++++++++++ .../payments-chart.component.ts | 38 +++++++++++++++++++ .../top-selling/top-selling.component.css | 0 .../top-selling/top-selling.component.html | 26 +++++++++++-- .../top-selling/top-selling.component.ts | 1 - .../dashboard/dashboard-routing.module.ts | 20 ++++++++++ .../pages/dashboard/dashboard.component.html | 18 +++++++-- .../src/pages/dashboard/dashboard.module.ts | 25 ++++++++++++ 14 files changed, 240 insertions(+), 14 deletions(-) create mode 100644 apps/angular/projects/ordering/src/pages/dashboard/components/order-status-chart/order-status-chart.component.html create mode 100644 apps/angular/projects/ordering/src/pages/dashboard/components/order-status-chart/order-status-chart.component.spec.ts create mode 100644 apps/angular/projects/ordering/src/pages/dashboard/components/order-status-chart/order-status-chart.component.ts create mode 100644 apps/angular/projects/ordering/src/pages/dashboard/components/payments-chart/payments-chart.component.html create mode 100644 apps/angular/projects/ordering/src/pages/dashboard/components/payments-chart/payments-chart.component.spec.ts create mode 100644 apps/angular/projects/ordering/src/pages/dashboard/components/payments-chart/payments-chart.component.ts delete mode 100644 apps/angular/projects/ordering/src/pages/dashboard/components/top-selling/top-selling.component.css create mode 100644 apps/angular/projects/ordering/src/pages/dashboard/dashboard-routing.module.ts create mode 100644 apps/angular/projects/ordering/src/pages/dashboard/dashboard.module.ts diff --git a/apps/angular/projects/ordering/src/ordering-routing.module.ts b/apps/angular/projects/ordering/src/ordering-routing.module.ts index 2948f4d6..b244fed3 100644 --- a/apps/angular/projects/ordering/src/ordering-routing.module.ts +++ b/apps/angular/projects/ordering/src/ordering-routing.module.ts @@ -1,9 +1,12 @@ import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; -import { DashboardComponent } from './pages/dashboard/dashboard.component'; const routes: Routes = [ - { path: '', component: DashboardComponent, pathMatch: 'full' }, + { + path: '', + loadChildren: () => import('./pages/dashboard/dashboard.module').then(m => m.DashboardModule), + pathMatch: 'full', + }, { path: 'orders', loadChildren: () => import('./pages/orders/orders.module').then(m => m.OrdersModule), diff --git a/apps/angular/projects/ordering/src/ordering.module.ts b/apps/angular/projects/ordering/src/ordering.module.ts index 4b89cfdb..724b0dfb 100644 --- a/apps/angular/projects/ordering/src/ordering.module.ts +++ b/apps/angular/projects/ordering/src/ordering.module.ts @@ -1,12 +1,9 @@ import { NgModule } from '@angular/core'; import { OrderingRoutingModule } from './ordering-routing.module'; -import { DashboardComponent } from './pages/dashboard/dashboard.component'; -import { TopSellingComponent } from './pages/dashboard/components/top-selling/top-selling.component'; -import { CommonModule } from '@angular/common'; @NgModule({ - declarations: [DashboardComponent, TopSellingComponent], - imports: [OrderingRoutingModule, CommonModule], + declarations: [], + imports: [OrderingRoutingModule], exports: [], }) export class OrderingModule {} diff --git a/apps/angular/projects/ordering/src/pages/dashboard/components/order-status-chart/order-status-chart.component.html b/apps/angular/projects/ordering/src/pages/dashboard/components/order-status-chart/order-status-chart.component.html new file mode 100644 index 00000000..5cb2e996 --- /dev/null +++ b/apps/angular/projects/ordering/src/pages/dashboard/components/order-status-chart/order-status-chart.component.html @@ -0,0 +1,18 @@ + +
+
+
+
+
{{ 'OrderingService::OrderStatuses' | abpLocalization }}
+
+
+
+
+ +
+
+ diff --git a/apps/angular/projects/ordering/src/pages/dashboard/components/order-status-chart/order-status-chart.component.spec.ts b/apps/angular/projects/ordering/src/pages/dashboard/components/order-status-chart/order-status-chart.component.spec.ts new file mode 100644 index 00000000..24501c16 --- /dev/null +++ b/apps/angular/projects/ordering/src/pages/dashboard/components/order-status-chart/order-status-chart.component.spec.ts @@ -0,0 +1,25 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { OrderStatusChartComponent } from './order-status-chart.component'; + +describe('OrderStatusChartComponent', () => { + let component: OrderStatusChartComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ OrderStatusChartComponent ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(OrderStatusChartComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/apps/angular/projects/ordering/src/pages/dashboard/components/order-status-chart/order-status-chart.component.ts b/apps/angular/projects/ordering/src/pages/dashboard/components/order-status-chart/order-status-chart.component.ts new file mode 100644 index 00000000..90570ffb --- /dev/null +++ b/apps/angular/projects/ordering/src/pages/dashboard/components/order-status-chart/order-status-chart.component.ts @@ -0,0 +1,25 @@ +import { Component, Input } from '@angular/core'; +import { OrderStatusDto } from '../../../../lib/proxy/orders'; + +@Component({ + selector: 'app-order-status-chart', + templateUrl: './order-status-chart.component.html', +}) +export class OrderStatusChartComponent { + @Input() + set data(value: OrderStatusDto[]) { + this.chartData.labels = [...value.map(x => x.orderStatus)]; + this.chartData.datasets = [ + { + label: 'Order Statuses', + data: [...value.map(x => x.countOfStatusOrder)], + backgroundColor: ['#fdcb6e', '#0984e3', '#ff7675'], + }, + ]; + } + + chartData = { + labels: [], + datasets: [], + }; +} diff --git a/apps/angular/projects/ordering/src/pages/dashboard/components/payments-chart/payments-chart.component.html b/apps/angular/projects/ordering/src/pages/dashboard/components/payments-chart/payments-chart.component.html new file mode 100644 index 00000000..2281bb3d --- /dev/null +++ b/apps/angular/projects/ordering/src/pages/dashboard/components/payments-chart/payments-chart.component.html @@ -0,0 +1,19 @@ + +
+
+
+
+
{{ 'OrderingService::OrderStatuses' | abpLocalization }}
+
+
+
+
+ +
+
+ diff --git a/apps/angular/projects/ordering/src/pages/dashboard/components/payments-chart/payments-chart.component.spec.ts b/apps/angular/projects/ordering/src/pages/dashboard/components/payments-chart/payments-chart.component.spec.ts new file mode 100644 index 00000000..cbdd8ee3 --- /dev/null +++ b/apps/angular/projects/ordering/src/pages/dashboard/components/payments-chart/payments-chart.component.spec.ts @@ -0,0 +1,25 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { PaymentsChartComponent } from './payments-chart.component'; + +describe('PaymentsChartComponent', () => { + let component: PaymentsChartComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ PaymentsChartComponent ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(PaymentsChartComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/apps/angular/projects/ordering/src/pages/dashboard/components/payments-chart/payments-chart.component.ts b/apps/angular/projects/ordering/src/pages/dashboard/components/payments-chart/payments-chart.component.ts new file mode 100644 index 00000000..265159d9 --- /dev/null +++ b/apps/angular/projects/ordering/src/pages/dashboard/components/payments-chart/payments-chart.component.ts @@ -0,0 +1,38 @@ +import { Component, Input } from '@angular/core'; +import { PaymentDto } from '../../../../lib/proxy/orders'; + +@Component({ + selector: 'app-payments-chart', + templateUrl: './payments-chart.component.html', +}) +export class PaymentsChartComponent { + @Input() + set data(value: PaymentDto[]) { + this.chartData.datasets = [ + { + label: 'Order Statuses', + data: [...value.map(x => x.rateOfPaymentMethod)], + backgroundColor: ['#fdcb6e', '#0984e3', '#ff7675'], + }, + ]; + this.chartData.labels = [...value.map(x => x.paymentMethod)]; + } + + chartData = { + labels: [], + datasets: [], + }; + + options = { + plugins: { + title: { + display: true, + text: 'Payment Methods', + fontSize: 16, + }, + legend: { + position: 'bottom', + }, + }, + }; +} diff --git a/apps/angular/projects/ordering/src/pages/dashboard/components/top-selling/top-selling.component.css b/apps/angular/projects/ordering/src/pages/dashboard/components/top-selling/top-selling.component.css deleted file mode 100644 index e69de29b..00000000 diff --git a/apps/angular/projects/ordering/src/pages/dashboard/components/top-selling/top-selling.component.html b/apps/angular/projects/ordering/src/pages/dashboard/components/top-selling/top-selling.component.html index 221d3692..adefee26 100644 --- a/apps/angular/projects/ordering/src/pages/dashboard/components/top-selling/top-selling.component.html +++ b/apps/angular/projects/ordering/src/pages/dashboard/components/top-selling/top-selling.component.html @@ -1,4 +1,24 @@ -

top-selling works!

-
- count {{ topSellingProducts.length}} +
+
+
+
+
{{ 'OrderingService::TopSelling' | abpLocalization }}
+
+
+
+
+ + + + + + +
+ diff --git a/apps/angular/projects/ordering/src/pages/dashboard/components/top-selling/top-selling.component.ts b/apps/angular/projects/ordering/src/pages/dashboard/components/top-selling/top-selling.component.ts index 8ca7f999..07f13f0f 100644 --- a/apps/angular/projects/ordering/src/pages/dashboard/components/top-selling/top-selling.component.ts +++ b/apps/angular/projects/ordering/src/pages/dashboard/components/top-selling/top-selling.component.ts @@ -4,7 +4,6 @@ import { TopSellingDto } from '../../../../lib/proxy/order-items'; @Component({ selector: 'app-top-selling', templateUrl: './top-selling.component.html', - styleUrls: ['./top-selling.component.css'], changeDetection: ChangeDetectionStrategy.OnPush, }) export class TopSellingComponent { diff --git a/apps/angular/projects/ordering/src/pages/dashboard/dashboard-routing.module.ts b/apps/angular/projects/ordering/src/pages/dashboard/dashboard-routing.module.ts new file mode 100644 index 00000000..ebb49f42 --- /dev/null +++ b/apps/angular/projects/ordering/src/pages/dashboard/dashboard-routing.module.ts @@ -0,0 +1,20 @@ +import { NgModule } from '@angular/core'; +import { RouterModule, Routes } from '@angular/router'; +import { DashboardComponent } from './dashboard.component'; + +const routes: Routes = [ + { + path: '', + component: DashboardComponent, + // canActivate: [AuthGuard, PermissionGuard], + // data: { + // requiredPolicy: eCatalogPolicyNames.ProductManagement, + // }, + }, +]; + +@NgModule({ + imports: [RouterModule.forChild(routes)], + exports: [RouterModule], +}) +export class DashboardRoutingModule {} diff --git a/apps/angular/projects/ordering/src/pages/dashboard/dashboard.component.html b/apps/angular/projects/ordering/src/pages/dashboard/dashboard.component.html index 3502cff7..dbefa3ea 100644 --- a/apps/angular/projects/ordering/src/pages/dashboard/dashboard.component.html +++ b/apps/angular/projects/ordering/src/pages/dashboard/dashboard.component.html @@ -1,7 +1,19 @@

dashboard works!

-
- - +
+
+
+ + +
+
+ + +
+
+ + +
+
diff --git a/apps/angular/projects/ordering/src/pages/dashboard/dashboard.module.ts b/apps/angular/projects/ordering/src/pages/dashboard/dashboard.module.ts new file mode 100644 index 00000000..0a66aec3 --- /dev/null +++ b/apps/angular/projects/ordering/src/pages/dashboard/dashboard.module.ts @@ -0,0 +1,25 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { ProductRoutingModule } from '@eshoponabp/catalog'; +import { ThemeSharedModule } from '@abp/ng.theme.shared'; +import { CoreModule } from '@abp/ng.core'; +import { DashboardRoutingModule } from './dashboard-routing.module'; +import { DashboardComponent } from './dashboard.component'; +import { TopSellingComponent } from './components/top-selling/top-selling.component'; +import { OrderStatusChartComponent } from './components/order-status-chart/order-status-chart.component'; +import { ChartModule } from '@abp/ng.components/chart.js'; +import { PaymentsChartComponent } from './components/payments-chart/payments-chart.component'; + +@NgModule({ + declarations: [DashboardComponent, TopSellingComponent, OrderStatusChartComponent, PaymentsChartComponent], + imports: [ + DashboardRoutingModule, + CommonModule, + ProductRoutingModule, + CommonModule, + ThemeSharedModule, + CoreModule, + ChartModule, + ], +}) +export class DashboardModule {}