Skip to content

Commit

Permalink
add HarvesterCronExpression formatter
Browse files Browse the repository at this point in the history
Signed-off-by: andy.lee <[email protected]>
  • Loading branch information
a110605 committed Aug 21, 2024
1 parent 4508639 commit a68a6cf
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 18 deletions.
11 changes: 6 additions & 5 deletions pkg/harvester/config/table-headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 2 additions & 13 deletions pkg/harvester/edit/harvesterhci.io.schedulevmbackup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
},
},
Expand Down Expand Up @@ -290,7 +280,6 @@ export default {
required
:tooltip="t('harvester.schedule.retain.tooltip')"
:disabled="isBackupTargetUnAvailable || isView"
@input="validateRetain"
/>
<LabeledInput
v-model.number="value.spec.maxFailure"
Expand Down
32 changes: 32 additions & 0 deletions pkg/harvester/formatters/HarvesterCronExpression.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<script>
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;
}
}
};
</script>

<template>
<span v-clean-tooltip="cronTooltipHint">
{{ value }}
</span>
</template>

0 comments on commit a68a6cf

Please sign in to comment.