import { Component, Injector, ViewChild } from '@angular/core'; import { AppComponentBase } from '@shared/common/app-component-base'; import { AuditLogServiceProxy, EntityChangeListDto, EntityPropertyChangeDto } from '@shared/service-proxies/service-proxies'; import * as moment from 'moment'; import { ModalDirective } from 'ngx-bootstrap'; @Component({ selector: 'entityChangeDetailModal', templateUrl: './entity-change-detail-modal.component.html' }) export class EntityChangeDetailModalComponent extends AppComponentBase { @ViewChild('entityChangeDetailModal', {static: true}) modal: ModalDirective; active = false; entityPropertyChanges: EntityPropertyChangeDto[]; entityChange: EntityChangeListDto; _isClinicSchedule: boolean = false; isOrder: boolean = false; isRoute: boolean = false; constructor( injector: Injector, private _auditLogService: AuditLogServiceProxy ) { super(injector); } getPropertyChangeValue(propertyChangeValue, propertyTypeFullName) { if (!propertyChangeValue) { return propertyChangeValue; } propertyChangeValue = propertyChangeValue.replace(/^['"]+/g, '').replace(/['"]+$/g, ''); if (this.isDate(propertyChangeValue, propertyTypeFullName)) { return moment(propertyChangeValue).format('YYYY-MM-DD HH:mm:ss'); } if (propertyChangeValue === 'null') { return ''; } return propertyChangeValue; } isDate(date, propertyTypeFullName): boolean { return propertyTypeFullName.includes('DateTime') && !isNaN(Date.parse(date).valueOf()); } show(record: EntityChangeListDto): void { const self = this; self.active = true; self.entityChange = record; self.spinnerService.show(); this.isOrder = record.entityTypeFullName=="SprintTek.Shipping.Orders.Order"? true : false; this.isRoute = record.entityTypeFullName=="SprintTek.Shipping.Routes.Route"? true : false; if(record.entityTypeFullName=="SprintTek.Laboratory.RouteScheduleDetail"){ this._isClinicSchedule = true; this._auditLogService.getClinicScheduleHistory(record.id, record.entityChangeSetId).subscribe((result) => { self.entityPropertyChanges = result; self.spinnerService.hide(); }); }else if(this.isRoute){ this._auditLogService.getRouteHistory(record.entityChangeSetId, record.entityTypeFullName, record.id, record.entityId).subscribe((result) => { self.entityPropertyChanges = result; self.spinnerService.hide(); }); }else{ this._isClinicSchedule = false; this._auditLogService.getEntityPropertyChanges(record.entityChangeSetId, record.entityTypeFullName, record.id).subscribe((result) => { self.entityPropertyChanges = result; self.spinnerService.hide(); }); } self.modal.show(); } close(): void { this.active = false; this.modal.hide(); } limitText(text: string){ var value = "" + text; var output = ""; for (var i = 0; i < value.length; i = i + 28) { output = output + value.substring(i, i + 28) + '\n'; } return output; } }