Move app stop/start into uninstall again and add restart button in main toolbar
This commit is contained in:
@@ -5,7 +5,7 @@ const i18n = useI18n();
|
||||
const t = i18n.t;
|
||||
|
||||
import { ref, onMounted, onBeforeUnmount, useTemplateRef } from 'vue';
|
||||
import { Button, ButtonGroup, ProgressBar } from '@cloudron/pankow';
|
||||
import { Button, ButtonGroup, ProgressBar, InputDialog } from '@cloudron/pankow';
|
||||
import PostInstallDialog from '../components/PostInstallDialog.vue';
|
||||
import SftpInfoDialog from '../components/SftpInfoDialog.vue';
|
||||
import Access from '../components/app/Access.vue';
|
||||
@@ -33,6 +33,8 @@ const appsModel = AppsModel.create();
|
||||
const tasksModel = TasksModel.create();
|
||||
const installationStateLabel = AppsModel.installationStateLabel;
|
||||
|
||||
const inputDialog = useTemplateRef('inputDialog');
|
||||
|
||||
const busy = ref(true);
|
||||
const id = ref('');
|
||||
const app = ref(null);
|
||||
@@ -161,47 +163,6 @@ function isViewEnabled(view, errorState) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const TARGET_RUN_STATE = {
|
||||
START: Symbol('start'),
|
||||
STOP: Symbol('stop'),
|
||||
};
|
||||
|
||||
function targetRunState() {
|
||||
// if we have an error, we want to retry the pending state, otherwise toggle the runstate
|
||||
if (app.value.error) {
|
||||
if (app.value.error.installationState === ISTATES.PENDING_START) return TARGET_RUN_STATE.START;
|
||||
else return TARGET_RUN_STATE.STOP;
|
||||
} else {
|
||||
if (app.value.runState === RSTATES.STOPPED) return TARGET_RUN_STATE.START;
|
||||
else return TARGET_RUN_STATE.STOP;
|
||||
}
|
||||
}
|
||||
|
||||
const toggleRunStateBusy = ref(false);
|
||||
async function onStartApp() {
|
||||
toggleRunStateBusy.value = true;
|
||||
|
||||
const [error] = await appsModel.start(app.value.id);
|
||||
if (error) {
|
||||
toggleRunStateBusy.value = false;
|
||||
return console.error(error);
|
||||
}
|
||||
|
||||
setTimeout(() => toggleRunStateBusy.value = false, 3000);
|
||||
}
|
||||
|
||||
async function onStopApp() {
|
||||
toggleRunStateBusy.value = true;
|
||||
|
||||
const [error] = await appsModel.stop(app.value.id);
|
||||
if (error) {
|
||||
toggleRunStateBusy.value = false;
|
||||
return console.error(error);
|
||||
}
|
||||
|
||||
setTimeout(() => toggleRunStateBusy.value = false, 3000);
|
||||
}
|
||||
|
||||
async function onStopAppTask() {
|
||||
if (!app.value.taskId) return;
|
||||
|
||||
@@ -236,6 +197,37 @@ function hashChange() {
|
||||
window.location.hash = `/app/${id.value}/${newView}`;
|
||||
}
|
||||
|
||||
const busyRestart = ref(false);
|
||||
|
||||
async function onRestartApp() {
|
||||
if (app.value.runState === RSTATES.STOPPED) {
|
||||
busyRestart.value = true;
|
||||
|
||||
const [error] = await appsModel.restart(id.value);
|
||||
if (error) return console.error(error);
|
||||
|
||||
busyRestart.value = false;
|
||||
return;
|
||||
}
|
||||
|
||||
const confirmed = await inputDialog.value.confirm({
|
||||
message: t('filemanager.toolbar.restartApp') + '?',
|
||||
confirmLabel: t('main.action.restart'),
|
||||
confirmStyle: 'danger',
|
||||
rejectLabel: t('main.dialog.cancel'),
|
||||
rejectStyle: 'secondary',
|
||||
});
|
||||
|
||||
if (!confirmed) return;
|
||||
|
||||
busyRestart.value = true;
|
||||
|
||||
const [error] = await appsModel.restart(id.value);
|
||||
if (error) return console.error(error);
|
||||
|
||||
busyRestart.value = false;
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
const tmp = window.location.hash.slice('#/app/'.length);
|
||||
if (!tmp) return;
|
||||
@@ -294,6 +286,7 @@ onBeforeUnmount(() => {
|
||||
|
||||
<template>
|
||||
<div class="configure-outer">
|
||||
<InputDialog ref="inputDialog" />
|
||||
<PostInstallDialog ref="postInstallDialog"/>
|
||||
<SftpInfoDialog ref="sftpInfoDialog"/>
|
||||
|
||||
@@ -313,12 +306,7 @@ onBeforeUnmount(() => {
|
||||
<Button v-if="app.taskId" danger tool plain icon="fa-solid fa-xmark" v-tooltip="'Cancel Task'" :loading="busyStopTask" :disabled="busyStopTask" @click="onStopAppTask()"/>
|
||||
<Button :menu="views" secondary class="pankow-no-desktop" tool>{{ views.find(v => v.id === currentView).label }}</Button>
|
||||
|
||||
<!--
|
||||
TODO check if this should be shown on stop confirmation
|
||||
<div>{{ $t('app.uninstall.startStop.description') }}</div>
|
||||
-->
|
||||
<Button v-if="!app.progress && targetRunState() === TARGET_RUN_STATE.START" secondary tool icon="fa-solid fa-circle-play" :loading="toggleRunStateBusy" :disabled="toggleRunStateBusy" v-tooltip="$t('app.uninstall.startStop.startAction')" @click="onStartApp()"/>
|
||||
<Button v-else-if="!app.progress" secondary tool icon="fa-solid fa-circle-stop" :loading="toggleRunStateBusy" :disabled="toggleRunStateBusy" v-tooltip="$t('app.uninstall.startStop.stopAction')" @click="onStopApp()"/>
|
||||
<Button v-if="!app.progress" secondary tool icon="fa-solid fa-arrows-rotate" :loading="busyRestart" :disabled="busyRestart" v-tooltip="$t('filemanager.toolbar.restartApp')" @click="onRestartApp()"/>
|
||||
|
||||
<ButtonGroup>
|
||||
<Button secondary tool :href="`/logs.html?appId=${app.id}`" target="_blank" v-tooltip="$t('app.logsActionTooltip')" icon="fa-solid fa-align-left" />
|
||||
|
||||
Reference in New Issue
Block a user