import { Component, ViewChild, Injector, Output, EventEmitter } from '@angular/core'; import { ModalDirective } from 'ngx-bootstrap'; import { finalize } from 'rxjs/operators'; import { TimeZoneServiceProxy, OrderNotificationOrderStatusTypeLookupTableDto, UserListDto, OrganizationUnitDto, OrderNotificationSmsTemplateLookupTableDto, OrderNotificationOrderTypeLookupTableDto, OrderNotificationsServiceProxy, CreateOrEditOrderNotificationDto, OrderNotificationOrderNotificationTemplateLookupTableDto , OrganizationUnitServiceProxy, CreateOrEditOrganizationUnitOrderNotificationDto, OrganizationUnitOrderNotificationsServiceProxy, OrganizationUnitOrderNotificationDto, ReportScheduleServiceProxy, CreateOrEditReportScheduleDto, CreateOrEditReportRecipientDto, ReportSchedulerServiceProxy, LocationServiceProxy, LocationNameDto, ParameterValueNameDto, ReportScheduleParameterCheckerInput } from '@shared/service-proxies/service-proxies'; import { AppComponentBase } from '@shared/common/app-component-base'; import * as moment from 'moment'; import { NUMBER_TYPE } from '@angular/compiler/src/output/output_ast'; import { ColorTransformCollection } from 'devexpress-richedit/lib/core/model/drawing/transform/color-transform-collection'; import { value } from 'devexpress-dashboard/model/index.metadata'; declare var $: any; @Component({ selector: 'editReportScheduleModalComponent', templateUrl: './edit-report-schedule-modal.component.html', providers: [ReportScheduleServiceProxy, ReportSchedulerServiceProxy] }) export class EditReportScheduleModalComponent extends AppComponentBase { @ViewChild('createOrEditModal', { static: true }) modal: ModalDirective; @Output() modalSave: EventEmitter = new EventEmitter(); active = false; saving = false; delete: any; form: any; isEmail: boolean; isSMS: boolean; organizationUnitId: any; // allOrganizationUnits: any; orderNotification: CreateOrEditOrderNotificationDto = new CreateOrEditOrderNotificationDto(); activeTabIndex: number = 0; orderNotificationTemplateDescription = ''; orderStatusTypeDescription = ''; smsTemplateDescription = ''; orderTypeDescription = ''; OrganizationalUnitNotification: any; organizationUnitOrderNotification: any; orgUnits: CreateOrEditOrganizationUnitOrderNotificationDto = new CreateOrEditOrganizationUnitOrderNotificationDto(); allOrderNotificationTemplates: OrderNotificationOrderNotificationTemplateLookupTableDto[]; allOrderStatusTypes: OrderNotificationOrderStatusTypeLookupTableDto[]; allSmsTemplates: OrderNotificationSmsTemplateLookupTableDto[]; allOrderTypes: OrderNotificationOrderTypeLookupTableDto[]; allUsers: UserListDto[]; allOrganizationUnits: OrganizationUnitDto[]; addOrg: any; input: any; // input: CreateOrEditReportScheduleDto= new CreateOrEditReportScheduleDto(); reportId: number; schedulerDescription: string; schedulerStartDate: Date; schedulerStartTime: any; repeat: number; startDay : number; exportType: any; schedulerIsActive: boolean; ftpIsActive : boolean; recipientInput: any reportScheduleRecipient: any; exists: boolean = false params: any reportScheduleId: number getLocationNames: LocationNameDto[]; dropdownValidation : boolean = false repeatValidation : boolean = false startDayValidation : boolean = false exportTypeValidation : boolean = false parameterNameValue: ParameterValueNameDto = new ParameterValueNameDto(); listParameterValueName : Array<{ pname: string, pvalue: string, pMultiValue: boolean }> = new Array(); timeZones: any; defaultTz: any; tz: any; ftpServerName: string; ftpUserName: string; ftpPassword: string; ftpFolderName: string; timeInterval: any; constructor( injector: Injector, private _orderNotificationsServiceProxy: OrderNotificationsServiceProxy, private _reportScheduleServiceProxy : ReportScheduleServiceProxy, private _organizationUnitService: OrganizationUnitServiceProxy, private _organizationUnitOrderNotification: OrganizationUnitOrderNotificationsServiceProxy, private _scheduler: ReportSchedulerServiceProxy, private _locationServiceProxy: LocationServiceProxy, private _timeZoneServiceProxy: TimeZoneServiceProxy ) { super(injector); } ngOnInit(): void { $('.kt-select2').select2(); $('.organization-unit').select2(); $('.user').select2(); } onShown(): void { let s = this; // this.repeatValidation = false; // this.startDayValidation = false // this.exportTypeValidation = false $('.kt-select2').select2(); $('.organization-unit').select2(); $('.user').select2(); // this.getParams(); if(this.listParameterValueName != null){ setTimeout(() => { this.listParameterValueName.forEach(element => { $('#'+element.pname).val(element.pvalue) // console.log(element.pvalue+"onshown") $('.kt-select2').select2(); }); }, 2000); } // var that = this; // $('#repeatInput').change(function() { // that.repeatValidation=true // console.log("repeatValidation"+that.repeatValidation) // }); // //startDateValidation // $('#startDayInput').change(function() { // that.startDayValidation=true // console.log("startDayValidation"+that.startDayValidation) // }); // $('#exportTypeInput').change(function() { // that.exportTypeValidation=true // console.log("exportTypeValidation"+that.exportTypeValidation) // }); // $('.kt-select2').on('select2:select', function (e) { // console.log(s.organizationUnitOrderNotification) // }); $('#repeatInput').change(function() { s.repeatValidation=true s.repeat= $('#repeatInput').val(); console.log(s.repeat) setTimeout(() => { $('#startDayInput').select2(); }, 1000); // console.log("repeatValidation"+that.repeatValidation) }); } show(reportScheduleId: number, reportId : number): void { // $('.kt-select2').select2(); let s = this; this.reportScheduleId = reportScheduleId this.reportId = reportId // this.organizationUnitOrderNotification = []; this.reportScheduleRecipient = [] this.spinnerService.show(); this.getEditReportSchedule(reportScheduleId); this._orderNotificationsServiceProxy.getAllUserForTableDropdown().subscribe(result => { this.allUsers = result; }); this._orderNotificationsServiceProxy.getAllOrgUnitsForTableDropdown().subscribe(result => { this.allOrganizationUnits = result; }); this._timeZoneServiceProxy.getTimeZoneForDropDown( ).subscribe(result => { this.timeZones = result.items; }); // this._orderNotificationsServiceProxy.getAllOrderTypeForTableDropdown().subscribe(result => { // this.allOrderTypes = result; // }); } getEditReportSchedule(reportScheduleId: number){ this._reportScheduleServiceProxy.getReportScheduleForEdit(reportScheduleId) .subscribe(result=> { this.exportType=[] let startTime = result.startDate.toDate().toDateString() + ' ' + result.startTime; this.reportId = result.reportId this.schedulerDescription = result.description // this.schedulerStartDate = new Date(result.) this.schedulerStartDate = result.startDate.toDate() this.schedulerStartTime = moment(startTime).toDate(); this.repeat = result.repeat; this.startDay = result.startDay this.exportType = result.exportType.split(",") this.schedulerIsActive = result.isActive this.ftpIsActive = result.ftpIsActive; this.ftpServerName= result.ftpServerName; this.ftpUserName= result.ftpUserName; this.ftpPassword= result.ftpPassword; this.ftpFolderName = result.ftpFolderName; this.defaultTz = result.timeZone; this.timeInterval = result.timeInterval; result.recipients.forEach(element => { this.reportScheduleRecipient.push(element) }); this.listParameterValueName=[] this._reportScheduleServiceProxy.getReportParameters(this.reportId) .pipe() .subscribe(result2=>{ this.params = result2 for(let a = 0; a < result.parameterNameValue.length ; a++){ if(this.params.map(function(e) { return e.name; }).indexOf(result.parameterNameValue[a].parameterName) >-1){ var paramIndex = this.params.map(function(e) { return e.name; }).indexOf(result.parameterNameValue[a].parameterName) this.listParameterValueName.push({pname:result.parameterNameValue[a].parameterName, pvalue:result.parameterNameValue[a].parameterValue, pMultiValue: paramIndex > -1 ? this.params[paramIndex].multiValue : false}) } } if(this.listParameterValueName != null){ var count= []; setTimeout(() => { this.listParameterValueName.forEach(element => { if(element.pMultiValue == true){ count.push(element.pvalue) $('#'+element.pname).val(count) $('.kt-select2').select2(); } else{ $('#'+element.pname).val(element.pvalue) $('.kt-select2').select2(); } $('.kt-select2').select2(); }); }, 2000); } }) this.active = true; this.spinnerService.hide() this.modal.show(); }) } updateUnits(id, data): void { // this.organizationUnitOrderNotification[id].organizationUnitId = data; this.reportScheduleRecipient[id].organizationUnitId = data; setTimeout(() => { $('.organization-unit').select2(); $('.user').select2(); }, 100); } updateUsers(id, data): void { // this.organizationUnitOrderNotification[id].userId = data; this.reportScheduleRecipient[id].userId = data; setTimeout(() => { $('.organization-unit').select2(); $('.user').select2(); }, 100); } updateRecipientType(id, data): void { let s = this; // this.organizationUnitOrderNotification[id].code = data; this.reportScheduleRecipient[id].code = data; setTimeout(() => { $('.organization-unit').select2(); $('.user').select2(); $('.organization-unit').on('select2:select', function (e) { s.updateUnits($(e.currentTarget).attr('id'), $(e.currentTarget).val()); }); $('.user').on('select2:select', function (e) { s.updateUsers($(e.currentTarget).attr('id'), $(e.currentTarget).val()); }); }, 100); } // updateSms(id, data): void { // this.organizationUnitOrderNotification[id].isSMS = data; // } // updateEmail(id, data): void { // this.organizationUnitOrderNotification[id].isEmail = data; // } updateIsActive(id, data): void { this.reportScheduleRecipient[id].isActive = data; } addRecipient(): void { let s = this; this.recipientInput = new CreateOrEditReportRecipientDto(); this.recipientInput.emailAddress = "" this.recipientInput.isActive = false this.recipientInput.organizationUnitId = null // this.recipientInput.reportScheduleId = null this.recipientInput.userId = null this.recipientInput.code = null // this.addOrg.isEmail = false; // this.addOrg.isSMS = false; // this.addOrg.isActive = false; // this.addOrg.organizationUnitId = null; // this.addOrg.emailAddress = ""; // this.addOrg.phoneNumber = ""; // this.addOrg.code = null; // this.addOrg.userId = null; // this.organizationUnitOrderNotification.push(this.addOrg); this.reportScheduleRecipient.push(this.recipientInput); setTimeout(() => { $('.organization-unit').select2(); $('.user').select2(); }, 10); } deleteRecipient(id: number): void { // this.delete = this.organizationUnitOrderNotification[id]; this.delete = this.reportScheduleRecipient[id]; // this._organizationUnitOrderNotification.delete(this.delete.id) // .subscribe(() => { // this.notify.success(this.l('SuccessfullyDeleted')); // }); this._reportScheduleServiceProxy.deleteReportScheduleRecipient(this.delete.id) .subscribe(result => { this.notify.success(this.l('SuccessfullyDeleted')); }); this.reportScheduleRecipient.splice(id, 1); } save(): void { this.saving = true; this.input = new CreateOrEditReportScheduleDto(); this.input.reportId = this.reportId this.input.reportScheduleId = this.reportScheduleId this.input.description = this.schedulerDescription; this.input.startDate = this.schedulerStartDate; this.input.startDate = new Date(this.schedulerStartDate.setHours(this.schedulerStartDate.getHours() - this.schedulerStartDate.getTimezoneOffset() / 60)); this.input.startTime = new Date(this.schedulerStartTime).toLocaleTimeString('en-US', { hour12: true, hour: "numeric", minute: "numeric", second: "numeric" }) as any; this.input.repeat = $('#repeatInput').val(); this.input.startDay = $('#startDayInput').val(); this.exportType = $('#exportTypeInput').val(); this.input.exportType = this.exportType.join(",").replace(/[^a-zA-Z,]/g,""); this.input.isActive = this.schedulerIsActive; this.input.ftpIsActive = this.ftpIsActive; this.input.ftpServerName = this.ftpServerName this.input.ftpUserName = this.ftpUserName this.input.ftpPassword = this.ftpPassword this.input.ftpFolderName = this.ftpFolderName; this.input.recipients = new CreateOrEditReportRecipientDto(); this.input.recipients = this.reportScheduleRecipient; this.input.parameterNameValue = [] var tz = $('#timezone').val(); this.input.timeZone = tz; this.input.timeInterval = this.timeInterval // this.params.forEach(element => { // var parameterNameValue: ParameterValueNameDto = new ParameterValueNameDto(); // parameterNameValue.parameterName=element.toString(); // parameterNameValue.parameterValue=$('#'+element).val().toString(); // this.input.parameterNameValue.push(parameterNameValue) // // console.log($('#'+element).val()) // }); if(this.params != undefined) { for(var a = 0 ; a < this.params.length ; a++){ var parameterNameValue: ParameterValueNameDto = new ParameterValueNameDto(); parameterNameValue.parameterName=this.params[a].name.toString(); parameterNameValue.parameterValue=$('#'+this.params[a].name).val().toString(); parameterNameValue.multiValue = this.params[a].multiValue; this.input.parameterNameValue.push(parameterNameValue) } } var checkerInput : ReportScheduleParameterCheckerInput = new ReportScheduleParameterCheckerInput(); checkerInput.reportId = this.reportId; checkerInput.parameterNameValue = this.input.parameterNameValue checkerInput.recipients = this.reportScheduleRecipient; checkerInput.reportScheduleId = this.reportScheduleId; checkerInput.repeat = $('#repeatInput').val(); // this._reportScheduleServiceProxy.reportScheduleParameterChecker(checkerInput) // .subscribe(result=>{ // if(result){ // this.message.warn( // this.l('SchedulerParameterWarning') // ); // this.saving= false // } // else{ // // this.message.warn( // // 'false' // // ); this._reportScheduleServiceProxy.updateReportSchedule(this.input) .subscribe(result=>{ this.notify.info(this.l('SavedSuccessfully')); this.close(); this.modalSave.emit(null); }) this.saving=false // // console.log("false") // } // }) } ngAfterViewInit(): void { // $('.kt-select2').select2(); // $('.organization-unit').select2(); // $('.user').select2(); } close(): void { // console.log("closed") this.active = false; this.modal.hide(); } // get params // getParams(){ // this._reportScheduleServiceProxy.getReportParameters(this.reportId) // .pipe() // .subscribe(result=>{ // this.params = result // setTimeout(() => { // $('.kt-select2').select2(); // }, 2000); // this.spinnerService.hide() // }) // } }