Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/expanded shortcuts #321

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,21 +162,24 @@ Here is an example of [UMD implementation](https://codepen.io/louismazel/pen/jQW

```js
[
{ key: 'thisWeek', label: 'This week', value: 'isoWeek' },
{ key: 'lastWeek', label: 'Last week', value: '-isoWeek' },
{ key: 'thisWeek', label: 'This week', value: 'isoWeek' },
{ key: 'nextWeek', label: 'Next week', value: '+isoWeek' },
{ key: 'last7Days', label: 'Last 7 days', value: 7 },
{ key: 'last30Days', label: 'Last 30 days', value: 30 },
{ key: 'thisMonth', label: 'This month', value: 'month' },
{ key: 'lastMonth', label: 'Last month', value: '-month' },
{ key: 'thisMonth', label: 'This month', value: 'month' },
{ key: 'nextMonth', label: 'Next month', value: '+month' },
{ key: 'lastYear', label: 'Last year', value: '-year' },
{ key: 'thisYear', label: 'This year', value: 'year' },
{ key: 'lastYear', label: 'Last year', value: '-year' }
{ key: 'nextYear', label: 'Next year', value: '+year' }
];
```

Shortcut types allowed are : `['day', '-day', 'isoWeek', '-isoWeek', 'quarter', 'month', '-month', 'year', '-year', 'week', '-week']`
Shortcut types allowed are : `['-day', 'day', '+day', '-isoWeek', 'isoWeek', '+isoWeek', 'quarter', '-month', 'month', '+month', '-year', 'year', '+year', '-week', 'week', '+week']`
For each shortcut, a `key`, `label` and `value` must be specified. The `key` is a unique key for that specific shortcut.
Additional values can be passed as a `callback` function that will be called whenever the user clicks on the shortcut. The callback receives an object as first argument with the `start` and `end` values, with the `shortcut` object itself.
You can use this feature for translate existings shortcuts.
You can use this feature to translate existing shortcuts.
If the **value of shortcut is a number** (Integer), this number correspond to number of day (for 5 --> Last 5 days).

If the **value of shortcut is a function**, we'll use it to generate the `start` and `end` values. This function should return an object with the start & end values. Both values **must be a moment object**. The function is called when the user clicks on the shortcut button.
Expand Down
2 changes: 1 addition & 1 deletion docs/css/app.279467f4.css → docs/css/app.8c41b8d9.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/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 http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=0"><link rel=icon href=favicon.ico><title>vue-ctk-date-time-picker</title><link href=css/app.279467f4.css rel=preload as=style><link href=js/app.ac586109.js rel=preload as=script><link href=js/chunk-vendors.a81c6b06.js rel=preload as=script><link href=css/app.279467f4.css rel=stylesheet></head><body><noscript><strong>We're sorry but vue-ctk-date-time-picker doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script src=js/chunk-vendors.a81c6b06.js></script><script src=js/app.ac586109.js></script></body></html>
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=0"><link rel=icon href=favicon.ico><title>vue-ctk-date-time-picker</title><link href=css/app.8c41b8d9.css rel=preload as=style><link href=js/app.82fda57e.js rel=preload as=script><link href=js/chunk-vendors.e202e294.js rel=preload as=script><link href=css/app.8c41b8d9.css rel=stylesheet></head><body><noscript><strong>We're sorry but vue-ctk-date-time-picker doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script src=js/chunk-vendors.e202e294.js></script><script src=js/app.82fda57e.js></script></body></html>
2 changes: 2 additions & 0 deletions docs/js/app.82fda57e.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/js/app.82fda57e.js.map

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions docs/js/app.ac586109.js

This file was deleted.

1 change: 0 additions & 1 deletion docs/js/app.ac586109.js.map

This file was deleted.

8 changes: 0 additions & 8 deletions docs/js/chunk-vendors.a81c6b06.js

This file was deleted.

1 change: 0 additions & 1 deletion docs/js/chunk-vendors.a81c6b06.js.map

This file was deleted.

8 changes: 8 additions & 0 deletions docs/js/chunk-vendors.e202e294.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/js/chunk-vendors.e202e294.js.map

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -464,14 +464,17 @@
})
),
customShortcuts: [
{ key: 'thisWeek', label: 'This week', value: 'isoWeek' },
{ key: 'lastWeek', label: 'Last week', value: '-isoWeek' },
{ key: 'thisWeek', label: 'This week', value: 'isoWeek' },
{ key: 'nextWeek', label: 'Next week', value: '+isoWeek' },
{ key: 'last7Days', label: 'Last 7 days', value: 7 },
{ key: 'last30Days', label: 'Last 30 days', value: 30 },
{ key: 'thisMonth', label: 'This month', value: 'month' },
{ key: 'lastMonth', label: 'Last month', value: '-month' },
{ key: 'thisMonth', label: 'This month', value: 'month' },
{ key: 'nextMonth', label: 'Next month', value: '+month' },
{ key: 'lastYear', label: 'Last year', value: '-year' },
{ key: 'thisYear', label: 'This year', value: 'year' },
{ key: 'lastYear', label: 'Last year', value: '-year' }
{ key: 'nextYear', label: 'Next year', value: '+year' }
]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,25 @@
import moment from 'moment'
import CustomButton from '@/VueCtkDateTimePicker/_subs/CustomButton'

const SHORTCUT_TYPES = ['day', 'date', '-day', 'isoWeek', 'quarter', '-isoWeek', 'month', '-month', 'year', '-year', 'week', '-week']
const SHORTCUT_TYPES = [
'-day',
'day',
'+day',
'date',
'-isoWeek',
'isoWeek',
'+isoWeek',
'quarter',
'-month',
'month',
'+month',
'-year',
'year',
'+year',
'-week',
'week',
'+week'
]

/**
* Component used to show a list of the shortcuts currently available
Expand Down Expand Up @@ -125,7 +143,13 @@
}

switch (value) {
case 'year': case 'month': case 'quarter': case 'week': case 'isoWeek': case 'day': case 'date':
case 'year':
case 'month':
case 'quarter':
case 'week':
case 'isoWeek':
case 'day':
case 'date':
return {
start: moment().startOf(value),
end: moment().endOf(value),
Expand All @@ -137,30 +161,60 @@
end: moment().subtract(1, 'months').endOf('month'),
value
}
case '+month':
return {
start: moment().add(1, 'months').startOf('month'),
end: moment().add(1, 'months').endOf('month'),
value
}
case '-year':
return {
start: moment().subtract(1, 'years').startOf('year'),
end: moment().subtract(1, 'years').endOf('year'),
value
}
case '+year':
return {
start: moment().add(1, 'years').startOf('year'),
end: moment().add(1, 'years').endOf('year'),
value
}
case '-week':
return {
start: moment().subtract(1, 'weeks').startOf('week'),
end: moment().subtract(1, 'weeks').endOf('week'),
value
}
case '+week':
return {
start: moment().add(1, 'weeks').startOf('week'),
end: moment().add(1, 'weeks').endOf('week'),
value
}
case '-isoWeek':
return {
start: moment().subtract(1, 'weeks').startOf('isoWeek'),
end: moment().subtract(1, 'weeks').endOf('isoWeek'),
value
}
case '+isoWeek':
return {
start: moment().add(1, 'weeks').startOf('isoWeek'),
end: moment().add(1, 'weeks').endOf('isoWeek'),
value
}
case '-day':
return {
start: moment().subtract(1, 'days').startOf('day'),
end: moment().subtract(1, 'days').endOf('day'),
value
}
case '+day':
return {
start: moment().add(1, 'days').startOf('day'),
end: moment().add(1, 'days').endOf('day'),
value
}
}
},
select (shortcut) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,11 @@
onScrollHours: debounce(function (scroll) {
const value = this.getValue(scroll)
const hour = this.isTwelveFormat
? this.apm
? this.apm.toLowerCase() === 'am'
? value + 1
: (value + 1 + 12)
:value
? this.apm
? this.apm.toLowerCase() === 'am'
? value + 1
: (value + 1 + 12)
: value
: value
if (this.isHoursDisabled(hour)) return
this.hour = hour === 24 && !this.isTwelveFormat ? 23 : hour
Expand Down
9 changes: 6 additions & 3 deletions src/VueCtkDateTimePicker/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,17 @@ export default {
customShortcuts: {
type: Array,
default: () => ([
{ key: 'thisWeek', label: 'This week', value: 'isoWeek' },
{ key: 'lastWeek', label: 'Last week', value: '-isoWeek' },
{ key: 'thisWeek', label: 'This week', value: 'isoWeek' },
{ key: 'nextWeek', label: 'Next week', value: '+isoWeek' },
{ key: 'last7Days', label: 'Last 7 days', value: 7 },
{ key: 'last30Days', label: 'Last 30 days', value: 30 },
{ key: 'thisMonth', label: 'This month', value: 'month' },
{ key: 'lastMonth', label: 'Last month', value: '-month' },
{ key: 'thisMonth', label: 'This month', value: 'month' },
{ key: 'nextMonth', label: 'Next month', value: '+month' },
{ key: 'lastYear', label: 'Last year', value: '-year' },
{ key: 'thisYear', label: 'This year', value: 'year' },
{ key: 'lastYear', label: 'Last year', value: '-year' }
{ key: 'nextYear', label: 'Next year', value: '+year' }
])
},
noValueToCustomElem: { type: Boolean, default: false },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@ describe('VueCtkDateTimePicker/PickersContainer/DatePicker/RangeShortcuts', () =
wrapper = shallowMount(RangeShortcuts, {
propsData: {
customShortcuts: [
{ key: 'thisWeek', label: 'This week', value: 'isoWeek' },
{ key: 'lastWeek', label: 'Last week', value: '-isoWeek' },
{ key: 'thisWeek', label: 'This week', value: 'isoWeek' },
{ key: 'nextWeek', label: 'Next week', value: '+isoWeek' },
{ key: 'last7Days', label: 'Last 7 days', value: 7 },
{ key: 'last30Days', label: 'Last 30 days', value: 30 },
{ key: 'thisMonth', label: 'This month', value: 'month' },
{ key: 'lastMonth', label: 'Last month', value: '-month' },
{ key: 'thisMonth', label: 'This month', value: 'month' },
{ key: 'nextMonth', label: 'Next month', value: '+month' },
{ key: 'lastYear', label: 'Last year', value: '-year' },
{ key: 'thisYear', label: 'This year', value: 'year' },
{ key: 'lastYear', label: 'Last year', value: '-year' }
{ key: 'nextYear', label: 'Next year', value: '+year' }
],
height: 200
}
Expand All @@ -33,20 +36,20 @@ describe('VueCtkDateTimePicker/PickersContainer/DatePicker/RangeShortcuts', () =
it('should be defined', () => {
const button = wrapper.find(CustomButton)
expect(button.exists()).toBeTruthy()
expect(button.text()).toEqual('This week')
expect(button.text()).toEqual('Last week')
})

it('should be selected if the "selectedShortcut" value is the current shortcut', () => {
wrapper.setData({
selectedShortcut: 'thisWeek'
selectedShortcut: 'lastWeek'
})
const button = wrapper.find(CustomButton)
expect(button.props().selected).toBeTruthy()
})

it('should not be selected if the "selectedShortcut" value is different than current', () => {
wrapper.setData({
selectedShortcut: 'lastWeek'
selectedShortcut: 'thisWeek'
})
const button = wrapper.find(CustomButton)
expect(button.props().selected).toBeFalsy()
Expand All @@ -56,7 +59,7 @@ describe('VueCtkDateTimePicker/PickersContainer/DatePicker/RangeShortcuts', () =
const wrapper = mount(RangeShortcuts, {
propsData: {
customShortcuts: [
{ key: 'thisWeek', label: 'This week', value: 'isoWeek' }
{ key: 'lastWeek', label: 'Last week', value: '-isoWeek' }
],
height: 200
}
Expand Down