diff options
Diffstat (limited to 'client/src/app/+admin/system/logs/logs.component.ts')
-rw-r--r-- | client/src/app/+admin/system/logs/logs.component.ts | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/client/src/app/+admin/system/logs/logs.component.ts b/client/src/app/+admin/system/logs/logs.component.ts new file mode 100644 index 000000000..17abb8409 --- /dev/null +++ b/client/src/app/+admin/system/logs/logs.component.ts | |||
@@ -0,0 +1,111 @@ | |||
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' | ||
7 | |||
8 | @Component({ | ||
9 | templateUrl: './logs.component.html', | ||
10 | styleUrls: [ './logs.component.scss' ] | ||
11 | }) | ||
12 | export class LogsComponent implements OnInit { | ||
13 | @ViewChild('logsElement') logsElement: ElementRef<HTMLElement> | ||
14 | |||
15 | loading = false | ||
16 | |||
17 | logs: LogRow[] = [] | ||
18 | timeChoices: { id: string, label: string }[] = [] | ||
19 | levelChoices: { id: LogLevel, label: string }[] = [] | ||
20 | |||
21 | startDate: string | ||
22 | level: LogLevel | ||
23 | |||
24 | constructor ( | ||
25 | private logsService: LogsService, | ||
26 | private notifier: Notifier, | ||
27 | private i18n: I18n | ||
28 | ) { } | ||
29 | |||
30 | ngOnInit (): void { | ||
31 | this.buildTimeChoices() | ||
32 | this.buildLevelChoices() | ||
33 | |||
34 | this.load() | ||
35 | } | ||
36 | |||
37 | refresh () { | ||
38 | this.logs = [] | ||
39 | this.load() | ||
40 | } | ||
41 | |||
42 | load () { | ||
43 | this.loading = true | ||
44 | |||
45 | this.logsService.getLogs(this.level, this.startDate) | ||
46 | .subscribe( | ||
47 | logs => { | ||
48 | this.logs = logs | ||
49 | |||
50 | setTimeout(() => { | ||
51 | this.logsElement.nativeElement.scrollIntoView({ block: 'end', inline: 'nearest' }) | ||
52 | }) | ||
53 | }, | ||
54 | |||
55 | err => this.notifier.error(err.message), | ||
56 | |||
57 | () => this.loading = false | ||
58 | ) | ||
59 | } | ||
60 | |||
61 | buildTimeChoices () { | ||
62 | const lastHour = new Date() | ||
63 | lastHour.setHours(lastHour.getHours() - 1) | ||
64 | |||
65 | const lastDay = new Date() | ||
66 | lastDay.setDate(lastDay.getDate() - 1) | ||
67 | |||
68 | const lastWeek = new Date() | ||
69 | lastWeek.setDate(lastWeek.getDate() - 7) | ||
70 | |||
71 | this.timeChoices = [ | ||
72 | { | ||
73 | id: lastWeek.toISOString(), | ||
74 | label: this.i18n('Last week') | ||
75 | }, | ||
76 | { | ||
77 | id: lastDay.toISOString(), | ||
78 | label: this.i18n('Last day') | ||
79 | }, | ||
80 | { | ||
81 | id: lastHour.toISOString(), | ||
82 | label: this.i18n('Last hour') | ||
83 | } | ||
84 | ] | ||
85 | |||
86 | this.startDate = lastHour.toISOString() | ||
87 | } | ||
88 | |||
89 | buildLevelChoices () { | ||
90 | this.levelChoices = [ | ||
91 | { | ||
92 | id: 'debug', | ||
93 | label: this.i18n('Debug') | ||
94 | }, | ||
95 | { | ||
96 | id: 'info', | ||
97 | label: this.i18n('Info') | ||
98 | }, | ||
99 | { | ||
100 | id: 'warn', | ||
101 | label: this.i18n('Warning') | ||
102 | }, | ||
103 | { | ||
104 | id: 'error', | ||
105 | label: this.i18n('Error') | ||
106 | } | ||
107 | ] | ||
108 | |||
109 | this.level = 'info' | ||
110 | } | ||
111 | } | ||