{"ast":null,"code":"import { FormGroup } from '@angular/forms';\nimport * as i0 from \"@angular/core\";\nimport * as i1 from \"src/app/shared/services/repository.service\";\nimport * as i2 from \"@angular/router\";\nimport * as i3 from \"@angular/material/snack-bar\";\nimport * as i4 from \"@angular/common\";\nimport * as i5 from \"@angular/material/checkbox\";\nimport * as i6 from \"@angular/material/form-field\";\nimport * as i7 from \"@angular/material/card\";\nimport * as i8 from \"@angular/material/button\";\nimport * as i9 from \"@angular/flex-layout/flex\";\nfunction UpdateUserRoleComponent_div_8_Template(rf, ctx) {\n  if (rf & 1) {\n    const _r1 = i0.ɵɵgetCurrentView();\n    i0.ɵɵelementStart(0, \"div\")(1, \"mat-checkbox\", 5);\n    i0.ɵɵlistener(\"change\", function UpdateUserRoleComponent_div_8_Template_mat_checkbox_change_1_listener($event) {\n      const role_r2 = i0.ɵɵrestoreView(_r1).$implicit;\n      const ctx_r2 = i0.ɵɵnextContext();\n      return i0.ɵɵresetView(ctx_r2.toggleRoleSelection($event, role_r2.name));\n    });\n    i0.ɵɵtext(2);\n    i0.ɵɵelementEnd()();\n  }\n  if (rf & 2) {\n    const role_r2 = ctx.$implicit;\n    const ctx_r2 = i0.ɵɵnextContext();\n    i0.ɵɵadvance();\n    i0.ɵɵproperty(\"checked\", ctx_r2.isSelected(role_r2.name));\n    i0.ɵɵadvance();\n    i0.ɵɵtextInterpolate1(\" \", role_r2.name, \" \");\n  }\n}\nexport class UpdateUserRoleComponent {\n  constructor(repository, router, route, snackBar) {\n    this.repository = repository;\n    this.router = router;\n    this.route = route;\n    this.snackBar = snackBar;\n    this.roles = []; // Replace 'any' with the specific role type if you have one\n    this.selectedRoles = new Set(); // Track selected roles\n    this.errorMessage = '';\n    this.userId = '';\n    this.loadRoles = () => {\n      this.repository.getData('api/roles') // Endpoint to get all roles\n      .subscribe({\n        next: roles => {\n          this.roles = roles; // Assuming 'roles' is an array of role objects\n        },\n        error: err => {\n          this.errorMessage = 'Error fetching roles';\n        }\n      });\n    };\n    this.initializeForm = () => {\n      if (this.userId) {\n        this.repository.getData(`api/account/users/${this.userId}/roles`) // Fetch user with roles\n        .subscribe({\n          next: userWithRoles => {\n            // Assuming userWithRoles.roles contains an array of role names\n            this.selectedRoles = new Set(userWithRoles.roles || []);\n          },\n          error: err => {\n            this.errorMessage = 'Error fetching user roles';\n          }\n        });\n      }\n    };\n    this.isSelected = roleName => {\n      return this.selectedRoles.has(roleName);\n    };\n    this.toggleRoleSelection = (event, roleName) => {\n      if (event.checked) {\n        this.selectedRoles.add(roleName);\n      } else {\n        this.selectedRoles.delete(roleName);\n      }\n    };\n    this.updateUserRole = () => {\n      if (this.userId) {\n        const apiUrl = `api/account/users/${this.userId}/roles`;\n        this.repository.update(apiUrl, Array.from(this.selectedRoles)).subscribe({\n          next: () => {\n            this.snackBar.open('User roles updated successfully', 'Close', {\n              duration: 2000\n            });\n            this.router.navigate(['/user-list']); // Redirect to user list or another appropriate page\n          },\n          error: err => {\n            this.errorMessage = 'Error updating user roles';\n          }\n        });\n      }\n    };\n    this.redirectToUserList = () => {\n      this.router.navigate(['/user-list']); // Adjust to your specific route\n    };\n  }\n  ngOnInit() {\n    this.userId = this.route.snapshot.paramMap.get('userId');\n    this.userRoleForm = new FormGroup({});\n    this.loadRoles(); // Fetch all roles\n    this.initializeForm(); // Fetch user roles and initialize the form\n  }\n  static #_ = this.ɵfac = function UpdateUserRoleComponent_Factory(t) {\n    return new (t || UpdateUserRoleComponent)(i0.ɵɵdirectiveInject(i1.RepositoryService), i0.ɵɵdirectiveInject(i2.Router), i0.ɵɵdirectiveInject(i2.ActivatedRoute), i0.ɵɵdirectiveInject(i3.MatSnackBar));\n  };\n  static #_2 = this.ɵcmp = /*@__PURE__*/i0.ɵɵdefineComponent({\n    type: UpdateUserRoleComponent,\n    selectors: [[\"app-update-user-role\"]],\n    decls: 14,\n    vars: 1,\n    consts: [[\"fxLayout\", \"row wrap\", \"fxLayoutAlign\", \"center center\"], [\"fxFlex\", \"500px\", \"fxFlex.xs\", \"100%\", 1, \"b-1\", \"shadow-none\"], [4, \"ngFor\", \"ngForOf\"], [\"mat-flat-button\", \"\", \"color\", \"primary\", 1, \"w-100\", \"action-button\", 3, \"click\"], [\"type\", \"button\", \"mat-flat-button\", \"\", \"color\", \"warn\", 1, \"w-100\"], [3, \"change\", \"checked\"]],\n    template: function UpdateUserRoleComponent_Template(rf, ctx) {\n      if (rf & 1) {\n        i0.ɵɵelementStart(0, \"section\", 0)(1, \"mat-card\", 1)(2, \"mat-card-header\")(3, \"mat-card-title\");\n        i0.ɵɵtext(4, \"Update User Roles\");\n        i0.ɵɵelementEnd()();\n        i0.ɵɵelementStart(5, \"mat-card-content\")(6, \"mat-label\");\n        i0.ɵɵtext(7, \"Roles\");\n        i0.ɵɵelementEnd();\n        i0.ɵɵtemplate(8, UpdateUserRoleComponent_div_8_Template, 3, 2, \"div\", 2);\n        i0.ɵɵelementEnd();\n        i0.ɵɵelementStart(9, \"mat-card-actions\")(10, \"button\", 3);\n        i0.ɵɵlistener(\"click\", function UpdateUserRoleComponent_Template_button_click_10_listener() {\n          return ctx.updateUserRole();\n        });\n        i0.ɵɵtext(11, \"Update Roles\");\n        i0.ɵɵelementEnd();\n        i0.ɵɵelementStart(12, \"button\", 4);\n        i0.ɵɵtext(13, \"Cancel\");\n        i0.ɵɵelementEnd()()()();\n      }\n      if (rf & 2) {\n        i0.ɵɵadvance(8);\n        i0.ɵɵproperty(\"ngForOf\", ctx.roles);\n      }\n    },\n    dependencies: [i4.NgForOf, i5.MatCheckbox, i6.MatLabel, i7.MatCard, i7.MatCardActions, i7.MatCardContent, i7.MatCardHeader, i7.MatCardTitle, i8.MatButton, i9.DefaultLayoutDirective, i9.DefaultLayoutAlignDirective, i9.DefaultFlexDirective],\n    styles: [\"/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiIsInNvdXJjZVJvb3QiOiIifQ== */\"]\n  });\n}","map":{"version":3,"names":["FormGroup","i0","ɵɵelementStart","ɵɵlistener","UpdateUserRoleComponent_div_8_Template_mat_checkbox_change_1_listener","$event","role_r2","ɵɵrestoreView","_r1","$implicit","ctx_r2","ɵɵnextContext","ɵɵresetView","toggleRoleSelection","name","ɵɵtext","ɵɵelementEnd","ɵɵadvance","ɵɵproperty","isSelected","ɵɵtextInterpolate1","UpdateUserRoleComponent","constructor","repository","router","route","snackBar","roles","selectedRoles","Set","errorMessage","userId","loadRoles","getData","subscribe","next","error","err","initializeForm","userWithRoles","roleName","has","event","checked","add","delete","updateUserRole","apiUrl","update","Array","from","open","duration","navigate","redirectToUserList","ngOnInit","snapshot","paramMap","get","userRoleForm","_","ɵɵdirectiveInject","i1","RepositoryService","i2","Router","ActivatedRoute","i3","MatSnackBar","_2","selectors","decls","vars","consts","template","UpdateUserRoleComponent_Template","rf","ctx","ɵɵtemplate","UpdateUserRoleComponent_div_8_Template","UpdateUserRoleComponent_Template_button_click_10_listener"],"sources":["C:\\Users\\fsengul\\Desktop\\MendereIT\\InventoryManagement\\InventryUI-Client\\src\\app\\pages\\ui-components\\users\\update-user-role\\update-user-role.component.ts","C:\\Users\\fsengul\\Desktop\\MendereIT\\InventoryManagement\\InventryUI-Client\\src\\app\\pages\\ui-components\\users\\update-user-role\\update-user-role.component.html"],"sourcesContent":["import { HttpErrorResponse } from '@angular/common/http';\nimport { Component, OnInit } from '@angular/core';\nimport { FormGroup, FormBuilder, Validators, FormControl } from '@angular/forms';\nimport { MatSnackBar } from '@angular/material/snack-bar';\nimport { ActivatedRoute, Router } from '@angular/router';\nimport { RepositoryService } from 'src/app/shared/services/repository.service';\n\n@Component({\n  selector: 'app-update-user-role',\n  templateUrl: './update-user-role.component.html',\n  styleUrls: ['./update-user-role.component.css']\n})\nexport class UpdateUserRoleComponent implements OnInit {\n\n  public userRoleForm: FormGroup;\n  public roles: any[] = []; // Replace 'any' with the specific role type if you have one\n  public selectedRoles: Set<string> = new Set(); // Track selected roles\n  public errorMessage: string = '';\n  private userId: string | null = '';\n\n  constructor(\n    private repository: RepositoryService,\n    private router: Router,\n    private route: ActivatedRoute,\n    private snackBar: MatSnackBar\n  ) { }\n\n  ngOnInit(): void {\n    this.userId = this.route.snapshot.paramMap.get('userId');\n    this.userRoleForm = new FormGroup({});\n\n    this.loadRoles(); // Fetch all roles\n    this.initializeForm(); // Fetch user roles and initialize the form\n  }\n\n  private loadRoles = () => {\n    this.repository.getData('api/roles') // Endpoint to get all roles\n      .subscribe({\n        next: (roles: any) => {\n          this.roles = roles; // Assuming 'roles' is an array of role objects\n        },\n        error: (err: HttpErrorResponse) => {\n          this.errorMessage = 'Error fetching roles';\n        }\n      });\n  }\n\n  private initializeForm = () => {\n    if (this.userId) {\n      this.repository.getData(`api/account/users/${this.userId}/roles`) // Fetch user with roles\n        .subscribe({\n          next: (userWithRoles: any) => {\n            // Assuming userWithRoles.roles contains an array of role names\n            this.selectedRoles = new Set(userWithRoles.roles || []);\n          },\n          error: (err: HttpErrorResponse) => {\n            this.errorMessage = 'Error fetching user roles';\n          }\n        });\n    }\n  }\n\n  public isSelected = (roleName: string): boolean => {\n    return this.selectedRoles.has(roleName);\n  }\n\n  public toggleRoleSelection = (event: any, roleName: string) => {\n    if (event.checked) {\n      this.selectedRoles.add(roleName);\n    } else {\n      this.selectedRoles.delete(roleName);\n    }\n  }\n\n  public updateUserRole = () => {\n    if (this.userId) {\n      const apiUrl = `api/account/users/${this.userId}/roles`;\n      this.repository.update(apiUrl, Array.from(this.selectedRoles))\n        .subscribe({\n          next: () => {\n            this.snackBar.open('User roles updated successfully', 'Close', {\n              duration: 2000\n            });\n            this.router.navigate(['/user-list']); // Redirect to user list or another appropriate page\n          },\n          error: (err: HttpErrorResponse) => {\n            this.errorMessage = 'Error updating user roles';\n          }\n        });\n    }\n  }\n\n  private redirectToUserList = () => {\n    this.router.navigate(['/user-list']); // Adjust to your specific route\n  }\n}\n","<section fxLayout=\"row wrap\" fxLayoutAlign=\"center center\">\n  <mat-card fxFlex=\"500px\" fxFlex.xs=\"100%\" class=\"b-1 shadow-none\">\n    <mat-card-header>\n      <mat-card-title>Update User Roles</mat-card-title>\n    </mat-card-header>\n    <mat-card-content>\n      <mat-label>Roles</mat-label>\n      <div *ngFor=\"let role of roles\">\n        <mat-checkbox\n          [checked]=\"isSelected(role.name)\"\n          (change)=\"toggleRoleSelection($event, role.name)\"\n        >\n          {{ role.name }}\n        </mat-checkbox>\n      </div>\n    </mat-card-content>\n    <mat-card-actions>\n      <button mat-flat-button color=\"primary\" class=\"w-100 action-button\" (click)=\"updateUserRole()\">Update Roles</button>\n      <button type=\"button\" mat-flat-button color=\"warn\" class=\"w-100\" >Cancel</button>\n    </mat-card-actions>\n  </mat-card>\n</section>\n"],"mappings":"AAEA,SAASA,SAAS,QAA8C,gBAAgB;;;;;;;;;;;;;;ICMxEC,EADF,CAAAC,cAAA,UAAgC,sBAI7B;IADCD,EAAA,CAAAE,UAAA,oBAAAC,sEAAAC,MAAA;MAAA,MAAAC,OAAA,GAAAL,EAAA,CAAAM,aAAA,CAAAC,GAAA,EAAAC,SAAA;MAAA,MAAAC,MAAA,GAAAT,EAAA,CAAAU,aAAA;MAAA,OAAAV,EAAA,CAAAW,WAAA,CAAUF,MAAA,CAAAG,mBAAA,CAAAR,MAAA,EAAAC,OAAA,CAAAQ,IAAA,CAAsC;IAAA,EAAC;IAEjDb,EAAA,CAAAc,MAAA,GACF;IACFd,EADE,CAAAe,YAAA,EAAe,EACX;;;;;IALFf,EAAA,CAAAgB,SAAA,EAAiC;IAAjChB,EAAA,CAAAiB,UAAA,YAAAR,MAAA,CAAAS,UAAA,CAAAb,OAAA,CAAAQ,IAAA,EAAiC;IAGjCb,EAAA,CAAAgB,SAAA,EACF;IADEhB,EAAA,CAAAmB,kBAAA,MAAAd,OAAA,CAAAQ,IAAA,MACF;;;ADDR,OAAM,MAAOO,uBAAuB;EAQlCC,YACUC,UAA6B,EAC7BC,MAAc,EACdC,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