2018-01-17 17:36:28 +00:00
|
|
|
import { Directive, Component, OnInit } from '@angular/core';
|
|
|
|
import { ApiService } from '../providers/api-service';
|
|
|
|
import { DataType } from '../shared/data-types.enum';
|
2018-01-22 17:23:56 +00:00
|
|
|
import * as moment from 'moment';
|
2018-06-04 14:23:16 +00:00
|
|
|
|
2018-01-17 17:36:28 +00:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
templateUrl: 'category-month.component.html'
|
|
|
|
})
|
|
|
|
export class CategoryMonthComponent implements OnInit {
|
|
|
|
|
2018-01-24 12:38:58 +00:00
|
|
|
disableCategoryButton1: boolean = false;
|
|
|
|
disableCategoryButton2: boolean = false;
|
|
|
|
disableCategoryButton3: boolean = false;
|
|
|
|
disableCategoryButton4: boolean = false;
|
2018-01-17 17:36:28 +00:00
|
|
|
|
|
|
|
weekPurchaseList = {
|
|
|
|
first: 0,
|
|
|
|
};
|
|
|
|
|
2018-01-24 12:51:03 +00:00
|
|
|
weekList1 = [];
|
|
|
|
weekList2 = [];
|
|
|
|
weekList3 = [];
|
|
|
|
weekList4 = [];
|
2018-01-25 11:18:31 +00:00
|
|
|
weekListValueSum1: number = 0;
|
|
|
|
weekListValueSum2: number = 0;
|
|
|
|
weekListValueSum3: number = 0;
|
|
|
|
weekListValueSum4: number = 0;
|
2018-03-02 16:31:14 +00:00
|
|
|
weekEssential1: number = 0;
|
|
|
|
weekEssential2: number = 0;
|
|
|
|
weekEssential3: number = 0;
|
|
|
|
weekEssential4: number = 0;
|
2018-01-24 12:38:58 +00:00
|
|
|
|
2018-01-22 17:23:56 +00:00
|
|
|
dayList: any[] = [];
|
|
|
|
valueList: number[] = [];
|
|
|
|
myWeek1: any;
|
|
|
|
myWeek2: any;
|
|
|
|
myWeek3: any;
|
|
|
|
myWeek4: any;
|
2018-01-24 13:18:51 +00:00
|
|
|
categoryLimit1: number = 6;
|
2018-01-24 12:38:58 +00:00
|
|
|
categoryLimit2: number = 6;
|
|
|
|
categoryLimit3: number = 6;
|
|
|
|
categoryLimit4: number = 6;
|
2018-01-17 17:36:28 +00:00
|
|
|
|
|
|
|
constructor(
|
|
|
|
private api: ApiService,
|
|
|
|
) {
|
2018-01-22 17:23:56 +00:00
|
|
|
this.setDate();
|
2018-01-17 17:36:28 +00:00
|
|
|
this.api.categoryTransactionList().subscribe(
|
|
|
|
result => {
|
2018-01-22 17:23:56 +00:00
|
|
|
this.setData(result);
|
2018-01-17 17:36:28 +00:00
|
|
|
},
|
|
|
|
error => {
|
|
|
|
console.log('Retrieval Error');
|
|
|
|
console.log( error._body );
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-01-24 12:38:58 +00:00
|
|
|
ngOnInit(): void {
|
|
|
|
}
|
|
|
|
|
2018-01-22 17:23:56 +00:00
|
|
|
private setDate () {
|
2018-01-24 12:38:58 +00:00
|
|
|
this.myWeek1 = moment().startOf('isoWeek').format('YYYY-MM-DD');
|
2018-01-22 17:23:56 +00:00
|
|
|
this.myWeek2 = moment(this.myWeek1).subtract(1, 'weeks').format('YYYY-MM-DD');
|
|
|
|
this.myWeek3 = moment(this.myWeek2).subtract(1, 'weeks').format('YYYY-MM-DD');
|
|
|
|
this.myWeek4 = moment(this.myWeek3).subtract(1, 'weeks').format('YYYY-MM-DD');
|
|
|
|
}
|
|
|
|
|
|
|
|
private setData (data: any) {
|
2018-01-24 12:38:58 +00:00
|
|
|
function prop<T, K extends keyof T>(obj: T, key: K) {
|
|
|
|
return obj[key];
|
|
|
|
}
|
2018-03-02 16:31:14 +00:00
|
|
|
this.weekList1 = prop(data.data.categories, this.myWeek1);
|
|
|
|
this.weekList2 = prop(data.data.categories, this.myWeek2);
|
|
|
|
this.weekList3 = prop(data.data.categories, this.myWeek3);
|
|
|
|
this.weekList4 = prop(data.data.categories, this.myWeek4);
|
2018-01-24 13:18:51 +00:00
|
|
|
this.getMaxValue(this.weekList1, this.weekList2, this.weekList3, this.weekList4);
|
2018-03-02 16:31:14 +00:00
|
|
|
this.weekEssential1 = prop(data.data.essentials, this.myWeek1);
|
|
|
|
this.weekEssential2 = prop(data.data.essentials, this.myWeek2);
|
|
|
|
this.weekEssential3 = prop(data.data.essentials, this.myWeek3);
|
|
|
|
this.weekEssential4 = prop(data.data.essentials, this.myWeek4);
|
2018-01-24 13:18:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private getMaxValue (data1: any,
|
|
|
|
data2: any,
|
|
|
|
data3: any,
|
|
|
|
data4: any) {
|
|
|
|
if (data1) {
|
2018-01-25 11:18:31 +00:00
|
|
|
this.weekListValueSum1 = data1.reduce(function (s, a) {return s + a.value;}, 0);
|
2018-01-24 13:18:51 +00:00
|
|
|
}
|
|
|
|
if (data2) {
|
2018-01-25 11:18:31 +00:00
|
|
|
this.weekListValueSum2 = data2.reduce(function (s, a) {return s + a.value;}, 0);
|
2018-01-24 13:18:51 +00:00
|
|
|
}
|
|
|
|
if (data3) {
|
2018-01-25 11:18:31 +00:00
|
|
|
this.weekListValueSum3 = data3.reduce(function (s, a) {return s + a.value;}, 0);
|
2018-01-24 13:18:51 +00:00
|
|
|
}
|
|
|
|
if (data4) {
|
2018-01-25 11:18:31 +00:00
|
|
|
this.weekListValueSum4 = data4.reduce(function (s, a) {return s + a.value;}, 0);
|
2018-01-24 13:18:51 +00:00
|
|
|
}
|
2018-01-22 17:23:56 +00:00
|
|
|
}
|
|
|
|
|
2018-01-24 12:38:58 +00:00
|
|
|
private loadMore1 () {
|
|
|
|
this.disableCategoryButton1 = true;
|
|
|
|
this.categoryLimit1 = 20;
|
|
|
|
}
|
|
|
|
private loadMore2 () {
|
|
|
|
this.disableCategoryButton2 = true;
|
|
|
|
this.categoryLimit2 = 20;
|
|
|
|
}
|
|
|
|
private loadMore3 () {
|
|
|
|
this.disableCategoryButton3 = true;
|
|
|
|
this.categoryLimit3 = 20;
|
|
|
|
}
|
|
|
|
private loadMore4 () {
|
|
|
|
this.disableCategoryButton4 = true;
|
|
|
|
this.categoryLimit4 = 20;
|
2018-01-17 17:36:28 +00:00
|
|
|
}
|
|
|
|
}
|