display retention policy and schedule in sites view

This commit is contained in:
Girish Ramakrishnan
2025-09-26 11:05:49 +02:00
parent defcf7d220
commit 70eb5c1053
3 changed files with 62 additions and 32 deletions

View File

@@ -8,31 +8,6 @@ const emit = defineEmits([ 'success' ]);
const backupSitesModel = BackupSitesModel.create();
const backupRetentions = [
{ name: '2 days', id: { keepWithinSecs: 2 * 24 * 60 * 60 }},
{ name: '1 week', id: { keepWithinSecs: 7 * 24 * 60 * 60 }}, // default
{ name: '1 month', id: { keepWithinSecs: 30 * 24 * 60 * 60 }},
{ name: '3 months', id: { keepWithinSecs: 3 * 30 * 24 * 60 * 60 }},
{ name: '2 daily, 4 weekly', id: { keepDaily: 2, keepWeekly: 4 }},
{ name: '3 daily, 4 weekly, 6 monthly', id: { keepDaily: 3, keepWeekly: 4, keepMonthly: 6 }},
{ name: '7 daily, 4 weekly, 12 monthly', id: { keepDaily: 7, keepWeekly: 4, keepMonthly: 12 }},
{ name: 'Forever', id: { keepWithinSecs: -1 }}
];
// values correspond to cron days
const cronDays = [
{ id: 0, name: 'Sunday' },
{ id: 1, name: 'Monday' },
{ id: 2, name: 'Tuesday' },
{ id: 3, name: 'Wednesday' },
{ id: 4, name: 'Thursday' },
{ id: 5, name: 'Friday' },
{ id: 6, name: 'Saturday' },
];
// generates 24h time sets (instead of american 12h) to avoid having to translate everything to locales eg. 12:00
const cronHours = Array.from({ length: 24 }).map(function (v, i) { return { id: i, name: (i < 10 ? '0' : '') + i + ':00' }; });
const id = ref('');
const busy = ref(false);
const formError = ref('');
@@ -92,8 +67,8 @@ defineExpose({
formError.value = false;
const currentRetentionString = JSON.stringify(site.retention);
let selectedRetention = backupRetentions.find(function (x) { return JSON.stringify(x.id) === currentRetentionString; });
if (!selectedRetention) selectedRetention = backupRetentions[0];
let selectedRetention = BackupSitesModel.backupRetentions.find(function (x) { return JSON.stringify(x.id) === currentRetentionString; });
if (!selectedRetention) selectedRetention = BackupSitesModel.backupRetentions[0];
configureRetention.value = selectedRetention.id;
if (site.schedule === 'never') {
@@ -105,10 +80,10 @@ defineExpose({
const tmpHours = tmp[2].split(',');
const tmpDays = tmp[5].split(',');
if (tmpDays[0] === '*') days.value = cronDays.map((day) => { return day.id; });
if (tmpDays[0] === '*') days.value = BackupSitesModel.cronDays.map((day) => { return day.id; });
else days.value = tmpDays.map((day) => { return parseInt(day, 10); });
if (tmpHours[0] === '*') hours.value = cronHours.map(h => h.id);
if (tmpHours[0] === '*') hours.value = BackupSitesModel.cronHours.map(h => h.id);
else hours.value = tmpHours.map((hour) => { return parseInt(hour, 10); });
}
@@ -139,15 +114,15 @@ defineExpose({
<Checkbox :label="$t('main.statusEnabled')" v-model="scheduleEnabled" />
<div v-if="scheduleEnabled" style="display: flex; gap: 10px; margin-left: 10px">
<div>{{ $t('backups.configureBackupSchedule.days') }}: <MultiSelect id="daysInput" :disabled="!scheduleEnabled" v-model="days" :options="cronDays" option-key="id" option-label="name"></MultiSelect></div>
<div>{{ $t('backups.configureBackupSchedule.hours') }}: <MultiSelect :disabled="!scheduleEnabled" v-model="hours" :options="cronHours" option-key="id" option-label="name"></MultiSelect></div>
<div>{{ $t('backups.configureBackupSchedule.days') }}: <MultiSelect id="daysInput" :disabled="!scheduleEnabled" v-model="days" :options="BackupSitesModel.cronDays" option-key="id" option-label="name"></MultiSelect></div>
<div>{{ $t('backups.configureBackupSchedule.hours') }}: <MultiSelect :disabled="!scheduleEnabled" v-model="hours" :options="BackupSitesModel.cronHours" option-key="id" option-label="name"></MultiSelect></div>
</div>
</FormGroup>
<FormGroup>
<label for="retentionInput">{{ $t('backups.configureBackupSchedule.retentionPolicy') }}</label>
<select id="retentionInput" v-model="configureRetention">
<option v-for="elem in backupRetentions" :key="elem.id" :value="elem.id">{{ elem.name }}</option>
<option v-for="elem in BackupSitesModel.backupRetentions" :key="elem.id" :value="elem.id">{{ elem.name }}</option>
</select>
</FormGroup>
</fieldset>