2017-07-05 17:08:23 +00:00
|
|
|
import { Directive, Component, OnInit } from '@angular/core';
|
2017-06-19 16:20:21 +00:00
|
|
|
import { Http, Response } from '@angular/http';
|
|
|
|
import { ApiService } from '../providers/api-service';
|
2017-04-27 14:29:31 +00:00
|
|
|
import { Router } from '@angular/router';
|
2017-08-30 11:35:43 +00:00
|
|
|
import { GraphWidget } from '../widgets/graph-widget.component';
|
2017-09-07 12:32:59 +00:00
|
|
|
import { DataType } from '../shared/data-types.enum';
|
2017-04-27 14:29:31 +00:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
templateUrl: 'dashboard.component.html'
|
|
|
|
})
|
|
|
|
export class DashboardComponent implements OnInit {
|
2017-09-07 12:58:51 +00:00
|
|
|
|
|
|
|
// Snippet data
|
|
|
|
public customersThisMonth: number;
|
|
|
|
public moneySpentThisMonth: number;
|
|
|
|
public pointsTotal: number;
|
|
|
|
public averageTransactionToday: number;
|
|
|
|
|
2017-07-18 10:35:43 +00:00
|
|
|
shuffledArray: any;
|
2017-04-27 14:29:31 +00:00
|
|
|
|
2017-08-30 11:35:43 +00:00
|
|
|
public widgetList = [
|
|
|
|
{
|
|
|
|
type: 'graph',
|
|
|
|
name: 'customers_last_7_days',
|
|
|
|
icon: 'icon-people',
|
|
|
|
title: 'Customers Last 7 Days',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'graph',
|
|
|
|
name: 'customers_last_30_days',
|
|
|
|
icon: 'icon-people',
|
|
|
|
title: 'Customers Last 30 Days',
|
|
|
|
},
|
2017-09-05 11:04:36 +00:00
|
|
|
{
|
|
|
|
type: 'graph',
|
|
|
|
name: 'sales_last_7_days',
|
|
|
|
icon: 'icon-diamond',
|
|
|
|
title: 'Sales Last 7 Days',
|
2017-09-07 12:32:59 +00:00
|
|
|
dataType: DataType.currency,
|
2017-09-05 11:04:36 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'graph',
|
|
|
|
name: 'sales_last_30_days',
|
|
|
|
icon: 'icon-diamond',
|
|
|
|
title: 'Sales Last 30 Days',
|
2017-09-07 12:32:59 +00:00
|
|
|
dataType: DataType.currency,
|
2017-09-05 11:04:36 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'graph',
|
|
|
|
name: 'purchases_last_7_days',
|
|
|
|
title: 'Purchases Last 7 Days',
|
2017-09-07 12:32:59 +00:00
|
|
|
dataType: DataType.currency,
|
2017-09-05 11:04:36 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'graph',
|
|
|
|
name: 'purchases_last_30_days',
|
|
|
|
title: 'Purchases Last 30 Days',
|
2017-09-07 12:32:59 +00:00
|
|
|
dataType: DataType.currency,
|
2017-09-05 11:04:36 +00:00
|
|
|
},
|
2017-08-30 11:35:43 +00:00
|
|
|
];
|
|
|
|
|
2017-07-04 14:44:13 +00:00
|
|
|
constructor(
|
2017-06-19 16:20:21 +00:00
|
|
|
private http: Http,
|
|
|
|
private api: ApiService,
|
2017-08-30 11:41:28 +00:00
|
|
|
) {
|
2017-07-04 14:44:13 +00:00
|
|
|
this.shuffle = this.shuffledArray;
|
|
|
|
this.api.breadcrumb_data(undefined)
|
2017-06-22 15:30:35 +00:00
|
|
|
.subscribe(
|
2017-08-30 11:41:28 +00:00
|
|
|
result => {
|
2017-06-22 15:30:35 +00:00
|
|
|
console.log(result);
|
|
|
|
this.customersThisMonth = result.customersthismonth;
|
|
|
|
this.moneySpentThisMonth = result.moneyspentthismonth;
|
|
|
|
this.pointsTotal = result.pointstotal;
|
|
|
|
this.averageTransactionToday = result.averagetransactiontoday;
|
|
|
|
}
|
2017-08-30 11:41:28 +00:00
|
|
|
);
|
2017-06-19 16:20:21 +00:00
|
|
|
}
|
2017-08-30 11:41:28 +00:00
|
|
|
|
2017-07-04 14:44:13 +00:00
|
|
|
// Fisher-Yates shuffle function
|
|
|
|
public shuffle(array) {
|
|
|
|
return new Promise(resolve => {
|
|
|
|
let counter = array.length;
|
|
|
|
|
|
|
|
// While there are elements in the array
|
|
|
|
while (counter > 0) {
|
|
|
|
// Pick a random index
|
2017-08-30 11:41:28 +00:00
|
|
|
const index = Math.floor(Math.random() * counter);
|
2017-07-04 14:44:13 +00:00
|
|
|
|
|
|
|
// Decrease counter by 1
|
|
|
|
counter--;
|
2017-04-27 14:29:31 +00:00
|
|
|
|
2017-07-04 14:44:13 +00:00
|
|
|
// And swap the last element with it
|
2017-08-30 11:41:28 +00:00
|
|
|
const temp = array[counter];
|
2017-07-04 14:44:13 +00:00
|
|
|
array[counter] = array[index];
|
|
|
|
array[index] = temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.shuffledArray = array;
|
|
|
|
resolve(true);
|
|
|
|
});
|
|
|
|
}
|
2017-08-30 11:41:28 +00:00
|
|
|
|
2017-04-27 14:29:31 +00:00
|
|
|
public brandSuccess = '#4dbd74';
|
|
|
|
public brandInfo = '#63c2de';
|
|
|
|
public brandDanger = '#f86c6b';
|
|
|
|
|
|
|
|
// convert Hex to RGBA
|
|
|
|
public convertHex(hex: string, opacity: number) {
|
|
|
|
hex = hex.replace('#', '');
|
|
|
|
const r = parseInt(hex.substring(0, 2), 16);
|
|
|
|
const g = parseInt(hex.substring(2, 4), 16);
|
|
|
|
const b = parseInt(hex.substring(4, 6), 16);
|
|
|
|
|
|
|
|
const rgba = 'rgba(' + r + ', ' + g + ', ' + b + ', ' + opacity / 100 + ')';
|
|
|
|
return rgba;
|
|
|
|
}
|
|
|
|
|
|
|
|
// events
|
|
|
|
public chartClicked(e: any): void {
|
|
|
|
console.log(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
public chartHovered(e: any): void {
|
|
|
|
console.log(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
// mainChart
|
|
|
|
|
|
|
|
public random(min: number, max: number) {
|
|
|
|
return Math.floor(Math.random() * (max - min + 1) + min);
|
|
|
|
}
|
|
|
|
|
|
|
|
public mainChartElements = 27;
|
|
|
|
public mainChartData1: Array<number> = [];
|
|
|
|
public mainChartData2: Array<number> = [];
|
|
|
|
public mainChartData3: Array<number> = [];
|
|
|
|
|
|
|
|
public mainChartData: Array<any> = [
|
|
|
|
{
|
|
|
|
data: this.mainChartData1,
|
|
|
|
label: 'Current'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
data: this.mainChartData2,
|
|
|
|
label: 'Previous'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
data: this.mainChartData3,
|
|
|
|
label: 'BEP'
|
|
|
|
}
|
|
|
|
];
|
|
|
|
/* tslint:disable:max-line-length */
|
|
|
|
public mainChartLabels: Array<any> = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday', 'Monday', 'Thursday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
|
|
|
|
/* tslint:enable:max-line-length */
|
|
|
|
public mainChartOptions: any = {
|
|
|
|
responsive: true,
|
|
|
|
maintainAspectRatio: false,
|
|
|
|
scales: {
|
|
|
|
xAxes: [{
|
|
|
|
gridLines: {
|
|
|
|
drawOnChartArea: false,
|
|
|
|
},
|
|
|
|
ticks: {
|
|
|
|
callback: function(value: any) {
|
|
|
|
return value.charAt(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}],
|
|
|
|
yAxes: [{
|
|
|
|
ticks: {
|
|
|
|
beginAtZero: true,
|
|
|
|
maxTicksLimit: 5,
|
|
|
|
stepSize: Math.ceil(250 / 5),
|
|
|
|
max: 250
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
},
|
|
|
|
elements: {
|
|
|
|
line: {
|
|
|
|
borderWidth: 2
|
|
|
|
},
|
|
|
|
point: {
|
|
|
|
radius: 0,
|
|
|
|
hitRadius: 10,
|
|
|
|
hoverRadius: 4,
|
|
|
|
hoverBorderWidth: 3,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
legend: {
|
|
|
|
display: false
|
|
|
|
}
|
|
|
|
};
|
|
|
|
public mainChartColours: Array<any> = [
|
|
|
|
{ // brandInfo
|
|
|
|
backgroundColor: this.convertHex(this.brandInfo, 10),
|
|
|
|
borderColor: this.brandInfo,
|
|
|
|
pointHoverBackgroundColor: '#fff'
|
|
|
|
},
|
|
|
|
{ // brandSuccess
|
|
|
|
backgroundColor: 'transparent',
|
|
|
|
borderColor: this.brandSuccess,
|
|
|
|
pointHoverBackgroundColor: '#fff'
|
|
|
|
},
|
|
|
|
{ // brandDanger
|
|
|
|
backgroundColor: 'transparent',
|
|
|
|
borderColor: this.brandDanger,
|
|
|
|
pointHoverBackgroundColor: '#fff',
|
|
|
|
borderWidth: 1,
|
|
|
|
borderDash: [8, 5]
|
|
|
|
}
|
|
|
|
];
|
|
|
|
public mainChartLegend = false;
|
|
|
|
public mainChartType = 'line';
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
// generate random values for mainChart
|
|
|
|
for (let i = 0; i <= this.mainChartElements; i++) {
|
|
|
|
this.mainChartData1.push(this.random(50, 200));
|
|
|
|
this.mainChartData2.push(this.random(80, 100));
|
2017-05-12 16:07:18 +00:00
|
|
|
this.mainChartData3.push(this.random(50, 200));
|
2017-04-27 14:29:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|