-
Notifications
You must be signed in to change notification settings - Fork 44
/
distributor.component.ts
106 lines (89 loc) · 2.86 KB
/
distributor.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import { Component, AfterViewInit } from '@angular/core';
import {
TdDataTableSortingOrder, ITdDataTableSortChangeEvent, ITdDataTableColumn,
TdLoadingService, LoadingType, LoadingMode
} from '@covalent/core';
import { IPageChangeEvent } from '@covalent/core';
import {Distributor, DistributorService} from "../../../services/items.service";
import {UsersService} from "../../../services/users.service";
import {Title} from "@angular/platform-browser";
@Component({
selector: 'app-distributor',
templateUrl: 'distributor.component.html',
styleUrls: ['distributor.component.scss']
})
export class DistributorComponent implements AfterViewInit {
selectedRows = [];
data: Distributor[] = [
];
columns: ITdDataTableColumn[] = [
{name: 'id', label: 'id' },
{name: 'name', label: 'Name' },
{name: 'retail_shop.name', 'label': 'Shop'}
];
filteredData: any[] = this.data;
filteredTotal: number = this.data.length;
shops: number[];
title: string;
searchTerm: string = '';
fromRow: number = 1;
currentPage: number = 1;
pageSize: number = 50;
sortBy: string = 'id';
sortOrder: TdDataTableSortingOrder = TdDataTableSortingOrder.Ascending;
constructor(
private _titleService: Title,
private _loadingService: TdLoadingService,
private _distributorService: DistributorService,
private _userService: UsersService) {
this._loadingService.create({
name: 'products',
type: LoadingType.Circular,
mode: LoadingMode.Indeterminate,
color: 'warn',
});
}
ngAfterViewInit(): void {
this._titleService.setTitle('Product');
this.title = 'Products';
if (this._userService.user) {
this.shops = this._userService.user.retail_shops;
}
this._userService.user$.subscribe((data)=>{
this.shops = data.retail_shops;
});
}
sort(sortEvent: ITdDataTableSortChangeEvent): void {
this.sortBy = sortEvent.name;
this.sortOrder = sortEvent.order;
this.filter();
}
search(searchTerm: string): void {
this.searchTerm = searchTerm;
this.filter();
}
page(pagingEvent: IPageChangeEvent): void {
this.fromRow = pagingEvent.fromRow;
this.currentPage = pagingEvent.page;
this.pageSize = pagingEvent.pageSize;
this.filter();
}
filter(): void {
this._loadingService.register('products');
let sortBy = this.sortBy;
if (this.sortOrder.toString() == 'DESC'){
sortBy = '-'.concat(sortBy);
}
this._distributorService.query({__retail_shop_id__in: this.shops, __include: ['retail_shop'],
__limit: this.pageSize, __page: this.currentPage, __order_by: sortBy})
.subscribe((resp: {data: Distributor[], total: number})=>{
this.data = resp.data;
this.filteredData = resp.data;
this.filteredTotal = resp.total;
this._loadingService.resolve('products');
});
}
goBack():void {
window.history.back();
}
}