WIP for lightings...
This commit is contained in:
@@ -2,6 +2,35 @@
|
||||
<h1> Lights </h1>
|
||||
</template>
|
||||
<script>
|
||||
|
||||
import { Cell, Group, GroupTitle } from 'vux'
|
||||
import Lights from '../models/lights'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
Cell,
|
||||
Group,
|
||||
GroupTitle
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
lights: []
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
fetchData () {
|
||||
var vm = this
|
||||
Lights.get({onSuccess: function (data) {
|
||||
vm.lights = data.Lights
|
||||
console.log(vm.lights)
|
||||
}})
|
||||
}
|
||||
},
|
||||
mounted () {
|
||||
// console.log('mounted')
|
||||
this.fetchData()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<style>
|
||||
</style>
|
||||
|
||||
51
src/prog/dashboard2/src/models/api.js
Normal file
51
src/prog/dashboard2/src/models/api.js
Normal file
@@ -0,0 +1,51 @@
|
||||
import axios from 'axios'
|
||||
|
||||
/*
|
||||
* Make the Request and call onSuccess method on the call back object.
|
||||
*/
|
||||
|
||||
export default {
|
||||
|
||||
request (route, data = 0, callback) {
|
||||
axios({
|
||||
method: route.method,
|
||||
url: this.server + route.url,
|
||||
data: data,
|
||||
timeout: this.timeout
|
||||
}).then(function (response) {
|
||||
// console.log('response...')
|
||||
if (callback && callback.onSuccess) {
|
||||
callback.onSuccess(response.data)
|
||||
}
|
||||
})
|
||||
},
|
||||
// server: '',
|
||||
server: 'http://192.168.1.6:8081',
|
||||
timeout: 1000,
|
||||
route: {
|
||||
|
||||
/*
|
||||
* The route tree for the Domo APIs.
|
||||
*/
|
||||
lights: {
|
||||
get: {
|
||||
url: '/v1/capabilities/lights',
|
||||
method: 'get'
|
||||
},
|
||||
set: {
|
||||
url: '/v1/capabilities/lights',
|
||||
method: 'post'
|
||||
}
|
||||
},
|
||||
sprinklers: {
|
||||
get: {
|
||||
url: '/v1/capabilities/sprinklers',
|
||||
method: 'get'
|
||||
},
|
||||
set: {
|
||||
url: '/v1/capabilities/sprinklers',
|
||||
method: 'post'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
2
src/prog/dashboard2/src/models/event-bus.js
Normal file
2
src/prog/dashboard2/src/models/event-bus.js
Normal file
@@ -0,0 +1,2 @@
|
||||
import Vue from 'vue'
|
||||
export const EventBus = new Vue()
|
||||
15
src/prog/dashboard2/src/models/lights.js
Normal file
15
src/prog/dashboard2/src/models/lights.js
Normal file
@@ -0,0 +1,15 @@
|
||||
import api from './api'
|
||||
|
||||
export default {
|
||||
|
||||
// get cpu info
|
||||
lights: {
|
||||
get (callback) {
|
||||
api.request(api.route.lights.get, callback)
|
||||
},
|
||||
set (light, callback) {
|
||||
var msg = '{"id": ' + light.id + ', "state": ' + light.state + '}'
|
||||
api.request(api.route.lights.set, msg, callback)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user