import { Component, EventEmitter, Injector, Output, ViewChild } from '@angular/core'; import { AppComponentBase } from '@shared/common/app-component-base'; import { ModalDirective } from 'ngx-bootstrap'; import { DomSanitizer } from '@angular/platform-browser'; import { FormGroup } from '@angular/forms'; import { FileUploader } from 'ng2-file-upload'; import { SelfHttp } from '@app/shared/common/utils/selfHttp.service'; import { RackTypeLookupTableModalComponent } from '@app/shared/lookup/rackTypeLookup/rackType-lookup-table-modal.component'; import { CreateOrEditWaferAreaFlowDto, CreateOrDeletWaferAreaFlowDto, AreaListDto } from './waferareaflow.model'; import { WaferAreaLookupTableModalComponent } from '@app/shared/lookup/waferAreaLookup/waferArea-lookup-table-modal.component'; import { WaferHttp } from '@app/shared/common/utils/waferhttp.service'; @Component({ selector: 'createOrEditWaferAreaFlowModal', templateUrl: './create-or-edit-waferareaflow-modal.component.html' }) export class CreateOrEditWaferAreaFlowModalComponent extends AppComponentBase { @ViewChild('createOrEditModal') modal: ModalDirective; @ViewChild('waferAreaLookupTableModal') waferAreaLookupTableModal: WaferAreaLookupTableModalComponent; @Output() modalSave: EventEmitter = new EventEmitter(); active = false; saving = false; createOrEditWaferAreaFlowDto: CreateOrEditWaferAreaFlowDto = new CreateOrEditWaferAreaFlowDto(); createOrDeletWaferAreaFlowDto: CreateOrDeletWaferAreaFlowDto = new CreateOrDeletWaferAreaFlowDto(); public uploader: FileUploader; fromCode: string; toCode: string; fromDescription: string; toDescription: string; isEdit = false; selectArea: string; unselectedlist: []; selectedlist: AreaListDto[]; constructor( injector: Injector, public sanitizer: DomSanitizer, public waferHttp: WaferHttp) { super(injector); } show(fromCode?, toCode?): void { const self = this; self.active = true; if (fromCode && toCode) { this.isEdit = true; this.fromCode = fromCode; this.toCode = toCode; this.waferHttp.get('api/WaferTraceAreaFlowManage/getDataForEdit', { FromCode: this.fromCode, ToCode: this.toCode }, res => { let result = JSON.parse(res); this.createOrEditWaferAreaFlowDto.FromCode = result.result[0].FROMAREACODE; this.createOrEditWaferAreaFlowDto.ToCode = result.result[0].TOAREACODE; this.createOrEditWaferAreaFlowDto.FromDescription = result.result[0].FROMAREANAME; this.createOrEditWaferAreaFlowDto.ToDescription = result.result[0].TOAREANAME; this.createOrEditWaferAreaFlowDto.Id = result.result[0].ID; }); } self.modal.show(); } onShown(): void { } getAllArea(fromcode: string): void { const self = this; self.active = true; this.fromCode = fromcode; this.waferHttp.get('api/WaferTraceAreaFlowManage/GetAllArea', { FromCode: this.fromCode }, res => { let result = JSON.parse(res); this.selectedlist = result.result; }); } getUnselectedArea(fromcode: string): void { const self = this; self.active = true; this.fromCode = fromcode; this.waferHttp.get('api/WaferTraceAreaFlowManage/GetUnSelectedArea', { FromCode: this.fromCode }, res => { let result = JSON.parse(res); this.unselectedlist = result.result; }); } openSelectFromAreaModal() { this.waferAreaLookupTableModal.code = this.fromCode; this.waferAreaLookupTableModal.show(); this.selectArea = 'from'; } openSelectToAreaModal() { this.waferAreaLookupTableModal.code = this.toCode; this.waferAreaLookupTableModal.show(); this.selectArea = 'to'; } openToAreaModal() { this.waferAreaLookupTableModal.code = this.toCode; this.waferAreaLookupTableModal.showToArea(this.fromCode); this.selectArea = 'to'; } setFromAreaNull() { this.fromCode = ''; } setToAreaNull() { this.toCode = ''; } getNewWaferArea() { if (this.selectArea === 'from') { this.fromCode = this.waferAreaLookupTableModal.code; this.getAllArea(this.fromCode); this.getUnselectedArea(this.fromCode); } else if ( this.selectArea === 'to') { this.toCode = this.waferAreaLookupTableModal.code; } } // save(): void { // this.createOrEditWaferAreaFlowDto.UserName = this.appSession.getShownLoginName(); // this.createOrEditWaferAreaFlowDto.FromCode = this.fromCode; // this.createOrEditWaferAreaFlowDto.ToCode = this.toCode; // this.waferHttp.post('api/WaferTraceAreaFlowManage/CreateOrEditWaferAreaFlow', this.createOrEditWaferAreaFlowDto, res => { // this.notify.info(this.l('SavedSuccessfully')); // this.close(); // this.modalSave.emit(null); // }); // } save(): void { this.createOrDeletWaferAreaFlowDto.UserName = this.appSession.getShownLoginName(); this.createOrDeletWaferAreaFlowDto.FromCode = this.fromCode; this.createOrDeletWaferAreaFlowDto.ToCodeList = this.selectedlist.map(k => k.TOAREACODE); console.log(this.createOrDeletWaferAreaFlowDto); this.waferHttp.post('api/WaferTraceAreaFlowManage/SaveAreaFlow', this.createOrDeletWaferAreaFlowDto, res => { this.notify.info(this.l('SavedSuccessfully')); this.close(); this.modalSave.emit(null); }); } close(): void { this.fromCode = ''; this.toCode = ''; this.active = false; this.createOrEditWaferAreaFlowDto = new CreateOrEditWaferAreaFlowDto(); this.isEdit = false; this.modal.hide(); } }