import { Component, OnInit } from '@angular/core'; import { KGridHelper } from '../../../_helpers/k-grid.class'; import { UserService } from '../user.service'; import { SortDescriptor, orderBy } from '@progress/kendo-data-query'; import { NotificationService } from '../../../_services/notification.service'; @Component({ selector: 'app-role', templateUrl: './role.component.html', styles: [] }) export class RoleComponent implements OnInit { public roles: string[] = []; public newRoleName: string = ''; public alreadyExistRoleName: string = ''; public error: string = ''; public loading: boolean = false; constructor(private _userService: UserService, public _notificationService: NotificationService,) { } ngOnInit() { this.loadRoles(); } private loadRoles() { this.loading = true; this._userService.getRoles().subscribe( response => this.roles = response as string[] ); } public addRole() { this.error = ''; this._userService.registerRole(this.newRoleName).subscribe( (response) => { console.log(response); this.newRoleName = ''; this._notificationService.notify("success", "Save Successfully"); this.loadRoles(); if (response == true) { } else if (response == false) { this.error = 'role name already exist'; this.alreadyExistRoleName = this.newRoleName; } }, err => { this.newRoleName = ''; this._notificationService.notify("danger", "Role name already exist"); }); } }