| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- var util = require('util');
- var Vue = require('vue'),
- VueMaterial = require('vue-material'),
- VueResource = require('vue-resource');
- var Light = require('../views/light.vue');
- Vue.use(VueMaterial);
- Vue.use(VueResource);
- var methods = {
- toggleSidenav: function () {
- this.$refs.leftSidenav.toggle();
- },
- sidenavOpen: function () {
- console.log('sidenav open');
- },
- selectLight: function (light) {
- this.$data.selectedLight = light;
- this.$refs.leftSidenav.close();
- },
- // lights
- refreshLights: function () {
- var that = this;
- this.$http.get('lights').then(function (result) {
- console.log('result', result);
- result.body.lights.forEach(function (light) {
- var tmp = that.$data.lights.find(function (l) { return light.id === l.id; });
- if (!tmp) return that.$data.lights.push(light);
- tmp = light;
- });
- // init a light selection
- if (!that.$data.selectedLight.id && that.$data.lights.length > 0) that.$data.selectedLight = result.body.lights[0];
- }, function (error) {
- console.log('error', error);
- });
- },
- setLightProperties: function (light) {
- var that = this;
- this.$http.put('lights/' + light.id, light.state).then(function (result) {
- console.log('result', result);
- that.refreshLights();
- }, function (error) {
- console.log('error', error);
- });
- }
- };
- var App = new Vue({
- el: '#app',
- http: {
- root: (process.env.API_ENDPOINT || '') + '/api',
- },
- components: {
- lightItem: Light
- },
- data: {
- lights: [],
- selectedLight: { state: {}}
- },
- methods: methods,
- mounted: function () {
- this.refreshLights();
- }
- });
|