import { Component, OnInit } from '@angular/core'; import { KGridHelper } from '../../../_helpers/k-grid.class'; import { NotificationService } from '../../../_services/notification.service'; import { AccountService } from '../../accounts/accounts-services'; import { AuthenticationService } from '../../../_services/authentication.service'; import { SortDescriptor, orderBy } from '@progress/kendo-data-query'; import { PageChangeEvent } from '@progress/kendo-angular-grid'; import { StoreService } from '../store.services'; import { LocalService } from '../../../_services/local.service'; @Component({ selector: 'app-item-list', templateUrl: './item-list.component.html', }) export class ItemListComponent implements OnInit { public kGrid: KGridHelper = new KGridHelper(); public openDilogConfirmation = false; public deleting = false; public ItemToDeleteCode = null; constructor(public _notificationService: NotificationService, public _storeService: StoreService, public _authenticationService: AuthenticationService, public _localService: LocalService) { } ngOnInit() { this.initializeProps(); this.getItemList(); } private initializeProps() { this.kGrid.loading = false; this.kGrid.pageSize = 20; this.kGrid.pageSizes = [20, 50, 100]; } public getItemList() { this.kGrid.loading = true; this._storeService.getItemList(this.kGrid.skip, this.kGrid.pageSize, this.kGrid.searchQuery, this.kGrid.hfId, this.kGrid.geoLvlCode, this.kGrid.hfType, this.kGrid.stockId).subscribe( (response: any) => { this.kGrid.data = []; this.kGrid.data = response.DtlList; this.kGrid.totalRecords = response.TotalCount; this.kGrid.gridView = { data: this.kGrid.data, total: this.kGrid.totalRecords }; this.kGrid.loading = false; console.log(this.kGrid.gridView); }, err => this.handleError(err) ); } public sortChange(sort: SortDescriptor[]): void { if (sort[0].field == 'asd') { return; } this.kGrid.sort = sort; this.sortData(); } private sortData() { this.kGrid.gridView = { data: orderBy(this.kGrid.data, this.kGrid.sort), total: this.kGrid.totalRecords }; } public pageChange(event: PageChangeEvent): void { this.kGrid.skip = event.skip; this.getItemList(); } private handleError(err: any) { this.kGrid.loading = false; if (err.status == 403) { this._authenticationService.logout(); } } onBinClick(aid: number) { alert(aid); } public changePagesize(value: any) { this.kGrid.pageSize = +value; this.kGrid.skip = 0; this.getItemList(); } public RemoveItemDefining(e) { this.ItemToDeleteCode = e; this.openDilogConfirmation = true; } public ConfirmDelete() { this._storeService.RemoveItemDefining(this.ItemToDeleteCode).subscribe((res: any) => { this.ItemToDeleteCode = null; this.openDilogConfirmation = false; this._notificationService.notify("success", "Delete Successful"); this.getItemList(); }, err => { this._notificationService.notify("danger", err.error); }); } }