Skip to content
This repository has been archived by the owner on Jan 7, 2022. It is now read-only.

Adding Allowed Date Ranges #226

Open
wants to merge 33 commits into
base: v1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
8ec5a39
* started functionality to support allowed date ranges instead of a d…
Jun 16, 2020
f24cce3
started to try and implement time support
Jun 16, 2020
f0ccf91
added reworks to my initial drunken attempted.
Jun 17, 2020
cad86f7
slight time changes a few TODOS to fix for later
Jun 17, 2020
9aeec23
adding dist to allow fork usage
Jun 17, 2020
1063383
Fix for the workaround for timeSelectinDisable
Jun 17, 2020
ba155a0
fix for when no max, min or ranges provided
Jun 18, 2020
3fa9416
* added back all the min-max for backward compatilibity
Jul 13, 2020
8af46c1
Added new props for backdrop-click
alanbosco Aug 19, 2020
d6770a1
Added new props for and hide backdrop
alanbosco Aug 19, 2020
05bf7c8
Merge branch 'alanbosco-feature-backdrop' into v1.x
mariomka Aug 21, 2020
f043e11
AddingDisabledDatesSupport: re-removed dist
phyzical Aug 22, 2020
7f4942d
AddingDisabledDatesSupport: various documentation added readme and de…
phyzical Aug 22, 2020
75b52df
AddingDisabledDatesSupport: DateTimePicker rework Needed to refactor …
phyzical Aug 22, 2020
e0b3319
AddingDisabledDatesSupport: UTC fix moved the UTC to date comparision…
phyzical Aug 22, 2020
dfb03ed
AddingDisabledDatesSupport: added back pre commit
phyzical Aug 22, 2020
cb006ea
AddingDisabledDatesSupport: removed console.log
phyzical Aug 22, 2020
7aa917c
* started functionality to support allowed date ranges instead of a d…
Jun 16, 2020
123238b
started to try and implement time support
Jun 16, 2020
b95e93c
added reworks to my initial drunken attempted.
Jun 17, 2020
7af3eba
slight time changes a few TODOS to fix for later
Jun 17, 2020
a5eaecd
adding dist to allow fork usage
Jun 17, 2020
ea185e8
Fix for the workaround for timeSelectinDisable
Jun 17, 2020
a9b3430
fix for when no max, min or ranges provided
Jun 18, 2020
1d67760
* added back all the min-max for backward compatilibity
Jul 13, 2020
dc7b0af
AddingDisabledDatesSupport: re-removed dist
phyzical Aug 22, 2020
3662648
AddingDisabledDatesSupport: various documentation added readme and de…
phyzical Aug 22, 2020
176008c
AddingDisabledDatesSupport: DateTimePicker rework Needed to refactor …
phyzical Aug 22, 2020
734b3d3
AddingDisabledDatesSupport: UTC fix moved the UTC to date comparision…
phyzical Aug 22, 2020
e03cc94
AddingDisabledDatesSupport: added back pre commit
phyzical Aug 22, 2020
b7c5b8a
AddingDisabledDatesSupport: removed console.log
phyzical Aug 22, 2020
3c855a8
AddingDisabledDatesSupport: Merge branch 'AddingDisabledDatesSupport'…
phyzical Aug 22, 2020
41ca708
AddingDisabledDatesSupport: update to demo to match code
phyzical Aug 22, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
node_modules/
npm-debug.log
test/coverage
dist
yarn-error.log
reports
demo/dist
.idea
dist
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,15 @@ phrases | `Object` | `{ok: 'Ok', cancel: 'Cancel'}` | Phrases.
use12-hour | `Boolean` | `false` | Display 12 hour (AM/PM) mode
hour-step | `Number` | `1` | Hour step.
minute-step | `Number` | `1` | Minute step.
min-datetime | ISO 8601 `String` | `null` | Minimum datetime.
max-datetime | ISO 8601 `String` | `null` | Maximum datetime.
min-datetime | ISO 8601 `String` | `null` | Minimum datetime. NOTE: Has no effect when allowed-date-time-ranges is provided
max-datetime | ISO 8601 `String` | `null` | Maximum datetime. NOTE: Has no effect when allowed-date-time-ranges is provided
auto | `Boolean` | `false` | Auto continue/close on select.
week-start | `Number` | auto from locale if _weekstart_ is available or `1` | First day of the week. 1 is Monday and 7 is Sunday.
flow | `Array` | Depends of *type* | Customize steps flow, steps available: time, date, month, year. Example: ['year', 'date', 'time']
title | `String` | `''` | Popup title.
hide-backdrop | `Boolean` | `false` | Show/Hide backdrop.
backdrop-click | `Boolean` | `true` | Enable/Disable backdrop click to cancel (outside click).
allowed-date-time-ranges | `Array` of `Array`'s of 2 `Datetime` | `[]` | Array of Arrays containing Allowed DateTime ranges i.e `[[DateTime.fromISO('2017-05-15T17:36'),DateTime.fromISO('2017-05-17T17:36')]]` (Allowed datetime ranges are the only selectable ranges)

Input inherits all props not defined above but `style` and `class` will be inherited by root element. [See inheritAttrs option](https://vuejs.org/v2/api/#inheritAttrs)

Expand Down
78 changes: 53 additions & 25 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,11 @@ <h2>Macro tokens</h2>
</div>
</div>

<h2>Complete demo</h2>
<h2>Complete demo min-max</h2>

<div class="example">
<div class="example-inputs">
<datetime
type="datetime"
<div class="example">
<div class="example-inputs">
<datetime type="datetime"
v-model="datetimeEmpty"
placeholder="Select date"
class="my-wrapper-class"
Expand All @@ -117,17 +116,17 @@ <h2>Complete demo</h2>
:max-datetime="maxDatetime"
:week-start="7"
use12-hour
auto
></datetime>

<div class="values">
<p>
<strong>Value:</strong> {{ datetimeEmpty }}
</p>
auto>
</datetime>

<div class="values">
<p>
<strong>Value:</strong> {{ datetimeEmpty }}
</p>
</div>
</div>
</div>
<div class="example-code">
<pre><code>&#x3C;datetime
<div class="example-code">
<pre><code>&#x3C;datetime
type=&#x22;datetime&#x22;
v-model=&#x22;datetimeEmpty&#x22;
input-class=&#x22;my-class&#x22;
Expand All @@ -143,19 +142,48 @@ <h2>Complete demo</h2>
use12-hour
auto
&#x3E;&#x3C;/datetime&#x3E;</code></pre>
</div>
</div>
</div>

<h2>Theming</h2>
<h2>Complete demo ranges</h2>

<div class="example">
<div class="example-inputs">
<datetime type="datetime" v-model="datetimeTheming" class="theme-orange"></datetime>

<div class="values">
<p>
<strong>Value:</strong> {{ datetimeTheming }}
</p>
<div class="example">
<div class="example-inputs">
<datetime type="datetime"
v-model="datetimeEmpty"
placeholder="Select date"
class="my-wrapper-class"
input-class="my-input-class"
value-zone="America/New_York"
zone="Asia/Shanghai"
:format="{ year: 'numeric', month: 'long', day: 'numeric', hour: 'numeric', minute: '2-digit', timeZoneName: 'short' }"
:phrases="{ok: 'Continue', cancel: 'Exit'}"
:allowed-date-time-ranges="allowedDateTimeRanges"
:week-start="7"
use12-hour
auto>
</datetime>

<div class="values">
<p>
<strong>Value:</strong> {{ datetimeEmpty }}
</p>
</div>
</div>
<div class="example-code">
<pre><code>&#x3C;datetime
type=&#x22;datetime&#x22;
v-model=&#x22;datetimeEmpty&#x22;
input-class=&#x22;my-class&#x22;
value-zone=&#x22;America/New_York&#x22;
zone=&#x22;Asia/Shanghai&#x22;
:format=&#x22;{ year: &#x27;numeric&#x27;, month: &#x27;long&#x27;, day: &#x27;numeric&#x27;, hour: &#x27;numeric&#x27;, minute: &#x27;2-digit&#x27;, timeZoneName: &#x27;short&#x27; }&#x22;
:phrases=&#x22;{ok: &#x27;Continue&#x27;, cancel: &#x27;Exit&#x27;}&#x22;
:allowed-date-time-ranges=&#x22;allowedDateTimeRanges&#x22;
:week-start=&#x22;7&#x22;
use12-hour
auto
&#x3E;&#x3C;/datetime&#x3E;</code></pre>
</div>
</div>
<div class="example-code">
Expand Down
32 changes: 28 additions & 4 deletions demo/src/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import Vue from 'vue'
import { DateTime as LuxonDateTime } from 'luxon'
import {
DateTime as LuxonDateTime
} from 'luxon'
import Datetime from '../../dist/vue-datetime'
import '../../dist/vue-datetime.css'
import './app.css'
Expand All @@ -17,10 +19,32 @@ new Vue({
datetime12: '2018-05-12T17:19:06.151Z',
datetime13: '2018-05-12T17:19:06.151Z',
datetimeEmpty: '',
minDatetime: LuxonDateTime.local().minus({ month: 1, days: 3 }).toISO(),
maxDatetime: LuxonDateTime.local().plus({ days: 3 }).toISO(),
allowedDateTimeRanges: [
[
LuxonDateTime.local().minus({
days: 5
}),
LuxonDateTime.local().minus({
days: 2
})
],
[
LuxonDateTime.local().plus({
days: 3
}),
LuxonDateTime.local().plus({
days: 5
})
]
],
minDatetime: LuxonDateTime.local().minus({
month: 1,
days: 3
}).toISO(),
maxDatetime: LuxonDateTime.local().plus({
days: 3
}).toISO(),
datetimeTheming: LuxonDateTime.local().toISO()
}
}
})

27 changes: 21 additions & 6 deletions src/Datetime.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<input v-if="hiddenName" type="hidden" :name="hiddenName" :value="value" @input="setValue">
<slot name="after"></slot>
<transition-group name="vdatetime-fade" tag="div">
<div key="overlay" v-if="isOpen" class="vdatetime-overlay" @click.self="cancel"></div>
<div key="overlay" v-if="isOpen && !hideBackdrop" class="vdatetime-overlay" @click.self="clickOutside"></div>
<datetime-popup
key="popup"
v-if="isOpen"
Expand All @@ -24,8 +24,7 @@
:use12-hour="use12Hour"
:hour-step="hourStep"
:minute-step="minuteStep"
:min-datetime="popupMinDatetime"
:max-datetime="popupMaxDatetime"
:allowed-date-time-ranges="allowedDateTimeRangesFormatted"
@confirm="confirm"
@cancel="cancel"
:auto="auto"
Expand All @@ -46,15 +45,13 @@
<script>
import { DateTime } from 'luxon'
import DatetimePopup from './DatetimePopup'
import { datetimeFromISO, startOfDay, weekStart } from './util'
import { datetimeFromISO, getAllowedDateTimeRanges, startOfDay, weekStart } from './util'

export default {
components: {
DatetimePopup
},

inheritAttrs: false,

props: {
value: {
type: String
Expand Down Expand Up @@ -119,6 +116,10 @@ export default {
type: String,
default: null
},
allowedDateTimeRanges: {
type: Array,
default: () => []
},
auto: {
type: Boolean,
default: false
Expand All @@ -134,6 +135,14 @@ export default {
},
title: {
type: String
},
hideBackdrop: {
type: Boolean,
default: false
},
backdropClick: {
type: Boolean,
default: true
}
},

Expand Down Expand Up @@ -182,6 +191,9 @@ export default {
popupDate () {
return this.datetime ? this.datetime.setZone(this.zone) : this.newPopupDatetime()
},
allowedDateTimeRangesFormatted () {
return getAllowedDateTimeRanges(this.allowedDateTimeRanges, this.popupMinDatetime, this.popupMaxDatetime)
},
popupMinDatetime () {
return this.minDatetime ? DateTime.fromISO(this.minDatetime).setZone(this.zone) : null
},
Expand Down Expand Up @@ -217,6 +229,9 @@ export default {
cancel () {
this.close()
},
clickOutside () {
if (this.backdropClick === true) { this.cancel() }
},
newPopupDatetime () {
let datetime = DateTime.utc().setZone(this.zone).set({ seconds: 0, milliseconds: 0 })

Expand Down
11 changes: 9 additions & 2 deletions src/DatetimeCalendar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

<script>
import { DateTime } from 'luxon'
import { monthDayIsDisabled, monthDays, months, weekdays } from './util'
import { getAllowedDateTimeRanges, monthDayIsDisabled, monthDays, months, weekdays } from './util'

export default {
props: {
Expand All @@ -51,6 +51,10 @@ export default {
type: DateTime,
default: null
},
allowedDateTimeRanges: {
type: Array,
default: () => []
},
weekStart: {
type: Number,
default: 1
Expand All @@ -66,6 +70,9 @@ export default {
},

computed: {
allowedDateTimeRangesFormatted () {
return getAllowedDateTimeRanges(this.allowedDateTimeRanges, this.minDate, this.maxDate)
},
newYear () {
return this.newDate.year
},
Expand All @@ -79,7 +86,7 @@ export default {
return monthDays(this.newYear, this.newMonth, this.weekStart).map(day => ({
number: day,
selected: day && this.year === this.newYear && this.month === this.newMonth && this.day === day,
disabled: !day || monthDayIsDisabled(this.minDate, this.maxDate, this.newYear, this.newMonth, day)
disabled: !day || monthDayIsDisabled(this.allowedDateTimeRangesFormatted, this.newYear, this.newMonth, day)
}))
}
},
Expand Down
11 changes: 9 additions & 2 deletions src/DatetimeMonthPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
</template>

<script>
import { getAllowedDateTimeRanges, monthIsDisabled, months } from './util'
import { DateTime } from 'luxon'
import { monthIsDisabled, months } from './util'

export default {
props: {
Expand All @@ -21,6 +21,10 @@ export default {
type: Number,
required: true
},
allowedDateTimeRanges: {
type: Array,
default: () => []
},
minDate: {
type: DateTime,
default: null
Expand All @@ -32,12 +36,15 @@ export default {
},

computed: {
allowedDateTimeRangesFormatted () {
return getAllowedDateTimeRanges(this.allowedDateTimeRanges, this.minDate, this.maxDate)
},
months () {
return months(this.month).map((month, index) => ({
number: ++index,
label: month,
selected: index === this.month,
disabled: !index || monthIsDisabled(this.minDate, this.maxDate, this.year, index)
disabled: !index || monthIsDisabled(this.allowedDateTimeRangesFormatted, this.year, index)
}))
}
},
Expand Down
Loading