import { Component, OnInit } from '@angular/core'; import { PageChangeEvent } from '@progress/kendo-angular-grid'; import { orderBy, SortDescriptor } from '@progress/kendo-data-query'; import { KGridHelper } from '../../../_helpers/k-grid.class'; import { NotificationService } from '../../../_services/notification.service'; import { EmployeeServices } from '../employee-services'; import { LocalService } from '../../../_services/local.service'; import { ItemViewModel } from '../../store/store-model'; import { EventTypeViewModel } from '../employee-class'; @Component({ selector: 'app-event-log-type', templateUrl: './event-log-type.component.html' }) export class EventLogTypeComponent implements OnInit { public kGrid: KGridHelper = new KGridHelper(); public vm: EventTypeViewModel = new EventTypeViewModel(); public createOrUpdateDialog = false; public deleteConfirmationDialog = false; public saving = false; public deleting = false; constructor(public _notificationService: NotificationService, public _employeeServices: EmployeeServices, public _localService: LocalService) { } ngOnInit() { this.initializeProps(); this.getEventLogTypes(); } private initializeProps() { this.kGrid.loading = false; this.kGrid.pageSize = 20; this.kGrid.pageSizes = [20, 50, 100]; } public getEventLogTypes() { this.kGrid.loading = true; this._employeeServices.getEventTypeList().subscribe( (response: any) => { console.log(response) this.kGrid.data = []; this.kGrid.data = response; this.kGrid.totalRecords = response.length; this.kGrid.gridView = { data: this.kGrid.data, total: this.kGrid.totalRecords }; this.kGrid.loading = false; console.log(this.kGrid.gridView); }, err => this.handleError(err) ); } CreateOrUpdateDialog() { this.vm = new EventTypeViewModel(); this.createOrUpdateDialog = true; } EditDialog(item) { this.vm = item; this.createOrUpdateDialog = true; } DeleteDialog(item) { this.vm = item; this.deleteConfirmationDialog = true; } OnSubmit() { this.saving = true; this._employeeServices.saveEventType(this.vm).subscribe((res) => { this._notificationService.notify('success', 'Saved Successfully'); this.saving = false; this.close(); this.getEventLogTypes(); }, (err) => { this._notificationService.notify('danger', 'Something Went Wrong'); }); } OnDelete() { this.deleting = true; this._employeeServices.deleteEventType(this.vm.Id).subscribe((res) => { this._notificationService.notify('success', 'Deleted Successfully'); this.deleting = false; this.close(); this.getEventLogTypes(); }, (err) => { this._notificationService.notify('danger', 'Something Went Wrong'); }); } public close() { this.createOrUpdateDialog = false; this.deleteConfirmationDialog = false; } 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.getEventLogTypes(); } 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.getEventLogTypes(); } }