diff --git a/dist/app/directives/watch/watch.component.js b/dist/app/directives/watch/watch.component.js index cfbfa18c..10d7c720 100644 --- a/dist/app/directives/watch/watch.component.js +++ b/dist/app/directives/watch/watch.component.js @@ -95,7 +95,7 @@ var WatchComponent = (function () { if (this.watchForm.valid) { this.twapi.upsertWatch(this.watchModel).then(function (res) { ga_service_1.GAService.event('CTA', 'WATCH_UPSERT', 'SUCCESS'); - _this.user.watches.push(res); + _this.user.upsertWatch(res); _this.watchSaved.emit(_this.user); }, function (error) { ga_service_1.GAService.event('CTA', 'WATCH_UPSERT', 'FAIL'); diff --git a/dist/app/directives/watch/watch.component.js.map b/dist/app/directives/watch/watch.component.js.map index 3eee4988..b16ab394 100644 --- a/dist/app/directives/watch/watch.component.js.map +++ b/dist/app/directives/watch/watch.component.js.map @@ -1 +1 @@ -{"version":3,"file":"watch.component.js","sourceRoot":"","sources":["watch.component.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,qBAA+D,eAAe,CAAC,CAAA;AAC/E,uBAA+E,iBAAiB,CAAC,CAAA;AACjG,8BAA2G,6BAA6B,CAAC,CAAA;AACzI,4BAAsB,4BAA4B,CAAC,CAAA;AACnD,2BAAqB,2BAA2B,CAAC,CAAA;AACjD,8BAA2B,gCAAgC,CAAC,CAAA;AAC5D,qBAA6C,eAAe,CAAC,CAAA;AAC7D,uBAAqC,2BAA2B,CAAC,CAAA;AACjE,2BAA0B,6BAA6B,CAAC,CAAA;AAaxD;IAsBE;;;;;OAKG;IACH,wBAAsB,SAA2B,EACvC,KAAmB,EAAU,OAAoB;QADrC,cAAS,GAAT,SAAS,CAAkB;QACvC,UAAK,GAAL,KAAK,CAAc;QAAU,YAAO,GAAP,OAAO,CAAa;QAzBjD,eAAU,GAAG,IAAI,mBAAY,EAAE,CAAC;QAG1C,UAAK,GAAY,IAAI,gBAAO,CAAC,EAAE,EAAE,mBAAU,CAAC,QAAQ,CAAC,CAAC;QACtD,UAAK,GAAY,IAAI,gBAAO,EAAE,CAAC;QA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BAAa,CAAC;YACtB,SAAS,EAAE,CAAC,4BAAY,EAAE,qBAAc,CAAC;YACzC,UAAU,EAAE,CAAC,wBAAe,EAAE,6BAAoB,CAAC;SACpD,CAAC;;sBAAA;IA8HF,qBAAC;AAAD,CAAC,AA1HD,IA0HC;AA1HY,sBAAc,iBA0H1B,CAAA","sourcesContent":["import { Component, Input, EventEmitter, Output, OnInit } from '@angular/core';\nimport {FORM_DIRECTIVES, FormBuilder, Control, ControlGroup, Validators} from '@angular/common';\nimport {TRANSLATE_PROVIDERS, TranslateService, TranslatePipe, TranslateLoader, TranslateStaticLoader} from 'ng2-translate/ng2-translate';\nimport { Watch } from './../../models/watch.model';\nimport { User } from './../../models/user.model';\nimport {TwAPIService} from './../../services/twapi.service';\nimport {Http, HTTP_PROVIDERS, Headers} from '@angular/http';\nimport { MD_BUTTON_DIRECTIVES } from '@angular2-material/button';\nimport { GAService } from './../../services/ga.service';\n\n@Component({\n selector: 'watch-form',\n templateUrl: 'app/directives/watch/watch.component.html',\n styleUrls: ['app/directives/watch/watch.component.css'],\n pipes: [TranslatePipe],\n providers: [TwAPIService, HTTP_PROVIDERS],\n directives: [FORM_DIRECTIVES, MD_BUTTON_DIRECTIVES]\n})\n/**\n * From to add, delete and update watches\n */\nexport class WatchComponent implements OnInit {\n\n @Input() watchModel: Watch;\n @Input() user: User;\n @Output() watchSaved = new EventEmitter();\n\n watchForm: ControlGroup;\n brand: Control = new Control('', Validators.required);\n model: Control = new Control();\n caliber: Control = new Control();\n year: Control = new Control('', Validators.compose(\n [Validators.maxLength(4),\n Validators.minLength(4)]\n ));\n serial: Control = new Control();\n brands: { name: string, icon: string, models: string }[] = [];\n models: string[] = [];\n filteredBrandList: { name: string, icon: string, models: string }[] = [];\n filteredModelList: string[] = [];\n error:boolean = false;\n submitAttempt:boolean = false;\n\n /**\n * Constructor with DI\n * @param {TranslateService} private translate [description]\n * @param {TwAPIService} private twapi [description]\n * @param {FormBuilder} private builder [description]\n */\n constructor(protected translate: TranslateService,\n private twapi: TwAPIService, private builder: FormBuilder) {\n\n translate.setDefaultLang('en');\n translate.use('en');\n\n //Construct form\n this.watchForm = builder.group({\n brand: this.brand,\n model: this.model,\n caliber: this.caliber,\n year: this.year,\n serial: this.serial\n });\n\n //Create an empty watch if none was passed\n if(this.watchModel === undefined){\n this.watchModel = new Watch(null, null);\n }\n }\n\n ngAfterViewInit() {\n //Get the known brands\n this.twapi.getBrands().then(\n res => {\n this.brands = res;\n }\n );\n }\n\n\n /**\n * [selectBrand description]\n * @param {string} brand [description]\n */\n selectBrand(brand: string){\n this.twapi.getModels(brand.toLowerCase()).then(\n res => this.models = res,\n error => this.models = []\n );\n this.filteredBrandList = [];\n this.watchModel.brand = brand;\n }\n\n selectModel(model: string) {\n this.filteredModelList = [];\n this.watchModel.name = model;\n }\n\n filterBrand(brand: string) {\n this.filteredBrandList = this.brands.filter(function(element: { name: string, icon: string, models: string }) {\n return element.name.toLowerCase().indexOf(brand.toLowerCase()) > -1;\n });\n }\n\n filterModel(model:string){\n this.filteredModelList = this.models.filter(function(element:string) {\n return element.toLowerCase().indexOf(model.toLowerCase()) > -1;\n });\n }\n\n ngOnInit() {\n }\n\n onSubmit(){\n this.submitAttempt = true;\n\n if (this.watchForm.valid) {\n this.twapi.upsertWatch(this.watchModel).then(\n res => {\n GAService.event('CTA', 'WATCH_UPSERT', 'SUCCESS');\n this.user.watches.push(res);\n this.watchSaved.emit(this.user)\n },\n error => {\n GAService.event('CTA', 'WATCH_UPSERT', 'FAIL');\n this.error = true\n }\n );\n }\n }\n\n onDelete(){\n this.twapi.deleteWatch(this.user, this.watchModel).then(\n res => {\n GAService.event('CTA', 'WATCH_DELETE', 'SUCCESS');\n this.watchSaved.emit(res)\n },\n error => {\n GAService.event('CTA', 'WATCH_DELETE', 'FAIL');\n this.error = true\n }\n );\n }\n}\n"]} \ No newline at end of file +{"version":3,"file":"watch.component.js","sourceRoot":"","sources":["watch.component.ts"],"names":[],"mappings":";;;;;;;;;;AAA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W,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,IAAI,CACrD,UAAA,GAAG;YACD,sBAAS,CAAC,KAAK,CAAC,KAAK,EAAE,cAAc,EAAE,SAAS,CAAC,CAAC;YAClD,KAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QAC3B,CAAC,EACD,UAAA,KAAK;YACH,sBAAS,CAAC,KAAK,CAAC,KAAK,EAAE,cAAc,EAAE,MAAM,CAAC,CAAC;YAC/C,KAAI,CAAC,KAAK,GAAG,IAAI,CAAA;QACnB,CAAC,CACF,CAAC;IACJ,CAAC;IAvHD;QAAC,YAAK,EAAE;;sDAAA;IACR;QAAC,YAAK,EAAE;;gDAAA;IACR;QAAC,aAAM,EAAE;;sDAAA;IAfX;QAAC,gBAAS,CAAC;YACT,QAAQ,EAAE,YAAY;YACtB,WAAW,EAAE,2CAA2C;YACxD,SAAS,EAAE,CAAC,0CAA0C,CAAC;YACvD,KAAK,EAAE,CAAC,6BAAa,CAAC;YACtB,SAAS,EAAE,CAAC,4BAAY,EAAE,qBAAc,CAAC;YACzC,UAAU,EAAE,CAAC,wBAAe,EAAE,6BAAoB,CAAC;SACpD,CAAC;;sBAAA;IA8HF,qBAAC;AAAD,CAAC,AA1HD,IA0HC;AA1HY,sBAAc,iBA0H1B,CAAA","sourcesContent":["import { Component, Input, EventEmitter, Output, OnInit } from '@angular/core';\nimport {FORM_DIRECTIVES, FormBuilder, Control, ControlGroup, Validators} from '@angular/common';\nimport {TRANSLATE_PROVIDERS, TranslateService, TranslatePipe, TranslateLoader, TranslateStaticLoader} from 'ng2-translate/ng2-translate';\nimport { Watch } from './../../models/watch.model';\nimport { User } from './../../models/user.model';\nimport {TwAPIService} from './../../services/twapi.service';\nimport {Http, HTTP_PROVIDERS, Headers} from '@angular/http';\nimport { MD_BUTTON_DIRECTIVES } from '@angular2-material/button';\nimport { GAService } from './../../services/ga.service';\n\n@Component({\n selector: 'watch-form',\n templateUrl: 'app/directives/watch/watch.component.html',\n styleUrls: ['app/directives/watch/watch.component.css'],\n pipes: [TranslatePipe],\n providers: [TwAPIService, HTTP_PROVIDERS],\n directives: [FORM_DIRECTIVES, MD_BUTTON_DIRECTIVES]\n})\n/**\n * From to add, delete and update watches\n */\nexport class WatchComponent implements OnInit {\n\n @Input() watchModel: Watch;\n @Input() user: User;\n @Output() watchSaved = new EventEmitter();\n\n watchForm: ControlGroup;\n brand: Control = new Control('', Validators.required);\n model: Control = new Control();\n caliber: Control = new Control();\n year: Control = new Control('', Validators.compose(\n [Validators.maxLength(4),\n Validators.minLength(4)]\n ));\n serial: Control = new Control();\n brands: { name: string, icon: string, models: string }[] = [];\n models: string[] = [];\n filteredBrandList: { name: string, icon: string, models: string }[] = [];\n filteredModelList: string[] = [];\n error:boolean = false;\n submitAttempt:boolean = false;\n\n /**\n * Constructor with DI\n * @param {TranslateService} private translate [description]\n * @param {TwAPIService} private twapi [description]\n * @param {FormBuilder} private builder [description]\n */\n constructor(protected translate: TranslateService,\n private twapi: TwAPIService, private builder: FormBuilder) {\n\n translate.setDefaultLang('en');\n translate.use('en');\n\n //Construct form\n this.watchForm = builder.group({\n brand: this.brand,\n model: this.model,\n caliber: this.caliber,\n year: this.year,\n serial: this.serial\n });\n\n //Create an empty watch if none was passed\n if(this.watchModel === undefined){\n this.watchModel = new Watch(null, null);\n }\n }\n\n ngAfterViewInit() {\n //Get the known brands\n this.twapi.getBrands().then(\n res => {\n this.brands = res;\n }\n );\n }\n\n\n /**\n * [selectBrand description]\n * @param {string} brand [description]\n */\n selectBrand(brand: string){\n this.twapi.getModels(brand.toLowerCase()).then(\n res => this.models = res,\n error => this.models = []\n );\n this.filteredBrandList = [];\n this.watchModel.brand = brand;\n }\n\n selectModel(model: string) {\n this.filteredModelList = [];\n this.watchModel.name = model;\n }\n\n filterBrand(brand: string) {\n this.filteredBrandList = this.brands.filter(function(element: { name: string, icon: string, models: string }) {\n return element.name.toLowerCase().indexOf(brand.toLowerCase()) > -1;\n });\n }\n\n filterModel(model:string){\n this.filteredModelList = this.models.filter(function(element:string) {\n return element.toLowerCase().indexOf(model.toLowerCase()) > -1;\n });\n }\n\n ngOnInit() {\n }\n\n onSubmit(){\n this.submitAttempt = true;\n\n if (this.watchForm.valid) {\n this.twapi.upsertWatch(this.watchModel).then(\n res => {\n GAService.event('CTA', 'WATCH_UPSERT', 'SUCCESS');\n this.user.upsertWatch(res);\n this.watchSaved.emit(this.user)\n },\n error => {\n GAService.event('CTA', 'WATCH_UPSERT', 'FAIL');\n this.error = true\n }\n );\n }\n }\n\n onDelete(){\n this.twapi.deleteWatch(this.user, this.watchModel).then(\n res => {\n GAService.event('CTA', 'WATCH_DELETE', 'SUCCESS');\n this.watchSaved.emit(res)\n },\n error => {\n GAService.event('CTA', 'WATCH_DELETE', 'FAIL');\n this.error = true\n }\n );\n }\n}\n"]} \ No newline at end of file diff --git a/src/app/directives/watch/watch.component.ts b/src/app/directives/watch/watch.component.ts index da1d43db..4c93e0b5 100644 --- a/src/app/directives/watch/watch.component.ts +++ b/src/app/directives/watch/watch.component.ts @@ -118,7 +118,7 @@ export class WatchComponent implements OnInit { this.twapi.upsertWatch(this.watchModel).then( res => { GAService.event('CTA', 'WATCH_UPSERT', 'SUCCESS'); - this.user.watches.push(res); + this.user.upsertWatch(res); this.watchSaved.emit(this.user) }, error => {