Skip to content

Commit

Permalink
Merge pull request #502 from AOEpeople/feature/#265015-mark-guests
Browse files Browse the repository at this point in the history
Feature/#265015 mark guests
  • Loading branch information
MalibusParty authored Aug 7, 2024
2 parents d03e3cf + a2fdcc9 commit 7a72a4f
Show file tree
Hide file tree
Showing 31 changed files with 117 additions and 57 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ node_modules
###< friendsofphp/php-cs-fixer ###

/src/Resources/style/output.css
/**/*.d.ts
/src/Resources/style/output.css.map
test_ci_cypress.sh
tests/e2e/cypress/videos/
Expand Down
11 changes: 2 additions & 9 deletions src/Mealz/MealBundle/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,16 +200,9 @@ public function listParticipantsByDate(DateTime $date): JsonResponse
return new JsonResponse(['message' => 'Day not found'], 404);
}

$list = [];
$data = $this->participationSrv->getParticipationList($day);
$participants = $this->participationSrv->getParticipationList($day);

foreach ($data as $participant) {
$list[] = $participant->getProfile()->getFirstName() . ' ' . $participant->getProfile()->getName();
}

$uniqueArray = array_unique($list);

return new JsonResponse(array_values($uniqueArray), 200);
return new JsonResponse($participants, 200);
}

private function addSlots(array &$slotArray, array $slots, Day $day, ?int $activeParticipations): void
Expand Down
4 changes: 2 additions & 2 deletions src/Mealz/MealBundle/Controller/ParticipantController.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,8 @@ private function addParticipationInfo(array $response, ArrayCollection $particip
/** @var Participant $participant */
foreach ($participants as $participant) {
$participationData = $this->participationHelper->getParticipationMealData($participant);
$response[$day->getId()][$participant->getProfile()->getFullName()]['booked'][] = $participationData;
$response[$day->getId()][$participant->getProfile()->getFullName()]['profile'] = $participant->getProfile()->getUsername();
$response[$day->getId()][$this->participationHelper->getParticipantName($participant)]['booked'][] = $participationData;
$response[$day->getId()][$this->participationHelper->getParticipantName($participant)]['profile'] = $participant->getProfile()->getUsername();
}

return $response;
Expand Down
14 changes: 12 additions & 2 deletions src/Mealz/MealBundle/Helper/ParticipationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ public function getParticipationMealData(Participant $participant): array
return $participationData;
}

public function getParticipantName(Participant $participant): string
{
$fullname = $participant->getProfile()->getFullName();
if (true === $participant->getProfile()->isGuest()) {
$fullname .= ' (Guest)';
}

return $fullname;
}

protected function compareNameOfParticipants(Participant $participant1, Participant $participant2): int
{
$result = strcasecmp($participant1->getProfile()->getName(), $participant2->getProfile()->getName());
Expand Down Expand Up @@ -144,7 +154,7 @@ private function getParticipationbySlot(Participant $participant, ?Slot $slot, b
$combinedDishes = $this->getCombinedDishesFromMeal($meal, $participant);

if (true === $meal->isParticipant($participant) && (null === $slot || $slot->isDisabled() || $slot->isDeleted())) {
$slots[''][$participant->getProfile()->getFullName()] = $this->getParticipationData(
$slots[''][$this->getParticipantName($participant)] = $this->getParticipationData(
$meal,
$profile,
$participant,
Expand All @@ -154,7 +164,7 @@ private function getParticipationbySlot(Participant $participant, ?Slot $slot, b
}

if (true === $meal->isParticipant($participant)) {
$slots[$slot->getTitle()][$participant->getProfile()->getFullName()] = $this->getParticipationData(
$slots[$slot->getTitle()][$this->getParticipantName($participant)] = $this->getParticipationData(
$meal,
$profile,
$participant,
Expand Down
18 changes: 17 additions & 1 deletion src/Mealz/MealBundle/Service/ParticipationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,23 @@ public function getCountByMeal(Meal $meal, bool $withoutCombined = false): int

public function getParticipationList(Day $day): array
{
return $this->participantRepo->getParticipantsByDay($day->getDateTime(), ['load_meal' => false]);
$participants = $this->participantRepo->getParticipantsByDay($day->getDateTime(), ['load_meal' => false]);

$profiles = array_map(
fn ($participant) => $participant->getProfile(),
$participants
);

$profileData = array_map(
fn ($profile) => [
'user' => $profile->getUsername(),
'fullName' => $profile->getFullName(),
'roles' => $profile->getRoles(),
],
array_unique($profiles)
);

return $profileData;
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/Resources/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
13 changes: 10 additions & 3 deletions src/Resources/src/api/getParticipationsByDay.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import useApi from '@/api/api';
import type { IProfile } from '@/stores/profilesStore';
import type { Dictionary } from '@/types/types';
import { onMounted, readonly, ref } from 'vue';

/**
Expand All @@ -7,7 +9,7 @@ import { onMounted, readonly, ref } from 'vue';
* @returns list of participants
*/
export function useParticipationsListData(date: string) {
const listDataState = ref<string[]>([]);
const listDataState = ref<IProfile[]>([]);
const loaded = ref(false);
const useParticipationsError = ref(false);

Expand All @@ -20,16 +22,21 @@ export function useParticipationsListData(date: string) {
return;
}

const { error, response: listData, request } = useApi<string[]>('GET', `/api/participations/day/${date}`);
const {
error,
response: listData,
request
} = useApi<Dictionary<IProfile>>('GET', `/api/participations/day/${date}`);
useParticipationsError.value = error.value;

if (loaded.value === false) {
await request();
loaded.value = true;

listDataState.value = listData.value as string[];
listDataState.value = Object.values(listData.value ?? {});
}
}

return {
useParticipationsError,
listData: readonly(listDataState),
Expand Down
1 change: 1 addition & 0 deletions src/Resources/src/components/dashboard/MealData.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
{{ title }}
<VeggiIcon
v-if="meal.diet && meal.diet !== Diet.MEAT"
class="aspect-square"
:diet="meal.diet"
:class="meal.diet === Diet.VEGAN ? 'h-[17px]' : 'ml-[2px] h-[14px]'"
/>
Expand Down
1 change: 1 addition & 0 deletions src/Resources/src/components/dashboard/VariationsData.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
{{ locale.substring(0, 2) === 'en' ? variation.title.en : variation.title.de }}
<VeggiIcon
v-if="variation.diet && variation.diet !== Diet.MEAT"
class="aspect-square"
:diet="variation.diet"
:class="variation.diet === Diet.VEGAN ? 'h-[17px]' : 'ml-[2px] h-[14px]'"
/>
Expand Down
4 changes: 2 additions & 2 deletions src/Resources/src/components/dishes/DishTableRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</span>
<VeggiIcon
:diet="dish.diet"
class="h-6"
class="aspect-square h-6"
/>
</td>
<td
Expand Down Expand Up @@ -49,7 +49,7 @@
</span>
<VeggiIcon
:diet="variation.diet"
class="h-6"
class="aspect-square h-6"
/>
</td>
<td
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const isLoading = ref(false);
watch(showParticipations, async () => {
if (showParticipations.value === true) {
isLoading.value = true;
participations.value = (await getParticipantsForEvent(props.date)) as string[];
participations.value = ((await getParticipantsForEvent(props.date)) as string[]).sort();
isLoading.value = false;
}
});
Expand Down
1 change: 1 addition & 0 deletions src/Resources/src/components/guest/GuestMeal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
{{ title }}
<VeggiIcon
v-if="meal.diet && meal.diet !== Diet.MEAT"
class="aspect-square"
:diet="meal.diet"
:class="meal.diet === Diet.VEGAN ? 'h-[17px]' : 'ml-[2px] h-[14px]'"
/>
Expand Down
1 change: 1 addition & 0 deletions src/Resources/src/components/guest/GuestVariation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
{{ locale.substring(0, 2) === 'en' ? variation.title.en : variation.title.de }}
<VeggiIcon
v-if="variation.diet && variation.diet !== Diet.MEAT"
class="aspect-square"
:diet="variation.diet ?? Diet.MEAT"
:class="variation.diet && variation.diet === Diet.VEGAN ? 'h-[17px]' : 'ml-[2px] h-[14px]'"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const props = defineProps<{
weekId: number;
}>();
const { ProfilesState, fetchAbsentingProfiles } = useProfiles(props.weekId);
const { ProfilesState, fetchAbsentingProfiles, getDisplayName } = useProfiles(props.weekId);
const { t } = useI18n();
const slot = useSlots();
Expand Down Expand Up @@ -130,13 +130,6 @@ const filteredProfiles = computed(() => {
});
});
function getDisplayName(profile: IProfile) {
if (profile.roles.includes('ROLE_GUEST')) {
return `(${t('menu.guest')}) ${profile.fullName}`;
}
return profile.fullName;
}
function handleClick() {
openProp.value = true;
useDetectClickOutside(combobox, () => (openProp.value = false));
Expand Down
3 changes: 1 addition & 2 deletions src/Resources/src/components/menuParticipants/MenuTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import MenuTableBody from '@/components/menuParticipants/MenuTableBody.vue';
import MenuTableHead from './MenuTableHead.vue';
import { useProgress } from '@marcoschulte/vue3-progress';
import LoadingSpinner from '../misc/LoadingSpinner.vue';
import process from 'node:process';
const props = defineProps<{
weekId: number;
Expand Down Expand Up @@ -49,7 +48,7 @@ onMounted(async () => {
});
// expose functions for testing
if (process?.env?.NODE_ENV === 'TEST') {
if (import.meta.env.VITE_ENV === 'TEST') {
defineExpose({ loaded });
}
</script>
10 changes: 8 additions & 2 deletions src/Resources/src/components/menuParticipants/MenuTableBody.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { useI18n } from 'vue-i18n';
import MenuTableRow from './MenuTableRow.vue';
import MenuTableDataRows from '@/components/menuParticipants/MenuTableDataRows.vue';
import { computed } from 'vue';
import getDisplayName from '@/services/useConvertDisplayName';

const props = defineProps<{
weekId: number;
Expand All @@ -43,7 +44,12 @@ const { t } = useI18n();
const participants = computed(() => getParticipants());

const filteredParticipants = computed(() => {
if (getFilter() === '') return participants.value;
return participants.value.filter((participant) => participant.toLowerCase().includes(getFilter().toLowerCase()));
if (getFilter() === '') {
return participants.value.map((participant) => getDisplayName(participant, t));
}

return participants.value
.filter((participant) => participant.toLowerCase().includes(getFilter().toLowerCase()))
.map((participant) => getDisplayName(participant, t));
});
</script>
2 changes: 1 addition & 1 deletion src/Resources/src/components/misc/VeggiIcon.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div class="group relative my-auto grid aspect-square content-center">
<div class="group relative my-auto grid content-center">
<img
v-if="diet === Diet.VEGETARIAN"
class="object-cover"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,24 @@
:key="index"
>
<tr :class="[0 ? 'border-gray-300' : 'border-gray-200', 'border-b']">
<td class="leading- h-6 whitespace-nowrap py-1 text-[12px] font-light text-primary">
<div v-if="participant === 'noParticipants'">
{{ t('flashMessage.success.participations.no') }}
</div>
<div v-else>
{{ participant }}
<td class="h-6 whitespace-nowrap py-1 text-[12px] font-light text-primary">
<div>
{{ getDisplayName(participant) }}
</div>
</td>
</tr>
</template>
</tbody>
</table>
<div v-if="filteredParticipants.length < 1">
{{ t('flashMessage.success.participations.no') }}
</div>
</div>
</template>

<script setup lang="ts">
import { filterParticipantsList } from '@/services/filterParticipantsList';
import { useProfiles } from '@/stores/profilesStore';
import { DialogTitle } from '@headlessui/vue';
import { useProgress } from '@marcoschulte/vue3-progress';
import { ref, watch } from 'vue';
Expand All @@ -57,6 +58,7 @@ const props = defineProps<{
}>();
const { filteredParticipants, setFilter } = filterParticipantsList(props.date);
const { getDisplayName } = useProfiles(0);
const { t } = useI18n();
const filterInput = ref('');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { type IBookedData, getShowParticipations } from '@/api/getShowParticipat
import ParticipantsTableSlot from './ParticipantsTableSlot.vue';
import { computed, onMounted, onUnmounted, ref } from 'vue';
import { type Dictionary } from '@/types/types';
import process from 'node:process';
const { participationsState, getMealsWithVariations, loadedState } = getShowParticipations();
Expand Down Expand Up @@ -116,7 +115,7 @@ function convertToIBookedData(participant: Dictionary<IBookedData>): Dictionary<
}
// expose functions for testing
if (process?.env?.NODE_ENV === 'TEST') {
if (import.meta.env.VITE_ENV === 'TEST') {
defineExpose({ scrollAmount, setScrollDirection, scrollDirectionDown, mealsWithVariations });
}
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
>
<div class="flex w-full flex-row">
<span>
{{ participantName }}
{{ getDisplayName(participantName, t) }}
</span>
<svg
v-if="isOfferingMeal"
Expand Down Expand Up @@ -41,6 +41,10 @@
import type { IBookedData, IMealWithVariations } from '@/api/getShowParticipations';
import ParticipantsTableData from './ParticipantsTableData.vue';
import { computed } from 'vue';
import getDisplayName from '@/services/useConvertDisplayName';
import { useI18n } from 'vue-i18n';
const { t } = useI18n();
const props = defineProps<{
participantName: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ onUpdated(() => {
}
});
if (process?.env?.NODE_ENV === 'TEST') {
if (import.meta.env.VITE_ENV === 'TEST') {
defineExpose({ tableHeight });
}
</script>
2 changes: 1 addition & 1 deletion src/Resources/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@
"notFound": "No profiles found for this query",
"shortQuery": "Min. 3 Buchstaben für Suche eingeben",
"search": "Filter participant",
"guest": "Gast",
"guest": "Guest",
"noMeals": "No dishes selected yet"
},
"printList": {
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const i18n = createI18n({
// fill stores with data
Promise.all([userDataStore.fillStore(), environmentStore.fillStore()]).then(() => {
const MainApp = createApp(App);
MainApp.config.performance = process.env.NODE_ENV !== 'production'; // enable Vue Devtools
MainApp.config.performance = import.meta.env.VITE_ENV !== 'production'; // enable Vue Devtools
MainApp.use(i18n);
MainApp.use(router);
MainApp.use(VueScreen);
Expand Down
Loading

0 comments on commit 7a72a4f

Please sign in to comment.