Various updates

This commit is contained in:
Tom Bloor 2019-07-15 12:38:06 +01:00
parent 5cd0db3faf
commit 0dcf98fed3
No known key found for this signature in database
GPG key ID: 4657C7EBE42CC5CC
5 changed files with 115 additions and 92 deletions

View file

@ -45,7 +45,7 @@
</div> </div>
</div> </div>
<div> <div>
<canvas baseChart <canvas baseChart #supplierChart
[datasets]="supplierMonthChartData" [datasets]="supplierMonthChartData"
[options]="supplierMonthChartOptions" [options]="supplierMonthChartOptions"
[colors]="sampleColours" [colors]="sampleColours"

View file

@ -1,7 +1,8 @@
import {Component, OnInit, Input, Output, EventEmitter} from '@angular/core'; import {Component, OnInit, Input, Output, EventEmitter, ViewChild, ElementRef} from '@angular/core';
import {ApiService} from '../providers/api-service'; import {ApiService} from '../providers/api-service';
import {Color} from 'ng2-charts'; import {BaseChartDirective, Color} from 'ng2-charts';
import {CurrencyPipe} from '@angular/common'; import {CurrencyPipe} from '@angular/common';
import {ChartType} from "chart.js";
@Component({ @Component({
templateUrl: 'more-graphs-and-tables.component.html', templateUrl: 'more-graphs-and-tables.component.html',
@ -17,6 +18,9 @@ export class MoreStuffComponent implements OnInit {
} }
ngOnInit(): void { ngOnInit(): void {
this.loadYearSpend();
this.loadSupplierBubble();
this.loadSupplierHistory();
} }
public showLegend = true; public showLegend = true;
@ -41,18 +45,33 @@ export class MoreStuffComponent implements OnInit {
/* /*
* Supplier Bubble Chart Setup * Supplier Bubble Chart Setup
*/ */
public supplierBubbleChartType = 'bubble';
private loadSupplierBubble() {
this.api.loadMiscUrl('organisation/external/supplier_count').subscribe(
result => {
console.log(result.data);
let graph_data = [];
result.data.map(item => {
graph_data.push({
t: item.date,
r: (item.value / 100000) + 5,
supplier: item.seller,
y: item.count,
value: item.value,
count: item.count,
});
});
console.log(graph_data);
this.supplierBubbleChartData[0].data = graph_data;
}
)
}
public supplierBubbleChartType: ChartType = 'bubble';
public supplierBubbleChartData: any[] = [ public supplierBubbleChartData: any[] = [
{ {
data: [ data: [],
{t: '20180123', y: 54.34, r: 32, supplier: 'Tims', count: 4}, label: ["Spend"],
{t: '20180101', y: 123.34, r: 123, supplier: 'Daves', count: 12},
{t: '20180314', y: 11.345, r: 33, supplier: 'erry', count: 13},
{t: '20180615', y: 112.6, r: 22, supplier: 'qwert', count: 124},
{t: '20180714', y: 91234.5, r: 8, supplier: 'Bobs', count: 1234},
{t: '20181230', y: 23.12, r: 67, supplier: 'Ben Bobs', count: 4},
],
label: ["Series A"],
backgroundColor: 'green', backgroundColor: 'green',
borderColor: 'blue', borderColor: 'blue',
hoverBackgroundColor: 'purple', hoverBackgroundColor: 'purple',
@ -66,17 +85,10 @@ export class MoreStuffComponent implements OnInit {
xAxes: [{ xAxes: [{
type: 'time', type: 'time',
time: { time: {
parser: 'YYYYMMDD',
unit: 'month' unit: 'month'
} }
}], }],
yAxes: [ yAxes: []
{
ticks: {
min: 0,
}
}
]
}, },
tooltips: { tooltips: {
callbacks: { callbacks: {
@ -90,18 +102,38 @@ export class MoreStuffComponent implements OnInit {
private bubbleTooltipCallback(tooltipItem: any, data: any) { private bubbleTooltipCallback(tooltipItem: any, data: any) {
let dataset = data.datasets[tooltipItem.datasetIndex]; let dataset = data.datasets[tooltipItem.datasetIndex];
let value = dataset.data[tooltipItem.index]; let value = dataset.data[tooltipItem.index];
return `${value.supplier}: ${this.currencyPipe.transform(value.y, 'GBP', 'symbol', '1.2-2')} over ${value.count} purchases`; return `${value.supplier}: ${this.currencyPipe.transform(value.value, 'GBP', 'symbol', '1.2-2')} over ${value.count} purchases`;
}
private loadYearSpend() {
this.api.loadMiscUrl('organisation/external/year_spend').subscribe(
result => {
let value_data = [];
let count_data = [];
console.log(result.data);
result.data.map(item => {
value_data.push({
t: item.date,
y: item.value,
});
count_data.push({
t: item.date,
y: item.count,
});
});
this.yearSpendChartData[0].data = value_data;
this.yearSpendChartData[1].data = count_data;
}
)
} }
public yearSpendChartData: any[] = [ public yearSpendChartData: any[] = [
{ {
data: [ data: [],
{t: '20180101', y: 123.34},
{t: '20180314', y: 11.345},
{t: '20180615', y: 112.6},
{t: '20180714', y: 91234.5},
{t: '20181230', y: 23.12},
],
label: ["Value"], label: ["Value"],
fill: false, fill: false,
borderColor: 'red', borderColor: 'red',
@ -110,13 +142,7 @@ export class MoreStuffComponent implements OnInit {
yAxisID: 'y-value', yAxisID: 'y-value',
}, },
{ {
data: [ data: [],
{t: '20180101', y: 12},
{t: '20180314', y: 11},
{t: '20180615', y: 1},
{t: '20180714', y: 9},
{t: '20181230', y: 23},
],
label: ["Count"], label: ["Count"],
fill: false, fill: false,
borderColor: 'blue', borderColor: 'blue',
@ -131,7 +157,6 @@ export class MoreStuffComponent implements OnInit {
xAxes: [{ xAxes: [{
type: 'time', type: 'time',
time: { time: {
parser: 'YYYYMMDD',
unit: 'month' unit: 'month'
} }
}], }],
@ -158,24 +183,38 @@ export class MoreStuffComponent implements OnInit {
} }
]; ];
public yearSpendChartLabels: string[] = []; public yearSpendChartLabels: string[] = [];
public yearSpendChartType = 'line'; public yearSpendChartType: ChartType = 'line';
randomData() { randomData() {
return Math.random(); return Math.random();
} }
@ViewChild('supplierChart', {read: BaseChartDirective, static: false}) supplierChart: BaseChartDirective;
private loadSupplierHistory() {
this.api.loadMiscUrl('organisation/external/supplier_history').subscribe(
result => {
let labels = [];
let year = [];
let half = [];
let quarter = [];
result.data.map(item => {
labels.push(item.name);
year.push(item.year_total);
half.push(item.half_total);
quarter.push(item.quarter_total);
});
this.supplierMonthChartData[0].data = quarter.slice(0,10);
this.supplierMonthChartData[1].data = half.slice(0,10);
this.supplierMonthChartData[2].data = year.slice(0,10);
this.supplierMonthChartLabels = labels.slice(0,10);
}
)
}
public supplierMonthChartData: any[] = [ public supplierMonthChartData: any[] = [
{ {
data: [ data: [],
this.randomData(),
this.randomData(),
this.randomData(),
this.randomData(),
this.randomData(),
this.randomData(),
this.randomData(),
this.randomData(),
],
label: ["3 Month"], label: ["3 Month"],
fill: false, fill: false,
borderColor: 'red', borderColor: 'red',
@ -183,16 +222,7 @@ export class MoreStuffComponent implements OnInit {
hoverBackgroundColor: 'red', hoverBackgroundColor: 'red',
}, },
{ {
data: [ data: [],
this.randomData(),
this.randomData(),
this.randomData(),
this.randomData(),
this.randomData(),
this.randomData(),
this.randomData(),
this.randomData(),
],
label: ["6 Month"], label: ["6 Month"],
fill: false, fill: false,
borderColor: 'red', borderColor: 'red',
@ -200,16 +230,7 @@ export class MoreStuffComponent implements OnInit {
hoverBackgroundColor: 'red', hoverBackgroundColor: 'red',
}, },
{ {
data: [ data: [],
this.randomData(),
this.randomData(),
this.randomData(),
this.randomData(),
this.randomData(),
this.randomData(),
this.randomData(),
this.randomData(),
],
label: ["12 Month"], label: ["12 Month"],
fill: false, fill: false,
borderColor: 'red', borderColor: 'red',
@ -218,30 +239,13 @@ export class MoreStuffComponent implements OnInit {
}, },
]; ];
public supplierMonthChartOptions: any = { public supplierMonthChartOptions: any = {
//maintainAspectRatio: false,
responsive: true, responsive: true,
scales: { scales: {
xAxes: [], xAxes: [],
yAxes: [] yAxes: []
}, },
}; };
public supplierMonthChartLabels: string[] = [ public supplierMonthChartLabels: string[] = [];
'some name', public supplierMonthChartType: ChartType = 'horizontalBar';
'another name',
'more names',
'again',
'some',
'random',
'names'
];
public supplierMonthChartType = 'horizontalBar';
private setChartData(dataCat: any) {
// now we just need some data and it will display!
}
// functions
// SAMPLE chart data
} }

View file

@ -48,6 +48,13 @@
</li> </li>
</ul> </ul>
</pagination-template> </pagination-template>
<select (change)="loadSuppliers(1)" [(ngModel)]="perPage">
<option>10</option>
<option>20</option>
<option>50</option>
<option>100</option>
<option>200</option>
</select>
</div> </div>
<div *ngIf="!supplierListAvailable" class="card-block"> <div *ngIf="!supplierListAvailable" class="card-block">
No Suppliers available. No Suppliers available.

View file

@ -11,6 +11,7 @@ import { PaginationInstance } from 'ngx-pagination';
export class SuppliersComponent implements OnInit, AfterViewInit { export class SuppliersComponent implements OnInit, AfterViewInit {
@Output() public onClick = new EventEmitter(); @Output() public onClick = new EventEmitter();
@Input() public categories: any; @Input() public categories: any;
public perPage: number = 10;
supplierList: any; supplierList: any;
supplierListAvailable = false; supplierListAvailable = false;
@ -19,7 +20,7 @@ export class SuppliersComponent implements OnInit, AfterViewInit {
public paginateConfig: PaginationInstance = { public paginateConfig: PaginationInstance = {
id: 'transpaginate', id: 'transpaginate',
itemsPerPage: 10, itemsPerPage: this.perPage,
currentPage: 1, currentPage: 1,
totalItems: 0 totalItems: 0
}; };
@ -37,7 +38,7 @@ export class SuppliersComponent implements OnInit, AfterViewInit {
} }
loadSuppliers(logPage: number) { loadSuppliers(logPage: number) {
this.api.externalSuppliers(logPage, this.sortBy, this.sortDir).subscribe( this.api.externalSuppliers(logPage, this.sortBy, this.sortDir, this.perPage).subscribe(
result => { result => {
this.supplierList = result.suppliers; this.supplierList = result.suppliers;
if (this.supplierList) { if (this.supplierList) {

View file

@ -144,7 +144,17 @@ export class ApiService {
); );
} }
public externalSuppliers(data, sortBy, sortDir) { public loadMiscUrl(extra_url) {
const key = this.sessionKey;
return this.http.post<any>(
this.apiUrl + '/v1/' + extra_url,
{
session_key : key,
}
);
}
public externalSuppliers(data, sortBy, sortDir, perPage) {
const key = this.sessionKey; const key = this.sessionKey;
return this.http.post<any>( return this.http.post<any>(
this.apiUrl + '/v1/organisation/external/suppliers', this.apiUrl + '/v1/organisation/external/suppliers',
@ -152,7 +162,8 @@ export class ApiService {
session_key : key, session_key : key,
page : data, page : data,
sort_by : sortBy, sort_by : sortBy,
sort_dir : sortDir sort_dir : sortDir,
per_page : perPage
} }
); );
} }