import { Component, ViewChild, Injector, Output, EventEmitter } from '@angular/core'; import { ModalDirective } from 'ngx-bootstrap'; import { finalize } from 'rxjs/operators'; import { OrderNotificationOrderStatusTypeLookupTableDto, UserListDto, OrganizationUnitDto, OrderNotificationSmsTemplateLookupTableDto, OrderNotificationOrderTypeLookupTableDto, OrderNotificationsServiceProxy, CreateOrEditOrderNotificationDto, OrderNotificationOrderNotificationTemplateLookupTableDto , OrganizationUnitServiceProxy, CreateOrEditOrganizationUnitOrderNotificationDto, OrganizationUnitOrderNotificationsServiceProxy, OrganizationUnitOrderNotificationDto, ReportScheduleServiceProxy, CreateOrEditReportScheduleDto, CreateOrEditReportRecipientDto } 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'; @Component({ selector: 'reportScheduleModalComponent', templateUrl: './report-schedule-modal.component.html', providers: [ReportScheduleServiceProxy] }) export class ReportScheduleModalComponent 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; reportId: number; schedulerDescription: string; schedulerStartDate: Date; schedulerStartTime: any; repeat: number; startDay : number; exportType: any; schedulerIsActive: boolean; recipientInput: any reportScheduleRecipient: any; exists: boolean = false constructor( injector: Injector, private _orderNotificationsServiceProxy: OrderNotificationsServiceProxy, private _reportScheduleServiceProxy : ReportScheduleServiceProxy, private _organizationUnitService: OrganizationUnitServiceProxy, private _organizationUnitOrderNotification: OrganizationUnitOrderNotificationsServiceProxy, ) { super(injector); } ngOnInit(): void { $('.kt-select2').select2(); $('.organization-unit').select2(); $('.user').select2(); } onShown(): void { let s = this; $('.kt-select2').select2(); $('.organization-unit').select2(); $('.user').select2(); // $('.kt-select2').on('select2:select', function (e) { // console.log(s.organizationUnitOrderNotification) // }); } show(reportId: number): void { $('.kt-select2').select2(); let s = this; // this.organizationUnitOrderNotification = []; this.reportScheduleRecipient = [] this._reportScheduleServiceProxy.getReportScheduleIfExisting(reportId) .subscribe(result=> { this.exists = result if (result){ this._reportScheduleServiceProxy.getReportScheduleForEdit(reportId) .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(",") // console.log(result.exportType) // console.log(this.exportType) this.schedulerIsActive = result.isActive; result.recipients.forEach(element => { this.reportScheduleRecipient.push(element) }); // console.log(this.exportType) // console.log(this.reportScheduleRecipient) }) this.active = true; this.modal.show(); } else{ this.reportScheduleRecipient = [] this.exportType = [] // this.isEmail = false; // this.isSMS = false; this.organizationUnitId = ""; this.reportId = reportId; this.schedulerIsActive = false this.repeat = null; this.schedulerDescription= "" this.schedulerStartDate = null; this.schedulerStartTime = null; this.active = true; this.modal.show(); } }) // if (!orderNotificationId) { // this.orderNotification = new CreateOrEditOrderNotificationDto(); // this.orderNotification.id = orderNotificationId; // this.orderNotificationTemplateDescription = ''; // this.orderStatusTypeDescription = ''; // this.smsTemplateDescription = ''; // this.orderTypeDescription = ''; // this.active = true; // this.modal.show(); // } // else { // this._orderNotificationsServiceProxy.getOrderNotificationForEdit(orderNotificationId).subscribe(result => { // this.organizationUnitOrderNotification = result.orderNotification.organizationUnitOrderNotification; // this.orderTypeDescription = result.orderTypeDescription; // this.orderNotification = result.orderNotification; // this.orderNotificationTemplateDescription = result.orderNotificationTemplateDescription; // this.orderStatusTypeDescription = result.orderStatusTypeDescription; // this.smsTemplateDescription = result.smsTemplateDescription; // this.orderTypeDescription = result.orderTypeDescription; // this.active = true; // this.modal.show(); // }); // } // this._orderNotificationsServiceProxy.getAllOrderNotificationTemplateForTableDropdown().subscribe(result => { // this.allOrderNotificationTemplates = result; // }); // this._orderNotificationsServiceProxy.getAllOrderStatusTypeForTableDropdown().subscribe(result => { // this.allOrderStatusTypes = result; // }); // this._orderNotificationsServiceProxy.getAllSmsTemplateForTableDropdown().subscribe(result => { // this.allSmsTemplates = result; // }); this._orderNotificationsServiceProxy.getAllUserForTableDropdown().subscribe(result => { this.allUsers = result; }); this._orderNotificationsServiceProxy.getAllOrgUnitsForTableDropdown().subscribe(result => { this.allOrganizationUnits = result; }); // this._orderNotificationsServiceProxy.getAllOrderTypeForTableDropdown().subscribe(result => { // this.allOrderTypes = result; // }); } // copy(orderNotificationId?: number): void { // $('.kt-select2').select2(); // $('.organization-unit').select2(); // $('.user').select2(); // let s = this; // // this.organizationUnitOrderNotification = []; // this.reportScheduleRecipient = [] // this._orderNotificationsServiceProxy.getOrderNotificationForEdit(orderNotificationId).subscribe(result => { // for (let index = 0; index < result.orderNotification.organizationUnitOrderNotification.length; index++) { // result.orderNotification.organizationUnitOrderNotification[index].id = 0; // result.orderNotification.organizationUnitOrderNotification[index].orderNotificationId = null; // } // this.organizationUnitOrderNotification = result.orderNotification.organizationUnitOrderNotification; // this.orderNotification = result.orderNotification; // this.orderNotification.id = null; // this.orderNotification.description = result.orderNotification.description + '-COPY'; // this.orderNotification.code = result.orderNotification.code + '-COPY'; // this.active = true; // this.modal.show(); // }); // this._orderNotificationsServiceProxy.getAllOrderNotificationTemplateForTableDropdown().subscribe(result => { // this.allOrderNotificationTemplates = result; // }); // this._orderNotificationsServiceProxy.getAllOrderStatusTypeForTableDropdown().subscribe(result => { // this.allOrderStatusTypes = result; // }); // this._orderNotificationsServiceProxy.getAllSmsTemplateForTableDropdown().subscribe(result => { // this.allSmsTemplates = result; // }); // this._orderNotificationsServiceProxy.getAllUserForTableDropdown().subscribe(result => { // this.allUsers = result; // }); // this._orderNotificationsServiceProxy.getAllOrgUnitsForTableDropdown().subscribe(result => { // this.allOrganizationUnits = result; // }); // this._orderNotificationsServiceProxy.getAllOrderTypeForTableDropdown().subscribe(result => { // this.allOrderTypes = result; // }); // } 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.description = this.schedulerDescription; this.input.startDate = this.schedulerStartDate; 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,""); console.log(this.exportType) console.log(this.input.exportType) this.input.isActive = this.schedulerIsActive; this.input.recipients = new CreateOrEditReportRecipientDto(); this.input.recipients = this.reportScheduleRecipient; // this.recipientInput = new CreateOrEditReportScheduleDto; // this.recipientInput. // this.recipientInput. // console.log(this.input) // // this.input.reportId = this.reportId // console.log("activesched"+this.schedulerIsActive); // console.log(this.reportScheduleRecipient); if(!this.exists){ this._reportScheduleServiceProxy.createReportSchedule(this.input) .subscribe(result=>{ this.notify.info(this.l('SavedSuccessfully')); this.close(); this.modalSave.emit(null); }) } else{ this._reportScheduleServiceProxy.updateReportSchedule(this.input) .subscribe(result=>{ this.notify.info(this.l('SavedSuccessfully')); this.close(); this.modalSave.emit(null); }) } // this.form = new CreateOrEditOrderNotificationDto(); // if (this.orderNotification.id) { // this.form.id = this.orderNotification.id; // } // this.form.code = this.orderNotification.code; // this.form.isActive = this.orderNotification.isActive; // this.form.description = this.orderNotification.description; // this.form.development = this.orderNotification.development; // this.form.organizationUnitOrderNotification = new CreateOrEditOrganizationUnitOrderNotificationDto(); // this.form.organizationUnitOrderNotification = this.organizationUnitOrderNotification; // this.form.orderNotificationTemplateId = Number((document.getElementById('orderNotificationTemplateId')).value); // this.form.smsTemplateId = Number((document.getElementById('smsTemplateId')).value); // this.form.orderStatusTypeId = Number((document.getElementById('orderStatusTypeId')).value); // this.form.orderTypeId = Number((document.getElementById('orderTypeId')).value); // this._orderNotificationsServiceProxy.createOrEdit(this.form) // .pipe(finalize(() => { this.saving = false; })) // .subscribe(() => { // this.notify.info(this.l('SavedSuccessfully')); // this.close(); // this.modalSave.emit(null); // }); } ngAfterViewInit(): void { // $('.kt-select2').select2(); // $('.organization-unit').select2(); // $('.user').select2(); } close(): void { this.active = false; this.modal.hide(); } }