import { Component, OnInit } from '@angular/core'; import { FormGroup, FormBuilder } from '@angular/forms'; import { TreeNode } from 'primeng/api'; import { PrivilegeConstants } from '../../../constants/privilege.constants'; import { ProfileService } from '../../../services/profile.service'; import { Profile } from '../profile.model'; import { MenuTreeNode } from '../menu-tree-node.model'; @Component({ selector: 'app-profile-list', templateUrl: './profile-list.component.html', styleUrls: ['./profile-list.component.css'] }) export class ProfileListComponent implements OnInit { profileForm: FormGroup; profile: Profile; profiles: Profile[]; menuList: MenuTreeNode[]; selectedProfile: Profile; menuTreeNode: MenuTreeNode[]; files: TreeNode[]; cols: any[]; selectedMenuItems = []; selectedCities: []; isView: boolean; profileEditPrivilege = PrivilegeConstants.PROFILE_EDIT; profileAddPrivilege = PrivilegeConstants.PROFILE_ADD; profileDeletePrivilege = PrivilegeConstants.PROFILE_DELETE; constructor( private formBuilder: FormBuilder, private profileService: ProfileService ) {} ngOnInit() { this.readProfile(); } readProfile(): void { this.profileService.get().subscribe(data => (this.profiles = data)); } deleteProfile(profile: Profile): void { if (profile.id != null) { if (confirm('Are you sure to delete this record ?') === true) { this.profileService .deleteById(profile.id) .subscribe(() => this.readProfile()); } } } removeProfile(id): void { const index = this.profiles.findIndex(profile => profile.id === id); this.profiles.splice(index, 1); } }