From 4b9f533691e8c8bc78feaa58668807d79d943074 Mon Sep 17 00:00:00 2001 From: Marco Crapts Date: Thu, 9 Feb 2023 23:28:26 +0100 Subject: [PATCH] refactor --- .drone.yml | 21 +++++++++++++++++++++ src/components/Chart.vue | 16 ++++++---------- src/components/Main.vue | 13 +++++++------ src/components/NavBar.vue | 27 ++++++++++++--------------- src/components/TimeWindows.vue | 1 - src/utils/types.ts | 7 +++++++ 6 files changed, 53 insertions(+), 32 deletions(-) create mode 100644 .drone.yml diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..6e827a3 --- /dev/null +++ b/.drone.yml @@ -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 diff --git a/src/components/Chart.vue b/src/components/Chart.vue index e6374a8..f35e89e 100644 --- a/src/components/Chart.vue +++ b/src/components/Chart.vue @@ -11,6 +11,8 @@ import 'highcharts/css/highcharts.scss' import Loader from '@/components/Loader.vue' import { capitalizeFirstLetter } from '@/utils/helpers' import type { Window } from '@/utils/types' +import type { navType } from '@/utils/types' +import { typeApi } from '@/utils/types' Highcharts.setOptions({ time: { @@ -20,7 +22,7 @@ Highcharts.setOptions({ const props = defineProps<{ activeWindow: Window - activeType: string + activeType: navType | null }>() const data = ref([]) @@ -28,19 +30,13 @@ const loading = ref(false) const chart = ref(null) const { activeWindow, activeType } = toRefs(props) -const fetchData = async (window: Window, type: string) => { +const fetchData = async (window: Window, type: navType) => { loading.value = true - const typeApi = { - temperatuur: 'temperature', - luchtvochtigheid: 'humidity' - } try { const [start, end] = [window.getStart(), window.getEnd()] const sample = Math.round((end - start) / 60 / 288) || 1 const host = import.meta.env.MODE === 'development' ? 'http://localhost:3000' : '' - const fetchUrl = `${host}/type/${ - typeApi[type as keyof typeof typeApi] - }/startDate/${start}/endDate/${end}/sample/${sample}` + const fetchUrl = `${host}/type/${typeApi[type]}/startDate/${start}/endDate/${end}/sample/${sample}` const response = await fetch(fetchUrl) loading.value = false return response.json() @@ -79,7 +75,7 @@ const renderChart = () => { title: { text: null }, minTickInterval: 0.1 }, - series: [{ name: capitalizeFirstLetter(activeType.value), data: chartData, type: 'line' }], + series: [{ name: capitalizeFirstLetter(activeType.value || ''), data: chartData, type: 'line' }], credits: { enabled: false } }) } diff --git a/src/components/Main.vue b/src/components/Main.vue index 99a95dc..48f64c7 100644 --- a/src/components/Main.vue +++ b/src/components/Main.vue @@ -16,17 +16,18 @@ import TimeWindows from '@/components/TimeWindows.vue' import Chart from '@/components/Chart.vue' import { windows } from '@/utils/helpers' import type { Window } from '@/utils/types' +import type { navType } from '@/utils/types' const defaultWindow = windows[1] -const activeType = ref('') +const activeType = ref(null) const activeWindow = ref(defaultWindow) const router = useRouter() -const currentRoute = useRoute() -if (currentRoute.params.type) activeType.value = currentRoute.params.type as string -if (currentRoute.params.window) { - activeWindow.value = windows.find((w) => w.label === currentRoute.params.window) || defaultWindow +const route = useRoute() +if (route.params.type) activeType.value = route.params.type as navType +if (route.params.window) { + activeWindow.value = windows.find((w) => w.label === route.params.window) || defaultWindow } const updateRoute = () => { @@ -42,7 +43,7 @@ const updateRoute = () => { } } -const setType = (newType: string) => { +const setType = (newType: navType) => { activeType.value = newType updateRoute() } diff --git a/src/components/NavBar.vue b/src/components/NavBar.vue index 069be34..8d55c6d 100644 --- a/src/components/NavBar.vue +++ b/src/components/NavBar.vue @@ -7,7 +7,7 @@ class="navbar-burger burger" aria-label="menu" aria-expanded="false" - data-target="navbarBasicExample" + data-target="navbar" :class="{ 'is-active': toggled }" @click="toggleMenu" > @@ -17,7 +17,7 @@ -