first commit
This commit is contained in:
43
src/components/Chart.vue
Normal file
43
src/components/Chart.vue
Normal file
@@ -0,0 +1,43 @@
|
||||
<template>
|
||||
<div ref="chart">chart</div>
|
||||
</template>
|
||||
<script>
|
||||
export default {
|
||||
props: ['window', 'type'],
|
||||
data() {
|
||||
return {
|
||||
data: []
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
async fetchData() {
|
||||
if (this.window.label) {
|
||||
try {
|
||||
const [start, end] = [this.window.getStart(), this.window.getEnd()]
|
||||
const sample = Math.round(((end - start) / 60) / 288) || 1
|
||||
const host = 'http://localhost:3000'
|
||||
const fetchUrl = `${host}/type/${this.type}/startDate/${start}/endDate/${end}/sample/${sample}`
|
||||
const response = await fetch(fetchUrl)
|
||||
this.data = await response.json()
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
}
|
||||
}
|
||||
},
|
||||
renderChart() {
|
||||
console.log('render chart', this.data)
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
window() {
|
||||
this.fetchData()
|
||||
},
|
||||
type() {
|
||||
this.fetchData()
|
||||
},
|
||||
data() {
|
||||
this.renderChart()
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -1,58 +0,0 @@
|
||||
<template>
|
||||
<div class="hello">
|
||||
<h1>{{ msg }}</h1>
|
||||
<p>
|
||||
For a guide and recipes on how to configure / customize this project,<br>
|
||||
check out the
|
||||
<a href="https://cli.vuejs.org" target="_blank" rel="noopener">vue-cli documentation</a>.
|
||||
</p>
|
||||
<h3>Installed CLI Plugins</h3>
|
||||
<ul>
|
||||
<li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-babel" target="_blank" rel="noopener">babel</a></li>
|
||||
<li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-eslint" target="_blank" rel="noopener">eslint</a></li>
|
||||
</ul>
|
||||
<h3>Essential Links</h3>
|
||||
<ul>
|
||||
<li><a href="https://vuejs.org" target="_blank" rel="noopener">Core Docs</a></li>
|
||||
<li><a href="https://forum.vuejs.org" target="_blank" rel="noopener">Forum</a></li>
|
||||
<li><a href="https://chat.vuejs.org" target="_blank" rel="noopener">Community Chat</a></li>
|
||||
<li><a href="https://twitter.com/vuejs" target="_blank" rel="noopener">Twitter</a></li>
|
||||
<li><a href="https://news.vuejs.org" target="_blank" rel="noopener">News</a></li>
|
||||
</ul>
|
||||
<h3>Ecosystem</h3>
|
||||
<ul>
|
||||
<li><a href="https://router.vuejs.org" target="_blank" rel="noopener">vue-router</a></li>
|
||||
<li><a href="https://vuex.vuejs.org" target="_blank" rel="noopener">vuex</a></li>
|
||||
<li><a href="https://github.com/vuejs/vue-devtools#vue-devtools" target="_blank" rel="noopener">vue-devtools</a></li>
|
||||
<li><a href="https://vue-loader.vuejs.org" target="_blank" rel="noopener">vue-loader</a></li>
|
||||
<li><a href="https://github.com/vuejs/awesome-vue" target="_blank" rel="noopener">awesome-vue</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'HelloWorld',
|
||||
props: {
|
||||
msg: String
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
||||
<style scoped lang="scss">
|
||||
h3 {
|
||||
margin: 40px 0 0;
|
||||
}
|
||||
ul {
|
||||
list-style-type: none;
|
||||
padding: 0;
|
||||
}
|
||||
li {
|
||||
display: inline-block;
|
||||
margin: 0 10px;
|
||||
}
|
||||
a {
|
||||
color: #42b983;
|
||||
}
|
||||
</style>
|
||||
65
src/components/NavBar.vue
Normal file
65
src/components/NavBar.vue
Normal file
@@ -0,0 +1,65 @@
|
||||
<template>
|
||||
<nav class="navbar is-primary" role="navigation" aria-label="main navigation">
|
||||
<div class="navbar-brand">
|
||||
<router-link to="/" class="navbar-item nav-title">DHT22</router-link>
|
||||
<a
|
||||
role="button"
|
||||
class="navbar-burger burger"
|
||||
aria-label="menu"
|
||||
aria-expanded="false"
|
||||
data-target="navbarBasicExample"
|
||||
:class="{'is-active': toggled}"
|
||||
@click="toggleMenu"
|
||||
>
|
||||
<span aria-hidden="true"></span>
|
||||
<span aria-hidden="true"></span>
|
||||
<span aria-hidden="true"></span>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="navbar-menu" :class="{'is-active': toggled}">
|
||||
<div class="navbar-start">
|
||||
<a
|
||||
class="navbar-item"
|
||||
:class="{'is-active': type === activeType}"
|
||||
:key="type"
|
||||
v-for="type in navTypes"
|
||||
@click="$emit('setType', type)"
|
||||
>{{capitalizeFirstLetter(type)}}</a>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</template>
|
||||
<script>
|
||||
export default {
|
||||
props: ['activeType'],
|
||||
data() {
|
||||
return {
|
||||
toggled: false
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
navTypes() {
|
||||
return ['temperature', 'humidity']
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
if (!this.activeType.label) {
|
||||
this.$emit('setType', this.navTypes[0])
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
toggleMenu() {
|
||||
this.toggled = !this.toggled
|
||||
},
|
||||
capitalizeFirstLetter(string) {
|
||||
return string.charAt(0).toUpperCase() + string.slice(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<style scoped>
|
||||
.nav-title {
|
||||
font-weight: bold;
|
||||
}
|
||||
</style>
|
||||
72
src/components/TimeWindows.vue
Normal file
72
src/components/TimeWindows.vue
Normal file
@@ -0,0 +1,72 @@
|
||||
<template>
|
||||
<div class="tabs is-centered">
|
||||
<ul>
|
||||
<li
|
||||
v-for="window in windows"
|
||||
:key="window.label"
|
||||
@click="$emit('setWindow', window)"
|
||||
:class="{'is-active': window.label === activeWindow.label}"
|
||||
>
|
||||
<a>{{window.label}}</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
import dayjs from 'dayjs'
|
||||
export default {
|
||||
props: ['activeWindow'],
|
||||
data() {
|
||||
return {
|
||||
windows: [{
|
||||
label: 'afgelopen uur',
|
||||
getStart: () => dayjs().subtract(1, 'hour').unix(),
|
||||
getEnd: () => dayjs().unix(),
|
||||
format: 'HH:mm',
|
||||
interval: 4
|
||||
}, {
|
||||
label: '24 uur',
|
||||
getStart: () => dayjs().subtract(1, 'days').unix(),
|
||||
getEnd: () => dayjs().unix(),
|
||||
format: 'HH:mm',
|
||||
interval: 4
|
||||
}, {
|
||||
label: 'vandaag',
|
||||
getStart: () => dayjs().startOf('day').add(1, 'day').subtract(24, 'hours').unix(),
|
||||
getEnd: () => dayjs().unix(),
|
||||
format: 'HH:mm',
|
||||
interval: 4
|
||||
}, {
|
||||
label: '3 dagen',
|
||||
getStart: () => dayjs().startOf('day').add(1, 'day').subtract(3, 'days').unix(),
|
||||
getEnd: () => dayjs().unix(),
|
||||
format: 'ddd D/M',
|
||||
interval: 24
|
||||
}, {
|
||||
label: 'week',
|
||||
getStart: () => dayjs().startOf('day').add(1, 'day').subtract(7, 'days').unix(),
|
||||
getEnd: () => dayjs().unix(),
|
||||
format: 'ddd D/M',
|
||||
interval: 24
|
||||
}, {
|
||||
label: 'maand',
|
||||
getStart: () => dayjs().startOf('day').add(1, 'day').subtract(1, 'months').unix(),
|
||||
getEnd: () => dayjs().unix(),
|
||||
format: 'ddd D/M',
|
||||
interval: 24
|
||||
}, {
|
||||
label: 'jaar',
|
||||
getStart: () => dayjs().startOf('day').add(1, 'day').subtract(1, 'year').unix(),
|
||||
getEnd: () => dayjs().unix(),
|
||||
format: 'ddd D/M',
|
||||
interval: 24 * 7
|
||||
}]
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
if (!this.activeWindow.label) {
|
||||
this.$emit('setWindow', this.windows[1])
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user