Skip to content

Commit

Permalink
changed MenuDay.vue, two events can now be input
Browse files Browse the repository at this point in the history
  • Loading branch information
IrisOlfermann committed Jul 26, 2024
1 parent 0477a42 commit 3732435
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 22 deletions.
22 changes: 12 additions & 10 deletions src/Mealz/MealBundle/Service/EventParticipationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ public function getEventParticipationData(Day $day, ?int $eventId = null, ?Profi
}
}

public function join(Profile $profile, Day $day): ?EventParticipation
public function join(Profile $profile, Day $day, int $eventId): ?EventParticipation
{
$eventParticipation = $day->getEvent();
$eventParticipation = $day->getEvent($day, $eventId);
if (null !== $eventParticipation && true === $this->doorman->isUserAllowedToJoinEvent($eventParticipation)) {
$participation = $this->createEventParticipation($profile, $eventParticipation);
$this->em->persist($participation);
Expand All @@ -99,20 +99,22 @@ public function joinAsGuest(
string $firstName,
string $lastName,
string $company,
Day $eventDay
Day $eventDay,
int $eventId
): EventParticipation {
$guestProfile = $this->guestPartSrv->getCreateGuestProfile(
$firstName,
$lastName,
$company,
$eventDay->getDateTime()
$eventDay->getDateTime(),
$eventId
);

$this->em->beginTransaction();

try {
$this->em->persist($guestProfile);
$eventParticipation = $eventDay->getEvent();
$eventParticipation = $eventDay->getEvent($eventDay, $eventId);
$participation = $this->createEventParticipation($guestProfile, $eventParticipation);

$this->em->persist($participation);
Expand All @@ -127,9 +129,9 @@ public function joinAsGuest(
}
}

public function leave(Profile $profile, Day $day): ?EventParticipation
public function leave(Profile $profile, Day $day, int $eventId): ?EventParticipation
{
$eventParticipation = $day->getEvent();
$eventParticipation = $day->getEvent($day, $eventId);
$participation = $eventParticipation->getParticipant($profile);

if (null !== $participation) {
Expand All @@ -147,16 +149,16 @@ public function leave(Profile $profile, Day $day): ?EventParticipation
*
* @psalm-return array<string>
*/
public function getParticipants(Day $day): array
public function getParticipants(Day $day, int $eventId): array
{
$eventParticipation = $day->getEvent();
$eventParticipation = $day->getEvent($day, $eventId);
if (null === $eventParticipation) {
return [];
}

return array_map(
fn (Participant $participant) => $this->getParticipantName($participant),
$day->getEvent()->getParticipants()->toArray()
$day->getEvent($day, $eventId)->getParticipants()->toArray()
);
}

Expand Down
2 changes: 2 additions & 0 deletions src/Resources/src/components/dashboard/Day.vue
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
class="col-start-2 row-start-2 print:hidden"
:day="day"
:dayId="dayID"
:eventId="eventId"
/>
</div>
</template>
Expand Down Expand Up @@ -132,6 +133,7 @@ const day = props.guestData ? props.guestData : dashboardStore.getDay(props.week
const weekday = computed(() => translateWeekday(day.date, locale));
const emptyDay = Object.keys(day.meals).length === 0;
const isEventDay = day.events.EventParticipation !== null;
const eventId = day.events[Object.keys(day.events)[0]][0].eventId;
const date = computed(() => {
if (day === null || day === undefined) {
return '';
Expand Down
54 changes: 42 additions & 12 deletions src/Resources/src/components/menu/MenuDay.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
v-model="selectedEventOne"
class="col-start-2 row-span-1 row-start-3 border-b border-t-[3px] px-2 py-[12px] md:px-4"
/>

<EventInput
v-if="selectedEventOne"
v-model="selectedEventTwo"
Expand All @@ -70,7 +69,7 @@
import MenuInput from '@/components/menu/MenuInput.vue';
import { Ref, computed, onMounted, ref, watch } from 'vue';
import { Dish } from '@/stores/dishesStore';
import { MealDTO, DayDTO, EventDTO } from '@/interfaces/DayDTO';
import { MealDTO, DayDTO } from '@/interfaces/DayDTO';
import { useDishes } from '@/stores/dishesStore';
import { translateWeekdayWithoutRef } from '@/tools/localeHelper';
import { useI18n } from 'vue-i18n';
Expand Down Expand Up @@ -167,18 +166,37 @@ watch(selectedDishTwo, () => {
});
watch(selectedEventOne, () => {
if (selectedEventOne.value !== null && selectedEventOne.value !== undefined) {
props.modelValue.events = selectedEventOne.value.id;
try{
const firstKey = Object.keys(props.modelValue.events)[0];
if (selectedEventOne.value !== null && selectedEventOne.value !== undefined) {
selectedDishes.value.events[firstKey] = [{
eventId: selectedEventOne.value.id,
eventSlug: selectedEventOne.value.slug,
}]
} else {
props.modelValue.event = null;
selectedDishes.value.events[firstKey][0].eventId = null;
}
}
catch(error){
console.error('Fehler: ', error)
}
});
watch(selectedEventTwo, () => {
try{
const secondKey = Object.keys(props.modelValue.events)[1];
if (selectedEventTwo.value !== null && selectedEventTwo.value !== undefined) {
props.modelValue.eventId = selectedEventTwo.value.id;
selectedDishes.value.events[secondKey] = [{
eventId: selectedEventTwo.value.id,
eventSlug: selectedEventTwo.value.slug,
}]
} else {
props.modelValue.eventId = null;
selectedDishes.value.events[secondKey][1].eventId = null;
}
}
catch(error){
console.error('Fehler: ', error)
}
});
Expand All @@ -190,11 +208,23 @@ onMounted(() => {
selectedDishTwo.value = getDishArrayBySlugs(
props.modelValue.meals[mealKeys.value[1]].map((meal: MealDTO) => meal.dishSlug)
);
// set Event from modelValue to be the initial value of the selectedEvent
selectedEventOne.value = getEventById(props.modelValue.eventId);
// set Event from modelValue to be the initial value of the selectedEvent
selectedEventTwo.value = getEventById(props.EventDTO.eventId);
try{
const firstKey = Object.keys(props.modelValue.events)[0];
const secondKey = Object.keys(props.modelValue.events)[1];
// set Events from modelValue to be the initial value of the selectedEvents
if (selectedEventOne.value !== null && selectedEventOne.value !== undefined) {
selectedDishes.value.events[firstKey] = [{
eventId: selectedEventTwo.value.id,
eventSlug: selectedEventTwo.value.slug,
}]
}
if (selectedEventTwo.value !== null && selectedEventTwo.value !== undefined) {
selectedDishes.value.events[secondKey] = [{
eventId: selectedEventTwo.value.id,
eventSlug: selectedEventTwo.value.slug,
}]
}
} catch(error){}
});
Expand Down

0 comments on commit 3732435

Please sign in to comment.