Linked Site and Tutor retrieval to front end.

This commit is contained in:
neviyn 2018-09-17 12:00:28 +01:00
parent cca23fa995
commit 95ad37c164
6 changed files with 128 additions and 15 deletions

View File

@ -12,6 +12,7 @@ import uk.co.neviyn.Observations.dao.SiteDao;
import uk.co.neviyn.Observations.dao.TutorDao;
import uk.co.neviyn.Observations.resources.ObservationResource;
import uk.co.neviyn.Observations.resources.TutorResource;
import uk.co.neviyn.Observations.resources.SiteResource;
public class ObservationsApplication extends Application<ObservationsConfiguration> {
@ -44,5 +45,7 @@ public class ObservationsApplication extends Application<ObservationsConfigurati
jersey.register(tutorResource);
final ObservationResource observationResource = new ObservationResource(observationDao);
jersey.register(observationResource);
final SiteResource siteResource = new SiteResource(siteDao);
jersey.register(siteResource);
}
}

View File

@ -0,0 +1,29 @@
package uk.co.neviyn.Observations.resources;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import uk.co.neviyn.Observations.api.SelectOption;
import uk.co.neviyn.Observations.dao.SiteDao;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.util.List;
import java.util.stream.Collectors;
@RequiredArgsConstructor
@Produces(MediaType.APPLICATION_JSON)
@Path("/site")
@Slf4j
public class SiteResource {
private final SiteDao dao;
@Path("/all")
@GET
public List<SelectOption<Integer>> allSites(){
return dao.allSites().stream().map(x -> new SelectOption<>(x.getName(), x.getId())).collect(Collectors.toList());
}
}

View File

@ -1979,6 +1979,15 @@
"integrity": "sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ==",
"dev": true
},
"axios": {
"version": "0.18.0",
"resolved": "http://registry.npmjs.org/axios/-/axios-0.18.0.tgz",
"integrity": "sha1-MtU+SFHv3AoRmTts0AB4nXDAUQI=",
"requires": {
"follow-redirects": "^1.3.0",
"is-buffer": "^1.1.5"
}
},
"babel-code-frame": {
"version": "6.26.0",
"resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.26.0.tgz",
@ -5751,7 +5760,6 @@
"version": "1.5.8",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.8.tgz",
"integrity": "sha512-sy1mXPmv7kLAMKW/8XofG7o9T+6gAjzdZK4AJF6ryqQYUa/hnzgiypoeUecZ53x7XiqKNEpNqLtS97MshW2nxg==",
"dev": true,
"requires": {
"debug": "=3.1.0"
},
@ -5760,7 +5768,6 @@
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
"dev": true,
"requires": {
"ms": "2.0.0"
}
@ -5768,11 +5775,15 @@
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=",
"dev": true
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
}
}
},
"font-awesome": {
"version": "4.7.0",
"resolved": "https://registry.npmjs.org/font-awesome/-/font-awesome-4.7.0.tgz",
"integrity": "sha1-j6jPBBGhoxr9B7BtKQK7n8gVoTM="
},
"for-in": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz",
@ -7530,8 +7541,7 @@
"is-buffer": {
"version": "1.1.6",
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz",
"integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==",
"dev": true
"integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w=="
},
"is-builtin-module": {
"version": "1.0.0",
@ -14362,6 +14372,11 @@
"resolved": "https://registry.npmjs.org/vue/-/vue-2.5.17.tgz",
"integrity": "sha512-mFbcWoDIJi0w0Za4emyLiW72Jae0yjANHbCVquMKijcavBGypqlF7zHRgMa5k4sesdv7hv2rB4JPdZfR+TPfhQ=="
},
"vue-awesome": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/vue-awesome/-/vue-awesome-3.1.2.tgz",
"integrity": "sha512-5Ax5GvbCQDz0zx4PvqJ8b8MEMRQ1IGYtOVQ6u2NBGcWjFnxq0tprCk/YtGAGlYGKwx+OQSoYKb0qZHc4qVfAIg=="
},
"vue-axios": {
"version": "2.1.3",
"resolved": "https://registry.npmjs.org/vue-axios/-/vue-axios-2.1.3.tgz",

View File

@ -9,8 +9,11 @@
"test:unit": "vue-cli-service test:unit"
},
"dependencies": {
"axios": "^0.18.0",
"bootstrap-vue": "^2.0.0-rc.11",
"font-awesome": "^4.7.0",
"vue": "^2.5.17",
"vue-awesome": "^3.1.2",
"vue-axios": "^2.1.3",
"vue-router": "^3.0.1",
"vuex": "^3.0.1"

View File

@ -2,8 +2,16 @@ import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import axios from 'axios';
import VueAxios from 'vue-axios';
import BootstrapVue from 'bootstrap-vue';
import Icon from 'vue-awesome/components/Icon';
Vue.config.productionTip = false;
axios.defaults.baseUrl = "http://localhost:8090/api";
Vue.use(VueAxios, axios);
Vue.use(BootstrapVue);
Vue.component('v-icon', Icon);
new Vue({
router,

View File

@ -1,18 +1,73 @@
<template>
<div class="home">
<img alt="Vue logo" src="../assets/logo.png">
<HelloWorld msg="Welcome to Your Vue.js App"/>
</div>
<b-container class="home">
<h1>Training Observations</h1>
<b-row>
<b-form-group label="Site">
<b-form-select v-model="site" :options="siteOptions"></b-form-select>
</b-form-group>
</b-row>
<b-row>
<b-form-group label="Description">
<b-form-input v-model="description" type="text"></b-form-input>
</b-form-group>
</b-row>
<b-row>
<b-form-group label="Type">
<b-form-select v-model="type">
<option :value=null>Select a training type</option>
<option value="INITIAL">INITIAL</option>
<option value="CONTINUING">CONTINUING</option>
</b-form-select>
</b-form-group>
</b-row>
<b-row>
<b-form-group label="Tutor(s)">
<p v-if="site == null">Select a site first.</p>
<v-icon name="spinner" spin v-if="loadingTutors"/>
<b-form-checkbox-group v-model="tutors" :options="tutorOptions"></b-form-checkbox-group>
</b-form-group>
</b-row>
</b-container>
</template>
<script>
// @ is an alias to /src
import HelloWorld from "@/components/HelloWorld.vue";
import Vue from 'vue'
import 'vue-awesome/icons/spinner';
export default {
name: "home",
components: {
HelloWorld
data () {
return {
site: null,
description: null,
type: null,
tutors: [],
siteOptions: [],
tutorOptions: [],
loadingTutors: false
}
},
mounted () {
Vue.axios.get("/api/site/all").then((response) => {
this.siteOptions = response.data;
})
},
watch: {
site: function () {
this.loadingTutors = true;
this.tutorOptions = [];
this.tutors = [];
this.getTutors();
}
},
methods: {
getTutors: function () {
if(this.site != null){
Vue.axios.get("/api/tutor/site/" + this.site).then((response) => {
this.tutorOptions = response.data;
this.loadingTutors = false;
})
}
}
}
};
</script>