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