dashboard3 wip

This commit is contained in:
2018-06-24 23:05:23 +02:00
parent 35cf081200
commit abb471c1a2
8 changed files with 228 additions and 16 deletions

View File

@@ -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) */

View File

@@ -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/

View 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'
}
}
}
}
}

View File

@@ -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>

View File

@@ -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

View 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
}