From d75c8e2858ecfc87fbd1e91082b74036a9f5cee5 Mon Sep 17 00:00:00 2001 From: Johannes Zellner Date: Thu, 13 Jul 2023 15:36:57 +0200 Subject: [PATCH] various filemanager and logs improvements --- frontend/filemanager.html | 4 ++-- frontend/src/components/LogsViewer.vue | 29 +++++++++++++++---------- frontend/src/models/LogsModel.js | 30 ++++++++++++++++++++++++++ frontend/src/views/Home.vue | 15 ++++--------- 4 files changed, 54 insertions(+), 24 deletions(-) diff --git a/frontend/filemanager.html b/frontend/filemanager.html index bd71c491b..c2e1a9490 100644 --- a/frontend/filemanager.html +++ b/frontend/filemanager.html @@ -2,9 +2,9 @@ - + - FileManager + File Manager
diff --git a/frontend/src/components/LogsViewer.vue b/frontend/src/components/LogsViewer.vue index 7e6a43468..d9ffd1968 100644 --- a/frontend/src/components/LogsViewer.vue +++ b/frontend/src/components/LogsViewer.vue @@ -8,10 +8,11 @@ {{ name }} @@ -54,6 +55,7 @@ export default { accessToken: localStorage.token, apiOrigin: API_ORIGIN || '', logsModel: null, + busyRestart: false, id: '', name: '', type: '', @@ -67,6 +69,15 @@ export default { }, onDownload() { this.logsModel.download(); + }, + async onRestartApp() { + if (this.type !== 'app') return; + + this.busyRestart = true; + + await this.logsModel.restartApp(); + + this.busyRestart = false; } }, async mounted() { @@ -113,12 +124,14 @@ export default { if (this.type === 'app') { try { const app = await this.logsModel.getApp(); - this.name = app.fqdn + ' (' + app.manifest.title + ')'; + this.name = `${app.label || app.fqdn} (${app.manifest.title})`; } catch (e) { console.error(`Failed to get app info for ${this.id}:`, e); } } + window.document.title = `Logs Viewer - ${this.name}`; + this.downloadUrl = this.logsModel.getDownloadUrl(); this.logsModel.stream((id, time, html) => { @@ -155,6 +168,7 @@ body { background-color: black; color: white; margin-bottom: 0 !important; + padding: 5px 10px; } .log-line { @@ -186,12 +200,5 @@ body { height: 5px; } -a.p-button:hover, a.p-button:focus { - color: white; - text-decoration: none; - background: #0d89ec; - border-color: #0d89ec; -} - diff --git a/frontend/src/models/LogsModel.js b/frontend/src/models/LogsModel.js index 6ce1c1fb2..ecb358de4 100644 --- a/frontend/src/models/LogsModel.js +++ b/frontend/src/models/LogsModel.js @@ -2,6 +2,8 @@ import moment from 'moment'; import superagent from 'superagent'; import { ansiToHtml } from 'anser'; +import { ISTATES } from '../constants.js'; +import { sleep } from 'pankow/utils'; // https://github.com/janl/mustache.js/blob/master/mustache.js#L60 const entityMap = { @@ -93,6 +95,34 @@ export function create(origin, accessToken, type, id) { } return result.body; + }, + async restartApp() { + if (type !== 'app') return; + + let error, result; + try { + result = await superagent.post(`${origin}/api/v1/apps/${id}/restart`).query({ access_token: accessToken }); + } catch (e) { + error = e; + } + + if (error || result.statusCode !== 202) { + console.error(`Failed to restart app ${this.id}`, error || result.statusCode); + return; + } + + while(true) { + let result; + try { + result = await superagent.get(`${origin}/api/v1/apps/${id}`).query({ access_token: accessToken }); + } catch (e) { + console.error(e); + } + + if (result && result.statusCode === 200 && result.body.installationState === ISTATES.INSTALLED) break; + + await sleep(2000); + } } }; } diff --git a/frontend/src/views/Home.vue b/frontend/src/views/Home.vue index e46afd0ff..f147ef012 100644 --- a/frontend/src/views/Home.vue +++ b/frontend/src/views/Home.vue @@ -58,8 +58,8 @@