import { Component, ViewChild, Injector, Output, EventEmitter} from '@angular/core'; import { ModalDirective } from 'ngx-bootstrap'; import { finalize } from 'rxjs/operators'; import { ClientAccountsServiceProxy, ClientConnectionDto, ClientConnectionsServiceProxy, CreateOrEditClientAccountDto, CreateOrEditClientConnectionDto, GetClientConnectionForViewDto, OrderSourceDto, OrderSourcesServiceProxy, PagedResultDtoOfGetClientConnectionForViewDto } from '@shared/service-proxies/service-proxies'; import { AppComponentBase } from '@shared/common/app-component-base'; import * as moment from 'moment'; import { CommonLookupCheckboxModalComponent } from '@app/shared/common/lookup/common-lookup-checkbox-modal.component'; import { CommonLookupModalComponent } from '@app/shared/common/lookup/common-lookup-modal.component'; import { AbpSessionService } from 'abp-ng2-module/dist/src/session/abp-session.service'; @Component({ selector: 'createOrEditClientAccountModal', templateUrl: './create-or-edit-client-account-modal.component.html' }) export class CreateOrEditClientAccountModalComponent extends AppComponentBase { @ViewChild('createOrEditModal', { static: true }) modal: ModalDirective; @Output() modalSave: EventEmitter = new EventEmitter(); active = false; saving = false; clientAccount: CreateOrEditClientAccountDto = new CreateOrEditClientAccountDto; connections: ClientConnectionDto[]; orderSources: OrderSourceDto[]; @ViewChild('routeTemplateList', {static: true}) routeTemplateList: CommonLookupModalComponent; routeTemplates: any; routeTemplateIds: number[]; routeTemplate = []; routeTemplateArray = []; searchRouteTemplate: boolean; routeTemplateId: any; txtRouteTemplateFilter: any; showSearchOnStartRouteTemplate: any; selectedRouteTemplate: any; constructor( injector: Injector, private _clientConnectionsServiceProxy: ClientConnectionsServiceProxy, private _clientAccountServiceProxy: ClientAccountsServiceProxy, private _orderSourcesServiceProxy: OrderSourcesServiceProxy, private _sessionService: AbpSessionService, ) { super(injector); } ngOnInit(){ this.getRouteTemplatesInit(); } show(clientAccountId?: number): void { this.getConnections(); this.getOrderSources(); this.clearRouteTemplateList(); if (!clientAccountId) { this.clientAccount = new CreateOrEditClientAccountDto(); this.clientAccount.id = clientAccountId; this.active = true; this.clientAccount.downloadRange = 7 this.clientAccount.downloadFrequency = 1 this.modal.show(); } else { this._clientAccountServiceProxy.getClientAccountForEdit(clientAccountId).subscribe(result => { if(result!=null){ this.clientAccount = result.clientAccount; } this.active = true; this.modal.show(); }); } } save(): void { this.saving = true; this.clientAccount.orderSourceId = $('#Accounts_OrderSource').val()==null ? null : Number($('#Accounts_OrderSource').val()); this.clientAccount.connectionId = $('#Accounts_Connection').val()==null ? null : Number($('#Accounts_Connection').val()); this.clientAccount.tenantId = this._sessionService.tenantId; console.log(this.clientAccount); if(this.clientAccount.accountNumber==null || this.clientAccount.connectionId==null || this.clientAccount.orderSourceId==null){ this.notify.info(this.l('Please provide all of the required field')); this.saving = false; }else{ if(this.clientAccount.downloadFrequency<1 && this.clientAccount.downloadFrequency<=60){ this.message.info('Download Frequency must be greater than 0 and less than 60'); this.saving = false; }else if(this.clientAccount.downloadFrequency>60){ this.message.info('Download Frequency must be less than or equal to 60'); this.saving = false; }else if(this.clientAccount.downloadRange>7){ this.message.info('Download Range must be less than or equal to 7'); this.saving = false; } else{ this._clientAccountServiceProxy.createOrEdit(this.clientAccount) .pipe(finalize(() => { this.saving = false;})) .subscribe(() => { this.notify.info(this.l('SavedSuccessfully')); this.close(); this.modalSave.emit(null); }); } } } close(): void { this.active = false; this.modal.hide(); } getConnections(){ this.spinnerService.show(); this._clientConnectionsServiceProxy.getConnections().subscribe(o =>{ this.connections = o; this.spinnerService.hide(); }); } getOrderSources(){ this.spinnerService.show(); this._orderSourcesServiceProxy.getOrderSources().subscribe(o =>{ this.orderSources = o; this.spinnerService.hide(); }); } onShown(){ $('.kt-select2').select2(); } getRouteTemplatesInit() { this.routeTemplateList.configure({ title: this.l('Select RouteTemplate'), dataSource: (skipCount: number, maxResultCount: number, filter: string, tenantId?: number, locationId?: number) => { console.log(this._clientAccountServiceProxy.getRouteTemplate(filter, undefined, skipCount, maxResultCount)); return this._clientAccountServiceProxy.getRouteTemplate(filter, undefined, skipCount, maxResultCount); } }); } getRouteTemplateList(filter : any) { this.routeTemplateList.show(); this.routeTemplateList.filterText = filter; } clearRouteTemplateList(){ this.txtRouteTemplateFilter = ''; this.routeTemplateId = null; this.showSearchOnStartRouteTemplate = true; } selectRouteTemplate(item) { var resultId = item.value; var name = item.name if (this.searchRouteTemplate) { this.routeTemplateId = resultId; this.txtRouteTemplateFilter = name; this.searchRouteTemplate = false; this.selectedRouteTemplate = name; } else { this.routeTemplateId = resultId; this.txtRouteTemplateFilter = name; this.selectedRouteTemplate = name; this.showSearchOnStartRouteTemplate = false; } } }