From 1979a7acdd9ff0148d420fe9855656a02f38466b Mon Sep 17 00:00:00 2001 From: Alekhd <90794297+Alikohd@users.noreply.github.com> Date: Fri, 13 Dec 2024 02:57:35 +0300 Subject: [PATCH] change precise filter for rooms to Less More --- .../sidebar/ui/admin/ReportsSection.vue | 2 +- .../sidebar/ui/admin/ServiceInfoSection.vue | 70 ++++++++++++------- .../com/example/gym/service/AdminService.java | 2 +- 3 files changed, 47 insertions(+), 27 deletions(-) diff --git a/frontend/src/features/sidebar/ui/admin/ReportsSection.vue b/frontend/src/features/sidebar/ui/admin/ReportsSection.vue index f52051d..0e60e7c 100644 --- a/frontend/src/features/sidebar/ui/admin/ReportsSection.vue +++ b/frontend/src/features/sidebar/ui/admin/ReportsSection.vue @@ -129,7 +129,7 @@ - + - + + + + + @@ -190,15 +204,17 @@ const editingMode = ref(false); const filters = ref({ name: '', - capacity: '', + minCapacity: '', + maxCapacity: '', address: '', - workingDays: [] as string[], // ПН,ВТ, ... + workingDays: [] as string[], // ПН, ВТ, ... openingTime: '', closingTime: '', trainers: [] as string[], sections: [] as string[], }); + const sortBy = ref('name'); const sortOrder = ref('asc'); @@ -377,8 +393,12 @@ const displayedRooms = computed(() => { filtered = filtered.filter(r => (r.name ?? '').toLowerCase().includes(filters.value.name.toLowerCase())); } - if (filters.value.capacity) { - filtered = filtered.filter(r => String(r.capacity ?? '').includes(filters.value.capacity.toString())); + if (filters.value.minCapacity) { + filtered = filtered.filter(r => r.capacity >= Number(filters.value.minCapacity)); + } + + if (filters.value.maxCapacity) { + filtered = filtered.filter(r => r.capacity <= Number(filters.value.maxCapacity)); } if (filters.value.address) { @@ -393,27 +413,27 @@ const displayedRooms = computed(() => { // Фильтрация по рабочим дням if (filters.value.workingDays.length > 0) { filtered = filtered.filter(r => { - if(!Array.isArray(r.workingDays) || r.workingDays.length===0) return false; + if (!Array.isArray(r.workingDays) || r.workingDays.length === 0) return false; // Проверяем, что все выбранные в фильтре дни присутствуют в массиве r.workingDays return filters.value.workingDays.every(dayFilter => r.workingDays.includes(dayFilter)); }); } // Фильтрация по секциям - if (filters.value.sections.length>0) { + if (filters.value.sections.length > 0) { filtered = filtered.filter(r => { - if(!Array.isArray(r.sections) || r.sections.length===0) return false; - return filters.value.sections.every(sec=> r.sections.includes(sec)); - }) + if (!Array.isArray(r.sections) || r.sections.length === 0) return false; + return filters.value.sections.every(sec => r.sections.includes(sec)); + }); } // Сортировка if (sortBy.value) { filtered.sort((a, b) => { - let aValue:any = ''; - let bValue:any = ''; + let aValue: any = ''; + let bValue: any = ''; - switch(sortBy.value) { + switch (sortBy.value) { case 'name': aValue = (a.name ?? '').toLowerCase(); bValue = (b.name ?? '').toLowerCase(); break; @@ -422,14 +442,14 @@ const displayedRooms = computed(() => { bValue = b.capacity ?? Number.MAX_SAFE_INTEGER; break; case 'address': - const aAddr = ((a.location?.address ?? '') + ', ' + (a.location?.number??'')).toLowerCase(); - const bAddr = ((b.location?.address ?? '') + ', ' + (b.location?.number??'')).toLowerCase(); + const aAddr = ((a.location?.address ?? '') + ', ' + (a.location?.number ?? '')).toLowerCase(); + const bAddr = ((b.location?.address ?? '') + ', ' + (b.location?.number ?? '')).toLowerCase(); aValue = aAddr; bValue = bAddr; break; case 'workingDays': // workingDays - массив, для сравнения превращаем в строку - aValue = Array.isArray(a.workingDays)? a.workingDays.join(', ').toLowerCase():''; - bValue = Array.isArray(b.workingDays)? b.workingDays.join(', ').toLowerCase():''; + aValue = Array.isArray(a.workingDays) ? a.workingDays.join(', ').toLowerCase() : ''; + bValue = Array.isArray(b.workingDays) ? b.workingDays.join(', ').toLowerCase() : ''; break; case 'openingTime': aValue = a.openingTime ?? ''; @@ -444,22 +464,22 @@ const displayedRooms = computed(() => { bValue = ''; } - if (typeof aValue==='string') aValue = aValue.toLowerCase(); - if (typeof bValue==='string') bValue = bValue.toLowerCase(); + if (typeof aValue === 'string') aValue = aValue.toLowerCase(); + if (typeof bValue === 'string') bValue = bValue.toLowerCase(); - if (aValuebValue) return sortOrder.value==='asc'?1:-1; + if (aValue < bValue) return sortOrder.value === 'asc' ? -1 : 1; + if (aValue > bValue) return sortOrder.value === 'asc' ? 1 : -1; return 0; }); } // Преобразуем данные для отображения - return filtered.map((room:any)=> { - const wd = Array.isArray(room.workingDays) && room.workingDays.length>0 ? room.workingDays.join(', ') : 'Не указано'; + return filtered.map((room: any) => { + const wd = Array.isArray(room.workingDays) && room.workingDays.length > 0 ? room.workingDays.join(', ') : 'Не указано'; const opening = room.openingTime || 'Не указано'; const closing = room.closingTime || 'Не указано'; const trainerNames = getTrainerNames(room.trainers); - const sec = Array.isArray(room.sections) && room.sections.length>0 ? room.sections.join(', ') : 'Не указано'; + const sec = Array.isArray(room.sections) && room.sections.length > 0 ? room.sections.join(', ') : 'Не указано'; return { name: room.name ?? 'Не указано', @@ -472,7 +492,7 @@ const displayedRooms = computed(() => { trainers: trainerNames, sections: sec, id: room.id ?? '' - } + }; }); }); diff --git a/gym-rest-api/src/main/java/com/example/gym/service/AdminService.java b/gym-rest-api/src/main/java/com/example/gym/service/AdminService.java index 1f119a2..73fd49b 100644 --- a/gym-rest-api/src/main/java/com/example/gym/service/AdminService.java +++ b/gym-rest-api/src/main/java/com/example/gym/service/AdminService.java @@ -283,7 +283,7 @@ public List getFinishedTrainings(LocalDate startDate, LocalDa int currentClientCount = training.getClients().size(); sectionStats.setClientCount(sectionStats.getClientCount() == null ? currentClientCount : sectionStats.getClientCount() + currentClientCount); - int totalSlots = training.getAvailableSlots(); + int totalSlots = training.getRoom().getCapacity(); double loadPercentage = totalSlots > 0 ? (currentClientCount / (double) totalSlots) * 100 : 0; sectionStats.setLoadPercentage(loadPercentage);