{"ast":null,"code":"import { __decorate } from \"tslib\";\nimport { Component } from '@angular/core';\nimport { FormGroup, FormControl, Validators } from '@angular/forms';\nimport { SuccessModalComponent } from 'src/app/shared/modals/success-modal/success-modal.component';\nlet AddDeviceComponent = class AddDeviceComponent {\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.categories = [];\n    this.brands = [];\n    this.suppliers = [];\n  }\n  ngOnInit() {\n    this.deviceForm = new FormGroup({\n      name: new FormControl('', [Validators.required, Validators.maxLength(60)]),\n      serialNumber: new FormControl('', [Validators.required, Validators.maxLength(100)]),\n      categoryId: new FormControl('', [Validators.required]),\n      brandId: new FormControl('', [Validators.required]),\n      supplierId: new FormControl('', [Validators.required]),\n      isFaulty: new FormControl(false)\n    });\n    this.loadDropdownData();\n  }\n  loadDropdownData() {\n    this.repository.getData('api/categories').subscribe(res => this.categories = res, err => this.errorHandler.handleError(err));\n    this.repository.getData('api/brands').subscribe(res => this.brands = res, err => this.errorHandler.handleError(err));\n    this.repository.getData('api/suppliers').subscribe(res => this.suppliers = res, err => this.errorHandler.handleError(err));\n  }\n  validateControl(controlName) {\n    return this.deviceForm.get(controlName).invalid && this.deviceForm.get(controlName).touched;\n  }\n  hasError(controlName, errorName) {\n    return this.deviceForm.get(controlName).hasError(errorName);\n  }\n  createDevice(deviceFormValue) {\n    if (this.deviceForm.valid) {\n      this.executeDeviceCreation(deviceFormValue);\n    }\n  }\n  executeDeviceCreation(deviceFormValue) {\n    const device = {\n      name: deviceFormValue.name,\n      serialNumber: deviceFormValue.serialNumber,\n      categoryId: deviceFormValue.categoryId,\n      brandId: deviceFormValue.brandId,\n      supplierId: deviceFormValue.supplierId,\n      isFaulty: deviceFormValue.isFaulty\n    };\n    console.log(device);\n    const apiUrl = 'api/devices';\n    this.repository.create(apiUrl, device).subscribe({\n      next: createdDevice => {\n        const config = {\n          initialState: {\n            modalHeaderText: 'Success Message',\n            modalBodyText: `Device: ${createdDevice.name} created successfully`,\n            okButtonText: 'OK'\n          }\n        };\n        this.bsModalRef = this.modal.show(SuccessModalComponent, config);\n        this.bsModalRef.content.redirectOnOk.subscribe(() => this.redirectToDeviceList());\n      },\n      error: err => {\n        this.errorHandler.handleError(err);\n        this.errorMessage = this.errorHandler.errorMessage;\n      }\n    });\n  }\n  redirectToDeviceList() {\n    this.router.navigate(['/ui-components/device']);\n  }\n};\nAddDeviceComponent = __decorate([Component({\n  selector: 'app-add-device',\n  templateUrl: './add-device.component.html',\n  styleUrls: ['./add-device.component.css']\n})], AddDeviceComponent);\nexport { AddDeviceComponent };","map":{"version":3,"names":["Component","FormGroup","FormControl","Validators","SuccessModalComponent","AddDeviceComponent","constructor","repository","errorHandler","router","modal","errorMessage","categories","brands","suppliers","ngOnInit","deviceForm","name","required","maxLength","serialNumber","categoryId","brandId","supplierId","isFaulty","loadDropdownData","getData","subscribe","res","err","handleError","validateControl","controlName","get","invalid","touched","hasError","errorName","createDevice","deviceFormValue","valid","executeDeviceCreation","device","console","log","apiUrl","create","next","createdDevice","config","initialState","modalHeaderText","modalBodyText","okButtonText","bsModalRef","show","content","redirectOnOk","redirectToDeviceList","error","navigate","__decorate","selector","templateUrl","styleUrls"],"sources":["C:\\Users\\fsengul\\Desktop\\MendereIT\\InventoryManagement\\InventryUI-Client\\src\\app\\pages\\ui-components\\device\\add-device\\add-device.component.ts"],"sourcesContent":["import { 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 { 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-device',\n  templateUrl: './add-device.component.html',\n  styleUrls: ['./add-device.component.css']\n})\nexport class AddDeviceComponent implements OnInit {\n\n  public deviceForm: FormGroup | any;\n  public errorMessage: string = '';\n  public bsModalRef?: BsModalRef;\n  public categories: any[] = [];\n  public brands: any[] = [];\n  public suppliers: any[] = [];\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.deviceForm = new FormGroup({\n      name: new FormControl('', [Validators.required, Validators.maxLength(60)]),\n      serialNumber: new FormControl('', [Validators.required, Validators.maxLength(100)]),\n      categoryId: new FormControl('', [Validators.required]),\n      brandId: new FormControl('', [Validators.required]),\n      supplierId: new FormControl('', [Validators.required]),\n      isFaulty: new FormControl(false)\n    });\n\n    this.loadDropdownData();\n  }\n\n  private loadDropdownData() {\n    this.repository.getData('api/categories')\n      .subscribe(res => this.categories = res as any[], err => this.errorHandler.handleError(err));\n    this.repository.getData('api/brands')\n      .subscribe(res => this.brands = res as any[], err => this.errorHandler.handleError(err));\n    this.repository.getData('api/suppliers')\n      .subscribe(res => this.suppliers = res as any[], err => this.errorHandler.handleError(err));\n  }\n\n  validateControl(controlName: string): boolean {\n    return this.deviceForm.get(controlName).invalid && this.deviceForm.get(controlName).touched;\n  }\n\n  hasError(controlName: string, errorName: string): boolean {\n    return this.deviceForm.get(controlName).hasError(errorName);\n  }\n\n  createDevice(deviceFormValue: any): void {\n    if (this.deviceForm.valid) {\n      this.executeDeviceCreation(deviceFormValue);\n    }\n  }\n\n  private executeDeviceCreation(deviceFormValue: any): void {\n    const device = {\n      name: deviceFormValue.name,\n      serialNumber: deviceFormValue.serialNumber,\n      categoryId: deviceFormValue.categoryId,\n      brandId: deviceFormValue.brandId,\n      supplierId: deviceFormValue.supplierId,\n      isFaulty: deviceFormValue.isFaulty\n    };\n console.log(device);\n    const apiUrl = 'api/devices';\n    this.repository.create(apiUrl, device)\n      .subscribe({\n        next: (createdDevice: any) => {\n          const config: ModalOptions = {\n            initialState: {\n              modalHeaderText: 'Success Message',\n              modalBodyText: `Device: ${createdDevice.name} created successfully`,\n              okButtonText: 'OK'\n            }\n          };\n          this.bsModalRef = this.modal.show(SuccessModalComponent, config);\n          this.bsModalRef.content.redirectOnOk.subscribe(() => this.redirectToDeviceList());\n        },\n        error: (err: any) => {\n          this.errorHandler.handleError(err);\n          this.errorMessage = this.errorHandler.errorMessage;\n        }\n      });\n  }\n\n  redirectToDeviceList(): void {\n    this.router.navigate(['/ui-components/device']);\n  }\n\n}\n"],"mappings":";AAAA,SAASA,SAAS,QAAgB,eAAe;AACjD,SAASC,SAAS,EAAEC,WAAW,EAAEC,UAAU,QAAQ,gBAAgB;AAGnE,SAASC,qBAAqB,QAAQ,6DAA6D;AAS5F,IAAMC,kBAAkB,GAAxB,MAAMA,kBAAkB;EAS7BC,YACUC,UAA6B,EAC7BC,YAA2C,EAC3CC,MAAc,EACdC,KAAqB;IAHrB,KAAAH,UAAU,GAAVA,UAAU;IACV,KAAAC,YAAY,GAAZA,YAAY;IACZ,KAAAC,MAAM,GAANA,MAAM;IACN,KAAAC,KAAK,GAALA,KAAK;IAVR,KAAAC,YAAY,GAAW,EAAE;IAEzB,KAAAC,UAAU,GAAU,EAAE;IACtB,KAAAC,MAAM,GAAU,EAAE;IAClB,KAAAC,SAAS,GAAU,EAAE;EAOxB;EAEJC,QAAQA,CAAA;IACN,IAAI,CAACC,UAAU,GAAG,IAAIf,SAAS,CAAC;MAC9BgB,IAAI,EAAE,IAAIf,WAAW,CAAC,EAAE,EAAE,CAACC,UAAU,CAACe,QAAQ,EAAEf,UAAU,CAACgB,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC;MAC1EC,YAAY,EAAE,IAAIlB,WAAW,CAAC,EAAE,EAAE,CAACC,UAAU,CAACe,QAAQ,EAAEf,UAAU,CAACgB,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;MACnFE,UAAU,EAAE,IAAInB,WAAW,CAAC,EAAE,EAAE,CAACC,UAAU,CAACe,QAAQ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