]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/system/logs/logs.component.ts
jobs/logs view select and empty state visual improvements
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / system / logs / logs.component.ts
CommitLineData
2c22613c 1import { Component, ElementRef, OnInit, ViewChild } from '@angular/core'
2c22613c 2import { Notifier } from '@app/core'
67ed6552
C
3import { LogLevel } from '@shared/models'
4import { LogRow } from './log-row.model'
5import { LogsService } from './logs.service'
2c22613c
C
6
7@Component({
8 templateUrl: './logs.component.html',
9 styleUrls: [ './logs.component.scss' ]
10})
11export class LogsComponent implements OnInit {
f36da21e 12 @ViewChild('logsElement', { static: true }) logsElement: ElementRef<HTMLElement>
2c22613c
C
13
14 loading = false
15
16 logs: LogRow[] = []
7f0d8561 17 timeChoices: { id: string, label: string, dateFormat: string }[] = []
2c22613c 18 levelChoices: { id: LogLevel, label: string }[] = []
566c125d 19 logTypeChoices: { id: 'audit' | 'standard', label: string }[] = []
2c22613c
C
20
21 startDate: string
22 level: LogLevel
566c125d 23 logType: 'audit' | 'standard'
2c22613c
C
24
25 constructor (
26 private logsService: LogsService,
66357162
C
27 private notifier: Notifier
28 ) { }
2c22613c
C
29
30 ngOnInit (): void {
31 this.buildTimeChoices()
32 this.buildLevelChoices()
566c125d 33 this.buildLogTypeChoices()
2c22613c
C
34
35 this.load()
36 }
37
38 refresh () {
39 this.logs = []
40 this.load()
41 }
42
43 load () {
44 this.loading = true
45
566c125d 46 this.logsService.getLogs({ isAuditLog: this.isAuditLog(), level: this.level, startDate: this.startDate })
2c22613c
C
47 .subscribe(
48 logs => {
49 this.logs = logs
50
51 setTimeout(() => {
52 this.logsElement.nativeElement.scrollIntoView({ block: 'end', inline: 'nearest' })
53 })
54 },
55
56 err => this.notifier.error(err.message),
57
58 () => this.loading = false
59 )
60 }
61
566c125d
C
62 isAuditLog () {
63 return this.logType === 'audit'
64 }
65
2c22613c
C
66 buildTimeChoices () {
67 const lastHour = new Date()
68 lastHour.setHours(lastHour.getHours() - 1)
69
70 const lastDay = new Date()
71 lastDay.setDate(lastDay.getDate() - 1)
72
73 const lastWeek = new Date()
74 lastWeek.setDate(lastWeek.getDate() - 7)
75
76 this.timeChoices = [
77 {
78 id: lastWeek.toISOString(),
7f0d8561
RK
79 label: $localize`Last week`,
80 dateFormat: 'shortDate'
2c22613c
C
81 },
82 {
83 id: lastDay.toISOString(),
7f0d8561
RK
84 label: $localize`Last day`,
85 dateFormat: 'short'
2c22613c
C
86 },
87 {
88 id: lastHour.toISOString(),
7f0d8561
RK
89 label: $localize`Last hour`,
90 dateFormat: 'mediumTime'
2c22613c
C
91 }
92 ]
93
94 this.startDate = lastHour.toISOString()
95 }
96
97 buildLevelChoices () {
98 this.levelChoices = [
99 {
100 id: 'debug',
7f0d8561 101 label: $localize`debug`
2c22613c
C
102 },
103 {
104 id: 'info',
7f0d8561 105 label: $localize`info`
2c22613c
C
106 },
107 {
108 id: 'warn',
7f0d8561 109 label: $localize`warning`
2c22613c
C
110 },
111 {
112 id: 'error',
7f0d8561 113 label: $localize`error`
2c22613c
C
114 }
115 ]
116
28e0e40d 117 this.level = 'warn'
2c22613c 118 }
566c125d
C
119
120 buildLogTypeChoices () {
121 this.logTypeChoices = [
122 {
123 id: 'standard',
66357162 124 label: $localize`Standard logs`
566c125d
C
125 },
126 {
127 id: 'audit',
66357162 128 label: $localize`Audit logs`
566c125d
C
129 }
130 ]
131
132 this.logType = 'audit'
133 }
2c22613c 134}