Skip to content

Commit

Permalink
fix(custom-period-input): parse initial period correctly (DEV-847) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
arsenijesavic authored Sep 7, 2023
1 parent 5532a94 commit fbdd8e9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/components/form/custom-period-input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const secondsToInterval = (seconds) => {
let period = ''
const minutes = Math.floor(seconds / 60)
const hours = Math.floor(seconds / 3600)
const days = Math.floor(seconds / 86400)
const weeks = Math.floor(seconds / 604800)
Expand All @@ -20,16 +21,18 @@ const secondsToInterval = (seconds) => {
period = 'days'
} else if (hours > 0) {
period = 'hours'
} else if (minutes > 0) {
period = 'minutes'
}
return { period, months, weeks, days, hours }
return { period, months, weeks, days, hours, minutes }
}
export default {
name: 'custom-period-input',
data () {
return {
period: 'days'
period: ''
}
},
Expand All @@ -51,6 +54,7 @@ export default {
},
set (value) {
if (this.type === 'time' && this.period !== '') {
if (this.period === 'minutes') { value = (value * 60) }
if (this.period === 'hours') { value = (value * 60) * 60 }
if (this.period === 'days') { value = value * 24 * 60 * 60 }
if (this.period === 'weeks') { value = value * 7 * 24 * 60 * 60 }
Expand All @@ -65,8 +69,15 @@ export default {
label () { return this.$t(`periods.${this.period}`) }
},
mounted () {
this.period = secondsToInterval(this.value).period
watch: {
value: {
handler: function (value) {
if (value && !this.period) {
this.period = secondsToInterval(this.value).period
}
},
immediate: true
}
}
}
Expand All @@ -87,7 +98,11 @@ div.custom-period-input
.col-6
q-btn-dropdown.full-width(:disable="disable" :label="label" outline no-caps rounded unelevated)
q-list
q-item(clickable v-close-popup @click="period = 'hours'")
q-item(clickable v-close-popup @click="period = 'minutes'")
q-item-section
q-item-label {{ $t('periods.minutes') }}

q-item(clickable v-close-popup @click="period = 'minutes'")
q-item-section
q-item-label {{ $t('periods.hours') }}

Expand Down
2 changes: 2 additions & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"delete": "Delete"
},
"periods": {
"minute": "Minute",
"minutes": "Minutes",
"hour": "Hour",
"hours": "Hours",
"day": "Day",
Expand Down

0 comments on commit fbdd8e9

Please sign in to comment.