Skip to content

Commit

Permalink
💊 [1.3.1] { hotfix } Range datepicker with empty values (#43)
Browse files Browse the repository at this point in the history
* 💊 { hotfix } Fix error with date range picker & empty values

* Finish fix for empty values in range mode

* 🏗️ Build1.3.1
  • Loading branch information
LouisMazel authored Oct 22, 2018
1 parent c83f057 commit e292dc2
Show file tree
Hide file tree
Showing 23 changed files with 76 additions and 59 deletions.
2 changes: 1 addition & 1 deletion demo/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><title>vue-ctk-date-time-picker</title><link rel=stylesheet href=./assets/main.css><link href=./static/css/app.596179cf1d5485374e4ea3ebb34a61c7.css rel=stylesheet></head><body><div id=app></div><script src=/build/build.js></script><script type=text/javascript src=./static/js/manifest.3ad1d5771e9b13dbdad2.js></script><script type=text/javascript src=./static/js/vendor.1eb7121699eee7ac0a43.js></script><script type=text/javascript src=./static/js/app.946a614ca530d8f4d7da.js></script></body></html>
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><title>vue-ctk-date-time-picker</title><link rel=stylesheet href=./assets/main.css><link href=./static/css/app.82ec24b8a763f7789a8bb63122344983.css rel=stylesheet></head><body><div id=app></div><script src=/build/build.js></script><script type=text/javascript src=./static/js/manifest.3ad1d5771e9b13dbdad2.js></script><script type=text/javascript src=./static/js/vendor.1eb7121699eee7ac0a43.js></script><script type=text/javascript src=./static/js/app.12e502addb1fc36b12c2.js></script></body></html>

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions demo/static/js/app.12e502addb1fc36b12c2.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions demo/static/js/app.12e502addb1fc36b12c2.js.map

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions demo/static/js/app.946a614ca530d8f4d7da.js

This file was deleted.

1 change: 0 additions & 1 deletion demo/static/js/app.946a614ca530d8f4d7da.js.map

This file was deleted.

2 changes: 1 addition & 1 deletion demo/static/js/manifest.3ad1d5771e9b13dbdad2.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/umd/vue-ctk-date-time-picker.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/umd/vue-ctk-date-time-picker.min.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/umd/vue-ctk-date-time-picker.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/umd/vue-ctk-date-time-picker.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/vue-ctk-date-time-picker.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/vue-ctk-date-time-picker.min.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/vue-ctk-date-time-picker.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/vue-ctk-date-time-picker.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-ctk-date-time-picker",
"version": "1.3.0",
"version": "1.3.1",
"description": "A vue component for select date & time (by Chronotruck)",
"author": "Louis Mazel <[email protected]>",
"main": "dist/vue-ctk-date-time-picker.min.js",
Expand Down
4 changes: 4 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@
start: '2018-04-05',
end: '2018-04-20'
},
rangeValues2: {
start: null,
end: null
},
timePickerValue: '14:26',
minuteInterval: 5,
minuteInterval2: 10,
Expand Down
1 change: 0 additions & 1 deletion src/vue-ctk-date-time-picker/_subs/CtkDatePickerAgenda.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@
:min-date="minDate"
:max-date="maxDate"
:disabled-dates="disabledDates"
:value="value"
:dark="dark"
@change-date="selectDate"
@change-month="changeMonth"
Expand Down
29 changes: 19 additions & 10 deletions src/vue-ctk-date-time-picker/_subs/CtkDateRangePicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</div>

<div class="flex justify-content-between">
<span class="datepicker-date dots-text flex-1">{{ getDateFormatted() }}</span>
<span class="datepicker-date dots-text flex-1">{{ getRangeDatesFormatted }}</span>
</div>
</div>
<div class="datetimepicker-container flex">
Expand All @@ -46,7 +46,6 @@
:color="color"
:min-date="minDate"
:max-date="maxDate"
:value="value"
:dark="dark"
class="date-range-picker"
range-mode
Expand Down Expand Up @@ -113,32 +112,42 @@
}
},
year () {
const date = this.dateTime.end ? this.dateTime.end : this.dateTime.start
const date = this.dateTime.start || this.dateTime.end
? this.dateTime.end ? this.dateTime.end : this.dateTime.start
: moment()
return date.format('YYYY')
},
getRangeDatesFormatted () {
const hasStartValues = this.value && this.value.start
const hasEndValues = this.value && this.value.end
if (!hasStartValues && !hasEndValues) {
return '... - ...'
} else if (hasStartValues || hasEndValues) {
const datesFormatted = hasStartValues ? `${moment(this.dateTime.start).locale(this.locale).format('ddd D MMM')}` : '...'
return hasEndValues ? `${datesFormatted} - ${moment(this.dateTime.end).locale(this.locale).format('ddd D MMM')}` : `${datesFormatted} - ...`
} else {
return null
}
}
},
watch: {
dateTime: {
handler () {
this.month = this.getMonth()
this.getDateFormatted()
},
deep: true
},
locale () {
this.month = this.getMonth()
this.getDateFormatted()
}
},
methods: {
getMonth () {
const date = this.dateTime.end ? this.dateTime.end : this.dateTime.start
const date = this.dateTime.start || this.dateTime.end
? this.dateTime.end ? this.dateTime.end : this.dateTime.start
: moment()
return new Month(date.month(), date.year())
},
getDateFormatted () {
const datesFormatted = `${moment(this.dateTime.start).locale(this.locale).format('ddd D MMM')}`
return this.dateTime.end ? `${datesFormatted} - ${moment(this.dateTime.end).locale(this.locale).format('ddd D MMM')}` : `${datesFormatted} - ?`
},
selectDate (dateTime) {
this.$emit('change-date', dateTime)
this.$refs['calendar-shortcut'].unSelectAllShortcuts()
Expand Down
27 changes: 13 additions & 14 deletions src/vue-ctk-date-time-picker/_subs/_subs/CtkDatePicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
v-for="day in monthDays"
:key="day.format('D')"
:class="{
selected: isSelected(day) && value && !isDisabled(day),
selected: isSelected(day) && !isDisabled(day),
disabled: (isDisabled(day) || isWeekEndDay(day)),
enable: !(isDisabled(day) || isWeekEndDay(day)),
between: isBetween(day) && rangeMode,
Expand Down Expand Up @@ -102,7 +102,6 @@
locale: {type: String, default: String},
inline: {type: Boolean, default: Boolean},
noWeekendsDays: {type: Boolean, default: Boolean},
value: {type: [String, Object], default: String},
rangeMode: {type: Boolean, default: false},
disabledDates: {type: Array, default: Array},
dark: {type: Boolean, default: false}
Expand All @@ -111,11 +110,7 @@
return {
transitionDaysName: 'slidenext',
transitionLabelName: 'slidevnext',
weekDays: getWeekDays(this.locale),
days: {
start: null,
end: null
}
weekDays: getWeekDays(this.locale)
}
},
computed: {
Expand Down Expand Up @@ -161,8 +156,12 @@
},
isSelected (day) {
const date = [
...(this.dateTime.start ? [this.dateTime.start.format('YYYY-MM-DD')] : [this.dateTime.format('YYYY-MM-DD')]),
...(this.dateTime.end ? [this.dateTime.end.format('YYYY-MM-DD')] : [])
...(this.dateTime.start
? [this.dateTime.start.format('YYYY-MM-DD')]
: this.rangeMode ? [] : [this.dateTime.format('YYYY-MM-DD')]),
...(this.dateTime.end
? [this.dateTime.end.format('YYYY-MM-DD')]
: this.rangeMode ? [] : [this.dateTime.format('YYYY-MM-DD')])
]
return date.indexOf(day.format('YYYY-MM-DD')) > -1
},
Expand All @@ -185,13 +184,13 @@
},
selectDate (day) {
if (this.rangeMode) {
if (!this.days.start || this.days.end || day.isBefore(this.days.start)) {
this.days.start = day
this.days.end = null
if (!this.dateTime.start || this.dateTime.end || day.isBefore(this.dateTime.start)) {
this.dateTime.start = day
this.dateTime.end = null
} else {
this.days.end = day
this.dateTime.end = day
}
this.$emit('change-date', this.days)
this.$emit('change-date', this.dateTime)
} else {
this.$emit('change-date', day)
}
Expand Down
38 changes: 22 additions & 16 deletions src/vue-ctk-date-time-picker/vue-ctk-date-time-picker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -186,30 +186,18 @@
? this.getRangeDatesTimeFormat(val)
: this.getDateTimeFormat(val))
)
} else if (this.rangeMode) {
this.$emit('input', this.getRangeDatesTimeFormat({}))
}
moment.locale(this.locale)
},
methods: {
getRangeDatesTime () {
const dates = {
start: moment(this.value.start),
end: this.value.end ? moment(this.value.end) : null
}
return dates
},
getDateTime () {
const date = this.disableDate
? this.value ? moment(`${moment().format('YYYY-MM-DD')} ${this.value}`) : moment()
: this.value ? moment(this.value) : moment()
return nearestMinutes(this.minuteInterval, date, moment)
},
getRangeDatesTimeFormat (day) {
const dates = {
start: moment(day.start).format(this.format),
end: day.end ? moment(day.end).format(this.format) : null
}
return dates
},
getDateTimeFormat (day) {
return nearestMinutes(this.minuteInterval, day, moment).format(this.format)
},
Expand All @@ -221,9 +209,27 @@
: null
return date ? nearestMinutes(this.minuteInterval, date, moment).locale(this.locale).format(this.formatted) : null
},
getRangeDatesTime () {
const hasStartValues = this.value && this.value.start
const hasEndValues = this.value && this.value.end
return { start: hasStartValues ? moment(this.value.start) : null, end: hasEndValues ? moment(this.value.end) : null }
},
getRangeDatesTimeFormat (day) {
const { start, end } = day
return {
start: start ? moment(start).format(this.format) : null,
end: end ? moment(end).format(this.format) : null
}
},
getRangeDatesFormatted () {
const datesFormatted = `${moment(this.value.start).locale(this.locale).format(this.formatted)}`
return this.value.end ? `${datesFormatted} - ${moment(this.value.end).locale(this.locale).format(this.formatted)}` : `${datesFormatted} - ?`
const hasStartValues = this.value && this.value.start
const hasEndValues = this.value && this.value.end
if (hasStartValues || hasEndValues) {
const datesFormatted = hasStartValues ? `${moment(this.value.start).locale(this.locale).format(this.formatted)}` : '...'
return hasEndValues ? `${datesFormatted} - ${moment(this.value.end).locale(this.locale).format(this.formatted)}` : `${datesFormatted} - ...`
} else {
return null
}
},
changeDate (day) {
this.$emit('input', (this.rangeMode ? this.getRangeDatesTimeFormat(day) : this.getDateTimeFormat(day)))
Expand Down

0 comments on commit e292dc2

Please sign in to comment.