mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
re-add feature to patch event
This commit is contained in:
parent
922c5c5f5c
commit
b5d5338002
@ -12,12 +12,17 @@ export interface CalendarRange {
|
|||||||
updatedBy: User;
|
updatedBy: User;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CalendarRangeEdit {
|
export interface CalendarRangeCreate {
|
||||||
user: UserAssociatedInterface,
|
user: UserAssociatedInterface,
|
||||||
startDate: DateTime,
|
startDate: DateTime,
|
||||||
endDate: DateTime
|
endDate: DateTime
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface CalendarRangeEdit {
|
||||||
|
startDate?: DateTime,
|
||||||
|
endDate?: DateTime
|
||||||
|
}
|
||||||
|
|
||||||
export interface Calendar {
|
export interface Calendar {
|
||||||
id: number;
|
id: number;
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<FullCalendar :options="calendarOptions" ref="calendarRef">
|
<FullCalendar :options="calendarOptions" ref="calendarRef">
|
||||||
<template v-slot:eventContent='arg'>
|
<template v-slot:eventContent='arg'>
|
||||||
<span :class="eventClasses(arg)">
|
<span :class="eventClasses(arg.event)">
|
||||||
<b v-if="arg.event.extendedProps.is === 'remote'">{{ arg.event.title}}</b>
|
<b v-if="arg.event.extendedProps.is === 'remote'">{{ arg.event.title}}</b>
|
||||||
<b v-else-if="arg.event.extendedProps.is === 'range'">{{ arg.timeText }}</b>
|
<b v-else-if="arg.event.extendedProps.is === 'range'">{{ arg.timeText }}</b>
|
||||||
<b v-else >no 'is'</b>
|
<b v-else >no 'is'</b>
|
||||||
@ -39,16 +39,21 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
|
||||||
import type {CalendarOptions, DatesSetArg, EventSourceInput, EventInput} from '@fullcalendar/vue3';
|
import type {
|
||||||
import {reactive, computed, ref, watch} from "vue";
|
CalendarOptions,
|
||||||
|
DatesSetArg,
|
||||||
|
EventInput,
|
||||||
|
EventInstance
|
||||||
|
} from '@fullcalendar/vue3';
|
||||||
|
import {reactive, computed, ref} from "vue";
|
||||||
import {useStore} from "vuex";
|
import {useStore} from "vuex";
|
||||||
import {key} from './store';
|
import {key} from './store';
|
||||||
import '@fullcalendar/core/vdom'; // solves problem with Vite
|
import '@fullcalendar/core/vdom'; // solves problem with Vite
|
||||||
import frLocale from '@fullcalendar/core/locales/fr';
|
|
||||||
import FullCalendar from '@fullcalendar/vue3';
|
import FullCalendar from '@fullcalendar/vue3';
|
||||||
import interactionPlugin from "@fullcalendar/interaction";
|
import frLocale from '@fullcalendar/core/locales/fr';
|
||||||
|
import interactionPlugin, {DropArg, EventResizeDoneArg} from "@fullcalendar/interaction";
|
||||||
import timeGridPlugin from "@fullcalendar/timegrid";
|
import timeGridPlugin from "@fullcalendar/timegrid";
|
||||||
import {EventApi, DateSelectArg} from "@fullcalendar/core";
|
import {EventApi, DateSelectArg, EventDropArg} from "@fullcalendar/core";
|
||||||
|
|
||||||
const store = useStore(key);
|
const store = useStore(key);
|
||||||
|
|
||||||
@ -60,11 +65,16 @@ const baseOptions = ref<CalendarOptions>({
|
|||||||
plugins: [interactionPlugin, timeGridPlugin],
|
plugins: [interactionPlugin, timeGridPlugin],
|
||||||
initialView: 'timeGridWeek',
|
initialView: 'timeGridWeek',
|
||||||
initialDate: new Date(),
|
initialDate: new Date(),
|
||||||
|
scrollTimeReset: false,
|
||||||
selectable: true,
|
selectable: true,
|
||||||
// when the dates are changes in the fullcalendar view OR when new events are added
|
// when the dates are changes in the fullcalendar view OR when new events are added
|
||||||
datesSet: onDatesSet,
|
datesSet: onDatesSet,
|
||||||
// when a date is selected
|
// when a date is selected
|
||||||
select: onDateSelect,
|
select: onDateSelect,
|
||||||
|
// when a event is resized
|
||||||
|
eventResize: onEventDropOrResize,
|
||||||
|
// when an event is moved
|
||||||
|
eventDrop: onEventDropOrResize,
|
||||||
selectMirror: false,
|
selectMirror: false,
|
||||||
editable: true,
|
editable: true,
|
||||||
slotMinTime: "08:00:00",
|
slotMinTime: "08:00:00",
|
||||||
@ -84,8 +94,7 @@ const ranges = computed<EventInput[]>(() => {
|
|||||||
* return the show classes for the event
|
* return the show classes for the event
|
||||||
* @param arg
|
* @param arg
|
||||||
*/
|
*/
|
||||||
const eventClasses = function(arg: EventApi): object {
|
const eventClasses = function(arg: EventInstance): object {
|
||||||
console.log('eventClasses', arg);
|
|
||||||
return {'calendarRangeItems': true};
|
return {'calendarRangeItems': true};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,6 +151,16 @@ function onClickDelete(event: EventApi): void {
|
|||||||
store.dispatch('calendarRanges/deleteRange', event.extendedProps.calendarRangeId);
|
store.dispatch('calendarRanges/deleteRange', event.extendedProps.calendarRangeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onEventDropOrResize(payload: EventDropArg | EventResizeDoneArg) {
|
||||||
|
const changedEvent = payload.event;
|
||||||
|
console.log('eventDropOrResize', payload);
|
||||||
|
|
||||||
|
store.dispatch('calendarRanges/patchRangeTime', {
|
||||||
|
calendarRangeId: payload.event.extendedProps.calendarRangeId,
|
||||||
|
start: payload.event.start,
|
||||||
|
end: payload.event.end,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
import {State} from './../index';
|
import {State} from './../index';
|
||||||
import {ActionContext, Module} from 'vuex';
|
import {ActionContext, Module} from 'vuex';
|
||||||
import {CalendarRange, CalendarRangeEdit} from "../../../../types";
|
import {CalendarRange, CalendarRangeCreate, CalendarRangeEdit} from "../../../../types";
|
||||||
import {fetchCalendarRangeForUser} from '../../../Calendar/api';
|
import {fetchCalendarRangeForUser} from '../../../Calendar/api';
|
||||||
import {calendarRangeToFullCalendarEvent} from '../../../Calendar/store/utils';
|
import {calendarRangeToFullCalendarEvent} from '../../../Calendar/store/utils';
|
||||||
import {UserAssociatedInterface} from "../../../../../../../ChillMainBundle/Resources/public/types";
|
|
||||||
import {EventInput} from '@fullcalendar/vue3';
|
import {EventInput} from '@fullcalendar/vue3';
|
||||||
import {makeFetch} from "../../../../../../../ChillMainBundle/Resources/public/lib/api/apiMethods";
|
import {makeFetch} from "../../../../../../../ChillMainBundle/Resources/public/lib/api/apiMethods";
|
||||||
import {datetimeToISO} from "../../../../../../../ChillMainBundle/Resources/public/chill/js/date";
|
import {datetimeToISO} from "../../../../../../../ChillMainBundle/Resources/public/chill/js/date";
|
||||||
@ -91,6 +90,17 @@ export default <Module<CalendarRangesState, State>>{
|
|||||||
state.key = state.key + 1;
|
state.key = state.key + 1;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
updateRange(state, range: CalendarRange) {
|
||||||
|
const found = state.ranges.find(r => r.calendarRangeId === range.id && r.is === "range");
|
||||||
|
const newEvent = calendarRangeToFullCalendarEvent(range);
|
||||||
|
|
||||||
|
if (found !== undefined) {
|
||||||
|
found.start = newEvent.start;
|
||||||
|
found.end = newEvent.end;
|
||||||
|
}
|
||||||
|
|
||||||
|
state.key = state.key + 1;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
fetchRanges(ctx: Context, payload: { start: Date, end: Date }): Promise<null> {
|
fetchRanges(ctx: Context, payload: { start: Date, end: Date }): Promise<null> {
|
||||||
@ -141,9 +151,9 @@ export default <Module<CalendarRangesState, State>>{
|
|||||||
endDate: {
|
endDate: {
|
||||||
datetime: datetimeToISO(end)
|
datetime: datetimeToISO(end)
|
||||||
},
|
},
|
||||||
} as CalendarRangeEdit;
|
} as CalendarRangeCreate;
|
||||||
|
|
||||||
return makeFetch<CalendarRangeEdit, CalendarRange>('POST', url, body)
|
return makeFetch<CalendarRangeCreate, CalendarRange>('POST', url, body)
|
||||||
.then((newRange) => {
|
.then((newRange) => {
|
||||||
|
|
||||||
ctx.commit('addRange', newRange);
|
ctx.commit('addRange', newRange);
|
||||||
@ -156,14 +166,33 @@ export default <Module<CalendarRangesState, State>>{
|
|||||||
throw error;
|
throw error;
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
deleteRange({commit}, calendarRangeId: number) {
|
deleteRange(ctx, calendarRangeId: number) {
|
||||||
const url = `/api/1.0/calendar/calendar-range/${calendarRangeId}.json`;
|
const url = `/api/1.0/calendar/calendar-range/${calendarRangeId}.json`;
|
||||||
|
|
||||||
makeFetch<undefined, never>('DELETE', url)
|
makeFetch<undefined, never>('DELETE', url)
|
||||||
.then((_) => {
|
.then((_) => {
|
||||||
commit('removeRange', calendarRangeId);
|
ctx.commit('removeRange', calendarRangeId);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
patchRangeTime(ctx, {calendarRangeId, start, end}: {calendarRangeId: number, start: Date, end: Date}): void {
|
||||||
|
const url = `/api/1.0/calendar/calendar-range/${calendarRangeId}.json`;
|
||||||
|
const body = {
|
||||||
|
startDate: {
|
||||||
|
datetime: datetimeToISO(start)
|
||||||
|
},
|
||||||
|
endDate: {
|
||||||
|
datetime: datetimeToISO(end)
|
||||||
|
},
|
||||||
|
} as CalendarRangeEdit;
|
||||||
|
|
||||||
|
makeFetch<CalendarRangeEdit, CalendarRange>('PATCH', url, body)
|
||||||
|
.then((range) => {
|
||||||
|
ctx.commit('updateRange', range);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.log(error);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user