{{ $t('app.uninstall.startStop.description') }}
{{ $t('app.uninstall.uninstall.description') }}
diff --git a/dashboard/src/models/AppsModel.js b/dashboard/src/models/AppsModel.js index af5fefec0..817cf006a 100644 --- a/dashboard/src/models/AppsModel.js +++ b/dashboard/src/models/AppsModel.js @@ -189,6 +189,30 @@ function create() { await sleep(2000); } }, + async start(id) { + let result; + try { + result = await fetcher.post(`${origin}/api/v1/apps/${id}/start`, {}, { access_token: accessToken }); + } catch (e) { + return [e]; + } + + if (result.status !== 202) return [result]; + return [null, result.body.taskId]; + + }, + async stop(id) { + let result; + try { + result = await fetcher.post(`${origin}/api/v1/apps/${id}/stop`, {}, { access_token: accessToken }); + } catch (e) { + return [e]; + } + + if (result.status !== 202) return [result]; + return [null, result.body.taskId]; + + }, async configure(id, setting, data) { let result; try { diff --git a/dashboard/src/models/TasksModel.js b/dashboard/src/models/TasksModel.js index 16b9a76a3..5ef61bf91 100644 --- a/dashboard/src/models/TasksModel.js +++ b/dashboard/src/models/TasksModel.js @@ -1,11 +1,26 @@ import { fetcher } from 'pankow'; +import { sleep } from 'pankow/utils'; function create() { const accessToken = localStorage.token; const origin = import.meta.env.VITE_API_ORIGIN || window.location.origin; return { + async wait(id) { + while(true) { + let result; + try { + result = await fetcher.get(`${origin}/api/v1/tasks/${id}`, { access_token: accessToken }); + } catch (e) { + return [e]; + } + + if (!result.body.active) return [result.body.error, result.body.result]; + + await sleep(2000); + } + }, async getLatestByType(type) { let error, result; try { @@ -49,7 +64,7 @@ function create() { if (error || result.status !== 204) return [error || result]; return [null]; - } + }, }; } diff --git a/dashboard/src/views/AppConfigureView.vue b/dashboard/src/views/AppConfigureView.vue index 984fe4b78..2d5cc26a8 100644 --- a/dashboard/src/views/AppConfigureView.vue +++ b/dashboard/src/views/AppConfigureView.vue @@ -6,7 +6,7 @@ import { useI18n } from 'vue-i18n'; const i18n = useI18n(); const t = i18n.t; -import { ref, onMounted, useTemplateRef } from 'vue'; +import { ref, onMounted, onUnmounted, useTemplateRef } from 'vue'; import { Button, ButtonGroup, TabView } from 'pankow'; import Info from '../components/app/Info.vue'; import Uninstall from '../components/app/Uninstall.vue'; @@ -41,6 +41,8 @@ const link = ref(''); const infoMenu = ref([]); const hasLocalStorage = ref(false); +let refreshTimer = null; + function onTabChanged(tab) { window.location.hash = `/app/${id.value}/${tab}`; } @@ -55,6 +57,7 @@ async function refresh() { link.value = result.fqdn.indexOf('http') !== 0 ? 'https://' + result.fqdn : result.fqdn; hasLocalStorage.value = result.manifest && result.manifest.addons && result.manifest.addons.localstorage; + infoMenu.value = []; infoMenu.value.push({ label: t('app.docsAction'), disabled: !result.manifest?.documentationUrl, @@ -98,6 +101,8 @@ async function refresh() { // TODO support real href links action: () => { window.location.href = result.manifest.website; } }); + + refreshTimer = setTimeout(refresh, 2000); } onMounted(async () => { @@ -114,6 +119,10 @@ onMounted(async () => { tabView.value.open(parts[1] || 'info'); }); +onUnmounted(() => { + if (refreshTimer) clearTimeout(refreshTimer); +}); +