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';
|
|
|
|
import 'rxjs/add/operator/map';
|
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:38:58 +00:00
|
|
|
weekList1 = {};
|
|
|
|
weekList2 = {};
|
|
|
|
weekList3 = {};
|
|
|
|
weekList4 = {};
|
|
|
|
|
2018-01-17 17:36:28 +00:00
|
|
|
categoryList: number[] = [];
|
2018-01-22 17:23:56 +00:00
|
|
|
dayList: any[] = [];
|
|
|
|
valueList: number[] = [];
|
|
|
|
myWeek1: any;
|
|
|
|
myWeek2: any;
|
|
|
|
myWeek3: any;
|
|
|
|
myWeek4: any;
|
2018-01-24 12:38:58 +00:00
|
|
|
categoryIdList: number[] = [];
|
|
|
|
categoryNameList: string[] = [];
|
|
|
|
categoryLimit1: number = 6;
|
|
|
|
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-24 12:38:58 +00:00
|
|
|
this.api.categoryList().subscribe(
|
|
|
|
result => {
|
|
|
|
this.setCategoryList(result.categories);
|
|
|
|
},
|
|
|
|
error => {
|
|
|
|
console.log('Retrieval Error');
|
|
|
|
console.log( error._body );
|
|
|
|
}
|
|
|
|
);
|
2018-01-17 17:36:28 +00:00
|
|
|
this.api.categoryTransactionList().subscribe(
|
|
|
|
result => {
|
|
|
|
console.log(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 {
|
|
|
|
}
|
|
|
|
|
|
|
|
private setCategoryList(data: any) {
|
|
|
|
this.categoryIdList = Object.keys(data.ids).map(key => data.ids[key]);
|
|
|
|
this.categoryNameList = Object.keys(data.names).map(key => data.names[key]);
|
2018-01-17 17:36:28 +00:00
|
|
|
}
|
|
|
|
|
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');
|
|
|
|
console.log(this.myWeek1);
|
|
|
|
console.log(this.myWeek2);
|
|
|
|
console.log(this.myWeek3);
|
|
|
|
console.log(this.myWeek4);
|
|
|
|
}
|
|
|
|
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
this.weekList1 = prop(data.data, this.myWeek1);
|
|
|
|
this.weekList2 = prop(data.data, this.myWeek2);
|
|
|
|
this.weekList3 = prop(data.data, this.myWeek3);
|
|
|
|
this.weekList4 = prop(data.data, this.myWeek4);
|
|
|
|
console.log(this.weekList1);
|
|
|
|
console.log(this.weekList2);
|
|
|
|
console.log(this.weekList3);
|
|
|
|
console.log(this.weekList4);
|
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
|
|
|
}
|
|
|
|
}
|