Skip to content

Commit

Permalink
feat: update methods to reflect native picker
Browse files Browse the repository at this point in the history
Signed-off-by: Grigory Vodyanov <[email protected]>
  • Loading branch information
GVodyanov committed Nov 4, 2024
1 parent 55fd3e1 commit 578f0b9
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 8 deletions.
33 changes: 26 additions & 7 deletions src/components/Editor/Properties/PropertyTitleTimePicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,23 @@
<div class="property-title-time-picker__time-pickers-from">
<DatePicker :date="startDate"
prefix="from"
@change="changeStart" />
<TimePicker :initial-date="startDate" />
@change="changeStartDate" />
<DatePicker :date="startDate"
type="time"
@change="changeStartTime" />
<NcTimezonePicker :value="startTimezone" @input="changeStartTimezone" />
</div>

<div class="property-title-time-picker__time-pickers-to">
<DatePicker :date="endDate"
prefix="from"
@change="changeEnd" />
<TimePicker :initial-date="endDate" />
@change="changeEndDate" />
<DatePicker :date="endDate"
type="time"
@change="changeEndTime" />
<NcTimezonePicker :value="endTimezone" @input="changeEndTimezone" />
</div>
</div>
<TimePicker :initial-date="startDate" />
<div v-if="isReadOnly"
class="property-title-time-picker__time-pickers property-title-time-picker__time-pickers--readonly">
<div class="property-title-time-picker-read-only-wrapper property-title-time-picker-read-only-wrapper--start-date">
Expand Down Expand Up @@ -232,9 +235,17 @@ export default {
*
* @param {Date} value The new start date
*/
changeStart(value) {
changeStartDate(value) {
this.$emit('update-start-date', value)
},
/**
* Update the start time

Check warning on line 242 in src/components/Editor/Properties/PropertyTitleTimePicker.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/Properties/PropertyTitleTimePicker.vue#L242

Added line #L242 was not covered by tests
*
* @param {Date} value The new start time
*/
changeStartTime(value) {
this.$emit('update-start-time', value)
},
/**
* Updates the timezone of the start date
*
Expand All @@ -253,9 +264,17 @@ export default {
*
* @param {Date} value The new end date
*/
changeEnd(value) {
changeEndDate(value) {
this.$emit('update-end-date', value)
},
/**
* Update the end time
*
* @param {Date} value The new end time
*/
changeEndTime(value) {
this.$emit('update-end-time', value)
},
/**
* Updates the timezone of the end date
*
Expand Down
6 changes: 5 additions & 1 deletion src/components/Shared/DatePicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
:min="minimumDate"
:max="maximumDate"
:value="date"
:type="type"
label=""
type="date"
class="date-time-picker"
@input="change" />
</template>
Expand Down Expand Up @@ -44,6 +44,10 @@ export default {
type: Date,
default: null,
},
type: {
type: String,
default: 'date',
},
},
computed: {
...mapStores(useDavRestrictionsStore),
Expand Down
24 changes: 24 additions & 0 deletions src/mixins/EditorMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,18 @@ export default {
startDate,
})
},
/**
* Updates the start time of this event
*
* @param {Date} startTime New start time
*/
updateStartTime(startTime) {
this.calendarObjectInstanceStore.changeStartDate({

Check warning on line 596 in src/mixins/EditorMixin.js

View check run for this annotation

Codecov / codecov/patch

src/mixins/EditorMixin.js#L595-L596

Added lines #L595 - L596 were not covered by tests
calendarObjectInstance: this.calendarObjectInstance,
startTime,
onlyTime: true,
})
},
/**
* Updates the timezone of this event's start date
*
Expand All @@ -613,6 +625,18 @@ export default {
endDate,
})
},
/**
* Updates the end time of this event
*
* @param {Date} endTime New end date
*/
updateEndTime(endTime) {
this.calendarObjectInstanceStore.changeEndDate({

Check warning on line 634 in src/mixins/EditorMixin.js

View check run for this annotation

Codecov / codecov/patch

src/mixins/EditorMixin.js#L633-L634

Added lines #L633 - L634 were not covered by tests
calendarObjectInstance: this.calendarObjectInstance,
endTime,
onlyTime: true,
})
},
/**
* Updates the timezone of this event's end date
*
Expand Down
38 changes: 38 additions & 0 deletions src/store/calendarObjectInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -1513,14 +1513,26 @@ export default defineStore('calendarObjectInstance', {
* @param {object} data The destructuring object for data
* @param {object} data.calendarObjectInstance The calendarObjectInstance object
* @param {Date} data.startDate The new start-date
* @param {boolean} onlyTime Only update time
*/
changeStartDate({
calendarObjectInstance,
startDate,
onlyTime = false,

Check warning on line 1521 in src/store/calendarObjectInstance.js

View check run for this annotation

Codecov / codecov/patch

src/store/calendarObjectInstance.js#L1521

Added line #L1521 was not covered by tests
}) {
const difference = startDate.getTime() - calendarObjectInstance.startDate.getTime()
const endDate = new Date(calendarObjectInstance.endDate.getTime() + difference)

if (onlyTime) {
startDate.setFullYear(calendarObjectInstance.startDate.getFullYear(), calendarObjectInstance.startDate.getMonth(), calendarObjectInstance.startDate.getDate())
endDate.setFullYear(calendarObjectInstance.startDate.getFullYear(), calendarObjectInstance.startDate.getMonth(), calendarObjectInstance.startDate.getDate())

Check warning on line 1528 in src/store/calendarObjectInstance.js

View check run for this annotation

Codecov / codecov/patch

src/store/calendarObjectInstance.js#L1527-L1528

Added lines #L1527 - L1528 were not covered by tests
}

if (!onlyTime) {
startDate.setHours(calendarObjectInstance.startDate.getHours(), calendarObjectInstance.startDate.getMinutes(), calendarObjectInstance.startDate.getSeconds())
endDate.setHours(calendarObjectInstance.startDate.getHours(), calendarObjectInstance.startDate.getMinutes(), calendarObjectInstance.startDate.getSeconds())

Check warning on line 1533 in src/store/calendarObjectInstance.js

View check run for this annotation

Codecov / codecov/patch

src/store/calendarObjectInstance.js#L1532-L1533

Added lines #L1532 - L1533 were not covered by tests
}

this.changeStartDateMutation({
calendarObjectInstance,
startDate,
Expand Down Expand Up @@ -1555,6 +1567,32 @@ export default defineStore('calendarObjectInstance', {
})
},

/**
*
* @param {object} data The destructuring object for data
* @param {object} data.calendarObjectInstance The calendarObjectInstance object
* @param {Date} data.endDate The new end-date
* @param {boolean} onlyTime Only update time
*/
changeEndDate({
calendarObjectInstance,
endDate,
onlyTime = false,
}) {

Check warning on line 1581 in src/store/calendarObjectInstance.js

View check run for this annotation

Codecov / codecov/patch

src/store/calendarObjectInstance.js#L1580-L1581

Added lines #L1580 - L1581 were not covered by tests
if (onlyTime) {
endDate.setFullYear(calendarObjectInstance.endDate.getFullYear(), calendarObjectInstance.endDate.getMonth(), calendarObjectInstance.endDate.getDate())

Check warning on line 1583 in src/store/calendarObjectInstance.js

View check run for this annotation

Codecov / codecov/patch

src/store/calendarObjectInstance.js#L1583

Added line #L1583 was not covered by tests
}

if (!onlyTime) {
endDate.setHours(calendarObjectInstance.endDate.getHours(), calendarObjectInstance.endDate.getMinutes(), calendarObjectInstance.endDate.getSeconds())

Check warning on line 1587 in src/store/calendarObjectInstance.js

View check run for this annotation

Codecov / codecov/patch

src/store/calendarObjectInstance.js#L1587

Added line #L1587 was not covered by tests
}

this.changeEndDateMutation({

Check warning on line 1590 in src/store/calendarObjectInstance.js

View check run for this annotation

Codecov / codecov/patch

src/store/calendarObjectInstance.js#L1590

Added line #L1590 was not covered by tests
calendarObjectInstance,
endDate,
})
},

/**
* Change the timezone of the event's end
*
Expand Down
2 changes: 2 additions & 0 deletions src/views/EditSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@
:user-timezone="currentUserTimezone"
:append-to-body="true"
@update-start-date="updateStartDate"
@update-start-time="updateStartTime"
@update-start-timezone="updateStartTimezone"
@update-end-date="updateEndDate"
@update-end-time="updateEndTime"
@update-end-timezone="updateEndTimezone"
@toggle-all-day="toggleAllDay" />

Expand Down

0 comments on commit 578f0b9

Please sign in to comment.