import { Component, ViewChild, Injector, Output, EventEmitter } from '@angular/core'; import { ModalDirective } from 'ngx-bootstrap'; import { LocationServiceProxy, UnlockLocationInput} from '@shared/service-proxies/service-proxies'; import { AppComponentBase } from '@shared/common/app-component-base'; import * as moment from 'moment-timezone'; @Component({ selector: 'unlockModal', templateUrl: './unlock-modal.component.html' }) export class UnlockModalComponent extends AppComponentBase { @ViewChild('createOrEditModal', { static: true }) modal: ModalDirective; @Output() modalSave: EventEmitter = new EventEmitter(); public steps: any = { hour: 1, minute: 60 }; active = false; saving = false; adjustment: any; unlockUntil: any; reason: any; locationId: any; unFreezeby: any time: any; item: UnlockLocationInput = new UnlockLocationInput; minDate: any; constructor( injector: Injector, private _locationService: LocationServiceProxy, ) { super(injector); } show(locationId): void { this.active = true; this.minDate = new Date(localStorage.getItem('loadDate')); this.locationId = locationId; this.modal.show(); } close(): void { this.active = false; this.modal.hide(); } save(): void { this.saving = true; this.item.unlock = false; //this.item.unlockTo = moment.parseZone(this.unlockUntil); this.item.unlockTo = new Date(moment(this.unlockUntil).format()).toLocaleString('en-US', { }) as any; var timeMoment = moment(this.time); this.item.time = new Date(timeMoment.format()).toLocaleTimeString('en-US', { hour12: true, hour: "numeric", minute: "numeric", second: "numeric" }) as any; this.item.cuttOffAddMinutes = this.adjustment; this.item.unlockReason = this.reason; this.item.unlockFrom = this.unlockUntil; this.item.id = this.locationId; this._locationService.unlockLocation( this.item ) .pipe() .subscribe(() => { this.notify.info(this.l('SavedSuccessfully')); this.modalSave.emit(null); this.reason = null; this.adjustment = null; this.close(); }); } }