Commit fe786311 authored by Mele's avatar Mele
Browse files

Frontend now shows all the Rooms in a building when you press the Card for it ^^

parent 035479c2
<template> <template>
<RouterLink :to="`/buildings/${buildingId}`" class="bau-card"> <div class="bau-card" @click="handleClick">
<div class="card-background" :style="{ backgroundImage: `url(${image})` }"></div> <div class="card-background" :style="{ backgroundImage: `url(${props.image})` }"></div>
<div class="card-content"> <div class="card-content">
<h3>{{ title }}</h3> <h3>{{ props.title }}</h3>
<p>{{ description }}</p> <p>{{ props.description }}</p>
</div>
</div> </div>
</RouterLink>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
defineProps<{ const emit = defineEmits(['select'])
const props = defineProps<{
title: string title: string
description: string description: string
image: string image: string
buildingId: string buildingId: string
}>() }>()
function handleClick() {
emit('select', props.buildingId)
}
</script> </script>
<style scoped> <style scoped>
......
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
import { defineComponent, ref, onMounted } from 'vue'; import { defineComponent, ref, onMounted } from 'vue';
import ChartCard from '../components/ChartCard.vue'; import ChartCard from '../components/ChartCard.vue';
const availableRooms = ['1/121', '1/131', '1/210', '1/211']
export default defineComponent({ export default defineComponent({
name: 'AboutView', name: 'AboutView',
components: { ChartCard }, components: { ChartCard },
...@@ -29,6 +31,7 @@ export default defineComponent({ ...@@ -29,6 +31,7 @@ export default defineComponent({
onMounted(async () => { onMounted(async () => {
try { try {
const url = 'http://localhost:8000/api/room_data_range?room=1/210&start=-7d&stop=now()'; const url = 'http://localhost:8000/api/room_data_range?room=1/210&start=-7d&stop=now()';
//const url = 'http://localhost:8000/api/room_data_range?room=${room.value}&start=${start.value}&stop=${stop.value}';
const response = await fetch(url); const response = await fetch(url);
if (!response.ok) { if (!response.ok) {
......
<script setup lang="ts"> <script setup lang="ts">
import { ref } from 'vue'
import BauCard from '../components/BauCard.vue' import BauCard from '../components/BauCard.vue'
import RoomCard from '../components/RoomCard.vue'
const buildings = [ const buildings = [
{ {
...@@ -15,21 +17,50 @@ const buildings = [ ...@@ -15,21 +17,50 @@ const buildings = [
image: '/images/building2.png', image: '/images/building2.png',
}, },
{ {
id: '2', id: '3',
title: 'Bau 2', title: 'Bau 3',
description: 'Informatik und IT-Räume', description: 'Informatik und IT-Räume',
image: '/images/building2.png', image: '/images/building2.png',
}, },
{ {
id: '2', id: '8',
title: 'Bau 2', title: 'Bau 8',
description: 'Informatik und IT-Räume', description: 'Informatik und IT-Räume',
image: '/images/building2.png', image: '/images/building2.png',
} }
] ]
const selectedBuildingId = ref<string | null>(null)
const rooms = ref<string[]>([])
const isLoading = ref(false)
const error = ref<string | null>(null)
async function loadRooms(buildingId: string) {
selectedBuildingId.value = buildingId
rooms.value = []
isLoading.value = true
error.value = null
try {
const response = await fetch(`http://localhost:8000/api/get_rooms_from_building?building=${buildingId}`)
const data = await response.json()
if (response.ok) {
rooms.value = data.rooms
} else {
throw new Error(data.detail || 'Fehler beim Laden der Räume')
}
} catch (err: any) {
error.value = err.message
} finally {
isLoading.value = false
}
}
</script> </script>
<template> <template>
<div class="layout">
<!-- Linke Spalte: Gebäude -->
<div class="building-grid"> <div class="building-grid">
<BauCard <BauCard
v-for="bau in buildings" v-for="bau in buildings"
...@@ -38,15 +69,40 @@ const buildings = [ ...@@ -38,15 +69,40 @@ const buildings = [
:title="bau.title" :title="bau.title"
:description="bau.description" :description="bau.description"
:image="bau.image" :image="bau.image"
@select="loadRooms"
/> />
</div> </div>
<!-- Rechte Spalte: Räume -->
<div class="room-panel">
<h3 v-if="selectedBuildingId">Räume in Bau {{ selectedBuildingId }}</h3>
<div v-if="isLoading">Lade Räume...</div>
<div v-else-if="error">{{ error }}</div>
<div v-else>
<RoomCard v-for="room in rooms" :key="room" :room="room" />
</div>
</div>
</div>
</template> </template>
<style scoped> <style scoped>
.layout {
display: flex;
padding: 2rem;
gap: 2rem;
}
.building-grid { .building-grid {
display: grid; display: grid;
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
gap: 1.5rem; gap: 1.5rem;
padding: 2rem; flex: 2;
}
.room-panel {
flex: 1;
display: flex;
flex-direction: column;
gap: 1rem;
} }
</style> </style>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment