Fixed stats graph being filled below line. Added page to show after successful observation submission.

This commit is contained in:
neviyn 2018-10-08 14:10:19 +01:00
parent ed3b748469
commit 02ed4b8b08
7 changed files with 238 additions and 205 deletions

View File

@ -53,7 +53,8 @@ data class ChartDataset(
val label: String, val label: String,
val backgroundColor: String, val backgroundColor: String,
val borderColor: String, val borderColor: String,
val data: List<Double> val data: List<Double>,
val fill: Boolean = false
){ ){
constructor(label: String, color: String, data: List<Double>): this(label, color, color, data) constructor(label: String, color: String, data: List<Double>): this(label, color, color, data)
} }

View File

@ -10,9 +10,9 @@ import org.springframework.security.config.annotation.web.configuration.EnableWe
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
import org.springframework.security.config.http.SessionCreationPolicy import org.springframework.security.config.http.SessionCreationPolicy
import org.springframework.security.core.AuthenticationException import org.springframework.security.core.AuthenticationException
import org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
import org.springframework.security.crypto.password.PasswordEncoder import org.springframework.security.crypto.password.PasswordEncoder
import org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint
import org.springframework.stereotype.Component import org.springframework.stereotype.Component
import java.io.IOException import java.io.IOException
import javax.servlet.ServletException import javax.servlet.ServletException

View File

@ -6,6 +6,8 @@
<b-collapse is-nav id="nav_collapse"> <b-collapse is-nav id="nav_collapse">
<b-navbar-nav> <b-navbar-nav>
<b-nav-item to="/">New Observation</b-nav-item> <b-nav-item to="/">New Observation</b-nav-item>
<b-nav-item to="/observations">View Observations</b-nav-item>
<b-nav-item to="/stats">Graphs</b-nav-item>
</b-navbar-nav> </b-navbar-nav>
<!-- Right aligned nav items --> <!-- Right aligned nav items -->
<b-navbar-nav class="ml-auto"> <b-navbar-nav class="ml-auto">
@ -31,12 +33,4 @@
text-align: center; text-align: center;
color: #2c3e50; color: #2c3e50;
} }
#nav {
padding: 10px;
}
#nav a.router-link-exact-active {
color: #42b983;
}
</style> </style>

View File

@ -6,6 +6,7 @@ import Stats from "./views/Stats.vue";
import NewSite from "./views/NewSite.vue"; import NewSite from "./views/NewSite.vue";
import NewTutor from "./views/NewTutor.vue"; import NewTutor from "./views/NewTutor.vue";
import ViewObservations from "./views/ViewObservations.vue"; import ViewObservations from "./views/ViewObservations.vue";
import ObservationComplete from "./views/ObservationComplete.vue";
Vue.use(Router); Vue.use(Router);
@ -40,6 +41,11 @@ export default new Router({
path: "/observations", path: "/observations",
name: "observations", name: "observations",
component: ViewObservations component: ViewObservations
},
{
path: "/complete",
name: "complete",
component: ObservationComplete
} }
] ]
}); });

View File

@ -91,14 +91,14 @@
</b-row> </b-row>
</b-form> </b-form>
<b-modal id="submissionModal" <b-modal id="submissionModal"
ref="modal" ref="submissionModal"
title="Enter password to confirm submission" title="Enter password to confirm submission"
@ok="handleOk" @ok="handleOk"
@shown="clearPassword"> @shown="clearPassword">
<form @submit.stop.prevent="handleSubmit"> <form @submit.stop.prevent="handleSubmit">
<b-form-input type="password" <b-form-input type="password"
placeholder="Enter password" placeholder="Enter password"
v-model="name"></b-form-input> v-model="submitPassword"></b-form-input>
</form> </form>
</b-modal> </b-modal>
</b-container> </b-container>
@ -209,23 +209,26 @@
showModal() { showModal() {
this.$refs.submissionModal.show(); this.$refs.submissionModal.show();
}, },
hideModal() {
this.$refs.submissionModal.hide();
this.submitPassword = null;
},
clearPassword() { clearPassword() {
this.submitPassword = null this.submitPassword = null
}, },
handleOk(evt) { handleOk(evt) {
// Prevent modal from closing // Prevent modal from closing
evt.preventDefault(); evt.preventDefault();
if (this.password) { if (this.submitPassword !== null) {
this.handleSubmit() this.handleSubmit()
} }
}, },
handleSubmit() { handleSubmit() {
var form = document.getElementById("submission-form"); var form = document.getElementById("submission-form");
if (form.checkValidity()) { if (form.checkValidity()) {
let axiosConfig = {
auth: {
username: "admin",
password: this.submitPassword
}
};
var self = this;
Vue.axios Vue.axios
.post("/observation", { .post("/observation", {
site: this.site, site: this.site,
@ -234,9 +237,9 @@
whom: this.whom, whom: this.whom,
type: this.type, type: this.type,
entries: JSON.parse(JSON.stringify(this.observations)) entries: JSON.parse(JSON.stringify(this.observations))
}) }, axiosConfig)
.then(function (response) { .then(function (response) {
this.hideModal(); self.$router.push("/complete");
console.log(response); console.log(response);
}) })
.catch(function (error) { .catch(function (error) {

View File

@ -0,0 +1,23 @@
<template>
<b-container>
<h2>Submission Complete</h2>
<p>{{ type }}/{{ description }} has been submitted successfully.</p>
<b-button size="lg" variant="primary" to="/">
Start New Observation
</b-button>
</b-container>
</template>
<script>
import {mapState} from "vuex";
export default {
name: "ObservationComplete",
computed: {
...mapState(["description", "type", "whom", "site", "tutors"])
}
}
</script>
<style scoped>
</style>

View File

@ -5,21 +5,23 @@
<h3 class="modal-title w-100">{{ errorStatus }}</h3> <h3 class="modal-title w-100">{{ errorStatus }}</h3>
</div> </div>
<div class="d-block"> <div class="d-block">
<br /> <br/>
<span style="font-size:20px;" v-html="errorMessage" /> <span style="font-size:20px;" v-html="errorMessage"/>
<button class="btn btn-warning" @click="$refs.errorModal.hide()"> <button class="btn btn-warning" @click="$refs.errorModal.hide()">
<v-icon name="exclamation-circle" /> Dismiss</button> <v-icon name="exclamation-circle"/>
Dismiss
</button>
</div> </div>
</b-modal> </b-modal>
<b-row> <b-row>
<b-col> <b-col>
<b-form-group label="Site"> <b-form-group label="Site">
<b-form-select class="text-center" v-model="siteSelection" :options="siteOptions" /> <b-form-select class="text-center" v-model="siteSelection" :options="siteOptions"/>
</b-form-group> </b-form-group>
</b-col> </b-col>
<b-col> <b-col>
<b-form-group label="Tutor"> <b-form-group label="Tutor">
<b-form-select class="text-center" v-model="tutorSelection" :options="tutorOptions" /> <b-form-select class="text-center" v-model="tutorSelection" :options="tutorOptions"/>
</b-form-group> </b-form-group>
</b-col> </b-col>
<b-col> <b-col>
@ -29,12 +31,13 @@
</b-col> </b-col>
<b-col> <b-col>
<b-form-group label="From"> <b-form-group label="From">
<date-picker v-model="startDate" @dp-change="changeStartDate" value="startDate" :config="dateOptions" /> <date-picker v-model="startDate" @dp-change="changeStartDate" value="startDate"
:config="dateOptions"/>
</b-form-group> </b-form-group>
</b-col> </b-col>
<b-col> <b-col>
<b-form-group label="To"> <b-form-group label="To">
<date-picker v-model="endDate" @dp-change="changeEndDate" value="endDate" :config="dateOptions" /> <date-picker v-model="endDate" @dp-change="changeEndDate" value="endDate" :config="dateOptions"/>
</b-form-group> </b-form-group>
</b-col> </b-col>
<b-col> <b-col>
@ -43,24 +46,27 @@
</b-row> </b-row>
<b-row> <b-row>
<b-col> <b-col>
<stats-view v-if="chartData != null && chartData != {}" v-bind:chartData="chartData" :options="options" /> <stats-view v-if="chartData != null && chartData !== {}" v-bind:chartData="chartData"
style="position: relative; height:80vh" :options="options"/>
</b-col> </b-col>
</b-row> </b-row>
</b-container> </b-container>
</template> </template>
<script> <script>
import Vue from "vue"; import Vue from "vue";
import StatsView from "../components/StatsView"; import StatsView from "../components/StatsView";
var moment = require("moment");
export default { var moment = require("moment");
export default {
name: "stats", name: "stats",
components: { StatsView }, components: {StatsView},
data: function() { data: function () {
return { return {
chartData: null, chartData: null,
options: { options: {
responsive: true, responsive: true,
maintainAspectRatio: false,
tooltips: { tooltips: {
mode: "index", mode: "index",
intersect: false intersect: false
@ -101,12 +107,12 @@ export default {
siteSelection: null, siteSelection: null,
siteOptions: [], siteOptions: [],
tutorSelection: null, tutorSelection: null,
tutorOptions: null, tutorOptions: [],
whom: null whom: null
}; };
}, },
methods: { methods: {
getFilteredAverage: function() { getFilteredAverage: function () {
Vue.axios Vue.axios
.post("/observations/chartdata", { .post("/observations/chartdata", {
'site': this.siteSelection, 'site': this.siteSelection,
@ -124,7 +130,7 @@ export default {
this.$refs.errorModal.show(); this.$refs.errorModal.show();
}); });
}, },
getTutors: function() { getTutors: function () {
if (this.siteSelection != null) { if (this.siteSelection != null) {
Vue.axios Vue.axios
.get("/site/" + this.siteSelection + "/tutors") .get("/site/" + this.siteSelection + "/tutors")
@ -133,15 +139,15 @@ export default {
}); });
} }
}, },
changeStartDate: function(e) { changeStartDate: function (e) {
this.startDate = e.date; this.startDate = e.date;
}, },
changeEndDate: function(e) { changeEndDate: function (e) {
this.endDate = e.date; this.endDate = e.date;
} }
}, },
watch: { watch: {
siteSelection: function() { siteSelection: function () {
this.tutorOptions = []; this.tutorOptions = [];
this.tutorSelection = null; this.tutorSelection = null;
this.getTutors(); this.getTutors();
@ -160,5 +166,5 @@ export default {
this.$refs.errorModal.show(); this.$refs.errorModal.show();
}); });
} }
}; };
</script> </script>