Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
co2ampel2
Web
Commits
3dd20147
Commit
3dd20147
authored
1 month ago
by
Mele
Browse files
Options
Download
Email Patches
Plain Diff
Frontend now works perfect
parent
fe786311
main
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
frontend/src/components/RoomCard.vue
+1
-1
frontend/src/components/RoomCard.vue
frontend/src/router/index.ts
+6
-0
frontend/src/router/index.ts
frontend/src/views/ChartView.vue
+65
-3
frontend/src/views/ChartView.vue
with
72 additions
and
4 deletions
+72
-4
frontend/src/components/RoomCard.vue
+
1
-
1
View file @
3dd20147
<
template
>
<RouterLink
:to=
"`/rooms/$
{room}`" class="room-card">
<RouterLink
:to=
"`/rooms/$
{
encodeURIComponent(
room
)
}`" class="room-card">
<div
class=
"card-content"
>
<h3>
{{
room
}}
</h3>
</div>
...
...
This diff is collapsed.
Click to expand it.
frontend/src/router/index.ts
+
6
-
0
View file @
3dd20147
...
...
@@ -39,6 +39,12 @@ const router = createRouter({
name
:
'
charts
'
,
component
:
ChartView
},
{
path
:
'
/rooms/:room
'
,
name
:
'
RoomChart
'
,
component
:
()
=>
import
(
'
../views/ChartView.vue
'
),
props
:
true
},
{
path
:
'
/about
'
,
name
:
'
about
'
,
...
...
This diff is collapsed.
Click to expand it.
frontend/src/views/ChartView.vue
+
65
-
3
View file @
3dd20147
<
template
>
<MyChart
/>
<div
class=
"chart-view"
>
<h2>
Daten für Raum:
{{
room
}}
</h2>
<ChartCard
title=
"CO₂ Verlauf"
:labels=
"labels"
:data=
"co2Data"
borderColor=
"#ff6384"
/>
<!-- Debug-Ausgabe -->
<pre>
Labels:
{{
labels
}}
</pre>
<pre>
CO₂:
{{
co2Data
}}
</pre>
</div>
</
template
>
<
script
setup
lang=
"ts"
>
import
MyChart
from
'
@/components/Chart.vue
'
<
script
lang=
"ts"
>
import
{
defineComponent
,
ref
,
onMounted
}
from
'
vue
'
import
{
useRoute
}
from
'
vue-router
'
import
ChartCard
from
'
../components/ChartCard.vue
'
export
default
defineComponent
({
name
:
'
ChartView
'
,
components
:
{
ChartCard
},
setup
()
{
const
route
=
useRoute
()
const
room
=
decodeURIComponent
(
route
.
params
.
room
as
string
)
const
labels
=
ref
<
string
[]
>
([])
const
co2Data
=
ref
<
number
[]
>
([])
onMounted
(
async
()
=>
{
try
{
const
url
=
`http://localhost:8000/api/room_data_range?room=
${
encodeURIComponent
(
room
)}
&start=-7d&stop=now()`
const
response
=
await
fetch
(
url
)
if
(
!
response
.
ok
)
{
throw
new
Error
(
`HTTP-Fehler:
${
response
.
status
}
`
)
}
const
json
=
await
response
.
json
()
const
entries
=
Object
.
entries
(
json
.
data
).
sort
(
([
a
],
[
b
])
=>
new
Date
(
a
).
getTime
()
-
new
Date
(
b
).
getTime
()
)
const
labelsArray
=
entries
.
map
(([
timestamp
])
=>
new
Date
(
timestamp
).
toLocaleTimeString
([],
{
hour
:
'
2-digit
'
,
minute
:
'
2-digit
'
})
)
const
co2DataArray
=
entries
.
map
(([,
values
])
=>
values
.
co2
)
labels
.
value
=
labelsArray
co2Data
.
value
=
co2DataArray
}
catch
(
err
)
{
console
.
error
(
'
❌ Fehler beim Laden der Daten:
'
,
err
)
}
})
return
{
room
,
labels
,
co2Data
}
}
})
</
script
>
<
style
scoped
>
.chart-view
{
padding
:
2rem
;
}
</
style
>
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets