Skip to content
Snippets Groups Projects
Commit 222687c9 authored by Bhabesh Bhabani Mukhopadhyay's avatar Bhabesh Bhabani Mukhopadhyay
Browse files

Sync for new Locally created observation

parent 86699105
No related branches found
No related tags found
No related merge requests found
...@@ -6,6 +6,8 @@ export default { ...@@ -6,6 +6,8 @@ export default {
CONST_EVENT_LOGIN_USER_DETAIL : 'eventloginuserdetail', CONST_EVENT_LOGIN_USER_DETAIL : 'eventloginuserdetail',
CONST_STATUS_PENDING : 1,
CONST_STORAGE_UUID : 'user-uuid', CONST_STORAGE_UUID : 'user-uuid',
CONST_STORAGE_USER_DETAIL : 'store-user-detail', CONST_STORAGE_USER_DETAIL : 'store-user-detail',
CONST_STORE_TIMESTAMP : 'store-time-stamp', CONST_STORE_TIMESTAMP : 'store-time-stamp',
......
...@@ -194,7 +194,11 @@ export default { ...@@ -194,7 +194,11 @@ export default {
jsonObservation = lstObservations.find(({observationId})=> observationId === id); // Selection Observation jsonObservation = lstObservations.find(({observationId})=> observationId === id); // Selection Observation
this.observation = jsonObservation; this.observation = jsonObservation;
this.observation.observationData = JSON.parse(jsonObservation.observationData); this.observation.observationData = JSON.parse(jsonObservation.observationData);
if(jsonObservation.statusTypeId) {}
else
{
this.observation.statusTypeId = CommonUtil.CONST_STATUS_PENDING;
}
/* For related Crop and Crop list */ /* For related Crop and Crop list */
this.getObservationCrops(jsonObservation); this.getObservationCrops(jsonObservation);
...@@ -438,7 +442,12 @@ export default { ...@@ -438,7 +442,12 @@ export default {
return false return false
} }
let This = this; let This = this;
let lstObservations = JSON.parse(localStorage.getItem(CommonUtil.CONST_STORAGE_OBSERVATION_LIST)); let lstObservations = JSON.parse(localStorage.getItem(CommonUtil.CONST_STORAGE_OBSERVATION_LIST));
/** Whether record to be updated */
let isRecordAvailable = lstObservations.find(({observationId})=> observationId === this.observationId);
this.observationForStore.cropOrganismId = this.crop.cropId; this.observationForStore.cropOrganismId = this.crop.cropId;
this.observationForStore.organismId = this.pest.pestId; this.observationForStore.organismId = this.pest.pestId;
...@@ -457,7 +466,7 @@ export default { ...@@ -457,7 +466,7 @@ export default {
this.observationForStore.observationIllustrationSet = this.observation.observationIllustrationSet; this.observationForStore.observationIllustrationSet = this.observation.observationIllustrationSet;
if(this.observationId) if(this.observationId && isRecordAvailable)
{ {
this.observationForStore.observationId = this.observationId; this.observationForStore.observationId = this.observationId;
let localObservationForStore = this.observationForStore; let localObservationForStore = this.observationForStore;
...@@ -499,6 +508,7 @@ export default { ...@@ -499,6 +508,7 @@ export default {
lstObservations = []; lstObservations = [];
} }
this.observationForStore.statusTypeId=CommonUtil.CONST_STATUS_PENDING;
lstObservations.push(this.observationForStore); lstObservations.push(this.observationForStore);
} }
localStorage.setItem(CommonUtil.CONST_STORAGE_OBSERVATION_LIST, JSON.stringify(lstObservations) ); localStorage.setItem(CommonUtil.CONST_STORAGE_OBSERVATION_LIST, JSON.stringify(lstObservations) );
......
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
</div> </div>
<div v-if="observations"> <div v-if="observations">
<ul class="list-group"> <ul class="list-group" v-if="isInitialized">
<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"> <router-link :to="{name: 'Observation', params: {observationId:obs.observationId}}" class="list-group-item list-group-item-action " v-bind:class="{'text-danger':obs.isNew, 'text-primary':obs.toUpload}" v-for="obs in observations" v-bind:key="obs.observationId">
{{ obs.timeOfObservation | dateFormat }} <b>{{obs.observationHeading}}</b> {{ obs.timeOfObservation | dateFormat }} <b>{{obs.observationHeading}}</b>
</router-link > </router-link >
...@@ -35,6 +35,7 @@ export default { ...@@ -35,6 +35,7 @@ export default {
data() { data() {
return { return {
/*msg: 'Startsiden'*/ /*msg: 'Startsiden'*/
isInitialized : false,
CONST_URL_DOMAIN : '', CONST_URL_DOMAIN : '',
observations : undefined, observations : undefined,
}; };
...@@ -43,8 +44,22 @@ export default { ...@@ -43,8 +44,22 @@ export default {
methods : { methods : {
getObservationsFromStore() getObservationsFromStore()
{ {
this.isInitialized = true;
let strObservations = localStorage.getItem(CommonUtil.CONST_STORAGE_OBSERVATION_LIST); let strObservations = localStorage.getItem(CommonUtil.CONST_STORAGE_OBSERVATION_LIST);
let lstObservations = JSON.parse(strObservations); let lstObservations = JSON.parse(strObservations);
lstObservations.forEach(function(observation){
if(observation.uploaded==false)
{
if(observation.observationId < 0)
{
observation.isNew = true;
}
else{
observation.toUpload = true;
}
}
});
this.observations = lstObservations; this.observations = lstObservations;
}, },
...@@ -57,6 +72,7 @@ export default { ...@@ -57,6 +72,7 @@ export default {
} }
}, },
mounted() { mounted() {
let valueObj = {"name":CommonUtil.CONST_STORAGE_OBSERVATION_LIST,"complete":false}; let valueObj = {"name":CommonUtil.CONST_STORAGE_OBSERVATION_LIST,"complete":false};
//this.$refs.Sync.syncObservationSendPrepare(valueObj); //this.$refs.Sync.syncObservationSendPrepare(valueObj);
this.CONST_URL_DOMAIN = this.$refs.CommonUtil.getDomain(); this.CONST_URL_DOMAIN = this.$refs.CommonUtil.getDomain();
......
...@@ -453,6 +453,7 @@ export default { ...@@ -453,6 +453,7 @@ export default {
let userUUID = localStorage.getItem(CommonUtil.CONST_STORAGE_UUID); let userUUID = localStorage.getItem(CommonUtil.CONST_STORAGE_UUID);
let jsonBody = JSON.stringify(observation); let jsonBody = JSON.stringify(observation);
fetch( fetch(
CommonUtil.CONST_URL_DOMAIN + CommonUtil.CONST_URL_SYNC_UPDATE_OBSERVATION, CommonUtil.CONST_URL_DOMAIN + CommonUtil.CONST_URL_SYNC_UPDATE_OBSERVATION,
{ {
...@@ -476,7 +477,29 @@ export default { ...@@ -476,7 +477,29 @@ export default {
}) })
.then((data)=>{ .then((data)=>{
let updatedObservation = JSON.parse(data); let updatedObservation = JSON.parse(data);
if(observation.observationId < 0)
{
let indexPosition = null;
let lstObservations = JSON.parse(localStorage.getItem(CommonUtil.CONST_STORAGE_OBSERVATION_LIST));
$.each(lstObservations, function(index, jsonObservation){
if(observation.observationId == jsonObservation.observationId)
{
indexPosition = index;
return false;
}
})
if(indexPosition)
{
/** Remove the Observation with nagative number (localy created ) */
lstObservations.splice(indexPosition,1);
localStorage.setItem(CommonUtil.CONST_STORAGE_OBSERVATION_LIST,JSON.stringify(lstObservations));
this.getObservationsFromServerTwowaySync(1,updatedObservation)
}
}
if(updatedObservation.observationId === observation.observationId) if(updatedObservation.observationId === observation.observationId)
{ {
this.updateObservationPOST(updatedObservation,totalTwoWaySyncPOST); this.updateObservationPOST(updatedObservation,totalTwoWaySyncPOST);
...@@ -551,7 +574,6 @@ export default { ...@@ -551,7 +574,6 @@ export default {
/** GET Observations */ /** GET Observations */
getObservationsFromServerTwowaySync(totalTwoWaySyncPOST,updatedObservation) getObservationsFromServerTwowaySync(totalTwoWaySyncPOST,updatedObservation)
{ {
console.log('-- inside GET ');
let This = this; let This = this;
let strUUID = localStorage.getItem(CommonUtil.CONST_STORAGE_UUID); let strUUID = localStorage.getItem(CommonUtil.CONST_STORAGE_UUID);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment