mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
reformat to indentation 2
This commit is contained in:
parent
17778ab346
commit
352b5b41b0
@ -1,8 +1,8 @@
|
|||||||
import {toRaw} from "vue";
|
import {toRaw} from "vue";
|
||||||
import {
|
import {
|
||||||
addIdToValue,
|
addIdToValue,
|
||||||
removeIdFromValue,
|
removeIdFromValue,
|
||||||
mapEntity
|
mapEntity
|
||||||
} from './utils';
|
} from './utils';
|
||||||
import {
|
import {
|
||||||
fetchCalendarRangeForUser,
|
fetchCalendarRangeForUser,
|
||||||
@ -24,101 +24,103 @@ import {datetimeToISO} from 'ChillMainAssets/chill/js/date';
|
|||||||
const fetchings = new Set();
|
const fetchings = new Set();
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
setCurrentDatesView({ commit, dispatch }, {start, end}) {
|
setCurrentDatesView({commit, dispatch}, {start, end}) {
|
||||||
commit('setCurrentDatesView', {start, end});
|
commit('setCurrentDatesView', {start, end});
|
||||||
|
|
||||||
|
return dispatch('fetchCalendarEvents');
|
||||||
|
},
|
||||||
|
fetchCalendarEvents({state, getters, dispatch}) {
|
||||||
|
if (state.currentView.start === null && state.currentView.end === null) {
|
||||||
|
return Promise.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
let promises = [];
|
||||||
|
for (const uid of state.currentView.users.keys()) {
|
||||||
|
let unique = `${uid}, ${state.currentView.start.toISOString()}, ${state.currentView.end.toISOString()}`;
|
||||||
|
|
||||||
|
if (fetchings.has(unique)) {
|
||||||
|
console.log('prevent from fetching for a user', unique);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
fetchings.add(unique);
|
||||||
|
|
||||||
|
promises.push(
|
||||||
|
dispatch(
|
||||||
|
'fetchCalendarRangeForUser',
|
||||||
|
{user: state.usersData.get(uid).user, start: state.currentView.start, end: state.currentView.end}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
promises.push(
|
||||||
|
dispatch(
|
||||||
|
'fetchCalendarRemotesForUser',
|
||||||
|
{user: state.usersData.get(uid).user, start: state.currentView.start, end: state.currentView.end}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.all(promises);
|
||||||
|
},
|
||||||
|
fetchCalendarRangeForUser({commit, getters}, {user, start, end}) {
|
||||||
|
if (!getters.isCalendarRangeLoadedForUser({user, start, end})) {
|
||||||
|
return fetchCalendarRangeForUser(user, start, end).then((ranges) => {
|
||||||
|
commit('addCalendarRangesForUser', {user, ranges, start, end});
|
||||||
|
|
||||||
return dispatch('fetchCalendarEvents');
|
|
||||||
},
|
|
||||||
fetchCalendarEvents({ state, getters, dispatch }) {
|
|
||||||
if (state.currentView.start === null && state.currentView.end === null) {
|
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
fetchCalendarRemotesForUser({commit, getters}, {user, start, end}) {
|
||||||
|
if (!getters.isCalendarRemoteLoadedForUser({user, start, end})) {
|
||||||
|
return fetchCalendarRemoteForUser(user, start, end).then((remotes) => {
|
||||||
|
commit('addCalendarRemotesForUser', {user, remotes, start, end});
|
||||||
|
|
||||||
let promises = [];
|
return Promise.resolve();
|
||||||
for (const uid of state.currentView.users.keys()) {
|
});
|
||||||
let unique = `${uid}, ${state.currentView.start.toISOString()}, ${state.currentView.end.toISOString()}`;
|
}
|
||||||
|
},
|
||||||
|
addPersonsInvolved({commit, dispatch}, payload) {
|
||||||
|
console.log('### action addPersonsInvolved', payload.result.type);
|
||||||
|
switch (payload.result.type) {
|
||||||
|
case 'person':
|
||||||
|
let aPersons = document.getElementById("chill_activitybundle_activity_persons");
|
||||||
|
aPersons.value = addIdToValue(aPersons.value, payload.result.id);
|
||||||
|
break;
|
||||||
|
case 'thirdparty':
|
||||||
|
let aThirdParties = document.getElementById("chill_activitybundle_activity_professionals");
|
||||||
|
aThirdParties.value = addIdToValue(aThirdParties.value, payload.result.id);
|
||||||
|
break;
|
||||||
|
case 'user':
|
||||||
|
let aUsers = document.getElementById("chill_activitybundle_activity_users");
|
||||||
|
aUsers.value = addIdToValue(aUsers.value, payload.result.id);
|
||||||
|
commit('showUserOnCalendar', {user: payload.result, ranges: false, remotes: true});
|
||||||
|
dispatch('fetchCalendarEvents');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
;
|
||||||
|
commit('addPersonsInvolved', payload);
|
||||||
|
},
|
||||||
|
removePersonInvolved({commit}, payload) {
|
||||||
|
//console.log('### action removePersonInvolved', payload);
|
||||||
|
switch (payload.type) {
|
||||||
|
case 'person':
|
||||||
|
let aPersons = document.getElementById("chill_activitybundle_activity_persons");
|
||||||
|
aPersons.value = removeIdFromValue(aPersons.value, payload.id);
|
||||||
|
break;
|
||||||
|
case 'thirdparty':
|
||||||
|
let aThirdParties = document.getElementById("chill_activitybundle_activity_professionals");
|
||||||
|
aThirdParties.value = removeIdFromValue(aThirdParties.value, payload.id);
|
||||||
|
break;
|
||||||
|
case 'user':
|
||||||
|
let aUsers = document.getElementById("chill_activitybundle_activity_users");
|
||||||
|
aUsers.value = removeIdFromValue(aUsers.value, payload.id);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
;
|
||||||
|
commit('removePersonInvolved', payload);
|
||||||
|
},
|
||||||
|
|
||||||
if (fetchings.has(unique)) {
|
// Calendar
|
||||||
console.log('prevent from fetching for a user', unique);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
fetchings.add(unique);
|
|
||||||
|
|
||||||
promises.push(
|
|
||||||
dispatch(
|
|
||||||
'fetchCalendarRangeForUser',
|
|
||||||
{user: state.usersData.get(uid).user, start: state.currentView.start, end: state.currentView.end}
|
|
||||||
)
|
|
||||||
);
|
|
||||||
promises.push(
|
|
||||||
dispatch(
|
|
||||||
'fetchCalendarRemotesForUser',
|
|
||||||
{user: state.usersData.get(uid).user, start: state.currentView.start, end: state.currentView.end}
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Promise.all(promises);
|
|
||||||
},
|
|
||||||
fetchCalendarRangeForUser({ commit, getters }, { user, start, end }) {
|
|
||||||
if (!getters.isCalendarRangeLoadedForUser({user, start, end})) {
|
|
||||||
return fetchCalendarRangeForUser(user, start, end).then((ranges) => {
|
|
||||||
commit('addCalendarRangesForUser', {user, ranges, start, end});
|
|
||||||
|
|
||||||
return Promise.resolve();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
fetchCalendarRemotesForUser({ commit, getters }, { user, start, end }) {
|
|
||||||
if (!getters.isCalendarRemoteLoadedForUser({user, start, end})) {
|
|
||||||
return fetchCalendarRemoteForUser(user, start, end).then((remotes) => {
|
|
||||||
commit('addCalendarRemotesForUser', {user, remotes, start, end});
|
|
||||||
|
|
||||||
return Promise.resolve();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
addPersonsInvolved({ commit, dispatch }, payload) {
|
|
||||||
console.log('### action addPersonsInvolved', payload.result.type);
|
|
||||||
switch (payload.result.type) {
|
|
||||||
case 'person':
|
|
||||||
let aPersons = document.getElementById("chill_activitybundle_activity_persons");
|
|
||||||
aPersons.value = addIdToValue(aPersons.value, payload.result.id);
|
|
||||||
break;
|
|
||||||
case 'thirdparty':
|
|
||||||
let aThirdParties = document.getElementById("chill_activitybundle_activity_professionals");
|
|
||||||
aThirdParties.value = addIdToValue(aThirdParties.value, payload.result.id);
|
|
||||||
break;
|
|
||||||
case 'user':
|
|
||||||
let aUsers = document.getElementById("chill_activitybundle_activity_users");
|
|
||||||
aUsers.value = addIdToValue(aUsers.value, payload.result.id);
|
|
||||||
commit('showUserOnCalendar', {user: payload.result, ranges: false, remotes: true});
|
|
||||||
dispatch('fetchCalendarEvents');
|
|
||||||
break;
|
|
||||||
};
|
|
||||||
commit('addPersonsInvolved', payload);
|
|
||||||
},
|
|
||||||
removePersonInvolved({ commit }, payload) {
|
|
||||||
//console.log('### action removePersonInvolved', payload);
|
|
||||||
switch (payload.type) {
|
|
||||||
case 'person':
|
|
||||||
let aPersons = document.getElementById("chill_activitybundle_activity_persons");
|
|
||||||
aPersons.value = removeIdFromValue(aPersons.value, payload.id);
|
|
||||||
break;
|
|
||||||
case 'thirdparty':
|
|
||||||
let aThirdParties = document.getElementById("chill_activitybundle_activity_professionals");
|
|
||||||
aThirdParties.value = removeIdFromValue(aThirdParties.value, payload.id);
|
|
||||||
break;
|
|
||||||
case 'user':
|
|
||||||
let aUsers = document.getElementById("chill_activitybundle_activity_users");
|
|
||||||
aUsers.value = removeIdFromValue(aUsers.value, payload.id);
|
|
||||||
break;
|
|
||||||
};
|
|
||||||
commit('removePersonInvolved', payload);
|
|
||||||
},
|
|
||||||
|
|
||||||
// Calendar
|
|
||||||
/**
|
/**
|
||||||
* set event startDate and endDate.
|
* set event startDate and endDate.
|
||||||
*
|
*
|
||||||
@ -130,92 +132,82 @@ export default {
|
|||||||
* @param start
|
* @param start
|
||||||
* @param end
|
* @param end
|
||||||
*/
|
*/
|
||||||
setEventTimes({ commit, state, getters }, {start, end}) {
|
setEventTimes({commit, state, getters}, {start, end}) {
|
||||||
console.log('### action createEvent', {start, end});
|
console.log('### action createEvent', {start, end});
|
||||||
let startDateInput = document.getElementById("chill_activitybundle_activity_startDate");
|
let startDateInput = document.getElementById("chill_activitybundle_activity_startDate");
|
||||||
startDateInput.value = datetimeToISO(start);
|
startDateInput.value = datetimeToISO(start);
|
||||||
let endDateInput = document.getElementById("chill_activitybundle_activity_endDate");
|
let endDateInput = document.getElementById("chill_activitybundle_activity_endDate");
|
||||||
endDateInput.value = datetimeToISO(end);
|
endDateInput.value = datetimeToISO(end);
|
||||||
let calendarRangeInput = document.getElementById("chill_activitybundle_activity_calendarRange");
|
let calendarRangeInput = document.getElementById("chill_activitybundle_activity_calendarRange");
|
||||||
calendarRangeInput.value = "";
|
calendarRangeInput.value = "";
|
||||||
|
|
||||||
if (getters.getMainUser === null || getters.getMainUser.id !== state.me.id) {
|
if (getters.getMainUser === null || getters.getMainUser.id !== state.me.id) {
|
||||||
let mainUserInput = document.getElementById("chill_activitybundle_activity_mainUser");
|
|
||||||
mainUserInput.value = state.me.id;
|
|
||||||
commit('setMainUser', state.me);
|
|
||||||
}
|
|
||||||
|
|
||||||
commit('setEventTimes', {start, end});
|
|
||||||
},
|
|
||||||
associateCalendarToRange({ state, commit, dispatch }, {range}) {
|
|
||||||
console.log('### action associateCAlendarToRange', range);
|
|
||||||
let startDateInput = document.getElementById("chill_activitybundle_activity_startDate");
|
|
||||||
startDateInput.value = datetimeToISO(range.start);
|
|
||||||
let endDateInput = document.getElementById("chill_activitybundle_activity_endDate");
|
|
||||||
endDateInput.value = datetimeToISO(range.end);
|
|
||||||
let calendarRangeInput = document.getElementById("chill_activitybundle_activity_calendarRange");
|
|
||||||
calendarRangeInput.value = Number(range.extendedProps.calendarRangeId);
|
|
||||||
|
|
||||||
const userId = range.extendedProps.userId;
|
|
||||||
if (state.activity.mainUser !== null && state.activity.mainUser.id !== userId) {
|
|
||||||
dispatch('setMainUser', state.usersData.get(userId).user);
|
|
||||||
|
|
||||||
// TODO: remove persons involved with this user
|
|
||||||
}
|
|
||||||
|
|
||||||
commit('associateCalendarToRange', {range});
|
|
||||||
return Promise.resolve();
|
|
||||||
},
|
|
||||||
setMainUser({ commit }, mainUser) {
|
|
||||||
console.log('setMainUser', mainUser);
|
|
||||||
let mainUserInput = document.getElementById("chill_activitybundle_activity_mainUser");
|
let mainUserInput = document.getElementById("chill_activitybundle_activity_mainUser");
|
||||||
mainUserInput.value = Number(mainUser.id);
|
mainUserInput.value = state.me.id;
|
||||||
|
commit('setMainUser', state.me);
|
||||||
commit('setMainUser', mainUser);
|
|
||||||
|
|
||||||
/*
|
|
||||||
const event = new CustomEvent('pick-entity-type-action', {detail: {
|
|
||||||
name: "chill_activitybundle_activity_mainUser",
|
|
||||||
entity: toRaw(mainUser),
|
|
||||||
action: 'add'
|
|
||||||
}});
|
|
||||||
document.dispatchEvent(event);
|
|
||||||
commit('setMainUser', mainUser);
|
|
||||||
|
|
||||||
*/
|
|
||||||
},
|
|
||||||
|
|
||||||
// Location
|
|
||||||
updateLocation({ commit }, value) {
|
|
||||||
console.log('### action: updateLocation', value);
|
|
||||||
let hiddenLocation = document.getElementById("chill_activitybundle_activity_location");
|
|
||||||
if (value.onthefly) {
|
|
||||||
const body = {
|
|
||||||
"type": "location",
|
|
||||||
"name": value.name === '__AccompanyingCourseLocation__' ? null : value.name,
|
|
||||||
"locationType": {
|
|
||||||
"id": value.locationType.id,
|
|
||||||
"type": "location-type"
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if (value.address.id) {
|
|
||||||
Object.assign(body, {
|
|
||||||
"address": {
|
|
||||||
"id": value.address.id
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
postLocation(body)
|
|
||||||
.then(
|
|
||||||
location => hiddenLocation.value = location.id
|
|
||||||
).catch(
|
|
||||||
err => {
|
|
||||||
console.log(err.message);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
hiddenLocation.value = value.id;
|
|
||||||
}
|
|
||||||
commit("updateLocation", value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
commit('setEventTimes', {start, end});
|
||||||
|
},
|
||||||
|
associateCalendarToRange({state, commit, dispatch}, {range}) {
|
||||||
|
console.log('### action associateCAlendarToRange', range);
|
||||||
|
let startDateInput = document.getElementById("chill_activitybundle_activity_startDate");
|
||||||
|
startDateInput.value = datetimeToISO(range.start);
|
||||||
|
let endDateInput = document.getElementById("chill_activitybundle_activity_endDate");
|
||||||
|
endDateInput.value = datetimeToISO(range.end);
|
||||||
|
let calendarRangeInput = document.getElementById("chill_activitybundle_activity_calendarRange");
|
||||||
|
calendarRangeInput.value = Number(range.extendedProps.calendarRangeId);
|
||||||
|
|
||||||
|
const userId = range.extendedProps.userId;
|
||||||
|
if (state.activity.mainUser !== null && state.activity.mainUser.id !== userId) {
|
||||||
|
dispatch('setMainUser', state.usersData.get(userId).user);
|
||||||
|
|
||||||
|
// TODO: remove persons involved with this user
|
||||||
|
}
|
||||||
|
|
||||||
|
commit('associateCalendarToRange', {range});
|
||||||
|
return Promise.resolve();
|
||||||
|
},
|
||||||
|
setMainUser({commit}, mainUser) {
|
||||||
|
console.log('setMainUser', mainUser);
|
||||||
|
let mainUserInput = document.getElementById("chill_activitybundle_activity_mainUser");
|
||||||
|
mainUserInput.value = Number(mainUser.id);
|
||||||
|
|
||||||
|
commit('setMainUser', mainUser);
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
// Location
|
||||||
|
updateLocation({commit}, value) {
|
||||||
|
console.log('### action: updateLocation', value);
|
||||||
|
let hiddenLocation = document.getElementById("chill_activitybundle_activity_location");
|
||||||
|
if (value.onthefly) {
|
||||||
|
const body = {
|
||||||
|
"type": "location",
|
||||||
|
"name": value.name === '__AccompanyingCourseLocation__' ? null : value.name,
|
||||||
|
"locationType": {
|
||||||
|
"id": value.locationType.id,
|
||||||
|
"type": "location-type"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if (value.address.id) {
|
||||||
|
Object.assign(body, {
|
||||||
|
"address": {
|
||||||
|
"id": value.address.id
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
postLocation(body)
|
||||||
|
.then(
|
||||||
|
location => hiddenLocation.value = location.id
|
||||||
|
).catch(
|
||||||
|
err => {
|
||||||
|
console.log(err.message);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
hiddenLocation.value = value.id;
|
||||||
|
}
|
||||||
|
commit("updateLocation", value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user