Skip to content

Commit

Permalink
add new features
Browse files Browse the repository at this point in the history
  • Loading branch information
Filippov committed Feb 2, 2018
1 parent 289b389 commit 611aeb0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
</mat-option>
</mat-select>
</mat-form-field>
<button mat-mini-fab [disabled]="!costsService.costsSortedProp" [color]="'primary'" class="" (click)="formReset()" matTooltip="Сбросить фильтры" [matTooltipPosition]="'above'">
<mat-icon class="costs-list-filter-button-icon">close</mat-icon>
</button>
</form>
</mat-list-item>
</mat-list>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class CostsListComponent implements OnInit {
@Output() costEdited = new EventEmitter<boolean>();
costs: any = [];
costsLoaded: boolean = false;
filterToggle: boolean = false;
filterToggle: boolean = true;
notifyOptions: any = {
position: ["bottom", "right"],
timeOut: 3000,
Expand All @@ -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;
}
Expand Down
19 changes: 13 additions & 6 deletions src/app/modules/finance/services/costs.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand All @@ -45,7 +45,6 @@ export class CostsService extends RootService {
this.costsFilterModel = model;
}


constructor(authHttp: AuthHttp) {
super(authHttp);
this.restUrl = 'api/costs';
Expand All @@ -55,8 +54,8 @@ export class CostsService extends RootService {
private costsFetched = new Subject<any>();
costsFetched$ = this.costsFetched.asObservable();

private costsSorted = new Subject<any>();
costsSorted$ = this.costsSorted.asObservable();
private costsSortingReset = new Subject<any>();
costsSortingReset$ = this.costsSortingReset.asObservable();

setDateInterval(dateInterval: DateInterval): void {
this.dateInterval = dateInterval;
Expand All @@ -79,21 +78,29 @@ 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);
}

return this.costs;
});
}

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) => {
Expand Down

0 comments on commit 611aeb0

Please sign in to comment.