Added csv dump button to observations view.

This commit is contained in:
neviyn 2018-10-30 16:47:26 +00:00
parent 770e4546e8
commit d25ec78fd9
3 changed files with 35 additions and 10 deletions

View File

@ -201,7 +201,7 @@ class Controller {
"Develop-Teamwork Leadership,Develop-Teamwork Workload,\"Develop-Knowledge, Skills and Attitudes\""
}
val data = getObservations(observationsRequest)
if(data.isEmpty()) return null
if (data.isEmpty()) return null
val builder = StringBuilder(csvHeaderString())
data.forEach {
builder.append('\n')

View File

@ -98,7 +98,7 @@ data class Observation(
val persons: Set<Person>
) {
fun toCsvFormat(): String {
return ",,${tutors.elementAt(0).name},$date,\"$observed\",\"Training\",\"Performance Improvement - Training\",\"${site.name}\",\"N/A\"," +
return ",,\"${tutors.elementAt(0).name}\",$date,\"$observed\",\"Training\",\"Performance Improvement - Training\",\"${site.name}\",\"N/A\"," +
"${roundScore(monitoring)},${roundScore(controlProcedural)},${roundScore(control)}," +
"${roundScore(conservatism)},${roundScore(teamworkCommunications)},${roundScore(teamworkLeadership)}," +
"${roundScore(teamworkWorkload)},${roundScore(knowledge)},\"${getStrengths(RatingCategory.MONITORING)}\"," +
@ -111,12 +111,12 @@ data class Observation(
"\"${getImprovements(RatingCategory.TEAMWORK_WORKLOAD)}\",\"${getImprovements(RatingCategory.KNOWLEDGE)}\""
}
private fun getStrengths(category: RatingCategory): String{
return entries.asSequence().filter { it.type == category }.map{ it.strengths }.joinToString()
private fun getStrengths(category: RatingCategory): String {
return entries.asSequence().filter { it.type == category }.map { it.strengths }.joinToString()
}
private fun getImprovements(category: RatingCategory): String{
return entries.asSequence().filter { it.type == category }.map{ it.improvements }.joinToString()
private fun getImprovements(category: RatingCategory): String {
return entries.asSequence().filter { it.type == category }.map { it.improvements }.joinToString()
}
private fun roundScore(input: Double?): String {
@ -127,7 +127,6 @@ data class Observation(
}
}
/**
* Entry giving specific details on observation performance for a tutor defined constraint.
*/

View File

@ -119,14 +119,15 @@
</b-col>
</b-row>
</b-container>
<b-button v-if="observationData != null" class="mt-2" variant="success" @click="getCSV()">CSV Dump</b-button>
</b-container>
</template>
<script>
import Vue from "vue";
import "vue-awesome/icons/search";
import Vue from "vue";
import "vue-awesome/icons/search";
var moment = require("moment");
var moment = require("moment");
export default {
name: "viewobservations",
title: "Observations History",
@ -199,6 +200,31 @@ export default {
);
});
}
},
getCSV: function() {
Vue.axios
.post("/observations/csv", {
site: this.siteSelection,
tutor: this.tutorSelection,
startDate: moment(this.startDate).format("YYYY-MM-DD"),
endDate: moment(this.endDate).format("YYYY-MM-DD"),
whom: this.whom,
person: this.person
})
.then(response => {
let blob = new Blob([response.data], {type: 'text/csv'});
let url = URL.createObjectURL(blob);
let link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'dump.csv');
document.body.appendChild(link);
link.click();
})
.catch(error => {
this.errorStatus = error.response.status;
this.errorMessage = error.response.data;
this.$refs.errorModal.show();
});
}
},
watch: {