From 51d823bff4c2ff9166da17728fac0dc36b417e18 Mon Sep 17 00:00:00 2001 From: Wroud Date: Fri, 15 May 2020 13:52:52 +0300 Subject: [PATCH] refactor(core): log viewer behavior --- .../ToolsPanel/LogViewTab/LogViewerService.ts | 42 ++++++++++--------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/webapp/packages/core/src/app/shared/ToolsPanel/LogViewTab/LogViewerService.ts b/webapp/packages/core/src/app/shared/ToolsPanel/LogViewTab/LogViewerService.ts index 5d63a909b0..c1ea820c17 100644 --- a/webapp/packages/core/src/app/shared/ToolsPanel/LogViewTab/LogViewerService.ts +++ b/webapp/packages/core/src/app/shared/ToolsPanel/LogViewTab/LogViewerService.ts @@ -20,7 +20,11 @@ import { ILogEntry } from './ILogEntry'; @injectable() export class LogViewerService { - @observable isActive = false; + @observable _isActive = false; + + get isActive() { + return this._isActive; + } @observable private log: ILogEntry[] = []; private interval: any = null; @@ -35,15 +39,10 @@ export class LogViewerService { } toggle() { - if (this.isActive) { + if (this._isActive) { this.stopLog(); - this.isActive = false; } else { - if (!this.isLogViewerAvailable()) { - throw new Error('Access denied'); - } this.startLog(); - this.isActive = true; } } @@ -52,9 +51,13 @@ export class LogViewerService { } async startLog() { - if (this.interval) { + if (this._isActive) { return; } + if (!this.isLogViewerAvailable()) { + throw new Error('Access denied'); + } + this._isActive = true; await this.updateLog(); const refreshInterval = this.coreSettingsService.settings.getValue('app.logViewer.refreshInterval'); this.interval = setInterval(() => { @@ -67,6 +70,7 @@ export class LogViewerService { clearInterval(this.interval); this.interval = null; } + this._isActive = false; } @action @@ -74,15 +78,6 @@ export class LogViewerService { this.log = []; } - @action - addNewEntries(entries: ILogEntry[]) { - this.log.unshift(...entries.reverse()); - const maxLogEntries = this.coreSettingsService.settings.getValue('app.logViewer.maxLogEntries'); - if (this.log.length > maxLogEntries) { - this.log.splice(maxLogEntries, this.log.length - maxLogEntries); - } - } - async loadLog(): Promise { const maxLogEntries = this.coreSettingsService.settings.getValue('app.logViewer.maxLogEntries'); const { log } = await this.graphQLService.gql.readSessionLog({ @@ -96,6 +91,15 @@ export class LogViewerService { return entries; } + @action + private addNewEntries(entries: ILogEntry[]) { + this.log.unshift(...entries.reverse()); + const maxLogEntries = this.coreSettingsService.settings.getValue('app.logViewer.maxLogEntries'); + if (this.log.length > maxLogEntries) { + this.log.splice(maxLogEntries, this.log.length - maxLogEntries); + } + } + private async updateLog() { if (!this.isLogViewerAvailable()) { return; @@ -110,8 +114,8 @@ export class LogViewerService { } private stopIfHasNoPermission() { - if (this.isActive && !this.isLogViewerAvailable()) { - this.toggle(); + if (this._isActive && !this.isLogViewerAvailable()) { + this.stopLog(); } }