{"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 AddCategoryComponent_mat_error_11_Template(rf, ctx) {\n  if (rf & 1) {\n    i0.ɵɵelementStart(0, \"mat-error\");\n    i0.ɵɵtext(1, \"\\u0130sim Gerekli\");\n    i0.ɵɵelementEnd();\n  }\n}\nfunction AddCategoryComponent_mat_error_12_Template(rf, ctx) {\n  if (rf & 1) {\n    i0.ɵɵelementStart(0, \"mat-error\");\n    i0.ɵɵtext(1, \"You have more than 60 characters\");\n    i0.ɵɵelementEnd();\n  }\n}\nexport class AddCategoryComponent {\n  constructor(repository, errorHandler, router, modal) {\n    this.repository = repository;\n    this.errorHandler = errorHandler;\n    this.router = router;\n    this.modal = modal;\n    this.errorMessage = '';\n    this.validateControl = controlName => {\n      if (this.categoryForm.get(controlName).invalid && this.categoryForm.get(controlName).touched) return true;\n      return false;\n    };\n    this.hasError = (controlName, errorName) => {\n      if (this.categoryForm.get(controlName).hasError(errorName)) return true;\n      return false;\n    };\n    this.createCategory = categoryFormValue => {\n      if (this.categoryForm.valid) this.executeCategoryCreation(categoryFormValue);\n    };\n    this.executeCategoryCreation = categoryFormValue => {\n      const category = {\n        name: categoryFormValue.name\n      };\n      const apiUrl = 'api/categories';\n      this.repository.create(apiUrl, category).subscribe({\n        next: createdCategory => {\n          const config = {\n            initialState: {\n              modalHeaderText: 'Success Message',\n              modalBodyText: `Category: ${createdCategory.name} created successfully`,\n              okButtonText: 'OK'\n            }\n          };\n          this.bsModalRef = this.modal.show(SuccessModalComponent, config);\n          this.bsModalRef.content.redirectOnOk.subscribe(_ => this.redirectToCategoryList());\n        },\n        error: err => {\n          this.errorHandler.handleError(err);\n          this.errorMessage = this.errorHandler.errorMessage;\n        }\n      });\n    };\n    this.redirectToCategoryList = () => {\n      this.router.navigate(['/ui-components/category']);\n    };\n  }\n  ngOnInit() {\n    this.categoryForm = new FormGroup({\n      name: new FormControl('', [Validators.required, Validators.maxLength(60)])\n    });\n  }\n  static #_ = this.ɵfac = function AddCategoryComponent_Factory(t) {\n    return new (t || AddCategoryComponent)(i0.ɵɵdirectiveInject(i1.RepositoryService), i0.ɵɵdirectiveInject(i2.RepositoryErrorHandlerService), i0.ɵɵdirectiveInject(i3.Router), i0.ɵɵdirectiveInject(i4.BsModalService));\n  };\n  static #_2 = this.ɵcmp = /*@__PURE__*/i0.ɵɵdefineComponent({\n    type: AddCategoryComponent,\n    selectors: [[\"app-add-category\"]],\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\", \"Category 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 AddCategoryComponent_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, \"Yeni Kategori Olu\\u015Ftur\");\n        i0.ɵɵelementEnd()();\n        i0.ɵɵelementStart(5, \"form\", 2);\n        i0.ɵɵlistener(\"ngSubmit\", function AddCategoryComponent_Template_form_ngSubmit_5_listener() {\n          return ctx.createCategory(ctx.categoryForm.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 60 characters long.\");\n        i0.ɵɵelementEnd();\n        i0.ɵɵtemplate(11, AddCategoryComponent_mat_error_11_Template, 2, 0, \"mat-error\", 6)(12, AddCategoryComponent_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, \"Create\");\n        i0.ɵɵelementEnd();\n        i0.ɵɵelementStart(16, \"button\", 8);\n        i0.ɵɵlistener(\"click\", function AddCategoryComponent_Template_button_click_16_listener() {\n          return ctx.redirectToCategoryList();\n        });\n        i0.ɵɵtext(17, \"Cancel\");\n        i0.ɵɵelementEnd()()()()();\n      }\n      if (rf & 2) {\n        i0.ɵɵadvance(5);\n        i0.ɵɵproperty(\"formGroup\", ctx.categoryForm);\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.categoryForm.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    styles: [\"/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiIsInNvdXJjZVJvb3QiOiIifQ== */\"]\n  });\n}","map":{"version":3,"names":["FormGroup","FormControl","Validators","SuccessModalComponent","i0","ɵɵelementStart","ɵɵtext","ɵɵelementEnd","AddCategoryComponent","constructor","repository","errorHandler","router","modal","errorMessage","validateControl","controlName","categoryForm","get","invalid","touched","hasError","errorName","createCategory","categoryFormValue","valid","executeCategoryCreation","category","name","apiUrl","create","subscribe","next","createdCategory","config","initialState","modalHeaderText","modalBodyText","okButtonText","bsModalRef","show","content","redirectOnOk","_","redirectToCategoryList","error","err","handleError","navigate","ngOnInit","required","maxLength","ɵɵdirectiveInject","i1","RepositoryService","i2","RepositoryErrorHandlerService","i3","Router","i4","BsModalService","_2","selectors","decls","vars","consts","template","AddCategoryComponent_Template","rf","ctx","ɵɵlistener","AddCategoryComponent_Template_form_ngSubmit_5_listener","value","ɵɵelement","ɵɵtemplate","AddCategoryComponent_mat_error_11_Template","AddCategoryComponent_mat_error_12_Template","AddCategoryComponent_Template_button_click_16_listener","ɵɵadvance","ɵɵproperty"],"sources":["C:\\Users\\fsengul\\Desktop\\MendereIT\\InventoryManagement\\InventryUI-Client\\src\\app\\pages\\ui-components\\category\\add-category\\add-category.component.ts","C:\\Users\\fsengul\\Desktop\\MendereIT\\InventoryManagement\\InventryUI-Client\\src\\app\\pages\\ui-components\\category\\add-category\\add-category.component.html"],"sourcesContent":["import { HttpErrorResponse } from '@angular/common/http';\nimport { Component, OnInit } from '@angular/core';\nimport { FormGroup, FormControl, Validators } from '@angular/forms';\nimport { Router } from '@angular/router';\nimport { BsModalRef, BsModalService, ModalOptions } from 'ngx-bootstrap/modal';\nimport { Category } from 'src/app/_interface/inventory/category';\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-add-category',\n  templateUrl: './add-category.component.html',\n  styleUrls: ['./add-category.component.css']\n})\nexport class AddCategoryComponent implements OnInit {\n\n  public categoryForm: FormGroup | any;\n  public errorMessage: string = '';\n  public bsModalRef?: BsModalRef;\n\n  constructor(\n    private repository: RepositoryService,\n    private errorHandler: RepositoryErrorHandlerService,\n    private router: Router,\n    private modal: BsModalService\n  ) { }\n\n  ngOnInit(): void {\n    this.categoryForm = new FormGroup({\n      name: new FormControl('', [Validators.required, Validators.maxLength(60)])\n    });\n  }\n\n  validateControl = (controlName: string) => {\n    if (this.categoryForm.get(controlName).invalid && this.categoryForm.get(controlName).touched)\n      return true;\n    \n    return false;\n  }\n\n  hasError = (controlName: string, errorName: string) => {\n    if (this.categoryForm.get(controlName).hasError(errorName))\n      return true;\n    \n    return false;\n  }\n\n  createCategory = (categoryFormValue: any) => {\n    if (this.categoryForm.valid)\n      this.executeCategoryCreation(categoryFormValue);\n  }\n\n  private executeCategoryCreation = (categoryFormValue: any) => {\n    const category: any = {\n      name: categoryFormValue.name\n    };\n\n    const apiUrl = 'api/categories';\n    this.repository.create(apiUrl, category)\n      .subscribe({\n        next: (createdCategory: any) => {\n          const config: ModalOptions = {\n            initialState: {\n              modalHeaderText: 'Success Message',\n              modalBodyText: `Category: ${createdCategory.name} created successfully`,\n              okButtonText: 'OK'\n            }\n          };\n\n          this.bsModalRef = this.modal.show(SuccessModalComponent, config);\n          this.bsModalRef.content.redirectOnOk.subscribe((_: any) => this.redirectToCategoryList());\n        },\n        error: (err: HttpErrorResponse) => {\n          this.errorHandler.handleError(err);\n          this.errorMessage = this.errorHandler.errorMessage;\n        }\n      });\n  }\n\n  redirectToCategoryList = () => {\n    this.router.navigate(['/ui-components/category']);\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>Yeni Kategori Oluştur</mat-card-title>\n    </mat-card-header>\n    <form [formGroup]=\"categoryForm\" autocomplete=\"off\" novalidate (ngSubmit)=\"createCategory(categoryForm.value)\">\n      <mat-card-content>\n        <mat-form-field appearance=\"outline\" class=\"w-100\" color=\"primary\">\n          <input matInput type=\"text\" placeholder=\"Category name\" formControlName=\"name\" id=\"name\">\n          <mat-hint align=\"end\">Not more than 60 characters long.</mat-hint>\n          <mat-error *ngIf=\"hasError('name', 'required')\">İsim Gerekli</mat-error>\n          <mat-error *ngIf=\"hasError('name', 'maxlength')\">You have more than 60 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]=\"!categoryForm.valid\">Create</button>\n        <button type=\"button\" mat-flat-button color=\"warn\" class=\"w-100\" (click)=\"redirectToCategoryList()\">Cancel</button>\n      </mat-card-actions>\n    </form>\n  </mat-card>\n</section>\n\n"],"mappings":"AAEA,SAASA,SAAS,EAAEC,WAAW,EAAEC,UAAU,QAAQ,gBAAgB;AAInE,SAASC,qBAAqB,QAAQ,6DAA6D;;;;;;;;;;;;;;;ICIzFC,EAAA,CAAAC,cAAA,gBAAgD;IAAAD,EAAA,CAAAE,MAAA,wBAAY;IAAAF,EAAA,CAAAG,YAAA,EAAY;;;;;IACxEH,EAAA,CAAAC,cAAA,gBAAiD;IAAAD,EAAA,CAAAE,MAAA,uCAAgC;IAAAF,EAAA,CAAAG,YAAA,EAAY;;;ADIvG,OAAM,MAAOC,oBAAoB;EAM/BC,YACUC,UAA6B,EAC7BC,YAA2C,EAC3CC,MAAc,EACdC,KAAqB;IAHrB,KAAAH,U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