import { Component, Injector, OnInit, ViewChild, ViewEncapsulation } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { appModuleAnimation } from '@shared/animations/routerTransition'; import { AppComponentBase } from '@shared/common/app-component-base'; import { DataType, ImportMappingsServiceProxy, ImportType } from '@shared/service-proxies/service-proxies'; import { CreateOrEditOrderSourceModalComponent } from './create-or-edit-orderSource-modal.component'; import { Location } from '@angular/common'; @Component({ templateUrl: './view-ordersource-mapping.component.html', encapsulation: ViewEncapsulation.None, animations: [appModuleAnimation()] }) export class OrderSourceMappingsComponent extends AppComponentBase { @ViewChild(CreateOrEditOrderSourceModalComponent, {static: false}) createOrEditMapping; mapping: any = []; orderSourceId: number; maxResultCount: number = 1000; goBackHistory: number; importType = ImportType; dataType = DataType; constructor ( injector: Injector, private _importMappingsServiceProxy: ImportMappingsServiceProxy, private _route: ActivatedRoute, private _location: Location ) { super(injector); } ngOnInit() { this.goBackHistory = window.history.length; this._route.paramMap.subscribe(params => { this.orderSourceId = parseInt(params.get('id')); }); this.getMappings(); } getMappings() { this.mapping = []; this._importMappingsServiceProxy.getAll( undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, this.orderSourceId, undefined, undefined, this.maxResultCount ).subscribe(result => { result.items.forEach(items => { this.mapping.push(items.importMapping); }); }); } createMappings() { this.spinnerService.show(); this._importMappingsServiceProxy.createMapping(this.orderSourceId).subscribe(() =>{ this.getMappings(); this.notify.info('Mappings successfully created'); this.spinnerService.hide(); }); } deleteImportMapping(id: number): void { this.message.confirm( '', '', (isConfirmed) => { if (isConfirmed) { this._importMappingsServiceProxy.delete(id) .subscribe(() => { this.getMappings(); this.notify.success(this.l('SuccessfullyDeleted')); }); } } ); } goBack() { this._location.back(); } }