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 }[] = []
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`
82 id: lastDay.toISOString(),
83 label: $localize`Last day`
86 id: lastHour.toISOString(),
87 label: $localize`Last hour`
91 this.startDate = lastHour.toISOString()
94 buildLevelChoices () {
98 label: $localize`Debug`
102 label: $localize`Info`
106 label: $localize`Warning`
110 label: $localize`Error`
117 buildLogTypeChoices () {
118 this.logTypeChoices = [
121 label: $localize`Standard logs`
125 label: $localize`Audit logs`
129 this.logType = 'audit'