{"ast":null,"code":"import { FormGroup, FormControl, Validators } from '@angular/forms';\nimport { SuccessModalComponent } from 'src/app/shared/modals/success-modal/success-modal.component';\nimport * as i0 from \"@angular/core\";\nimport * as i1 from \"src/app/shared/services/repository.service\";\nimport * as i2 from \"src/app/shared/services/repository-error-handler.service\";\nimport * as i3 from \"@angular/router\";\nimport * as i4 from \"ngx-bootstrap/modal\";\nimport * as i5 from \"@angular/common\";\nimport * as i6 from \"@angular/material/form-field\";\nimport * as i7 from \"@angular/material/input\";\nimport * as i8 from \"@angular/material/card\";\nimport * as i9 from \"@angular/material/button\";\nimport * as i10 from \"@angular/flex-layout/flex\";\nimport * as i11 from \"@angular/forms\";\nfunction UpdateRoleComponent_mat_error_11_Template(rf, ctx) {\n  if (rf & 1) {\n    i0.ɵɵelementStart(0, \"mat-error\");\n    i0.ɵɵtext(1, \"Name is required\");\n    i0.ɵɵelementEnd();\n  }\n}\nfunction UpdateRoleComponent_mat_error_12_Template(rf, ctx) {\n  if (rf & 1) {\n    i0.ɵɵelementStart(0, \"mat-error\");\n    i0.ɵɵtext(1, \"You have more than 50 characters\");\n    i0.ɵɵelementEnd();\n  }\n}\nexport class UpdateRoleComponent {\n  constructor(repository, errorHandler, router, modal, route) {\n    this.repository = repository;\n    this.errorHandler = errorHandler;\n    this.router = router;\n    this.modal = modal;\n    this.route = route;\n    this.errorMessage = '';\n    this.roleId = '';\n    this.initializeForm = () => {\n      if (this.roleId) {\n        this.repository.getData(`api/roles/${this.roleId}`).subscribe({\n          next: role => {\n            this.roleForm.setValue({\n              name: role.name\n            });\n          },\n          error: err => {\n            this.errorHandler.handleError(err);\n            this.errorMessage = this.errorHandler.errorMessage;\n          }\n        });\n      }\n    };\n    this.validateControl = controlName => {\n      if (this.roleForm.get(controlName).invalid && this.roleForm.get(controlName).touched) return true;\n      return false;\n    };\n    this.hasError = (controlName, errorName) => {\n      if (this.roleForm.get(controlName).hasError(errorName)) return true;\n      return false;\n    };\n    this.updateRole = roleFormValue => {\n      if (this.roleForm.valid) this.executeRoleUpdate(roleFormValue);\n    };\n    this.executeRoleUpdate = roleFormValue => {\n      const updatedRole = {\n        name: roleFormValue.name\n      };\n      const apiUrl = `api/roles/${this.roleId}`;\n      this.repository.update(apiUrl, updatedRole).subscribe({\n        next: () => {\n          const config = {\n            initialState: {\n              modalHeaderText: 'Success Message',\n              modalBodyText: `Role updated successfully`,\n              okButtonText: 'OK'\n            }\n          };\n          this.bsModalRef = this.modal.show(SuccessModalComponent, config);\n          this.bsModalRef.content.redirectOnOk.subscribe(() => this.redirectToRoleList());\n        },\n        error: err => {\n          this.errorHandler.handleError(err);\n          this.errorMessage = this.errorHandler.errorMessage;\n        }\n      });\n    };\n    this.redirectToRoleList = () => {\n      this.router.navigate(['/ui-components/roles']);\n    };\n  }\n  ngOnInit() {\n    this.roleId = this.route.snapshot.paramMap.get('id');\n    this.roleForm = new FormGroup({\n      name: new FormControl('', [Validators.required, Validators.maxLength(50)])\n    });\n    this.initializeForm();\n  }\n  static #_ = this.ɵfac = function UpdateRoleComponent_Factory(t) {\n    return new (t || UpdateRoleComponent)(i0.ɵɵdirectiveInject(i1.RepositoryService), i0.ɵɵdirectiveInject(i2.RepositoryErrorHandlerService), i0.ɵɵdirectiveInject(i3.Router), i0.ɵɵdirectiveInject(i4.BsModalService), i0.ɵɵdirectiveInject(i3.ActivatedRoute));\n  };\n  static #_2 = this.ɵcmp = /*@__PURE__*/i0.ɵɵdefineComponent({\n    type: UpdateRoleComponent,\n    selectors: [[\"app-update-role\"]],\n    decls: 18,\n    vars: 4,\n    consts: [[\"fxLayout\", \"row wrap\", \"fxLayoutAlign\", \"center center\"], [\"fxFlex\", \"500px\", \"fxFlex.xs\", \"100%\", 1, \"b-1\", \"shadow-none\"], [\"autocomplete\", \"off\", \"novalidate\", \"\", 3, \"ngSubmit\", \"formGroup\"], [\"appearance\", \"outline\", \"color\", \"primary\", 1, \"w-100\"], [\"matInput\", \"\", \"type\", \"text\", \"placeholder\", \"Role name\", \"formControlName\", \"name\", \"id\", \"name\"], [\"align\", \"end\"], [4, \"ngIf\"], [\"mat-flat-button\", \"\", \"color\", \"primary\", 1, \"w-100\", \"action-button\", 3, \"disabled\"], [\"type\", \"button\", \"mat-flat-button\", \"\", \"color\", \"warn\", 1, \"w-100\", 3, \"click\"]],\n    template: function UpdateRoleComponent_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, \"Rol\\u00FC G\\u00FCncelle\");\n        i0.ɵɵelementEnd()();\n        i0.ɵɵelementStart(5, \"form\", 2);\n        i0.ɵɵlistener(\"ngSubmit\", function UpdateRoleComponent_Template_form_ngSubmit_5_listener() {\n          return ctx.updateRole(ctx.roleForm.value);\n        });\n        i0.ɵɵelementStart(6, \"mat-card-content\")(7, \"mat-form-field\", 3);\n        i0.ɵɵelement(8, \"input\", 4);\n        i0.ɵɵelementStart(9, \"mat-hint\", 5);\n        i0.ɵɵtext(10, \"Not more than 50 characters long.\");\n        i0.ɵɵelementEnd();\n        i0.ɵɵtemplate(11, UpdateRoleComponent_mat_error_11_Template, 2, 0, \"mat-error\", 6)(12, UpdateRoleComponent_mat_error_12_Template, 2, 0, \"mat-error\", 6);\n        i0.ɵɵelementEnd()();\n        i0.ɵɵelementStart(13, \"mat-card-actions\")(14, \"button\", 7);\n        i0.ɵɵtext(15, \"Update\");\n        i0.ɵɵelementEnd();\n        i0.ɵɵelementStart(16, \"button\", 8);\n        i0.ɵɵlistener(\"click\", function UpdateRoleComponent_Template_button_click_16_listener() {\n          return ctx.redirectToRoleList();\n        });\n        i0.ɵɵtext(17, \"Cancel\");\n        i0.ɵɵelementEnd()()()()();\n      }\n      if (rf & 2) {\n        i0.ɵɵadvance(5);\n        i0.ɵɵproperty(\"formGroup\", ctx.roleForm);\n        i0.ɵɵadvance(6);\n        i0.ɵɵproperty(\"ngIf\", ctx.hasError(\"name\", \"required\"));\n        i0.ɵɵadvance();\n        i0.ɵɵproperty(\"ngIf\", ctx.hasError(\"name\", \"maxlength\"));\n        i0.ɵɵadvance(2);\n        i0.ɵɵproperty(\"disabled\", !ctx.roleForm.valid);\n      }\n    },\n    dependencies: [i5.NgIf, i6.MatFormField, i6.MatHint, i6.MatError, i7.MatInput, i8.MatCard, i8.MatCardActions, i8.MatCardContent, i8.MatCardHeader, i8.MatCardTitle, i9.MatButton, i10.DefaultLayoutDirective, i10.DefaultLayoutAlignDirective, i10.DefaultFlexDirective, i11.ɵNgNoValidate, i11.DefaultValueAccessor, i11.NgControlStatus, i11.NgControlStatusGroup, i11.FormGroupDirective, i11.FormControlName],\n    encapsulation: 2\n  });\n}","map":{"version":3,"names":["FormGroup","FormControl","Validators","SuccessModalComponent","i0","ɵɵelementStart","ɵɵtext","ɵɵelementEnd","UpdateRoleComponent","constructor","repository","errorHandler","router","modal","route","errorMessage","roleId","initializeForm","getData","subscribe","next","role","roleForm","setValue","name","error","err","handleError","validateControl","controlName","get","invalid","touched","hasError","errorName","updateRole","roleFormValue","valid","executeRoleUpdate","updatedRole","apiUrl","update","config","initialState","modalHeaderText","modalBodyText","okButtonText","bsModalRef","show","content","redirectOnOk","redirectToRoleList","navigate","ngOnInit","snapshot","paramMap","required","maxLength","_","ɵɵdirectiveInject","i1","RepositoryService","i2","RepositoryErrorHandlerService","i3","Router","i4","BsModalService","ActivatedRoute","_2","selectors","decls","vars","consts","template","UpdateRoleComponent_Template","rf","ctx","ɵɵlistener","UpdateRoleComponent_Template_form_ngSubmit_5_listener","value","ɵɵelement","ɵɵtemplate","UpdateRoleComponent_mat_error_11_Template","UpdateRoleComponent_mat_error_12_Template","UpdateRoleComponent_Template_button_click_16_listener","ɵɵadvance","ɵɵproperty"],"sources":["C:\\Users\\fsengul\\Desktop\\MendereIT\\InventoryManagement\\InventryUI-Client\\src\\app\\pages\\ui-components\\roles\\update-role\\update-role.component.ts","C:\\Users\\fsengul\\Desktop\\MendereIT\\InventoryManagement\\InventryUI-Client\\src\\app\\pages\\ui-components\\roles\\update-role\\update-role.component.html"],"sourcesContent":["import { HttpErrorResponse } from '@angular/common/http';\nimport { Component, Inject, OnInit } from '@angular/core';\nimport { FormGroup, FormControl, Validators } from '@angular/forms';\nimport { Router, ActivatedRoute } from '@angular/router';\nimport { BsModalRef, BsModalService, ModalOptions } from 'ngx-bootstrap/modal';\nimport { SuccessModalComponent } from 'src/app/shared/modals/success-modal/success-modal.component';\nimport { RepositoryErrorHandlerService } from 'src/app/shared/services/repository-error-handler.service';\nimport { RepositoryService } from 'src/app/shared/services/repository.service';\n\n@Component({\n  selector: 'app-update-role',\n  templateUrl: './update-role.component.html',\n})\nexport class UpdateRoleComponent implements OnInit {\n\n  public roleForm: FormGroup | any;\n  public errorMessage: string = '';\n  public bsModalRef?: BsModalRef;\n  private roleId: string | null = '';\n\n  constructor(\n    private repository: RepositoryService,\n    private errorHandler: RepositoryErrorHandlerService,\n    private router: Router,\n    private modal: BsModalService,\n    private route: ActivatedRoute\n  ) { }\n\n  ngOnInit(): void {\n    this.roleId = this.route.snapshot.paramMap.get('id');\n    this.roleForm = new FormGroup({\n      name: new FormControl('', [Validators.required, Validators.maxLength(50)])\n    });\n    this.initializeForm();\n  }\n\n  private initializeForm = () => {\n    if (this.roleId) {\n      this.repository.getData(`api/roles/${this.roleId}`)\n        .subscribe({\n          next: (role: any) => {\n            this.roleForm.setValue({\n              name: role.name\n            });\n          },\n          error: (err: HttpErrorResponse) => {\n            this.errorHandler.handleError(err);\n            this.errorMessage = this.errorHandler.errorMessage;\n          }\n        });\n    }\n  }\n\n  validateControl = (controlName: string) => {\n    if (this.roleForm.get(controlName).invalid && this.roleForm.get(controlName).touched)\n      return true;\n\n    return false;\n  }\n\n  hasError = (controlName: string, errorName: string) => {\n    if (this.roleForm.get(controlName).hasError(errorName))\n      return true;\n\n    return false;\n  }\n\n  updateRole = (roleFormValue: any) => {\n    if (this.roleForm.valid)\n      this.executeRoleUpdate(roleFormValue);\n  }\n\n  private executeRoleUpdate = (roleFormValue: any) => {\n    const updatedRole: any = {\n      name: roleFormValue.name\n    };\n\n    const apiUrl = `api/roles/${this.roleId}`;\n    this.repository.update(apiUrl, updatedRole)\n      .subscribe({\n        next: () => {\n          const config: ModalOptions = {\n            initialState: {\n              modalHeaderText: 'Success Message',\n              modalBodyText: `Role updated successfully`,\n              okButtonText: 'OK'\n            }\n          };\n\n          this.bsModalRef = this.modal.show(SuccessModalComponent, config);\n          this.bsModalRef.content.redirectOnOk.subscribe(() => this.redirectToRoleList());\n        },\n        error: (err: HttpErrorResponse) => {\n          this.errorHandler.handleError(err);\n          this.errorMessage = this.errorHandler.errorMessage;\n        }\n      });\n  }\n\n  redirectToRoleList = () => {\n    this.router.navigate(['/ui-components/roles']);\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>Rolü Güncelle</mat-card-title>\n    </mat-card-header>\n    <form [formGroup]=\"roleForm\" autocomplete=\"off\" novalidate (ngSubmit)=\"updateRole(roleForm.value)\">\n      <mat-card-content>\n        <mat-form-field appearance=\"outline\" class=\"w-100\" color=\"primary\">\n          <input matInput type=\"text\" placeholder=\"Role name\" formControlName=\"name\" id=\"name\">\n          <mat-hint align=\"end\">Not more than 50 characters long.</mat-hint>\n          <mat-error *ngIf=\"hasError('name', 'required')\">Name is required</mat-error>\n          <mat-error *ngIf=\"hasError('name', 'maxlength')\">You have more than 50 characters</mat-error>\n        </mat-form-field>\n      </mat-card-content>\n      <mat-card-actions>\n        <button mat-flat-button color=\"primary\" class=\"w-100 action-button\" [disabled]=\"!roleForm.valid\">Update</button>\n        <button type=\"button\" mat-flat-button color=\"warn\" class=\"w-100\" (click)=\"redirectToRoleList()\">Cancel</button>\n      </mat-card-actions>\n    </form>\n  </mat-card>\n</section>\n"],"mappings":"AAEA,SAASA,SAA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