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.

114 lines
2.4 KiB

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