Skip to content

Commit c2d2e12

Browse files
committed
wip: KDateTimeRange does not support changes to the min and max properties #1123
wip: KDateTimeRange does not support changes to the min and max properties #1123 docs: added time components
1 parent ccd4c7e commit c2d2e12

File tree

9 files changed

+469
-270
lines changed

9 files changed

+469
-270
lines changed

core/client/components/form/KDateTimeRangeField.vue

+6-12
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,14 @@
1717
<template v-slot:control>
1818
<KDateTimeRange
1919
v-model="model"
20-
:options="options"
21-
:min="min"
22-
:max="max"
20+
v-bind="props"
2321
dense
2422
@update:modelValue="onChanged"
2523
/>
2624
</template>
2725
<!-- Helper -->
2826
<template v-if="hasHelper" v-slot:append>
29-
<k-action
27+
<KAction
3028
:id="properties.name + '-helper'"
3129
:label="helperLabel"
3230
:icon="helperIcon"
@@ -44,26 +42,22 @@
4442
<script>
4543
import _ from 'lodash'
4644
import { baseField } from '../../mixins'
45+
import KAction from '../action/KAction.vue'
4746
import KDateTimeRange from '../time/KDateTimeRange.vue'
4847
4948
export default {
5049
mixins: [baseField],
5150
components: {
51+
KAction,
5252
KDateTimeRange
5353
},
5454
computed: {
5555
formattedDateTimeRange () {
5656
// TODO
5757
return this.model
5858
},
59-
options () {
60-
return _.get(this.properties.field, 'options', {})
61-
},
62-
min () {
63-
return _.get(this.properties.field, 'min')
64-
},
65-
max () {
66-
return _.get(this.properties.field, 'max')
59+
props () {
60+
return _.omit(_.get(this.properties, 'field'), ['component', 'dense'])
6761
}
6862
},
6963
methods: {

core/client/components/form/KDatetimeField.vue

+6-13
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,14 @@
1717
<template v-slot:control>
1818
<KDateTime
1919
v-model="model"
20-
:options="options"
21-
:min="min"
22-
:max="max"
20+
v-bind="props"
2321
dense
2422
@update:modelValue="onChanged"
2523
/>
2624
</template>
2725
<!-- Helper -->
2826
<template v-if="hasHelper" v-slot:append>
29-
<k-action
27+
<KAction
3028
:id="properties.name + '-helper'"
3129
:label="helperLabel"
3230
:icon="helperIcon"
@@ -44,26 +42,21 @@
4442
<script>
4543
import _ from 'lodash'
4644
import { baseField } from '../../mixins'
45+
import KAction from '../action/KAction.vue'
4746
import KDateTime from '../time/KDateTime.vue'
4847
4948
export default {
5049
mixins: [baseField],
5150
components: {
51+
KAction,
5252
KDateTime
5353
},
5454
computed: {
5555
formattedDateTime () {
56-
// TODO
5756
return this.model
5857
},
59-
options () {
60-
return _.get(this.properties.field, 'options', {})
61-
},
62-
min () {
63-
return _.get(this.properties.field, 'min')
64-
},
65-
max () {
66-
return _.get(this.properties.field, 'max')
58+
props () {
59+
return _.omit(_.get(this.properties, 'field'), ['component', 'dense'])
6760
}
6861
},
6962
methods: {

core/client/components/time/KAbsoluteTimeRange.vue

+6-13
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
<template>
22
<KDateTimeRange
33
v-model="dateTimeRangeModel"
4-
:options="dateTimeRangeOptions"
5-
:min="props.min"
6-
:max="props.max"
7-
:dense="props.dense"
8-
:disabled="props.disabled"
4+
:min="min"
5+
:max="max"
6+
:dense="dense"
7+
:disabled="disabled"
98
/>
109
</template>
1110

1211
<script setup>
12+
import moment from 'moment'
1313
import { ref, watch, onMounted, onBeforeUnmount } from 'vue'
14-
import KDateTimeRange from './KDateTimeRange.vue'
1514
import { Events } from '../../events'
1615
import { Time } from '../../time'
17-
import moment from 'moment'
16+
import KDateTimeRange from './KDateTimeRange.vue'
1817
1918
const props = defineProps({
2019
min: {
@@ -49,12 +48,6 @@ const dateTimeRangeModel = ref({
4948
start: start.toISOString(),
5049
end: end.toISOString()
5150
})
52-
const dateTimeRangeOptions = ref({
53-
separator: '-',
54-
date: {
55-
format: 'DD/MM/YYYY'
56-
}
57-
})
5851
5952
// Watch
6053
watch(dateTimeRangeModel, (newDateTimeRange, oldDateTimeRange) => {

core/client/components/time/KDate.vue

+51-28
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
11
<template>
2-
<q-btn
3-
id="date-button"
4-
:icon="icon"
5-
:label="label"
6-
flat
7-
no-caps
8-
:disable="disabled"
9-
:dense="dense"
10-
>
2+
<q-btn v-bind="computedButton">
113
<q-popup-proxy>
124
<q-date
135
id="date-picker"
14-
v-model="model"
15-
v-bind="picker"
6+
v-model="computedModel"
7+
v-bind="computedPicker"
168
/>
179
</q-popup-proxy>
1810
</q-btn>
@@ -23,16 +15,29 @@ import _ from 'lodash'
2315
import moment from 'moment'
2416
import { computed } from 'vue'
2517
import { Time } from '../../time.js'
18+
import { i18n } from '../../i18n.js'
2619
2720
// Props
2821
const props = defineProps({
2922
modelValue: {
3023
type: String,
31-
default: () => null
24+
default: null
3225
},
33-
options: {
26+
picker: {
3427
type: Object,
35-
default: () => {}
28+
default: () => null
29+
},
30+
format: {
31+
type: String,
32+
default: null
33+
},
34+
placeholder: {
35+
type: String,
36+
default: null
37+
},
38+
icon: {
39+
type: String,
40+
default: 'las la-calendar'
3641
},
3742
disabled: {
3843
type: Boolean,
@@ -51,28 +56,46 @@ const emit = defineEmits(['update:modelValue'])
5156
const mask = 'YYYY/MM/DD'
5257
5358
// Computed
54-
const icon = computed(() => {
55-
return _.get(props.options, 'icon')
56-
})
57-
const label = computed(() => {
58-
if (props.modelValue) return moment(props.modelValue, mask).format(format.value)
59-
return _.get(props.options, 'helper')
60-
})
61-
const model = computed({
59+
const computedModel = computed({
6260
get: function () {
6361
return props.modelValue
6462
},
6563
set: function (value) {
6664
emit('update:modelValue', value)
6765
}
6866
})
69-
const format = computed(() => {
70-
const dateDateFormat = _.get(Time.getFormat(), 'date.short')
71-
const defaultYearFormat = _.get(Time.getFormat(), 'year.long')
72-
return _.get(props.options, 'format', `${dateDateFormat}/${defaultYearFormat}`)
67+
const computedButton = computed(() => {
68+
// compute format
69+
let format = props.format
70+
if (_.isEmpty(format)) {
71+
const dateFormat = _.get(Time.getFormat(), 'date.short')
72+
const yearFormat = _.get(Time.getFormat(), 'year.long')
73+
format = `${dateFormat}/${yearFormat}`
74+
}
75+
// compute label
76+
let label
77+
if (!_.isEmpty(computedModel.value)) label = moment(computedModel.value, mask).format(format)
78+
else label = i18n.tie(props.placeholder)
79+
// define button spec
80+
const spec = {
81+
id: 'date-button',
82+
label,
83+
flat: true,
84+
noCaps: true,
85+
disable: props.disabled,
86+
dense: true,
87+
class: props.dense ? 'q-px-xs': 'q-pa-sm'
88+
}
89+
// add icon if defined
90+
if (props.icon) spec.icon = props.icon
91+
return spec
7392
})
74-
const picker = computed(() => {
75-
return _.merge({}, _.get(props.options, 'picker'), { mask })
93+
const computedPicker = computed(() => {
94+
const picker = { mask }
95+
return _.merge({}, props.picker, picker)
7696
})
7797
98+
// Immediate
99+
if (_.isEmpty(props.modelValue) &&
100+
_.isEmpty(props.placeholder)) computedModel.value = moment.utc().format(mask)
78101
</script>

0 commit comments

Comments
 (0)