From a68a6cff5bd68e8cc4321ad4db351dbf4edd2348 Mon Sep 17 00:00:00 2001 From: "andy.lee" Date: Wed, 21 Aug 2024 10:07:09 +0800 Subject: [PATCH] add HarvesterCronExpression formatter Signed-off-by: andy.lee --- pkg/harvester/config/table-headers.js | 11 ++++--- .../edit/harvesterhci.io.schedulevmbackup.vue | 15 ++------- .../formatters/HarvesterCronExpression.vue | 32 +++++++++++++++++++ 3 files changed, 40 insertions(+), 18 deletions(-) create mode 100644 pkg/harvester/formatters/HarvesterCronExpression.vue diff --git a/pkg/harvester/config/table-headers.js b/pkg/harvester/config/table-headers.js index 1529e02041b..63a53ba5745 100644 --- a/pkg/harvester/config/table-headers.js +++ b/pkg/harvester/config/table-headers.js @@ -45,11 +45,12 @@ export const SNAPSHOT_TARGET_VOLUME = { // The column of cron expression volume on VM schedules list page export const VM_SCHEDULE_CRON = { - name: 'CronExpression', - labelKey: 'harvester.tableHeaders.cronExpression', - value: 'spec.cron', - align: 'center', - sort: 'spec.cron', + name: 'CronExpression', + labelKey: 'harvester.tableHeaders.cronExpression', + value: 'spec.cron', + align: 'center', + sort: 'spec.cron', + formatter: 'HarvesterCronExpression', }; // The column of retain on VM schedules list page diff --git a/pkg/harvester/edit/harvesterhci.io.schedulevmbackup.vue b/pkg/harvester/edit/harvesterhci.io.schedulevmbackup.vue index d4fcc3fca42..820315e3ecf 100644 --- a/pkg/harvester/edit/harvesterhci.io.schedulevmbackup.vue +++ b/pkg/harvester/edit/harvesterhci.io.schedulevmbackup.vue @@ -180,18 +180,8 @@ export default { }, validateFailure(count) { - if (count > this.value.spec.retain) { - this.$set(this, 'maxFailure', this.value.spec.retain); - } else if (count < 2) { - this.$set(this, 'maxFailure', 2); - } - }, - - validateRetain(count) { - if (count > 250) { - this.$set(this, 'retain', 250); - } else if (count < 2) { - this.$set(this, 'retain', 2); + if (this.value.spec.retain && count > this.value.spec.retain) { + this.$set(this.value.spec, 'maxFailure', this.value.spec.retain); } }, }, @@ -290,7 +280,6 @@ export default { required :tooltip="t('harvester.schedule.retain.tooltip')" :disabled="isBackupTargetUnAvailable || isView" - @input="validateRetain" /> +import cronstrue from 'cronstrue'; + +export default { + props: { + value: { + type: String, + default: '' + }, + }, + computed: { + cronTooltipHint() { + let cronHint = ''; + + try { + cronHint = cronstrue.toString(this.value, { verbose: true }); + } catch (e) { + cronHint = this.t('generic.invalidCron'); + } + + return cronHint || this.value.spec.cron; + } + + } +}; + + +