import { Component, OnInit } from '@angular/core'; import { LocalDataSource } from 'ng2-smart-table'; import { SmartTableData } from '../../@core/data/smart-table'; import { PageapiService } from '../pageapi.service'; import { NbToastrService, NbWindowControlButtonsConfig, NbWindowRef, NbWindowService } from '@nebular/theme'; import { UserFormComponent } from './user-form/user-form.component'; import { NbComponentStatus, NbGlobalLogicalPosition, NbGlobalPhysicalPosition, NbGlobalPosition, NbToastrConfig, } from '@nebular/theme'; @Component({ selector: 'ngx-users', templateUrl: './users.component.html', styleUrls: ['./users.component.scss'] }) export class UsersComponent { settings = { actions: { position: 'right', // left|right }, mode: 'external', add: { addButtonContent: '', createButtonContent: '', cancelButtonContent: '', }, edit: { editButtonContent: '', saveButtonContent: '', cancelButtonContent: '', }, delete: { deleteButtonContent: '', confirmDelete: true, }, columns: { index: { title: 'ID', type: 'number', }, userName: { title: 'Name', type: 'string', }, email: { title: 'E-mail', type: 'string', }, mobileNo: { title: 'Mobile No', type: 'string', }, role: { title: 'Role', type: 'string', }, }, }; source: LocalDataSource = new LocalDataSource(); minimize = false; maximize = false; fullScreen = true; close = true; formData:any=[] index = 1; destroyByClick = true; duration = 2000; hasIcon = true; position: NbGlobalPosition = NbGlobalPhysicalPosition.TOP_RIGHT; preventDuplicates = false; status: NbComponentStatus = 'primary'; constructor(private toastrService: NbToastrService,private service: SmartTableData,public _api:PageapiService,private windowService: NbWindowService) { const data = this.service.getData(); this.getuserlistApi() } onDeleteConfirm(event): void { console.log(event) let passData = event.data if (window.confirm('Are you sure you want to delete?')) { //event.confirm.resolve(); let deletedata = {'isActive':0,'id':passData.id} this._api.addUserFormDetails (deletedata).subscribe(res => { if (res.status == 200) { console.log(res) this.getuserlistApi(); this.showToast('success', 'Data Removed Successfully', 'Removed User Data Completed..!'); }else{ this.showToast('warning', 'Somthing is Wrong...!', 'Edit User Data Failed..!'); } }) } else { event.confirm.reject(); } } onCreateConfirm(event) { console.log("Create Event In Console") console.log(event); const buttonsConfig: NbWindowControlButtonsConfig = { minimize: this.minimize, maximize: this.maximize, fullScreen: this.fullScreen, close: this.close, }; let config= { hasBackdrop: true, width: '500px', height: '300px', } const windowRef: NbWindowRef = this.windowService.open(UserFormComponent, { title: `New User`, buttons: buttonsConfig , }); // Subscribe to the afterClosed event windowRef.onClose.subscribe((data) => { // Handle the window closure console.log(data); if(data == 1){ this.showToast('success', 'Data Saved Successfully', 'Add User Data Completed..!'); this.getuserlistApi(); console.log('Window closed 123'); }else if(data == 0){ this.showToast('warning', 'Somthing is Wrong...!', 'Add User Data Failed..!'); } }); } onSaveConfirm(event) { console.log("Edit Event In Console") console.log(event); const buttonsConfig: NbWindowControlButtonsConfig = { minimize: this.minimize, maximize: this.maximize, fullScreen: this.fullScreen, close: this.close, }; const windowRef: NbWindowRef = this.windowService.open(UserFormComponent, { title: `Edit User`, context: event.data , buttons: buttonsConfig }); // Subscribe to the afterClosed event windowRef.onClose.subscribe((data) => { // Handle the window closure console.log(data); if(data == 1){ this.showToast('success', 'Data Changed Successfully', 'Edit User Data Completed..!'); this.getuserlistApi(); console.log('Window closed 123'); }else if(data == 0){ this.showToast('warning', 'Somthing is Wrong...!', 'Edit User Data Failed..!'); } }); } getuserlistApi(){ let param ={} this._api.getusers(param).subscribe(res => { console.log(res) if(res.status == 200){ let passData = res.data let admin = passData.filter(arr=>{return arr.role == 'ADMIN'}) admin.forEach((element:any, index) => { element.index = index +1 }); // console.log(data) this.source.load(admin); } }) } private showToast(type: NbComponentStatus, title: string, body: string) { const config = { status: type, destroyByClick: this.destroyByClick, duration: this.duration, hasIcon: this.hasIcon, position: this.position, preventDuplicates: this.preventDuplicates, }; const titleContent = title ? ` ${title}` : ''; this.index += 1; this.toastrService.show( body, `${titleContent}`, config); } }