From 611aeb0fb93925903753335986c53a25ce9ff05e Mon Sep 17 00:00:00 2001 From: Filippov Date: Fri, 2 Feb 2018 22:00:49 +0300 Subject: [PATCH] add new features --- .../costs-filter/costs-filter.component.html | 3 +++ .../costs-filter/costs-filter.component.ts | 5 +++++ .../costs-list/costs-list.component.ts | 4 ++-- .../modules/finance/services/costs.service.ts | 19 +++++++++++++------ 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/app/modules/finance/components/costs-filter/costs-filter.component.html b/src/app/modules/finance/components/costs-filter/costs-filter.component.html index 3960c2b..f7bb489 100644 --- a/src/app/modules/finance/components/costs-filter/costs-filter.component.html +++ b/src/app/modules/finance/components/costs-filter/costs-filter.component.html @@ -13,6 +13,9 @@ + diff --git a/src/app/modules/finance/components/costs-filter/costs-filter.component.ts b/src/app/modules/finance/components/costs-filter/costs-filter.component.ts index 1319cdf..5e980f4 100644 --- a/src/app/modules/finance/components/costs-filter/costs-filter.component.ts +++ b/src/app/modules/finance/components/costs-filter/costs-filter.component.ts @@ -36,4 +36,9 @@ export class CostsFilterComponent implements OnInit, OnDestroy { let val = e.value; this.costsService.costsSorter(val); } + + formReset() { + this.costsFilterForm.reset(); + this.costsService.resetCostsSorter(); + } } diff --git a/src/app/modules/finance/components/costs-list/costs-list.component.ts b/src/app/modules/finance/components/costs-list/costs-list.component.ts index 4ad5dd2..9338bd9 100644 --- a/src/app/modules/finance/components/costs-list/costs-list.component.ts +++ b/src/app/modules/finance/components/costs-list/costs-list.component.ts @@ -14,7 +14,7 @@ export class CostsListComponent implements OnInit { @Output() costEdited = new EventEmitter(); costs: any = []; costsLoaded: boolean = false; - filterToggle: boolean = false; + filterToggle: boolean = true; notifyOptions: any = { position: ["bottom", "right"], timeOut: 3000, @@ -28,7 +28,7 @@ export class CostsListComponent implements OnInit { ngOnInit() { this.getCosts(); - this.costsService.costsSorted$.subscribe(data => { + this.costsService.costsSortingReset$.subscribe(data => { if (data) { this.costs = this.costsService.costs; } diff --git a/src/app/modules/finance/services/costs.service.ts b/src/app/modules/finance/services/costs.service.ts index d6c57d0..bfae3e4 100644 --- a/src/app/modules/finance/services/costs.service.ts +++ b/src/app/modules/finance/services/costs.service.ts @@ -15,10 +15,10 @@ import {CostsFilterModel} from "../../../models/costs-filter.model"; @Injectable() export class CostsService extends RootService { protected restUrl: string; + dateInterval: DateInterval; - costsFilterParams: any = {}; costsSortedProp: boolean = false; - costsSortAttr: null; + costsSortAttr; costs = []; originalCosts = []; @@ -45,7 +45,6 @@ export class CostsService extends RootService { this.costsFilterModel = model; } - constructor(authHttp: AuthHttp) { super(authHttp); this.restUrl = 'api/costs'; @@ -55,8 +54,8 @@ export class CostsService extends RootService { private costsFetched = new Subject(); costsFetched$ = this.costsFetched.asObservable(); - private costsSorted = new Subject(); - costsSorted$ = this.costsSorted.asObservable(); + private costsSortingReset = new Subject(); + costsSortingReset$ = this.costsSortingReset.asObservable(); setDateInterval(dateInterval: DateInterval): void { this.dateInterval = dateInterval; @@ -79,12 +78,13 @@ export class CostsService extends RootService { let endDate = this.dateInterval.endDate ? this.dateInterval.endDate.toISOString() : null; const fetchUrl = `${this.restUrl}?startDate=${startDate}&endDate=${endDate}`; return this.fetch(options, fetchUrl).finally(() => this.costsFetched.next(true)).map((res: Response) => { + this.costs = []; _.forEach(res, (item) => { this.costs.push(item); this.originalCosts.push(item); }); - if (this.costsSorted && this.costsSortAttr) { + if (this.costsSortedProp) { return this.costsSorter(this.costsSortAttr); } @@ -92,8 +92,15 @@ export class CostsService extends RootService { }); } + resetCostsSorter() { + this.costsSortedProp = false; + this.costs = _.clone(this.originalCosts); + this.costsSortingReset.next(true); + } + costsSorter(sortAttr): any { this.costsSortedProp = true; + this.costsSortAttr = sortAttr; if (sortAttr === 'amount_up') { this.costs.sort((a, b) => {