-
Bhabesh Bhabani Mukhopadhyay authored
Selected Observation routed to related components and observation id passed as parameter and accepted to Observation component as props
Bhabesh Bhabani Mukhopadhyay authoredSelected Observation routed to related components and observation id passed as parameter and accepted to Observation component as props
ObservationList.vue 2.55 KiB
import { DateTime } from "luxon";
<template>
<div>
<div class="hello" >
<h1>{{ $t("startpage") }}</h1>
<router-link to="/observation" custom v-slot="{ navigate }">
<button type="button" class="btn btn-primary" @click="navigate">+</button>
</router-link>
</div>
<div v-if="observations">
<ul class="list-group">
<router-link :to="{name: 'Observation', params: {observationId:obs.observationId}}" class="list-group-item list-group-item-action " v-for="obs in observations" v-bind:key="obs.observationId">
{{ obs.timeOfObservation | dateFormat }} <b>{{obs.observationHeading}}</b>
</router-link >
</ul>
</div>
<div v-else class="alert alert-warning" role="alert">
<p class="text-danger">You don't have any observations.</p>
</div>
</div>
</template>
<script>
import CommonUtil from '@/components/CommonUtil'
import { DateTime } from 'luxon'
export default {
name: "ObservationList",
data() {
return {
/*msg: 'Startsiden'*/
observations : undefined,
};
},
methods : {
/** TODO
* This function need to be shifted for two way sync process
*/
fetchFromServer()
{
let strUUID = localStorage.getItem(CommonUtil.CONST_STORAGE_UUID);
let jsonHeader = { Authorization: strUUID };
fetch(CommonUtil.CONST_URL_DOMAIN + CommonUtil.CONST_URL_USER_OBSERVATION_LIST, {
method: "GET",
headers: jsonHeader,
}).then((response) => response.json())
.then((data) => {
localStorage.setItem(CommonUtil.CONST_STORAGE_OBSERVATION_LIST,JSON.stringify(data));
})
},
getObservationsFromStore()
{
let strObservations = localStorage.getItem(CommonUtil.CONST_STORAGE_OBSERVATION_LIST);
let lstObservations = JSON.parse(strObservations);
this.observations = lstObservations;
},
},
filters: {
dateFormat: function(timeStr) {
//return DateTime.fromISO(timeStr).toISODate();
return DateTime.fromISO(timeStr).toLocaleString(DateTime.DATETIME_MED);
}
},
mounted() {
this.fetchFromServer(); // TODO - Tobe shifted to two way Sync process
this.getObservationsFromStore();
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1,
h2 {
font-weight: normal;
}
ul {
list-style-type: none;
padding: 0;
}
li {
display: inline-block;
margin: 0 10px;
}
a {
color: #42b983;
}
</style>