Untitled
unknown
plain_text
3 years ago
3.1 kB
5
Indexable
import { Component, OnInit, ViewChild } from '@angular/core'; import {HoursService} from "../services/hours.service"; import {Observable} from "rxjs"; import {Router} from "@angular/router"; import {FilePreviewOverlayService} from "../file-preview-overlay/file-preview-overlay.service"; import {FilePreviewOverlayRef} from "../file-preview-overlay/file-preview-overlay-ref"; import Swal from 'sweetalert2'; import { ElementRef } from '@angular/core'; import { isContext } from 'vm'; @Component({ selector: 'app-view-log', templateUrl: './view-log.component.html', styleUrls: ['./view-log.component.css'] }) export class ViewLogComponent implements OnInit { drivingLogs: Observable<IDrivingLogs[]>; constructor(private hoursService: HoursService, private router: Router, private overlayService: FilePreviewOverlayService) { this.drivingLogs = this.hoursService.getValues() this.hoursService.refreshClocks().then(r => console.log(r)); } ngOnInit() {} async confirmDeletion(date: Date) { Swal.fire({ position: 'center', icon: 'question', title: 'Delete Entry?', showCancelButton: true, confirmButtonText: 'Yes', cancelButtonText: 'No', }).then((result) => { if (result.isConfirmed) { this.delete(date); } else { // Swal.fire({ // timer: 1000, // titleText: 'Entry Was Not Deleted', // showConfirmButton: false // }) // setTimeout(() => { // Swal.fire({ // timer: 1000, // titleText: 'Entry Was Not Deleted', // showConfirmButton: false // }); // this.router.navigateByUrl('/dash-container/enter-time')}, 1); // setTimeout(() => this.router.navigateByUrl('/dash-container/view-log'), 1) } }); } async delete(date: Date) { const key = new Date(date).toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' }) await this.hoursService.del(key) // this.drivingLogs = values(); this.hoursService.refreshClocks(); Swal.fire({ position: 'center', icon: 'success', title: 'Entry Deleted Successfully', showConfirmButton: false, timer: 2000, }); } async downloadLog() { let dialogRef: FilePreviewOverlayRef = this.overlayService.open(); this.router.navigateByUrl('/dash-container/pdf-log') setTimeout(() => dialogRef.close(), 1000) } formatEntry(entryLog: IDrivingLogs) { const date = entryLog.date.toLocaleDateString('en-US', {month: 'short', day: 'numeric', year:'numeric'}) let totalHours = entryLog.dayHours + entryLog.nightHours; let totalMinutes = entryLog.dayMins + entryLog.nightMins; totalHours += Math.floor(totalMinutes / 60); totalMinutes = totalMinutes % 60; return `${date} - ${totalHours} hrs ${totalMinutes} mins ` } } export interface IDrivingLogs { date: Date, dayHours: number, dayMins: number, nightHours: number, nightMins: number, myNotes: string, }
Editor is loading...