Wip on the Light management.
This commit is contained in:
54
src/ui/Domo/docs/lights.txt
Normal file
54
src/ui/Domo/docs/lights.txt
Normal file
@@ -0,0 +1,54 @@
|
||||
curl -v http://192.168.1.6:8081/v1/capabilities/lights
|
||||
* Hostname was NOT found in DNS cache
|
||||
* Trying 192.168.1.6...
|
||||
* Connected to 192.168.1.6 (192.168.1.6) port 8081 (#0)
|
||||
> GET /v1/capabilities/lights HTTP/1.1
|
||||
> User-Agent: curl/7.35.0
|
||||
> Host: 192.168.1.6:8081
|
||||
> Accept: */*
|
||||
>
|
||||
< HTTP/1.1 200 OK
|
||||
< Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept
|
||||
< Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
|
||||
< Access-Control-Allow-Origin: *
|
||||
< Cache-Control: no-store, no-cache, must-revalidate, max-age=0
|
||||
< Connection: close
|
||||
< Content-Type: application/json; charset=utf-8
|
||||
< Pragma: no-cache
|
||||
<
|
||||
{
|
||||
"Lights" : [
|
||||
{
|
||||
"id" : 1,
|
||||
"interruptor" : 0,
|
||||
"name" : "Bureau JB",
|
||||
"sender" : 12797322,
|
||||
"speach_name" : "bureau",
|
||||
"state" : true,
|
||||
"zone" : ""
|
||||
},
|
||||
{
|
||||
"id" : 2,
|
||||
"interruptor" : 1,
|
||||
"name" : "Salon",
|
||||
"sender" : 12797322,
|
||||
"speach_name" : "salon",
|
||||
"state" : false,
|
||||
"zone" : ""
|
||||
},
|
||||
{
|
||||
"id" : 3,
|
||||
"interruptor" : 2,
|
||||
"name" : "Sapin",
|
||||
"sender" : 12797322,
|
||||
"speach_name" : "sapin",
|
||||
"state" : false,
|
||||
"zone" : ""
|
||||
}
|
||||
],
|
||||
"id" : "/v1/capabilities/lights",
|
||||
"response_code" : 200,
|
||||
"status" : "OK"
|
||||
}
|
||||
|
||||
* Closing connection 0
|
||||
@@ -16,6 +16,7 @@
|
||||
"fastclick": "^1.0.6",
|
||||
"font-awesome": "^4.6.1",
|
||||
"vue": "^1.0.21",
|
||||
"vue-resource": "^0.7.0",
|
||||
"vue-router": "^0.7.13",
|
||||
"vux": "0.0.116"
|
||||
},
|
||||
|
||||
60
src/ui/Domo/src/components/Light.vue
Normal file
60
src/ui/Domo/src/components/Light.vue
Normal file
@@ -0,0 +1,60 @@
|
||||
<template>
|
||||
<div class="weui_cell weui_cell_switch">
|
||||
<div class="weui_cell_hd weui_cell_primary">
|
||||
<label class="weui_label" :style="labelStyle">{{{data.name}}}</label>
|
||||
<inline-desc v-if="inlineDesc">{{inlineDesc}}</inline-desc>
|
||||
</div>
|
||||
<div class="weui_cell_ft">
|
||||
<input class="weui_switch" type="checkbox" :disabled="disabled" v-model="value"/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import InlineDesc from 'vux/components/inline-desc'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
InlineDesc
|
||||
},
|
||||
computed: {
|
||||
labelStyle: function () {
|
||||
let isHTML = /<\/?[^>]*>/.test(this.title)
|
||||
let width = Math.min(isHTML ? 5 : (this.title.length + 1), 14) + 'em'
|
||||
return {
|
||||
width
|
||||
}
|
||||
}
|
||||
},
|
||||
props: {
|
||||
title: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
data: {},
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
value: {
|
||||
type: Boolean,
|
||||
twoWay: true
|
||||
},
|
||||
inlineDesc: {
|
||||
type: String
|
||||
}
|
||||
},
|
||||
ready: function () {},
|
||||
watch: {
|
||||
value: function (newVal) {
|
||||
this.$dispatch('on-change', newVal)
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.weui_cell_switch .weui_cell_ft {
|
||||
font-size: 0;
|
||||
}
|
||||
</style>
|
||||
@@ -1,6 +1,107 @@
|
||||
<template>
|
||||
<h1>Lights</h1>
|
||||
<group>
|
||||
|
||||
<!--<div v-for="(index, item) in items">
|
||||
{{ index }} {{ item.message }}
|
||||
-->
|
||||
<light v-for="item in lights" :data="item" :value="item.state" @on-change="change"></light>
|
||||
</group>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Group from 'vux/components/group'
|
||||
import Cell from 'vux/components/cell'
|
||||
import Light from './Light'
|
||||
|
||||
export default {
|
||||
// Data
|
||||
data () {
|
||||
// console.log('Data init.');
|
||||
return {
|
||||
lights: []
|
||||
}
|
||||
},
|
||||
ready () {
|
||||
console.log('Get Lights state')
|
||||
this.getLights()
|
||||
},
|
||||
// Components used.
|
||||
components: {
|
||||
Group,
|
||||
Cell,
|
||||
Light
|
||||
},
|
||||
methods: {
|
||||
change (e) {
|
||||
console.log(e)
|
||||
},
|
||||
getLights () {
|
||||
this.$http.get('http://192.168.1.6:8081/v1/capabilities/lights')
|
||||
.then(function (response) {
|
||||
this.$set('lights', response.data.Lights)
|
||||
console.log('Success!:', response.data)
|
||||
}, function (err) {
|
||||
console.log(err)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
<!--
|
||||
|
||||
// GET request
|
||||
this.$http({url: '/someUrl', method: 'GET'}).then(function (response) {
|
||||
// success callback
|
||||
}, function (response) {
|
||||
// error callback
|
||||
});
|
||||
|
||||
quote: ''
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
getQuote() {
|
||||
this.$http
|
||||
.get('http://localhost:3001/api/random-quote', (data) => {
|
||||
this.quote = data;
|
||||
})
|
||||
.error((err) => console.log(err))
|
||||
}
|
||||
|
||||
lightProvider.service ('LightService', function ($http, $q) {
|
||||
|
||||
// Get the Array of All the Lights.
|
||||
this.getLights = function() {
|
||||
return $http.get('/v1/capabilities/lights').then (function (results) {
|
||||
// Result of the Get.
|
||||
if (results.data.response_code == 200)
|
||||
return results.data.Lights;
|
||||
else
|
||||
return $q.reject(results.data.status);
|
||||
}, function(error) {
|
||||
return $q.reject('Failed to make the Request');
|
||||
});
|
||||
};
|
||||
|
||||
// Set a new Light State.
|
||||
this.setLight = function ($id, $state) {
|
||||
|
||||
msg = '{"id": '+ $id + ', "state": ' + $state + '}';
|
||||
return $http.post('/v1/capabilities/lights', msg).then (function (results) {
|
||||
|
||||
if (results.data.response_code == 200)
|
||||
return $q.resolve(results.data.status);
|
||||
else
|
||||
return $q.reject(results.data.status);
|
||||
}, function(error) {
|
||||
return $q.reject('Failed to make the Request');
|
||||
});
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
|
||||
-->
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import Vue from 'vue'
|
||||
import Router from 'vue-router'
|
||||
import VueResource from 'vue-resource'
|
||||
|
||||
import App from './App'
|
||||
|
||||
@@ -13,6 +14,7 @@ import Settings from './components/Settings'
|
||||
const FastClick = require('fastclick')
|
||||
FastClick.attach(document.body)
|
||||
|
||||
Vue.use(VueResource)
|
||||
Vue.use(Router)
|
||||
Vue.config.devtools = true
|
||||
|
||||
|
||||
Reference in New Issue
Block a user