{"version":3,"sources":["src/app/services/permission/permission.directive.ts"],"sourcesContent":["import {\n Directive,\n ElementRef,\n Input,\n OnDestroy,\n OnInit,\n Renderer2,\n inject,\n} from '@angular/core';\nimport { Store } from '@ngxs/store';\nimport { Subject } from 'rxjs';\nimport { UserState } from 'src/app/store/user/user.state';\n\n@Directive({\n selector: '[vRequiredRoles]',\n})\nexport class CheckRoleDirective implements OnInit, OnDestroy {\n private store = inject(Store);\n\n private renderer = inject(Renderer2);\n\n @Input('vRequiredRoles') roles: string[] = [];\n @Input() permissionUIMode: 'disable' | 'hide' = 'hide';\n\n private onDestroy$ = new Subject();\n\n constructor(private elementRef: ElementRef) {}\n\n ngOnInit() {\n this.store\n .select(UserState.checkPermissionRole(this.roles))\n .subscribe(hasPermission => {\n if (this.permissionUIMode === 'disable') {\n this.setUiModeDisabled(hasPermission);\n } else if (this.permissionUIMode === 'hide') {\n this.setUiModeHidden(hasPermission);\n }\n });\n }\n\n setUiModeDisabled(hasPermission: boolean) {\n if (hasPermission) {\n this.renderer.removeAttribute(this.elementRef.nativeElement, 'disabled');\n } else {\n this.renderer.setAttribute(\n this.elementRef.nativeElement,\n 'disabled',\n 'true'\n );\n }\n }\n\n setUiModeHidden(hasPermission: boolean) {\n if (hasPermission) {\n this.renderer.setStyle(\n this.elementRef.nativeElement,\n 'visibility',\n 'visible'\n );\n } else {\n this.renderer.setStyle(\n this.elementRef.nativeElement,\n 'visibility',\n 'hidden'\n );\n }\n }\n\n ngOnDestroy() {\n this.onDestroy$.next(true);\n this.onDestroy$.unsubscribe();\n }\n}\n"],"names":["CheckRoleDirective","constructor","elementRef","store","inject","Store","renderer","Renderer2","roles","permissionUIMode","onDestroy$","Subject","ngOnInit","select","UserState","checkPermissionRole","subscribe","hasPermission","setUiModeDisabled","setUiModeHidden","removeAttribute","nativeElement","setAttribute","setStyle","ngOnDestroy","next","unsubscribe","ɵɵdirectiveInject","ElementRef","selectors","inputs"],"mappings":";;gIAgBA,IAAaA,GAAkB,IAAA,CAAzB,MAAOA,CAAkB,CAU7BC,YAAoBC,EAAsB,CAAtB,KAAAA,WAAAA,EATZ,KAAAC,MAAQC,EAAOC,CAAK,EAEpB,KAAAC,SAAWF,EAAOG,CAAS,EAEV,KAAAC,MAAkB,CAAA,EAClC,KAAAC,iBAAuC,OAExC,KAAAC,WAAa,IAAIC,CAEoB,CAE7CC,UAAQ,CACN,KAAKT,MACFU,OAAOC,EAAUC,oBAAoB,KAAKP,KAAK,CAAC,EAChDQ,UAAUC,GAAgB,CACrB,KAAKR,mBAAqB,UAC5B,KAAKS,kBAAkBD,CAAa,EAC3B,KAAKR,mBAAqB,QACnC,KAAKU,gBAAgBF,CAAa,CAEtC,CAAC,CACL,CAEAC,kBAAkBD,EAAsB,CAClCA,EACF,KAAKX,SAASc,gBAAgB,KAAKlB,WAAWmB,cAAe,UAAU,EAEvE,KAAKf,SAASgB,aACZ,KAAKpB,WAAWmB,cAChB,WACA,MAAM,CAGZ,CAEAF,gBAAgBF,EAAsB,CAChCA,EACF,KAAKX,SAASiB,SACZ,KAAKrB,WAAWmB,cAChB,aACA,SAAS,EAGX,KAAKf,SAASiB,SACZ,KAAKrB,WAAWmB,cAChB,aACA,QAAQ,CAGd,CAEAG,aAAW,CACT,KAAKd,WAAWe,KAAK,EAAI,EACzB,KAAKf,WAAWgB,YAAW,CAC7B,iDAvDW1B,GAAkB2B,EAAAC,CAAA,CAAA,CAAA,CAAA,+BAAlB5B,EAAkB6B,UAAA,CAAA,CAAA,GAAA,iBAAA,EAAA,CAAA,EAAAC,OAAA,CAAAtB,MAAA,CAAA,EAAA,iBAAA,OAAA,EAAAC,iBAAA,kBAAA,CAAA,CAAA,CAAA,SAAlBT,CAAkB,GAAA","debug_id":"60ff6c47-8503-5e4e-b3a6-26d858255ca4"}