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 { 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<HTMLElement | null>(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 }
})
}

View File

@@ -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<string>('')
const activeType = ref<navType | null>(null)
const activeWindow = ref<Window>(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()
}

View File

@@ -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 @@
</a>
</div>
<div class="navbar-menu" :class="{ 'is-active': toggled }">
<div class="navbar-menu" id="navbar" :class="{ 'is-active': toggled }">
<div class="navbar-start">
<a
class="navbar-item"
@@ -33,28 +33,25 @@
</template>
<script setup lang="ts">
import { capitalizeFirstLetter } from '@/utils/helpers'
import { ref, onMounted } from 'vue'
import { ref } from 'vue'
import type { navType } from '@/utils/types'
const props = defineProps<{
activeType: string
activeType: navType | null
}>()
const emit = defineEmits<{
(e: 'set-type', type: string): void
(e: 'set-type', type: navType): void
}>()
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) => {
const setType = (type: navType) => {
toggled.value = false
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>
<style scoped lang="scss">
@import '@/style/_variables.scss';

View File

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

View File

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