import { Component, OnInit, ViewChild, Output, EventEmitter, Injector } from "@angular/core"; import { appModuleAnimation } from "@shared/animations/routerTransition"; import { AppComponentBase } from "@shared/common/app-component-base"; import { ModalDirective } from "ngx-bootstrap"; import * as moment from 'moment'; import { ControllerRouteServiceProxy, UpdateCompleteRouteInput } from "@shared/service-proxies/service-proxies"; import { finalize } from "rxjs/operators"; @Component({ selector: 'markAsCompleteModalComponent', templateUrl: 'mark-as-complete-modal.component.html', animations: [appModuleAnimation()], }) export class MarkAsCompleteModalComponent extends AppComponentBase implements OnInit { @ViewChild('createOrEditModal', { static: true }) modal: ModalDirective; @Output() modalSave: EventEmitter = new EventEmitter(); active = false; saving = false; pickupEta: Date; pickUpFrom: Date; todaysDate:Date; updateCompletedInput = new UpdateCompleteRouteInput(); routeId: number; constructor( injector: Injector, private _controllerRouteService: ControllerRouteServiceProxy ) { super(injector); } show(Id?: number): void { this.todaysDate = new Date(Date.now()); this.pickupEta = this.todaysDate; this.pickUpFrom = this.todaysDate; this.routeId = Id; this.active = true; this.modal.show(); } save(){ console.log(this.routeId); this.updateCompletedInput.dateCompleted = moment.utc(moment(this.pickupEta).format('YYYY-MM-DD') + ' ' + moment(this.pickUpFrom).format('HH:mm:ss')); this.updateCompletedInput.id = this.routeId; this._controllerRouteService.updateCompletedRoute(this.updateCompletedInput) .pipe(finalize(() => { this.saving = false; })) .subscribe(() => { this.notify.info(this.l('Saved Successfully')); this.close(); }); } ngOnInit(){ } close(): void { this.modal.hide(); this.active = false; } }