1 import { Component, ElementRef, OnInit, ViewChild } from '@angular/core'
2 import { LogsService } from '@app/+admin/system/logs/logs.service'
3 import { Notifier } from '@app/core'
4 import { LogRow } from '@app/+admin/system/logs/log-row.model'
5 import { I18n } from '@ngx-translate/i18n-polyfill'
6 import { LogLevel } from '@shared/models/server/log-level.type'
9 templateUrl: './logs.component.html',
10 styleUrls: [ './logs.component.scss' ]
12 export class LogsComponent implements OnInit {
13 @ViewChild('logsElement') logsElement: ElementRef<HTMLElement>
18 timeChoices: { id: string, label: string }[] = []
19 levelChoices: { id: LogLevel, label: string }[] = []
25 private logsService: LogsService,
26 private notifier: Notifier,
31 this.buildTimeChoices()
32 this.buildLevelChoices()
45 this.logsService.getLogs(this.level, this.startDate)
51 this.logsElement.nativeElement.scrollIntoView({ block: 'end', inline: 'nearest' })
55 err => this.notifier.error(err.message),
57 () => this.loading = false
62 const lastHour = new Date()
63 lastHour.setHours(lastHour.getHours() - 1)
65 const lastDay = new Date()
66 lastDay.setDate(lastDay.getDate() - 1)
68 const lastWeek = new Date()
69 lastWeek.setDate(lastWeek.getDate() - 7)
73 id: lastWeek.toISOString(),
74 label: this.i18n('Last week')
77 id: lastDay.toISOString(),
78 label: this.i18n('Last day')
81 id: lastHour.toISOString(),
82 label: this.i18n('Last hour')
86 this.startDate = lastHour.toISOString()
89 buildLevelChoices () {
93 label: this.i18n('Debug')
97 label: this.i18n('Info')
101 label: this.i18n('Warning')
105 label: this.i18n('Error')