]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/+admin/system/logs/logs.component.ts
Merge remote-tracking branch 'weblate/develop' into develop
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / system / logs / logs.component.ts
index 51f04718817eb9b3331770b1ed9807ba84787542..48318f07baaa55b827e9df2ee4f243d5f1590ed4 100644 (file)
@@ -1,6 +1,5 @@
 import { Component, ElementRef, OnInit, ViewChild } from '@angular/core'
-import { Notifier } from '@app/core'
-import { I18n } from '@ngx-translate/i18n-polyfill'
+import { LocalStorageService, Notifier } from '@app/core'
 import { LogLevel } from '@shared/models'
 import { LogRow } from './log-row.model'
 import { LogsService } from './logs.service'
@@ -10,12 +9,14 @@ import { LogsService } from './logs.service'
   styleUrls: [ './logs.component.scss' ]
 })
 export class LogsComponent implements OnInit {
+  private static LOCAL_STORAGE_LOG_TYPE_CHOICE_KEY = 'admin-logs-log-type-choice'
+
   @ViewChild('logsElement', { static: true }) logsElement: ElementRef<HTMLElement>
 
   loading = false
 
   logs: LogRow[] = []
-  timeChoices: { id: string, label: string }[] = []
+  timeChoices: { id: string, label: string, dateFormat: string }[] = []
   levelChoices: { id: LogLevel, label: string }[] = []
   logTypeChoices: { id: 'audit' | 'standard', label: string }[] = []
 
@@ -26,7 +27,7 @@ export class LogsComponent implements OnInit {
   constructor (
     private logsService: LogsService,
     private notifier: Notifier,
-    private i18n: I18n
+    private localStorage: LocalStorageService
   ) { }
 
   ngOnInit (): void {
@@ -34,11 +35,16 @@ export class LogsComponent implements OnInit {
     this.buildLevelChoices()
     this.buildLogTypeChoices()
 
+    this.loadPreviousChoices()
+
     this.load()
   }
 
   refresh () {
     this.logs = []
+
+    this.localStorage.setItem(LogsComponent.LOCAL_STORAGE_LOG_TYPE_CHOICE_KEY, this.logType)
+
     this.load()
   }
 
@@ -78,15 +84,18 @@ export class LogsComponent implements OnInit {
     this.timeChoices = [
       {
         id: lastWeek.toISOString(),
-        label: this.i18n('Last week')
+        label: $localize`Last week`,
+        dateFormat: 'shortDate'
       },
       {
         id: lastDay.toISOString(),
-        label: this.i18n('Last day')
+        label: $localize`Last day`,
+        dateFormat: 'short'
       },
       {
         id: lastHour.toISOString(),
-        label: this.i18n('Last hour')
+        label: $localize`Last hour`,
+        dateFormat: 'mediumTime'
       }
     ]
 
@@ -97,19 +106,19 @@ export class LogsComponent implements OnInit {
     this.levelChoices = [
       {
         id: 'debug',
-        label: this.i18n('Debug')
+        label: $localize`debug`
       },
       {
         id: 'info',
-        label: this.i18n('Info')
+        label: $localize`info`
       },
       {
         id: 'warn',
-        label: this.i18n('Warning')
+        label: $localize`warning`
       },
       {
         id: 'error',
-        label: this.i18n('Error')
+        label: $localize`error`
       }
     ]
 
@@ -120,14 +129,18 @@ export class LogsComponent implements OnInit {
     this.logTypeChoices = [
       {
         id: 'standard',
-        label: this.i18n('Standard logs')
+        label: $localize`Standard logs`
       },
       {
         id: 'audit',
-        label: this.i18n('Audit logs')
+        label: $localize`Audit logs`
       }
     ]
+  }
+
+  private loadPreviousChoices () {
+    this.logType = this.localStorage.getItem(LogsComponent.LOCAL_STORAGE_LOG_TYPE_CHOICE_KEY)
 
-    this.logType = 'audit'
+    if (this.logType !== 'standard' && this.logType !== 'audit') this.logType = 'audit'
   }
 }