move helper functions out of the model and into the view

This commit is contained in:
Girish Ramakrishnan
2025-10-07 14:41:10 +02:00
parent 1a674a30ac
commit 773435fb7f
2 changed files with 35 additions and 39 deletions
-35
View File
@@ -1,7 +1,6 @@
import { fetcher } from '@cloudron/pankow';
import { API_ORIGIN } from '../constants.js';
import { cronDays, cronHours } from '../utils.js';
function create() {
const accessToken = localStorage.token;
@@ -220,41 +219,7 @@ const backupRetentions = [
{ name: 'Forever', id: { keepWithinSecs: -1 }}
];
function prettyBackupSchedule(pattern) {
if (!pattern) return '';
const tmp = pattern.split(' ');
if (tmp.length === 1) return pattern.charAt(0).toUpperCase() + pattern.slice(1); // case for 'never' - capitalize
const hours = tmp[2].split(','), days = tmp[5].split(',');
let prettyDay;
if (days.length === 7 || days[0] === '*') {
prettyDay = 'Everyday';
} else {
prettyDay = days.map(function (day) { return cronDays[parseInt(day, 10)].name.substr(0, 3); }).join(',');
}
const prettyHour = hours.map(function (hour) { return cronHours[parseInt(hour, 10)].name; }).join(',');
return prettyDay + ' at ' + prettyHour;
};
function prettyBackupRetention(retention) {
function stableStringify(obj) { return JSON.stringify(obj, Object.keys(obj).sort()); }
const tmp = backupRetentions.find(function (p) { return stableStringify(p.id) === stableStringify(retention); });
return tmp ? tmp.name : '';
}
function prettyBackupContents(contents) {
if (!contents) return 'Everything';
if (contents.include) return `Only ${contents.include.length} item(s)`;
if (contents.exclude) return `Exclude ${contents.exclude.length} item(s)`;
return '';
}
export default {
create,
backupRetentions,
prettyBackupSchedule,
prettyBackupRetention,
prettyBackupContents
};