terminal: support cron/scheduler

This commit is contained in:
Johannes Zellner
2023-07-14 16:39:27 +02:00
parent ee2cd0b573
commit b239e81065

View File

@@ -8,16 +8,19 @@
<span class="title">{{ name }}</span>
</template>
<template #right>
<!-- Scheduler/cron tasks -->
<Button severity="success" :label="$t('terminal.scheduler')" v-show="usesAddon('scheduler')" icon="pi pi-angle-down" iconPos="right" @click="onSchedulerMenu" aria-haspopup="true" aria-controls="schedulerMenu" style="margin-right: 5px" />
<Menu ref="schedulerMenu" id="schedulerMenu" :model="schedulerMenuModel" :popup="true" />
<!-- addon actions -->
<Button severity="help" style="margin-right: 5px;" @click="terminalInject('mysql')" v-show="usesAddon('mysql')" :disabled="!connected" label="MySQL"/>
<Button severity="help" style="margin-right: 5px;" @click="terminalInject('postgresql')" v-show="usesAddon('postgresql')" :disabled="!connected" label="Postgres"/>
<Button severity="help" style="margin-right: 5px;" @click="terminalInject('mongodb')" v-show="usesAddon('mongodb')" :disabled="!connected" label="MongoDB"/>
<Button severity="help" style="margin-right: 5px;" @click="terminalInject('redis')" v-show="usesAddon('redis')" :disabled="!connected" label="Redis"/>
<Button severity="success" style="margin-right: 5px;" @click="terminalInject('mysql')" v-show="usesAddon('mysql')" :disabled="!connected" label="MySQL"/>
<Button severity="success" style="margin-right: 5px;" @click="terminalInject('postgresql')" v-show="usesAddon('postgresql')" :disabled="!connected" label="Postgres"/>
<Button severity="success" style="margin-right: 5px;" @click="terminalInject('mongodb')" v-show="usesAddon('mongodb')" :disabled="!connected" label="MongoDB"/>
<Button severity="success" style="margin-right: 5px;" @click="terminalInject('redis')" v-show="usesAddon('redis')" :disabled="!connected" label="Redis"/>
<a style="margin-left: 20px; margin-right: 5px;" :href="'/frontend/logs.html?appId=' + id" target="_blank"><Button severity="secondary" icon="pi pi-align-left" :label="$t('logs.title')" /></a>
<a style="margin-right: 5px;" :href="'/frontend/filemanager.html#/home/app/' + id" target="_blank"><Button type="button" severity="secondary" icon="pi pi-folder" :label="$t('filemanager.title')" /></a>
<Button type="button" :label="$t('filemanager.toolbar.restartApp')" severity="secondary" icon="pi pi-sync" @click="onRestartApp" :loading="busyRestart"/>
<a style="margin-left: 20px; margin-right: 5px;" :href="'/frontend/logs.html?appId=' + id" target="_blank"><Button icon="pi pi-align-left" :label="$t('logs.title')" /></a>
<a style="margin-right: 5px;" :href="'/frontend/filemanager.html#/home/app/' + id" target="_blank"><Button type="button" icon="pi pi-folder" :label="$t('filemanager.title')" /></a>
<Button type="button" :label="$t('filemanager.toolbar.restartApp')" icon="pi pi-sync" @click="onRestartApp" :loading="busyRestart"/>
</template>
</TopBar>
</template>
@@ -67,7 +70,9 @@ export default {
busyRestart: false,
connected: false,
addons: {},
schedulerTasks: [],
manifestVersion: '',
schedulerMenuModel: [],
id: '',
name: '',
socket: null,
@@ -78,7 +83,7 @@ export default {
usesAddon(addon) {
return !!Object.keys(this.addons).find(function (a) { return a === addon; });
},
terminalInject(addon, extra) {
terminalInject(addon, command) {
if (!this.socket) return;
let cmd = '';
@@ -106,8 +111,8 @@ export default {
} else {
cmd = 'redis-cli -h "${CLOUDRON_REDIS_HOST}" -p "${CLOUDRON_REDIS_PORT}" -a "${CLOUDRON_REDIS_PASSWORD}" --no-auth-warning';
}
} else if (addon === 'scheduler' && extra) {
cmd = extra.command;
} else if (addon === 'scheduler' && command) {
cmd = command;
}
if (!cmd) return;
@@ -117,6 +122,9 @@ export default {
this.socket.send(cmd);
this.terminal.focus();
},
onSchedulerMenu(event) {
this.$refs.schedulerMenu.toggle(event);
},
async onRestartApp() {
if (this.type !== 'app') return;
@@ -202,6 +210,13 @@ export default {
this.name = `${app.label || app.fqdn} (${app.manifest.title})`;
this.addons = app.manifest.addons;
this.manifestVersion = app.manifest.manifestVersion;
this.schedulerMenuModel = !app.manifest.addons.scheduler ? [] : Object.keys(app.manifest.addons.scheduler).map((k) => {
return {
label: () => k,
command: () => this.terminalInject('scheduler', app.manifest.addons.scheduler[k].command)
};
});
} catch (e) {
console.error(`Failed to get app info for ${this.id}:`, e);
}