quick fixes to make calendar app work

This commit is contained in:
Julien Fastré 2022-05-09 18:01:09 +02:00
parent 0ec0708807
commit f4b1a25a67
3 changed files with 41 additions and 21 deletions

View File

@ -131,6 +131,9 @@ class CalendarType extends AbstractType
return implode(',', $personIds); return implode(',', $personIds);
}, },
function (?string $personsAsString): array { function (?string $personsAsString): array {
if (null === $personsAsString) {
return [];
}
return array_map( return array_map(
fn (string $id): ?Person => $this->om->getRepository(Person::class)->findOneBy(['id' => (int) $id]), fn (string $id): ?Person => $this->om->getRepository(Person::class)->findOneBy(['id' => (int) $id]),
explode(',', $personsAsString) explode(',', $personsAsString)
@ -151,6 +154,9 @@ class CalendarType extends AbstractType
return implode(',', $thirdpartyIds); return implode(',', $thirdpartyIds);
}, },
function (?string $thirdpartyAsString): array { function (?string $thirdpartyAsString): array {
if (null === $thirdpartyAsString) {
return [];
}
return array_map( return array_map(
fn (string $id): ?ThirdParty => $this->om->getRepository(ThirdParty::class)->findOneBy(['id' => (int) $id]), fn (string $id): ?ThirdParty => $this->om->getRepository(ThirdParty::class)->findOneBy(['id' => (int) $id]),
explode(',', $thirdpartyAsString) explode(',', $thirdpartyAsString)
@ -230,6 +236,7 @@ class CalendarType extends AbstractType
public function getBlockPrefix() public function getBlockPrefix()
{ {
return 'chill_calendarbundle_calendar'; // as the js share some hardcoded items from activity, we have to rewrite block prefix
return 'chill_activitybundle_activity';
} }
} }

View File

@ -29,3 +29,8 @@ services:
arguments: arguments:
$azure: '@knpu.oauth2.provider.azure' $azure: '@knpu.oauth2.provider.azure'
tags: ['console.command'] tags: ['console.command']
Chill\CalendarBundle\Security\:
autoconfigure: true
autowire: true
resource: '../../Security/'

View File

@ -34,7 +34,8 @@ const store = createStore({
strict: debug, strict: debug,
state: { state: {
activity: mapEntity(window.entity), // activity is the calendar entity actually activity: mapEntity(window.entity), // activity is the calendar entity actually
currentEvent: null currentEvent: null,
availableLocations: [],
}, },
getters: { getters: {
suggestedEntities(state) { suggestedEntities(state) {
@ -58,6 +59,10 @@ const store = createStore({
.filter(p => !existingPersonIds.includes(p.id)) .filter(p => !existingPersonIds.includes(p.id))
}, },
suggestedRequestor(state) { suggestedRequestor(state) {
if (state.activity.accompanyingPeriod.requestor === null) {
return [];
}
const existingPersonIds = state.activity.persons.map(p => p.id); const existingPersonIds = state.activity.persons.map(p => p.id);
const existingThirdPartyIds = state.activity.thirdParties.map(p => p.id); const existingThirdPartyIds = state.activity.thirdParties.map(p => p.id);
return [state.activity.accompanyingPeriod.requestor] return [state.activity.accompanyingPeriod.requestor]
@ -67,11 +72,14 @@ const store = createStore({
); );
}, },
suggestedUser(state) { suggestedUser(state) {
const existingUserIds = state.activity.users.map(p => p.id); if (null === state.activity.users) {
return [state.activity.accompanyingPeriod.user] return [];
.filter( }
u => !existingUserIds.includes(u.id) const existingUserIds = state.activity.users.map(p => p.id);
); return [state.activity.accompanyingPeriod.user]
.filter(
u => u !== null && !existingUserIds.includes(u.id)
);
}, },
suggestedResources(state) { suggestedResources(state) {
const resources = state.activity.accompanyingPeriod.resources; const resources = state.activity.accompanyingPeriod.resources;
@ -132,15 +140,15 @@ const store = createStore({
console.log('### action addPersonsInvolved', payload.result.type); console.log('### action addPersonsInvolved', payload.result.type);
switch (payload.result.type) { switch (payload.result.type) {
case 'person': case 'person':
let aPersons = document.getElementById("chill_calendarbundle_calendar_persons"); let aPersons = document.getElementById("chill_activitybundle_activity_persons");
aPersons.value = addIdToValue(aPersons.value, payload.result.id); aPersons.value = addIdToValue(aPersons.value, payload.result.id);
break; break;
case 'thirdparty': case 'thirdparty':
let aThirdParties = document.getElementById("chill_calendarbundle_calendar_professionals"); let aThirdParties = document.getElementById("chill_activitybundle_activity_professionals");
aThirdParties.value = addIdToValue(aThirdParties.value, payload.result.id); aThirdParties.value = addIdToValue(aThirdParties.value, payload.result.id);
break; break;
case 'user': case 'user':
let aUsers = document.getElementById("chill_calendarbundle_calendar_invites"); let aUsers = document.getElementById("chill_activitybundle_activity_invites");
aUsers.value = addIdToValue(aUsers.value, payload.result.id); aUsers.value = addIdToValue(aUsers.value, payload.result.id);
break; break;
}; };
@ -150,15 +158,15 @@ const store = createStore({
//console.log('### action removePersonInvolved', payload); //console.log('### action removePersonInvolved', payload);
switch (payload.type) { switch (payload.type) {
case 'person': case 'person':
let aPersons = document.getElementById("chill_calendarbundle_calendar_persons"); let aPersons = document.getElementById("chill_activitybundle_activity_persons");
aPersons.value = removeIdFromValue(aPersons.value, payload.id); aPersons.value = removeIdFromValue(aPersons.value, payload.id);
break; break;
case 'thirdparty': case 'thirdparty':
let aThirdParties = document.getElementById("chill_calendarbundle_calendar_professionals"); let aThirdParties = document.getElementById("chill_activitybundle_activity_professionals");
aThirdParties.value = removeIdFromValue(aThirdParties.value, payload.id); aThirdParties.value = removeIdFromValue(aThirdParties.value, payload.id);
break; break;
case 'user': case 'user':
let aUsers = document.getElementById("chill_calendarbundle_calendar_invites"); let aUsers = document.getElementById("chill_activitybundle_activity_invites");
aUsers.value = removeIdFromValue(aUsers.value, payload.id); aUsers.value = removeIdFromValue(aUsers.value, payload.id);
break; break;
}; };
@ -168,23 +176,23 @@ const store = createStore({
// Calendar // Calendar
createEvent({ commit }, payload) { createEvent({ commit }, payload) {
console.log('### action createEvent', payload); console.log('### action createEvent', payload);
let startDateInput = document.getElementById("chill_calendarbundle_calendar_startDate"); let startDateInput = document.getElementById("chill_activitybundle_activity_startDate");
startDateInput.value = payload.startStr; startDateInput.value = payload.startStr;
let endDateInput = document.getElementById("chill_calendarbundle_calendar_endDate"); let endDateInput = document.getElementById("chill_activitybundle_activity_endDate");
endDateInput.value = payload.endStr; endDateInput.value = payload.endStr;
let mainUserInput = document.getElementById("chill_calendarbundle_calendar_mainUser"); let mainUserInput = document.getElementById("chill_activitybundle_activity_mainUser");
mainUserInput.value = payload.users.logged.id; mainUserInput.value = payload.users.logged.id;
commit('setEvents', payload); commit('setEvents', payload);
}, },
updateEvent({ commit }, payload) { updateEvent({ commit }, payload) {
console.log('### action updateEvent', payload); console.log('### action updateEvent', payload);
let startDateInput = document.getElementById("chill_calendarbundle_calendar_startDate"); let startDateInput = document.getElementById("chill_activitybundle_activity_startDate");
startDateInput.value = payload.event.start.toISOString(); startDateInput.value = payload.event.start.toISOString();
let endDateInput = document.getElementById("chill_calendarbundle_calendar_endDate"); let endDateInput = document.getElementById("chill_activitybundle_activity_endDate");
endDateInput.value = payload.event.end.toISOString(); endDateInput.value = payload.event.end.toISOString();
let calendarRangeInput = document.getElementById("chill_calendarbundle_calendar_calendarRange"); let calendarRangeInput = document.getElementById("chill_activitybundle_activity_calendarRange");
calendarRangeInput.value = Number(payload.event.extendedProps.calendarRangeId); calendarRangeInput.value = Number(payload.event.extendedProps.calendarRangeId);
let mainUserInput = document.getElementById("chill_calendarbundle_calendar_mainUser"); let mainUserInput = document.getElementById("chill_activitybundle_activity_mainUser");
mainUserInput.value = Number(payload.event.source.id); mainUserInput.value = Number(payload.event.source.id);
commit('setEvents', payload); commit('setEvents', payload);
}, },
@ -192,7 +200,7 @@ const store = createStore({
// Location // Location
updateLocation({ commit }, value) { updateLocation({ commit }, value) {
console.log('### action: updateLocation', value); console.log('### action: updateLocation', value);
let hiddenLocation = document.getElementById("chill_calendarbundle_calendar_location"); let hiddenLocation = document.getElementById("chill_activitybundle_activity_location");
if (value.onthefly) { if (value.onthefly) {
const body = { const body = {
"type": "location", "type": "location",