You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
2.7 KiB

  1. <template lang='pug'>
  2. v-toolbar.radius-7(flat, :color='$vuetify.theme.dark ? "grey darken-4-l3" : "grey lighten-3"')
  3. .body-2.mr-3 {{$t('common:duration.every')}}
  4. v-text-field(
  5. solo
  6. hide-details
  7. flat
  8. reverse
  9. v-model='minutes'
  10. style='flex: 1 1 70px;'
  11. )
  12. .body-2.mx-3 {{$t('common:duration.minutes')}}
  13. v-divider.mr-3
  14. v-text-field(
  15. solo
  16. hide-details
  17. flat
  18. reverse
  19. v-model='hours'
  20. style='flex: 1 1 70px;'
  21. )
  22. .body-2.mx-3 {{$t('common:duration.hours')}}
  23. v-divider.mr-3
  24. v-text-field(
  25. solo
  26. hide-details
  27. flat
  28. reverse
  29. v-model='days'
  30. style='flex: 1 1 70px;'
  31. )
  32. .body-2.mx-3 {{$t('common:duration.days')}}
  33. v-divider.mr-3
  34. v-text-field(
  35. solo
  36. hide-details
  37. flat
  38. reverse
  39. v-model='months'
  40. style='flex: 1 1 70px;'
  41. )
  42. .body-2.mx-3 {{$t('common:duration.months')}}
  43. v-divider.mr-3
  44. v-text-field(
  45. solo
  46. hide-details
  47. flat
  48. reverse
  49. v-model='years'
  50. style='flex: 1 1 70px;'
  51. )
  52. .body-2.mx-3 {{$t('common:duration.years')}}
  53. </template>
  54. <script>
  55. import _ from 'lodash'
  56. import moment from 'moment'
  57. export default {
  58. props: {
  59. value: {
  60. type: String,
  61. default: 'PT5M'
  62. }
  63. },
  64. data() {
  65. return {
  66. duration: moment.duration(0)
  67. }
  68. },
  69. computed: {
  70. years: {
  71. get() { return this.duration.years() || 0 },
  72. set(val) { this.rebuild(_.toNumber(val), 'years') }
  73. },
  74. months: {
  75. get() { return this.duration.months() || 0 },
  76. set(val) { this.rebuild(_.toNumber(val), 'months') }
  77. },
  78. days: {
  79. get() { return this.duration.days() || 0 },
  80. set(val) { this.rebuild(_.toNumber(val), 'days') }
  81. },
  82. hours: {
  83. get() { return this.duration.hours() || 0 },
  84. set(val) { this.rebuild(_.toNumber(val), 'hours') }
  85. },
  86. minutes: {
  87. get() { return this.duration.minutes() || 0 },
  88. set(val) { this.rebuild(_.toNumber(val), 'minutes') }
  89. }
  90. },
  91. watch: {
  92. value(newValue, oldValue) {
  93. this.duration = moment.duration(newValue)
  94. }
  95. },
  96. methods: {
  97. rebuild(val, unit) {
  98. if (!_.isFinite(val) || val < 0) {
  99. val = 0
  100. }
  101. const newDuration = {
  102. minutes: this.duration.minutes(),
  103. hours: this.duration.hours(),
  104. days: this.duration.days(),
  105. months: this.duration.months(),
  106. years: this.duration.years()
  107. }
  108. _.set(newDuration, unit, val)
  109. this.duration = moment.duration(newDuration)
  110. this.$emit('input', this.duration.toISOString())
  111. }
  112. },
  113. mounted() {
  114. this.duration = moment.duration(this.value)
  115. }
  116. }
  117. </script>