Files
cloudron-box/dashboard/src/views/SystemView.vue
T

188 lines
6.1 KiB
Vue
Raw Normal View History

2025-02-17 11:18:57 +01:00
<script setup>
2025-04-09 19:17:23 +02:00
import { useI18n } from 'vue-i18n';
const i18n = useI18n();
const t = i18n.t;
2025-05-22 16:51:26 +02:00
import { ref, useTemplateRef, onMounted } from 'vue';
import { Button, InputDialog, SingleSelect } from 'pankow';
import { prettyDecimalSize, sleep } from 'pankow/utils';
2025-03-16 11:12:49 +01:00
import moment from 'moment-timezone';
2025-05-22 16:26:24 +02:00
import SettingsItem from '../components/SettingsItem.vue';
2025-02-17 11:18:57 +01:00
import Section from '../components/Section.vue';
2025-05-22 16:26:24 +02:00
import SystemUpdate from '../components/SystemUpdate.vue';
import PrivateRegistry from '../components/PrivateRegistry.vue';
import CloudronModel from '../models/CloudronModel.js';
2025-05-22 16:51:26 +02:00
import DashboardModel from '../models/DashboardModel.js';
import SystemModel from '../models/SystemModel.js';
2025-05-22 16:26:24 +02:00
2025-05-22 16:51:26 +02:00
const systemModel = SystemModel.create();
const dashboardModel = DashboardModel.create();
2025-05-22 16:26:24 +02:00
const cloudronModel = CloudronModel.create();
2025-04-09 19:17:23 +02:00
2025-05-22 16:51:26 +02:00
const config = ref({});
const info = ref({});
const uptime = ref('');
const activeSince = ref('');
const memory = ref({});
const cpus = ref({});
2025-05-22 16:26:24 +02:00
// Timezone
const allTimezones = moment.tz.names().map(t => { return { id: t }; });
const timeZone = ref('');
const currentTimeZone = ref('');
2025-04-09 19:17:23 +02:00
2025-05-22 16:26:24 +02:00
async function onTimeZoneChange(value) {
const [error] = await cloudronModel.setTimeZone(value);
if (error) return console.error(error);
2025-04-09 19:17:23 +02:00
2025-05-22 16:26:24 +02:00
currentTimeZone.value = value;
2025-02-17 11:18:57 +01:00
}
2025-05-22 16:26:24 +02:00
// Language
const allLanguages = ref([]);
const language = ref('');
const currentLanguage = ref('');
async function onLanguageChange(value) {
const [error] = await cloudronModel.setLanguage(value);
2025-02-17 11:18:57 +01:00
if (error) return console.error(error);
2025-05-22 16:26:24 +02:00
currentLanguage.value = value;
}
2025-05-22 16:51:26 +02:00
const inputDialog = useTemplateRef('inputDialog');
async function onReboot() {
const confirmed = await inputDialog.value.confirm({
title: t('main.rebootDialog.title'),
message: t('main.rebootDialog.description'),
confirmLabel: t('main.rebootDialog.rebootAction'),
confirmStyle: 'danger',
rejectLabel: t('main.dialog.cancel'),
});
if (!confirmed) return;
await systemModel.reboot();
// now poll until the backend does not respond anymore to trigger the unreachable overlay
while (true) {
const [error] = await dashboardModel.config();
if (error) break;
await sleep(1000);
}
}
2025-05-22 16:26:24 +02:00
onMounted(async () => {
2025-05-22 16:51:26 +02:00
let [error, result] = await systemModel.memory();
if (error) return console.error(error);
memory.value = result;
[error, result] = await systemModel.cpus();
if (error) return console.error(error);
cpus.value = result;
[error, result] = await cloudronModel.getTimeZone();
2025-02-17 11:18:57 +01:00
if (error) return console.error(error);
2025-05-22 16:26:24 +02:00
timeZone.value = result;
currentTimeZone.value = result;
[error, result] = await cloudronModel.languages();
2025-02-17 11:18:57 +01:00
if (error) return console.error(error);
2025-05-22 16:26:24 +02:00
allLanguages.value = result.map(l => {
return {
id: l,
display: t(`lang.${l}`)
};
});
2025-05-22 16:26:24 +02:00
[error, result] = await cloudronModel.getLanguage();
2025-02-17 11:18:57 +01:00
if (error) return console.error(error);
2025-05-22 16:26:24 +02:00
language.value = result;
currentLanguage.value = result;
2025-05-22 16:51:26 +02:00
[error, result] = await systemModel.info();
if (error) return console.error(error);
info.value = result;
uptime.value = moment.duration(info.value.uptimeSecs, 'seconds').locale(navigator.language).humanize();
activeSince.value = info.value.activationTime ? moment(info.value.activationTime).fromNow() : 'unknown';
[error, result] = await dashboardModel.config();
if (error) return console.error(error);
config.value = result;
2025-02-17 11:18:57 +01:00
});
</script>
<template>
<div class="content">
2025-05-22 16:51:26 +02:00
<InputDialog ref="inputDialog"/>
<Section :title="$t('settings.title')">
<template #header-buttons>
<Button href="/logs.html?id=box" target="_blank">{{ $t('main.action.logs') }}</Button>
<Button @click="onReboot()">{{ $t('main.action.reboot') }}</Button>
</template>
<div class="info-row">
<div class="info-label">{{ $t('system.info.platformVersion') }}</div>
<div class="info-value">v{{ config.version }} ({{ config.ubuntuVersion }})</div>
</div>
<div class="info-row">
<div class="info-label">{{ $t('system.info.vendor') }}</div>
<div class="info-value">{{ info.sysVendor }}</div>
</div>
<div class="info-row">
<div class="info-label">{{ $t('system.info.product') }}</div>
<div class="info-value">{{ info.productName }}</div>
</div>
<div class="info-row">
<div class="info-label">CPU</div>
<div class="info-value">{{ cpus.length ? `${cpus.length} Core "${cpus[0].model}"` : '' }}</div>
</div>
<div class="info-row">
<div class="info-label">{{ $t('system.info.memory') }}</div>
<div class="info-value">{{ prettyDecimalSize(memory.memory) }} RAM <span v-show="memory.swap">&amp; {{ prettyDecimalSize(memory.swap) }} Swap</span></div>
</div>
<div class="info-row">
<div class="info-label">{{ $t('system.info.uptime') }}</div>
<div class="info-value">{{ uptime }}</div>
</div>
<div class="info-row" ng-show="info.activationTime">
<div class="info-label">{{ $t('system.info.activationTime') }}</div>
<div class="info-value">{{ activeSince }}</div>
</div>
</Section>
<Section :title="$t('system.locale.title')" :padding="false">
2025-05-22 16:26:24 +02:00
<SettingsItem wrap>
<FormGroup>
<label>{{ $t('settings.timezone.title') }}</label>
<div v-html="$t('settings.timezone.description', { timeZone })"></div>
</FormGroup>
<div style="display: flex; gap: 6px; align-items: center;">
<SingleSelect style="min-width: 160px" v-model="timeZone" :searchThreshold="10" :options="allTimezones" option-key="id" option-label="id" @select="onTimeZoneChange" />
</div>
</SettingsItem>
<SettingsItem wrap>
<FormGroup>
<label>{{ $t('settings.language.title') }}</label>
<div>{{ $t('settings.language.description') }}</div>
</FormGroup>
<div style="display: flex; gap: 6px; align-items: center;">
<SingleSelect v-model="language" :options="allLanguages" option-key="id" option-label="display" @select="onLanguageChange" />
</div>
</SettingsItem>
2025-02-17 11:18:57 +01:00
</Section>
2025-02-17 16:38:30 +01:00
2025-05-22 16:26:24 +02:00
<SystemUpdate />
<PrivateRegistry />
2025-02-17 11:18:57 +01:00
</div>
</template>