dashboard3 wip
This commit is contained in:
@@ -14,3 +14,5 @@ Scanning ...
|
||||
00:12:6F:33:C9:FE Cabasse Stream Source
|
||||
98:D3:35:00:A6:1C HC-05
|
||||
```
|
||||
|
||||
https://askubuntu.com/questions/248817/how-to-i-connect-a-raw-serial-terminal-to-a-bluetooth-connection
|
||||
@@ -18,7 +18,7 @@ USE_PROCD=1
|
||||
start_service () {
|
||||
|
||||
procd_open_instance
|
||||
procd_set_param command "$PROG" -p $PORT -f -h /usr/local/share/uhttpd/ -U /usr/local/configs/uhttpd/
|
||||
procd_set_param command "$PROG" -p $PORT -f -h /usr/local/share/uhttpd/ -U /usr/local/configs/uhttpd/ -u /usr/local/bin/plugins/
|
||||
procd_set_param pidfile "$PIDFILE"
|
||||
procd_set_param respawn
|
||||
procd_set_param stdout 1 # forward stdout of the command to logd
|
||||
|
||||
@@ -444,7 +444,7 @@ int main(int argc, char **argv)
|
||||
break;
|
||||
#else
|
||||
case 'a':
|
||||
case 'u':
|
||||
//case 'u':
|
||||
//case 'U':
|
||||
case 'X':
|
||||
fprintf(stderr, "uhttpd: UBUS support not compiled, "
|
||||
@@ -456,7 +456,7 @@ int main(int argc, char **argv)
|
||||
conf.ubus_prefix = optarg;
|
||||
break;
|
||||
case 'u':
|
||||
conf.ubus_prefix = optarg;
|
||||
conf.lua_prefix = optarg;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
@@ -509,7 +509,8 @@ int main(int argc, char **argv)
|
||||
return 1;
|
||||
#endif
|
||||
#ifdef HAVE_REST_API_PLUGING
|
||||
if (uh_plugin_init("uhttpd_rest-api-plugin.so"))
|
||||
snprintf(uh_buf, 4096, "%s/uhttpd_rest-api-plugin.so", conf.lua_prefix);
|
||||
if (uh_plugin_init(uh_buf))
|
||||
return 1;
|
||||
#endif
|
||||
/* fork (if not disabled) */
|
||||
|
||||
@@ -27,4 +27,7 @@ export default {
|
||||
}
|
||||
|
||||
## example ....
|
||||
https://appdividend.com/2018/05/08/vuex-axios-get-request-tutorial-with-example/
|
||||
|
||||
a suivre !!!!=>
|
||||
|
||||
https://appdividend.com/2018/05/08/vuex-axios-get-request-tutorial-with-example/
|
||||
|
||||
76
src/prog/dashboard3/src/api/domo.js
Normal file
76
src/prog/dashboard3/src/api/domo.js
Normal file
@@ -0,0 +1,76 @@
|
||||
import axios from 'axios'
|
||||
|
||||
/*
|
||||
* Make the Request and call onSuccess method on the call back object.
|
||||
*/
|
||||
|
||||
export default {
|
||||
|
||||
request (route, data = null) {
|
||||
// console.log('data:', data)
|
||||
return new Promise((resolve, reject) => {
|
||||
axios({
|
||||
method: route.method,
|
||||
url: this.server + route.url,
|
||||
timeout: this.timeout,
|
||||
data: data
|
||||
}).then((response) => {
|
||||
// console.log('response...')
|
||||
resolve(response)
|
||||
}).catch((error) => {
|
||||
console.log(error)
|
||||
reject(error)
|
||||
})
|
||||
})
|
||||
},
|
||||
etag_request (route, version, data = null) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios({
|
||||
method: route.method,
|
||||
url: this.server + route.url,
|
||||
headers: { 'If-None-Match': version, 'Prefer': 'wait=' + this.etag_timeout },
|
||||
timeout: this.timeout * 30,
|
||||
data: data
|
||||
}).then((response) => {
|
||||
// console.log('response...', response)
|
||||
if (response.status === 200) {
|
||||
resolve(response.data)
|
||||
} else if (response.status === 204) {
|
||||
reject(response)
|
||||
} else if (response.status === 412) {
|
||||
reject(response)
|
||||
}
|
||||
}).catch((error) => {
|
||||
if (error.response) {
|
||||
// console.log('request error: ', error.response)
|
||||
reject(error.response)
|
||||
} else {
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
// server: '',
|
||||
server: 'http://192.168.1.129:8080',
|
||||
timeout: 1000,
|
||||
etag_timeout: 10,
|
||||
route: {
|
||||
/*
|
||||
* The route tree for the network APIs.
|
||||
*/
|
||||
v1: {
|
||||
outlets: {
|
||||
},
|
||||
sequences: {
|
||||
},
|
||||
shutters: {
|
||||
},
|
||||
sprinklers: {
|
||||
get: {
|
||||
url: '/v1/sprinklers',
|
||||
method: 'get'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,14 +3,14 @@
|
||||
<!-- content -->
|
||||
<q-list>
|
||||
<q-list-header>Sprinklers</q-list-header>
|
||||
<q-item link v-ripple.mat>
|
||||
<q-item link v-ripple.mat v-for="sprinkler in sprinklers" :key="sprinkler.id">
|
||||
<q-item-side icon="settings" />
|
||||
<q-item-main label="Zone A" />
|
||||
<q-item-main :label="sprinkler.name" />
|
||||
<q-item-side right>
|
||||
<q-toggle v-model="checked_one" />
|
||||
<q-toggle v-model="sprinkler.state" />
|
||||
</q-item-side>
|
||||
</q-item>
|
||||
<q-item link v-ripple.mat>
|
||||
<!--<q-item link v-ripple.mat>
|
||||
<q-item-side icon="settings" />
|
||||
<q-item-main label="Zone B" />
|
||||
<q-item-side right>
|
||||
@@ -23,14 +23,23 @@
|
||||
<q-item-side right>
|
||||
<q-toggle v-model="checked_three" />
|
||||
</q-item-side>
|
||||
</q-item>
|
||||
</q-item>-->
|
||||
</q-list>
|
||||
</q-page>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { mapState } from 'vuex'
|
||||
|
||||
export default {
|
||||
name: 'PageSprinklers'
|
||||
name: 'PageSprinklers',
|
||||
mounted () {
|
||||
console.log('mounted')
|
||||
this.$store.dispatch('sprinklers/load')
|
||||
},
|
||||
computed: mapState([
|
||||
'sprinklers'
|
||||
])
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
import Vue from 'vue'
|
||||
import Vuex from 'vuex'
|
||||
import axios from 'axios'
|
||||
import VueAxios from 'vue-axios'
|
||||
|
||||
import domoStore from './domo-store'
|
||||
import sprinklers from './modules/sprinklers'
|
||||
|
||||
Vue.use(Vuex)
|
||||
Vue.use(VueAxios, axios)
|
||||
|
||||
const debug = process.env.NODE_ENV !== 'production'
|
||||
|
||||
const store = new Vuex.Store({
|
||||
modules: {
|
||||
domoStore
|
||||
}
|
||||
domoStore,
|
||||
sprinklers
|
||||
},
|
||||
strict: debug
|
||||
})
|
||||
|
||||
export default store
|
||||
|
||||
119
src/prog/dashboard3/src/store/modules/sprinklers.js
Normal file
119
src/prog/dashboard3/src/store/modules/sprinklers.js
Normal file
@@ -0,0 +1,119 @@
|
||||
import api from '../../api/domo'
|
||||
|
||||
// initial state
|
||||
// shape: [{ id, quantity }]
|
||||
const state = {
|
||||
sprinklers: []
|
||||
}
|
||||
|
||||
// getters
|
||||
const getters = {
|
||||
/*
|
||||
cartProducts: (state, getters, rootState) => {
|
||||
return state.items.map(({ id, quantity }) => {
|
||||
const product = rootState.products.all.find(product => product.id === id)
|
||||
return {
|
||||
title: product.title,
|
||||
price: product.price,
|
||||
quantity
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
cartTotalPrice: (state, getters) => {
|
||||
return getters.cartProducts.reduce((total, product) => {
|
||||
return total + product.price * product.quantity
|
||||
}, 0)
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
// actions
|
||||
const actions = {
|
||||
load ({ commit }) {
|
||||
api.request(api.route.v1.sprinklers.get)
|
||||
.then(data => {
|
||||
console.log('on est la.', data)
|
||||
commit('SET_SPRINKLERS', data.data.sprinklers)
|
||||
})
|
||||
}
|
||||
}
|
||||
/*
|
||||
axios
|
||||
.get('http://localhost:4000/results')
|
||||
.then(r => r.data)
|
||||
.then(coins => {
|
||||
commit('SET_COINS', coins)
|
||||
})
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
checkout ({ commit, state }, products) {
|
||||
const savedCartItems = [...state.items]
|
||||
commit('setCheckoutStatus', null)
|
||||
// empty cart
|
||||
commit('setCartItems', { items: [] })
|
||||
shop.buyProducts(
|
||||
products,
|
||||
() => commit('setCheckoutStatus', 'successful'),
|
||||
() => {
|
||||
commit('setCheckoutStatus', 'failed')
|
||||
// rollback to the cart saved before sending the request
|
||||
commit('setCartItems', { items: savedCartItems })
|
||||
}
|
||||
)
|
||||
},
|
||||
|
||||
addProductToCart ({ state, commit }, product) {
|
||||
commit('setCheckoutStatus', null)
|
||||
if (product.inventory > 0) {
|
||||
const cartItem = state.items.find(item => item.id === product.id)
|
||||
if (!cartItem) {
|
||||
commit('pushProductToCart', { id: product.id })
|
||||
} else {
|
||||
commit('incrementItemQuantity', cartItem)
|
||||
}
|
||||
// remove 1 item from stock
|
||||
commit('products/decrementProductInventory', { id: product.id }, { root: true })
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// mutations
|
||||
const mutations = {
|
||||
SET_SPRINKLERS (state, sprinklers) {
|
||||
console.log('sprinkler', sprinklers)
|
||||
state.sprinklers = sprinklers
|
||||
}
|
||||
/*
|
||||
pushProductToCart (state, { id }) {
|
||||
state.items.push({
|
||||
id,
|
||||
quantity: 1
|
||||
})
|
||||
},
|
||||
|
||||
incrementItemQuantity (state, { id }) {
|
||||
const cartItem = state.items.find(item => item.id === id)
|
||||
cartItem.quantity++
|
||||
},
|
||||
|
||||
setCartItems (state, { items }) {
|
||||
state.items = items
|
||||
},
|
||||
|
||||
setCheckoutStatus (state, status) {
|
||||
state.checkoutStatus = status
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state,
|
||||
getters,
|
||||
actions,
|
||||
mutations
|
||||
}
|
||||
Reference in New Issue
Block a user