| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <style>
- .red {
- color: #f00;
- }
- </style>
- <template>
- <md-layout md-align="center" md-gutter="16">
- <md-card>
- <md-card-header>
- <div class="md-title">{{ light.name }}</div>
- <div class="md-subhead">{{ light.type }}</div>
- <md-switch v-model="light.state.on" class="md-warn"></md-switch>
- </md-card-header>
- <md-card-content v-show="light.state.on">
- <color-picker v-model="colors"></color-picker>
- </md-card-content>
- <md-card-actions>
- <md-button @click.native="reset()" :disabled="!light.state.on">Reset</md-button>
- <md-menu>
- <md-button md-menu-trigger :disabled="!light.state.on">Preset Colors</md-button>
- <md-menu-content>
- <md-menu-item @selected="setColor('white')">White</md-menu-item>
- <md-menu-item @selected="setColor('red')">Red</md-menu-item>
- <md-menu-item @selected="setColor('blue')">Blue</md-menu-item>
- <md-menu-item @selected="setColor('green')">Green</md-menu-item>
- <md-menu-item @selected="setColor('purple')">Purple</md-menu-item>
- </md-menu-content>
- </md-menu>
- <md-button @click.native="colorLoop()" :disabled="!light.state.on">Color Loop</md-button>
- </md-card-actions>
- </md-card>
- </md-layout>
- </template>
- <script>
- var Color = require('color');
- var Vue = require('vue'),
- VueColor = require('vue-color');
- module.exports = {
- props: ['light'],
- data: function () {
- return {
- colors: {
- hex: '#00ff00',
- a: 0
- }
- };
- },
- http: {
- root: (process.env.API_ENDPOINT || '') + '/api',
- },
- components: {
- 'color-picker': VueColor.Chrome
- },
- methods: {
- reset: function () {
- this.setProps({ reset: true });
- },
- colorLoop: function () {
- console.error('Not implemented')
- },
- setColor: function (color) {
- Vue.set(this.$props.light.state, 'rgb', Color(color).rgb().array());
- },
- setRgb: function (r, g, b) {
- Vue.set(this.$props.light.state, 'rgb', [r, g, b]);
- },
- setBrightness: function (brightness) {
- Vue.set(this.$props.light.state, 'bri', brightness);
- }
- },
- watch: {
- light: {
- handler: function (newVal, oldVal) {
- var that = this;
- // this is setting a new light
- if (newVal.id !== oldVal.id) {
- console.log(newVal.state)
- if (!newVal.state.rgb) return;
- console.log(this.$data, Color.rgb(newVal.state.rgb).hex())
- Vue.nextTick(function () {
- that.$data.colors = {
- hex: Color.rgb(newVal.state.rgb).hex(),
- a: 255. / newVal.state.bri
- };
- });
- return;
- }
- console.log('light changed, commit changes', newVal, oldVal);
- this.$root.setLightProperties(this.$props.light);
- },
- deep: true
- },
- colors: {
- handler: function (newVal, oldVal) {
- this.setRgb(newVal.rgba.r, newVal.rgba.g, newVal.rgba.b);
- this.setBrightness(newVal.rgba.a * 255);
- }
- }
- }
- }
- </script>
|