1 import { Component, ElementRef, OnInit, ViewChild } from '@angular/core'
2 import { Notifier } from '@app/core'
3 import { LogLevel } from '@shared/models'
4 import { LogRow } from './log-row.model'
5 import { LogsService } from './logs.service'
8 templateUrl: './logs.component.html',
9 styleUrls: [ './logs.component.scss' ]
11 export class LogsComponent implements OnInit {
12 @ViewChild('logsElement', { static: true }) logsElement: ElementRef<HTMLElement>
17 timeChoices: { id: string, label: string, dateFormat: string }[] = []
18 levelChoices: { id: LogLevel, label: string }[] = []
19 logTypeChoices: { id: 'audit' | 'standard', label: string }[] = []
23 logType: 'audit' | 'standard'
26 private logsService: LogsService,
27 private notifier: Notifier
31 this.buildTimeChoices()
32 this.buildLevelChoices()
33 this.buildLogTypeChoices()
46 this.logsService.getLogs({ isAuditLog: this.isAuditLog(), level: this.level, startDate: this.startDate })
52 this.logsElement.nativeElement.scrollIntoView({ block: 'end', inline: 'nearest' })
56 err => this.notifier.error(err.message),
58 () => this.loading = false
63 return this.logType === 'audit'
67 const lastHour = new Date()
68 lastHour.setHours(lastHour.getHours() - 1)
70 const lastDay = new Date()
71 lastDay.setDate(lastDay.getDate() - 1)
73 const lastWeek = new Date()
74 lastWeek.setDate(lastWeek.getDate() - 7)
78 id: lastWeek.toISOString(),
79 label: $localize`Last week`,
80 dateFormat: 'shortDate'
83 id: lastDay.toISOString(),
84 label: $localize`Last day`,
88 id: lastHour.toISOString(),
89 label: $localize`Last hour`,
90 dateFormat: 'mediumTime'
94 this.startDate = lastHour.toISOString()
97 buildLevelChoices () {
101 label: $localize`debug`
105 label: $localize`info`
109 label: $localize`warning`
113 label: $localize`error`
120 buildLogTypeChoices () {
121 this.logTypeChoices = [
124 label: $localize`Standard logs`
128 label: $localize`Audit logs`
132 this.logType = 'audit'