]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/system/logs/logs.component.ts
Fix boolean types, add missing downloadEnabled
[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[] = []
17 timeChoices: { id: string, label: string }[] = []
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(),
66357162 79 label: $localize`Last week`
2c22613c
C
80 },
81 {
82 id: lastDay.toISOString(),
66357162 83 label: $localize`Last day`
2c22613c
C
84 },
85 {
86 id: lastHour.toISOString(),
66357162 87 label: $localize`Last hour`
2c22613c
C
88 }
89 ]
90
91 this.startDate = lastHour.toISOString()
92 }
93
94 buildLevelChoices () {
95 this.levelChoices = [
96 {
97 id: 'debug',
66357162 98 label: $localize`Debug`
2c22613c
C
99 },
100 {
101 id: 'info',
66357162 102 label: $localize`Info`
2c22613c
C
103 },
104 {
105 id: 'warn',
66357162 106 label: $localize`Warning`
2c22613c
C
107 },
108 {
109 id: 'error',
66357162 110 label: $localize`Error`
2c22613c
C
111 }
112 ]
113
28e0e40d 114 this.level = 'warn'
2c22613c 115 }
566c125d
C
116
117 buildLogTypeChoices () {
118 this.logTypeChoices = [
119 {
120 id: 'standard',
66357162 121 label: $localize`Standard logs`
566c125d
C
122 },
123 {
124 id: 'audit',
66357162 125 label: $localize`Audit logs`
566c125d
C
126 }
127 ]
128
129 this.logType = 'audit'
130 }
2c22613c 131}