mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 21:34:25 +00:00
rdv: plages de disponibilites: copy the next day + refresh after save
This commit is contained in:
parent
e1ccc8aba5
commit
6bfc180951
@ -24,10 +24,13 @@
|
|||||||
<input type="checkbox" id="weekends" class="form-check-input" @click="toggleWeekends" />
|
<input type="checkbox" id="weekends" class="form-check-input" @click="toggleWeekends" />
|
||||||
<label class="form-check-label" for="weekends">{{ $t('show_weekends') }}</label>
|
<label class="form-check-label" for="weekends">{{ $t('show_weekends') }}</label>
|
||||||
</div>
|
</div>
|
||||||
<button class="btn btn-action"
|
<div>
|
||||||
|
<button class="btn btn-action"
|
||||||
@click.prevent="copyDay">
|
@click.prevent="copyDay">
|
||||||
{{ $t('copy_range_to_next_day')}}
|
{{ $t('copy_range_to_next_day')}}
|
||||||
</button>
|
</button>
|
||||||
|
<p>{{ $t('copy_range_how_to')}}</p>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -38,7 +41,7 @@ import FullCalendar from '@fullcalendar/vue3';
|
|||||||
import dayGridPlugin from '@fullcalendar/daygrid';
|
import dayGridPlugin from '@fullcalendar/daygrid';
|
||||||
import interactionPlugin from '@fullcalendar/interaction';
|
import interactionPlugin from '@fullcalendar/interaction';
|
||||||
import timeGridPlugin from '@fullcalendar/timegrid';
|
import timeGridPlugin from '@fullcalendar/timegrid';
|
||||||
import { fetchCalendar, fetchCalendarRangesByUser } from '../_api/api';
|
import { deleteCalendarRange, fetchCalendar, fetchCalendarRangesByUser, patchCalendarRange, postCalendarRange } from '../_api/api';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "App",
|
name: "App",
|
||||||
@ -77,7 +80,8 @@ export default {
|
|||||||
center: 'title',
|
center: 'title',
|
||||||
right: 'dayGridMonth,timeGridWeek,timeGridDay'
|
right: 'dayGridMonth,timeGridWeek,timeGridDay'
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@ -89,11 +93,19 @@ export default {
|
|||||||
get() {
|
get() {
|
||||||
return this.showMyCalendar;
|
return this.showMyCalendar;
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
init() {
|
init() {
|
||||||
this.fetchData()
|
this.fetchData();
|
||||||
|
},
|
||||||
|
resetCalendar() {
|
||||||
|
this.fetchData();
|
||||||
|
this.calendarEvents.new = {
|
||||||
|
events: [],
|
||||||
|
color: "#3788d8"
|
||||||
|
};
|
||||||
|
this.updateEventsSource();
|
||||||
},
|
},
|
||||||
fetchData() {
|
fetchData() {
|
||||||
fetchCalendarRangesByUser(this.userId).then(calendarRanges => new Promise((resolve, reject) => {
|
fetchCalendarRangesByUser(this.userId).then(calendarRanges => new Promise((resolve, reject) => {
|
||||||
@ -157,6 +169,7 @@ export default {
|
|||||||
events: events,
|
events: events,
|
||||||
color: "#3788d8"
|
color: "#3788d8"
|
||||||
};
|
};
|
||||||
|
this.lastNewDate = new Date(payload.startStr);
|
||||||
this.updateEventsSource();
|
this.updateEventsSource();
|
||||||
this.$store.dispatch('createRange', payload);
|
this.$store.dispatch('createRange', payload);
|
||||||
},
|
},
|
||||||
@ -166,50 +179,107 @@ export default {
|
|||||||
payload.event.setProp('color', '#3788d8');
|
payload.event.setProp('color', '#3788d8');
|
||||||
this.$store.dispatch('updateRange', payload);
|
this.$store.dispatch('updateRange', payload);
|
||||||
},
|
},
|
||||||
onClickSave(payload) {
|
onClickSave(payload) {
|
||||||
this.$store.dispatch('saveRanges', payload);
|
if (this.$store.state.newCalendarRanges.length > 0){
|
||||||
|
this.$store.state.newCalendarRanges.map(cr => {
|
||||||
|
postCalendarRange({
|
||||||
|
user: {
|
||||||
|
type: 'user',
|
||||||
|
id: window.userId,
|
||||||
|
},
|
||||||
|
startDate: {
|
||||||
|
datetime: `${cr.start.toISOString().split('.')[0]}+0000`, //should be like "2021-08-20T15:00:00+0200",
|
||||||
|
},
|
||||||
|
endDate: {
|
||||||
|
datetime: `${cr.end.toISOString().split('.')[0]}+0000`, // TODO check if OK with time zone
|
||||||
|
},
|
||||||
|
}).then((_r) => this.resetCalendar());
|
||||||
|
});
|
||||||
|
this.$store.dispatch('clearNewCalendarRanges', payload);
|
||||||
|
}
|
||||||
|
if (this.$store.state.updateCalendarRanges.length > 0){
|
||||||
|
this.$store.state.updateCalendarRanges.map(cr => {
|
||||||
|
patchCalendarRange(cr.id,
|
||||||
|
{
|
||||||
|
startDate: {
|
||||||
|
datetime: `${cr.start.toISOString().split('.')[0]}+0000`, //should be like "2021-08-20T15:00:00+0200",
|
||||||
|
},
|
||||||
|
endDate: {
|
||||||
|
datetime: `${cr.end.toISOString().split('.')[0]}+0000`, // TODO check if OK with time zone
|
||||||
|
},
|
||||||
|
}).then((_r) => this.resetCalendar());
|
||||||
|
})
|
||||||
|
this.$store.dispatch('clearUpdateCalendarRanges', payload);
|
||||||
|
}
|
||||||
|
if (this.$store.state.deleteCalendarRanges.length > 0){
|
||||||
|
this.$store.state.deleteCalendarRanges.map(cr => {
|
||||||
|
deleteCalendarRange(cr.id).then((_r) => this.resetCalendar());;
|
||||||
|
})
|
||||||
|
this.$store.dispatch('deleteUpdateCalendarRanges', payload);
|
||||||
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
onDelete(payload) {
|
onDelete(payload) {
|
||||||
payload.setProp('color', '#dddddd');
|
payload.setProp('color', '#dddddd');
|
||||||
this.$store.dispatch('deleteRange', payload);
|
this.$store.dispatch('deleteRange', payload);
|
||||||
},
|
},
|
||||||
copyDay(payload) {
|
isSameDay(date1, date2) {
|
||||||
console.log(payload);
|
return date1.getFullYear() === date2.getFullYear() &&
|
||||||
// TODO get current day, or get current new events
|
date1.getMonth() === date2.getMonth() &&
|
||||||
|
date1.getDate() === date2.getDate();
|
||||||
|
},
|
||||||
|
isFriday(date) {
|
||||||
|
return date.getDay() === 5
|
||||||
|
},
|
||||||
|
// disableCopyDayButton() { //TODO does not update!
|
||||||
|
// return this.calendarEvents.new.events.length === 0
|
||||||
|
// },
|
||||||
|
copyDay(_payload) {
|
||||||
console.log(this.calendarEvents.new);
|
console.log(this.calendarEvents.new);
|
||||||
if (this.calendarEvents.new.events) {
|
if (this.calendarEvents.new.events.length > 0) {
|
||||||
// TODO copy all events of the **LAST** day and create a array of events for the next day
|
// Create the copied events
|
||||||
// TODO if showWeekends, copy on the next day always, else, skip weekends
|
let increment = !this.calendarOptions.weekends && this.isFriday(this.lastNewDate) ? 24*60*60*1000*3 : 24*60*60*1000;
|
||||||
let events = this.calendarEvents.new.events.map(i => {
|
let events = this.calendarEvents.new.events.filter(
|
||||||
let startDate = new Date(new Date(i.start).getTime() + 24*60*60*1000);
|
i => this.isSameDay(new Date(i.start), this.lastNewDate)).map(
|
||||||
let endDate = new Date(new Date(i.end).getTime() + 24*60*60*1000);
|
i => {
|
||||||
return ({
|
let startDate = new Date(new Date(i.start).getTime() + increment);
|
||||||
start: startDate.toISOString(),
|
let endDate = new Date(new Date(i.end).getTime() + increment);
|
||||||
end: endDate.toISOString()
|
return ({
|
||||||
})
|
start: startDate.toISOString(),
|
||||||
}
|
end: endDate.toISOString()
|
||||||
|
})
|
||||||
|
}
|
||||||
);
|
);
|
||||||
let copiedEvents = {
|
let copiedEvents = {
|
||||||
events: events,
|
events: events,
|
||||||
color: "#3788d8"
|
color: "#3788d8"
|
||||||
};
|
};
|
||||||
console.log(copiedEvents)
|
console.log(copiedEvents);
|
||||||
//TODO in a loop : this.$store.dispatch('createRange', payload);
|
|
||||||
|
// Add to the calendar
|
||||||
let newEvents = this.calendarEvents.new.events;
|
let newEvents = this.calendarEvents.new.events;
|
||||||
newEvents.push(...copiedEvents.events);
|
newEvents.push(...copiedEvents.events);
|
||||||
this.calendarEvents.new = {
|
this.calendarEvents.new = {
|
||||||
events: newEvents,
|
events: newEvents,
|
||||||
color: "#3788d8"
|
color: "#3788d8"
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log(this.calendarEvents.new.events)
|
|
||||||
this.updateEventsSource();
|
this.updateEventsSource();
|
||||||
|
|
||||||
|
// Set the last new date
|
||||||
|
this.lastNewDate = new Date(copiedEvents.events[copiedEvents.events.length - 1].start);
|
||||||
|
|
||||||
|
// Dispatch in store for saving
|
||||||
|
for (let i = 0; i < copiedEvents.events.length; i++) {
|
||||||
|
let eventObj = {
|
||||||
|
start: new Date(copiedEvents.events[i].start),
|
||||||
|
end: new Date(copiedEvents.events[i].end)
|
||||||
|
}
|
||||||
|
this.$store.dispatch('createRange', eventObj);
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
console.log('no new events to copy-paste!')
|
console.log('no new events to copy-paste!')
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
|
@ -4,7 +4,8 @@ const appMessages = {
|
|||||||
show_my_calendar: "Afficher mon calendrier",
|
show_my_calendar: "Afficher mon calendrier",
|
||||||
show_weekends: "Afficher les week-ends",
|
show_weekends: "Afficher les week-ends",
|
||||||
copy_range_to_next_day: "Copier les plages du jour au jour suivant",
|
copy_range_to_next_day: "Copier les plages du jour au jour suivant",
|
||||||
copy_range_to_next_week: "Copier les plages de la semaine à la semaine suivante"
|
copy_range_to_next_week: "Copier les plages de la semaine à la semaine suivante",
|
||||||
|
copy_range_how_to: "Créez les plages de disponibilités durant une journée et copiez-les facilement au jour suivant avec ce bouton. Si les week-ends sont cachés, le jour suivant un vendredi sera le lundi."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,48 +55,15 @@ const store = createStore({
|
|||||||
console.log('### action deleteRange', payload);
|
console.log('### action deleteRange', payload);
|
||||||
commit('deleteRange', payload);
|
commit('deleteRange', payload);
|
||||||
},
|
},
|
||||||
saveRanges({ commit }, payload) {
|
clearNewCalendarRanges({ commit }, payload) {
|
||||||
console.log('### action saveRange', payload);
|
commit('clearNewCalendarRanges', payload);
|
||||||
console.log(this.state)
|
|
||||||
if (this.state.newCalendarRanges.length > 0){
|
|
||||||
this.state.newCalendarRanges.map(cr => {
|
|
||||||
postCalendarRange({
|
|
||||||
user: {
|
|
||||||
type: 'user',
|
|
||||||
id: window.userId,
|
|
||||||
},
|
|
||||||
startDate: {
|
|
||||||
datetime: `${cr.start.toISOString().split('.')[0]}+0000`, //should be like "2021-08-20T15:00:00+0200",
|
|
||||||
},
|
|
||||||
endDate: {
|
|
||||||
datetime: `${cr.end.toISOString().split('.')[0]}+0000`, // TODO check if OK with time zone
|
|
||||||
},
|
|
||||||
});
|
|
||||||
})
|
|
||||||
commit('clearNewCalendarRanges');
|
|
||||||
}
|
|
||||||
if (this.state.updateCalendarRanges.length > 0){
|
|
||||||
this.state.updateCalendarRanges.map(cr => {
|
|
||||||
patchCalendarRange(cr.id,
|
|
||||||
{
|
|
||||||
startDate: {
|
|
||||||
datetime: `${cr.start.toISOString().split('.')[0]}+0000`, //should be like "2021-08-20T15:00:00+0200",
|
|
||||||
},
|
|
||||||
endDate: {
|
|
||||||
datetime: `${cr.end.toISOString().split('.')[0]}+0000`, // TODO check if OK with time zone
|
|
||||||
},
|
|
||||||
});
|
|
||||||
})
|
|
||||||
commit('clearUpdateCalendarRanges');
|
|
||||||
}
|
|
||||||
if (this.state.deleteCalendarRanges.length > 0){
|
|
||||||
this.state.deleteCalendarRanges.map(cr => {
|
|
||||||
deleteCalendarRange(cr.id);
|
|
||||||
})
|
|
||||||
commit('deleteUpdateCalendarRanges');
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
clearUpdateCalendarRanges({ commit }, payload) {
|
||||||
|
commit('clearUpdateCalendarRanges', payload);
|
||||||
|
},
|
||||||
|
deleteUpdateCalendarRanges({ commit }, payload) {
|
||||||
|
commit('deleteUpdateCalendarRanges', payload);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user