This commit is contained in:
2023-02-09 23:28:26 +01:00
parent bd15f631f9
commit 4b9f533691
6 changed files with 53 additions and 32 deletions

21
.drone.yml Normal file
View File

@@ -0,0 +1,21 @@
kind: pipeline
type: ssh
name: default
server:
host: nuc.home
user: marco
ssh_key:
from_secret: ssh_key
steps:
- name: deploy
commands:
- cd /home/marco/containers/data/sensor-web-v2
- git pull
- cd /home/marco/containers
- docker-compose up --build -d sensor-web-v2
trigger:
branch:
- master

View File

@@ -11,6 +11,8 @@ import 'highcharts/css/highcharts.scss'
import Loader from '@/components/Loader.vue' import Loader from '@/components/Loader.vue'
import { capitalizeFirstLetter } from '@/utils/helpers' import { capitalizeFirstLetter } from '@/utils/helpers'
import type { Window } from '@/utils/types' import type { Window } from '@/utils/types'
import type { navType } from '@/utils/types'
import { typeApi } from '@/utils/types'
Highcharts.setOptions({ Highcharts.setOptions({
time: { time: {
@@ -20,7 +22,7 @@ Highcharts.setOptions({
const props = defineProps<{ const props = defineProps<{
activeWindow: Window activeWindow: Window
activeType: string activeType: navType | null
}>() }>()
const data = ref([]) const data = ref([])
@@ -28,19 +30,13 @@ const loading = ref(false)
const chart = ref<HTMLElement | null>(null) const chart = ref<HTMLElement | null>(null)
const { activeWindow, activeType } = toRefs(props) const { activeWindow, activeType } = toRefs(props)
const fetchData = async (window: Window, type: string) => { const fetchData = async (window: Window, type: navType) => {
loading.value = true loading.value = true
const typeApi = {
temperatuur: 'temperature',
luchtvochtigheid: 'humidity'
}
try { try {
const [start, end] = [window.getStart(), window.getEnd()] const [start, end] = [window.getStart(), window.getEnd()]
const sample = Math.round((end - start) / 60 / 288) || 1 const sample = Math.round((end - start) / 60 / 288) || 1
const host = import.meta.env.MODE === 'development' ? 'http://localhost:3000' : '' const host = import.meta.env.MODE === 'development' ? 'http://localhost:3000' : ''
const fetchUrl = `${host}/type/${ const fetchUrl = `${host}/type/${typeApi[type]}/startDate/${start}/endDate/${end}/sample/${sample}`
typeApi[type as keyof typeof typeApi]
}/startDate/${start}/endDate/${end}/sample/${sample}`
const response = await fetch(fetchUrl) const response = await fetch(fetchUrl)
loading.value = false loading.value = false
return response.json() return response.json()
@@ -79,7 +75,7 @@ const renderChart = () => {
title: { text: null }, title: { text: null },
minTickInterval: 0.1 minTickInterval: 0.1
}, },
series: [{ name: capitalizeFirstLetter(activeType.value), data: chartData, type: 'line' }], series: [{ name: capitalizeFirstLetter(activeType.value || ''), data: chartData, type: 'line' }],
credits: { enabled: false } credits: { enabled: false }
}) })
} }

View File

@@ -16,17 +16,18 @@ import TimeWindows from '@/components/TimeWindows.vue'
import Chart from '@/components/Chart.vue' import Chart from '@/components/Chart.vue'
import { windows } from '@/utils/helpers' import { windows } from '@/utils/helpers'
import type { Window } from '@/utils/types' import type { Window } from '@/utils/types'
import type { navType } from '@/utils/types'
const defaultWindow = windows[1] const defaultWindow = windows[1]
const activeType = ref<string>('') const activeType = ref<navType | null>(null)
const activeWindow = ref<Window>(defaultWindow) const activeWindow = ref<Window>(defaultWindow)
const router = useRouter() const router = useRouter()
const currentRoute = useRoute() const route = useRoute()
if (currentRoute.params.type) activeType.value = currentRoute.params.type as string if (route.params.type) activeType.value = route.params.type as navType
if (currentRoute.params.window) { if (route.params.window) {
activeWindow.value = windows.find((w) => w.label === currentRoute.params.window) || defaultWindow activeWindow.value = windows.find((w) => w.label === route.params.window) || defaultWindow
} }
const updateRoute = () => { const updateRoute = () => {
@@ -42,7 +43,7 @@ const updateRoute = () => {
} }
} }
const setType = (newType: string) => { const setType = (newType: navType) => {
activeType.value = newType activeType.value = newType
updateRoute() updateRoute()
} }

View File

@@ -7,7 +7,7 @@
class="navbar-burger burger" class="navbar-burger burger"
aria-label="menu" aria-label="menu"
aria-expanded="false" aria-expanded="false"
data-target="navbarBasicExample" data-target="navbar"
:class="{ 'is-active': toggled }" :class="{ 'is-active': toggled }"
@click="toggleMenu" @click="toggleMenu"
> >
@@ -17,7 +17,7 @@
</a> </a>
</div> </div>
<div class="navbar-menu" :class="{ 'is-active': toggled }"> <div class="navbar-menu" id="navbar" :class="{ 'is-active': toggled }">
<div class="navbar-start"> <div class="navbar-start">
<a <a
class="navbar-item" class="navbar-item"
@@ -33,28 +33,25 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { capitalizeFirstLetter } from '@/utils/helpers' import { capitalizeFirstLetter } from '@/utils/helpers'
import { ref, onMounted } from 'vue' import { ref } from 'vue'
import type { navType } from '@/utils/types'
const props = defineProps<{ const props = defineProps<{
activeType: string activeType: navType | null
}>() }>()
const emit = defineEmits<{ const emit = defineEmits<{
(e: 'set-type', type: string): void (e: 'set-type', type: navType): void
}>() }>()
const setType = (type: navType) => {
const toggled = ref(false)
const navTypes = ref<string[]>(['temperatuur', 'luchtvochtigheid'])
onMounted(() => {
if (!props.activeType) {
emit('set-type', navTypes.value[0])
}
})
const toggleMenu = () => (toggled.value = !toggled.value)
const setType = (type: string) => {
toggled.value = false toggled.value = false
emit('set-type', type) emit('set-type', type)
} }
const toggled = ref(false)
const navTypes: navType[] = ['temperatuur', 'luchtvochtigheid']
if (!props.activeType) setType(navTypes[0])
const toggleMenu = () => (toggled.value = !toggled.value)
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
@import '@/style/_variables.scss'; @import '@/style/_variables.scss';

View File

@@ -13,7 +13,6 @@
</div> </div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { defineProps, defineEmits } from 'vue'
import type { Window } from '@/utils/types' import type { Window } from '@/utils/types'
const props = defineProps<{ const props = defineProps<{

View File

@@ -5,3 +5,10 @@ export interface Window {
format: string format: string
interval: number interval: number
} }
export const typeApi = {
temperatuur: 'temperature',
luchtvochtigheid: 'humidity'
}
export type navType = keyof typeof typeApi