1 import { Component, ElementRef, OnInit, ViewChild } from '@angular/core'
2 import { Notifier } from '@app/core'
3 import { I18n } from '@ngx-translate/i18n-polyfill'
4 import { LogLevel } from '@shared/models'
5 import { LogRow } from './log-row.model'
6 import { LogsService } from './logs.service'
9 templateUrl: './logs.component.html',
10 styleUrls: [ './logs.component.scss' ]
12 export class LogsComponent implements OnInit {
13 @ViewChild('logsElement', { static: true }) logsElement: ElementRef<HTMLElement>
18 timeChoices: { id: string, label: string }[] = []
19 levelChoices: { id: LogLevel, label: string }[] = []
20 logTypeChoices: { id: 'audit' | 'standard', label: string }[] = []
24 logType: 'audit' | 'standard'
27 private logsService: LogsService,
28 private notifier: Notifier,
33 this.buildTimeChoices()
34 this.buildLevelChoices()
35 this.buildLogTypeChoices()
48 this.logsService.getLogs({ isAuditLog: this.isAuditLog(), level: this.level, startDate: this.startDate })
54 this.logsElement.nativeElement.scrollIntoView({ block: 'end', inline: 'nearest' })
58 err => this.notifier.error(err.message),
60 () => this.loading = false
65 return this.logType === 'audit'
69 const lastHour = new Date()
70 lastHour.setHours(lastHour.getHours() - 1)
72 const lastDay = new Date()
73 lastDay.setDate(lastDay.getDate() - 1)
75 const lastWeek = new Date()
76 lastWeek.setDate(lastWeek.getDate() - 7)
80 id: lastWeek.toISOString(),
81 label: this.i18n('Last week')
84 id: lastDay.toISOString(),
85 label: this.i18n('Last day')
88 id: lastHour.toISOString(),
89 label: this.i18n('Last hour')
93 this.startDate = lastHour.toISOString()
96 buildLevelChoices () {
100 label: this.i18n('Debug')
104 label: this.i18n('Info')
108 label: this.i18n('Warning')
112 label: this.i18n('Error')
119 buildLogTypeChoices () {
120 this.logTypeChoices = [
123 label: this.i18n('Standard logs')
127 label: this.i18n('Audit logs')
131 this.logType = 'audit'