Skip to content

Commit

Permalink
Adds dynamic command list & vuex support
Browse files Browse the repository at this point in the history
  • Loading branch information
AchillesKal committed Jan 21, 2017
1 parent e505192 commit db36e48
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 35 deletions.
1 change: 1 addition & 0 deletions front-end/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<meta charset="utf-8">
<title>front-end</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
</head>
<body>
<div id="app"></div>
Expand Down
42 changes: 37 additions & 5 deletions front-end/src/components/CommandList.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,46 @@
<template>
<div class="commands">
<h2 class="text-center">Commands</h2>
<ul>
<li v-for="(command, index) in commands" class="">
<a href="#" :title="command.help"> {{ command.command }} </a>
</li>
</ul>
</div>
</template>

<script>
export default {
import store from '../store'
export default {
created () {
this.getCommands()
},
data () {
return {
commands: {},
}
},
methods: {
getCommands() {
this.$http.get('http://127.0.0.1:5000/rspet/api/v1.1/help?state=' + this.hostState)
.then((response) => {
this.commands = response.body.commands
})
.catch((response) => {
console.log(response);
});
}
},
computed: {
hostState () {
return store.state.hostState;
}
},
watch: {
hostState: function() {
this.getCommands()
}
}
}
</script>

<style>
</style>
55 changes: 35 additions & 20 deletions front-end/src/components/HostsList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,51 @@
<div class="hosts">
<h2 class='text-center'>Hosts</h2>
<ul>
<li v-for="host in hosts">
<label><input type="checkbox" /> {{ host.hostname }} - {{ host.ip }} - {{ host.port }}</label>
<li v-for="(host, index) in hosts">
<label><input type="checkbox" name="host" :value="host.id" v-model="selectedHosts" /> {{ host.hostname }} - {{ host.ip }} - {{ host.port }}</label>
</li>
</ul>
</div>
</template>

<script>
export default {
created () {
this.getHosts()
},
data () {
return {
hosts: {}
import store from '../store'
export default {
created () {
this.getHosts()
},
data () {
return {
hosts: {},
selectedHosts: []
}
},
methods: {
getHosts() {
this.$http.get('http://localhost:5000/rspet/api/v1.0/hosts')
.then((response) => {
this.hosts = response.body.hosts;
})
.catch((response) => {
console.log(response);
});
}
},
watch: {
selectedHosts: function(hosts) {
if (hosts.length === 0) {
store.commit('setHostState', "basic");
}
},
methods: {
getHosts () {
this.$http.get('http://localhost:5000/rspet/api/v1.0/hosts')
.then((response) => {
this.hosts = response.body.hosts
console.log(this.hosts)
})
.catch((response) => {
console.log(response);
});
else if (hosts.length === 1) {
store.commit('setHostState', "connected");
} else {
store.commit('setHostState', "multiple");
}
store.commit('setCurrentHosts', hosts);
}
}
}
</script>

<style>
Expand Down
1 change: 0 additions & 1 deletion front-end/src/components/SingleHost.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
this.$http.get('http://localhost:5000/rspet/api/v1.0/hosts')
.then((response) => {
this.hosts = response.body.hosts
console.log(this.hosts)
})
.catch((response) => {
console.log(response);
Expand Down
9 changes: 0 additions & 9 deletions front-end/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,6 @@ import VueResource from 'vue-resource';

Vue.use(VueResource);
Vue.use(Vuex);
// Vue.use(VueRouter);

// const routes = [
// { path: '/', component: HostsList }
// ];
//
// const router = new VueRouter({
// routes // short for routes: routes
// });

new Vue({
el: '#app',
Expand Down
21 changes: 21 additions & 0 deletions front-end/src/store.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Vuex from 'vuex'
import Vue from 'vue'

Vue.use(Vuex)

var store = new Vuex.Store({
state: {
currentHosts: '',
hostState: 'basic'
},
mutations: {
setCurrentHosts (state, hosts) {
state.currentHosts = hosts
},
setHostState (state, hostState) {
state.hostState = hostState
}
}
})

export default store

0 comments on commit db36e48

Please sign in to comment.