diff --git a/src/Bundle/ChillCalendarBundle/Resources/public/vuejs/Calendar/store/getters.js b/src/Bundle/ChillCalendarBundle/Resources/public/vuejs/Calendar/store/getters.js index a33d49dbb..8cf1cc8bc 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/public/vuejs/Calendar/store/getters.js +++ b/src/Bundle/ChillCalendarBundle/Resources/public/vuejs/Calendar/store/getters.js @@ -2,15 +2,33 @@ import {USER_CALENDAR_SHOW_RANGES, USER_CALENDAR_SHOW_EVENTS} from './../const'; import {calendarRangeToFullCalendarEvent} from './utils'; export default { + /** + * get the main user of the event/Calendar + * + * @param state + * @returns {*|null} + */ getMainUser(state) { return state.activity.mainUser || null; }, + /** + * return the date of the event/Calendar + * + * @param state + * @returns {Date} + */ getEventDate(state) { if (null === state.activity.start) { return new Date(); } throw 'transform date to object ?'; }, + /** + * Compute the event sources to show on the FullCalendar + * + * @param state + * @returns {*[]} + */ getEventSources(state) { console.log('getEventSources'); let sources = []; @@ -50,12 +68,32 @@ export default { return sources; }, + /** + * get the user data for a specific user + * + * @param state + * @returns {function(*): unknown} + */ getUserData: (state) => (user) => { return state.usersData.get(user.id); }, + /** + * return true if the user has an entry in userData + * + * @param state + * @returns {function(*): boolean} + */ hasUserData: (state) => (user) => { return state.usersData.has(user.id); }, + /** + * return true if there was a fetch query for event between this date (start and end), + * those date are included. + * + * @param state + * @param getters + * @returns {(function({user: *, start: *, end: *}): (boolean))|*} + */ isCalendarRangeLoadedForUser: (state, getters) => ({user, start, end}) => { if (!getters.hasUserData(user)) { return false; @@ -69,6 +107,9 @@ export default { return false; }, + + + suggestedEntities(state, getters) { if (typeof (state.activity.accompanyingPeriod) === 'undefined') { return []; diff --git a/src/Bundle/ChillCalendarBundle/Resources/public/vuejs/Calendar/store/index.js b/src/Bundle/ChillCalendarBundle/Resources/public/vuejs/Calendar/store/index.js index 5eecb9471..12f9240f8 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/public/vuejs/Calendar/store/index.js +++ b/src/Bundle/ChillCalendarBundle/Resources/public/vuejs/Calendar/store/index.js @@ -22,13 +22,25 @@ const store = createStore({ activity: mapEntity(window.entity), // activity is the calendar entity actually currentEvent: null, availableLocations: [], + /** + * the current user + */ me: null, - initialDate: null, + /** + * store information about current view + */ currentView: { start: null, end: null, users: new Map(), }, + /** + * store a list of existing event, to avoid storing them twice + */ + existingEvents: new Set(), + /** + * store user data + */ usersData: new Map(), }, getters, diff --git a/src/Bundle/ChillCalendarBundle/Resources/public/vuejs/Calendar/store/mutations.js b/src/Bundle/ChillCalendarBundle/Resources/public/vuejs/Calendar/store/mutations.js index 2aa1f3ab6..e516f2fa9 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/public/vuejs/Calendar/store/mutations.js +++ b/src/Bundle/ChillCalendarBundle/Resources/public/vuejs/Calendar/store/mutations.js @@ -44,6 +44,15 @@ export default { } ; }, + /** + * Add CalendarRange object for an user + * + * @param state + * @param user + * @param ranges + * @param start + * @param end + */ addCalendarRangesForUser(state, {user, ranges, start, end}) { let userData; if (state.usersData.has(user.id)) { @@ -53,7 +62,14 @@ export default { state.usersData.set(user.id, userData); } - const eventRanges = ranges.map(r => calendarRangeToFullCalendarEvent(r)); + const eventRanges = ranges + .filter(r => !state.existingEvents.has(`range_${r.id}`)) + .map(r => { + // add to existing ids + state.existingEvents.add(`range_${r.id}`); + return r; + }) + .map(r => calendarRangeToFullCalendarEvent(r)); userData.calendarRanges = userData.calendarRanges.concat(eventRanges); userData.calendarRangesLoaded.push({start, end});