{"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\";\nfunction AddBrandComponent_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 AddBrandComponent_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 AddBrandComponent {\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.brandForm.get(controlName).invalid && this.brandForm.get(controlName).touched) return true;\n      return false;\n    };\n    this.hasError = (controlName, errorName) => {\n      if (this.brandForm.get(controlName).hasError(errorName)) return true;\n      return false;\n    };\n    this.createBrand = brandFormValue => {\n      if (this.brandForm.valid) this.executeBrandCreation(brandFormValue);\n    };\n    this.executeBrandCreation = brandFormValue => {\n      const brand = {\n        name: brandFormValue.name\n      };\n      console.log(brand);\n      const apiUrl = 'api/brands';\n      this.repository.create(apiUrl, brand).subscribe({\n        next: createdBrand => {\n          const config = {\n            initialState: {\n              modalHeaderText: 'Success Message',\n              modalBodyText: `Brand: ${createdBrand.name} created successfully`,\n              okButtonText: 'OK'\n            }\n          };\n          this.bsModalRef = this.modal.show(SuccessModalComponent, config);\n          this.bsModalRef.content.redirectOnOk.subscribe(_ => this.redirectToBrandList());\n        },\n        error: err => {\n          this.errorHandler.handleError(err);\n          this.errorMessage = this.errorHandler.errorMessage;\n        }\n      });\n    };\n    this.redirectToBrandList = () => {\n      this.router.navigate(['/ui-components/brand']);\n    };\n  }\n  ngOnInit() {\n    this.brandForm = new FormGroup({\n      name: new FormControl('', [Validators.required, Validators.maxLength(60)])\n    });\n  }\n  static #_ = this.ɵfac = function AddBrandComponent_Factory(t) {\n    return new (t || AddBrandComponent)(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: AddBrandComponent,\n    selectors: [[\"app-add-brand\"]],\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\", \"Brand 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 AddBrandComponent_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 marka olu\\u015Ftur\");\n        i0.ɵɵelementEnd()();\n        i0.ɵɵelementStart(5, \"form\", 2);\n        i0.ɵɵlistener(\"ngSubmit\", function AddBrandComponent_Template_form_ngSubmit_5_listener() {\n          return ctx.createBrand(ctx.brandForm.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, \"En fazla 60 karakter uzunlu\\u011Funda olmal\\u0131d\\u0131r.\");\n        i0.ɵɵelementEnd();\n        i0.ɵɵtemplate(11, AddBrandComponent_mat_error_11_Template, 2, 0, \"mat-error\", 6)(12, AddBrandComponent_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, \"Olu\\u015Ftur\");\n        i0.ɵɵelementEnd();\n        i0.ɵɵelementStart(16, \"button\", 8);\n        i0.ɵɵlistener(\"click\", function AddBrandComponent_Template_button_click_16_listener() {\n          return ctx.redirectToBrandList();\n        });\n        i0.ɵɵtext(17, \"\\u00C7\\u0131k\");\n        i0.ɵɵelementEnd()()()()();\n      }\n      if (rf & 2) {\n        i0.ɵɵadvance(5);\n        i0.ɵɵproperty(\"formGroup\", ctx.brandForm);\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.brandForm.valid);\n      }\n    },\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","AddBrandComponent","constructor","repository","errorHandler","router","modal","errorMessage","validateControl","controlName","brandForm","get","invalid","touched","hasError","errorName","createBrand","brandFormValue","valid","executeBrandCreation","brand","name","console","log","apiUrl","create","subscribe","next","createdBrand","config","initialState","modalHeaderText","modalBodyText","okButtonText","bsModalRef","show","content","redirectOnOk","_","redirectToBrandList","error","err","handleError","navigate","ngOnInit","required","maxLength","ɵɵdirectiveInject","i1","RepositoryService","i2","RepositoryErrorHandlerService","i3","Router","i4","BsModalService","_2","selectors","decls","vars","consts","template","AddBrandComponent_Template","rf","ctx","ɵɵlistener","AddBrandComponent_Template_form_ngSubmit_5_listener","value","ɵɵelement","ɵɵtemplate","AddBrandComponent_mat_error_11_Template","AddBrandComponent_mat_error_12_Template","AddBrandComponent_Template_button_click_16_listener","ɵɵadvance","ɵɵproperty"],"sources":["C:\\Users\\Cem\\Desktop\\InventryUI-Client\\src\\app\\pages\\ui-components\\brand\\add-brand\\add-brand.component.ts","C:\\Users\\Cem\\Desktop\\InventryUI-Client\\src\\app\\pages\\ui-components\\brand\\add-brand\\add-brand.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 { 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-brand',\n  templateUrl: './add-brand.component.html',\n  styleUrls: ['./add-brand.component.css']\n})\nexport class AddBrandComponent implements OnInit {\n  public brandForm: 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.brandForm = new FormGroup({\n      name: new FormControl('', [Validators.required, Validators.maxLength(60)])\n    });\n  }\n\n  validateControl = (controlName: string) => {\n    if (this.brandForm.get(controlName).invalid && this.brandForm.get(controlName).touched)\n      return true;\n    \n    return false;\n  }\n\n  hasError = (controlName: string, errorName: string) => {\n    if (this.brandForm.get(controlName).hasError(errorName))\n      return true;\n    \n    return false;\n  }\n\n  createBrand = (brandFormValue: any) => {\n    if (this.brandForm.valid)\n      this.executeBrandCreation(brandFormValue);\n  }\n\n  private executeBrandCreation = (brandFormValue: any) => {\n    const brand: any = {\n      name: brandFormValue.name\n    };\n\n    console.log(brand);\n    const apiUrl = 'api/brands';\n    this.repository.create(apiUrl, brand)\n      .subscribe({\n        next: (createdBrand: any) => {\n          const config: ModalOptions = {\n            initialState: {\n              modalHeaderText: 'Success Message',\n              modalBodyText: `Brand: ${createdBrand.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.redirectToBrandList());\n        },\n        error: (err: HttpErrorResponse) => {\n          this.errorHandler.handleError(err);\n          this.errorMessage = this.errorHandler.errorMessage;\n        }\n      });\n  }\n\n  redirectToBrandList = () => {\n    this.router.navigate(['/ui-components/brand']);\n  }\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 marka oluştur</mat-card-title>\n    </mat-card-header>\n    <form [formGroup]=\"brandForm\" autocomplete=\"off\" novalidate (ngSubmit)=\"createBrand(brandForm.value)\">\n      <mat-card-content>\n        <mat-form-field appearance=\"outline\" class=\"w-100\" color=\"primary\">\n          <input matInput type=\"text\" placeholder=\"Brand name\" formControlName=\"name\" id=\"name\">\n          <mat-hint align=\"end\">En fazla 60 karakter uzunluğunda olmalıdır.</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 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]=\"!brandForm.valid\">Oluştur</button>\n        <button type=\"button\" mat-flat-button color=\"warn\" class=\"w-100\" (click)=\"redirectToBrandList()\">Çık</button>\n      </mat-card-actions>\n    </form>\n  </mat-card>\n</section>\n\n"],"mappings":"AAEA,SAASA,SAAS,EAAEC,WAAW,EAAEC,UAAU,QAAQ,gBAAgB;AAGnE,SAASC,qBAAqB,QAAQ,6DAA6D;;;;;;;;ICKzFC,EAAA,CAAAC,cAAA,gBAAgD;IAAAD,EAAA,CAAAE,MAAA,uBAAgB;IAAAF,EAAA,CAAAG,YAAA,EAAY;;;;;IAC5EH,EAAA,CAAAC,cAAA,gBAAiD;IAAAD,EAAA,CAAAE,MAAA,uCAAgC;IAAAF,EAAA,CAAAG,YAAA,EAAY;;;ADGvG,OAAM,MAAOC,iBAAiB;EAK5BC,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;IAPR,KAAAC,YAAY,GAAW,EAAE;IAgBhC,KAAAC,eAAe,GAAIC,WAAmB,IAAI;MACxC,IAAI,IAAI,CAACC,SAAS,CAACC,GAAG,CAACF,WAAW,CAAC,CAACG,OAAO,IAAI,IAAI,CAACF,SAAS,CAACC,GAAG,CAACF,WAAW,CAAC,CAACI,OAAO,EACpF,OAAO,IAAI;MAEb,OAAO,KAAK;IACd,CAAC;IAED,KAAAC,QAAQ,GAAG,CAACL,WAAmB,EAAEM,SAAiB,KAAI;MACpD,IAAI,IAAI,CAACL,SAAS,CAACC,GAAG,CAACF,WAAW,CAAC,CAACK,QA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