display retention policy and schedule in sites view
This commit is contained in:
@@ -193,6 +193,57 @@ function 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' }; });
|
||||
|
||||
function prettyBackupSchedule(pattern) {
|
||||
if (!pattern) return '';
|
||||
const tmp = pattern.split(' ');
|
||||
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 : '';
|
||||
}
|
||||
|
||||
export default {
|
||||
create,
|
||||
backupRetentions,
|
||||
cronDays,
|
||||
cronHours,
|
||||
prettyBackupSchedule,
|
||||
prettyBackupRetention
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user