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

#VOAPP-57 : Sync feature for POI

parent 324bcca4
No related branches found
No related tags found
No related merge requests found
......@@ -47,6 +47,8 @@ export default {
CONST_URL_SYNC_UPDATE_OBSERVATIONS : '/rest/observation/syncobservationlistfromapp',
CONST_URL_SYNC_UPDATE_OBSERVATION : '/rest/observation/syncobservationfromapp',
CONST_URL_SYNC_UPDATE_POI : '/rest/poi/syncpoifromapp',
CONST_URL_USER_OBSERVATION_LIST : '/rest/observation/list/user',
CONST_URL_USER_POI : '/rest/poi/user',
......
......@@ -8,19 +8,23 @@
<div ><input id='poiName' ref='poiName' v-model="poi.name"/></div>
<div class="clearfix"/>
<div class='row'>
<div class='col-10'>
<div class='col-7'>
<select v-model="poi.pointOfInterestTypeId">
<option v-for="poiType in poiTypes" v-bind:key="poiType.point_of_interest_type_id" :value='poiType.point_of_interest_type_id'>{{poiType.default_name}}</option>
</select>
</div>
<div class="col-1">
<div class="col-2">
<button class="btn btn-success" @click="validate">Save</button>
</div>
<div class="col-3">
<button v-show="isDeleteBttnVisible" class="btn btn-danger " v-on:click="callForRemovePOI"> Delete </button>
</div>
</div>
</div>
<div id="poiMarker" style="display:none">
<img src="@/assets/map_icon.png">
</div>
<!-- For Saving -->
<Modal
v-show="isModalVisible"
v-on:close="closeModal"
......@@ -38,6 +42,25 @@
Please chose the option below :
</template>
</Modal>
<!-- For Delete -->
<Modal
v-show="isModalDelVisible"
v-on:close="closeDelModal"
v-on:action="actionDelModal"
>
<template v-slot:header>
!! ALERT !!
</template>
<template v-slot:body>
<font color='red'><b> DELETE </b> information for : {{poi.name}} ?</font>
</template>
<template v-slot:footer>
Please chose the option below :
</template>
</Modal>
<modal-simple
......@@ -101,6 +124,8 @@ export default{
data() {
return {
isDeleteBttnVisible : true,
isModalDelVisible : false,
isModalVisible : false,
isModalSimpleVisible : false,
poi : {},
......@@ -113,6 +138,53 @@ export default{
}
},
methods : {
callForRemovePOI()
{
this.isModalDelVisible = true;
},
closeDelModal(){
this.isModalDelVisible = false;
},
actionDelModal()
{
if(this.poi.pointOfInterestId)
{
if(this.poi.pointOfInterestId < 0)
{
/** Just remove it locally */
this.removeLocalPOI(this.poi.pointOfInterestId);
this.$router.replace({path:'/places'});
}
else
{
/** Mark the record - for sending to server */
this.poi.deleted=true;
this.saveToStore();
}
}
this.isModalDelVisible = false;
},
removeLocalPOI(id)
{
let lstPOI = JSON.parse(localStorage.getItem(CommonUtil.CONST_STORAGE_POI_LIST));
let indexPosition = null;
$.each(lstPOI, function(index, poi){
if(poi.pointOfInterestId===id)
{
indexPosition = index;
return false;
}
});
if(indexPosition)
{
lstPOI.splice(indexPosition,1);
localStorage.setItem(CommonUtil.CONST_STORAGE_POI_LIST,JSON.stringify(lstPOI));
}
},
validate()
{
if((!this.poi.name) || (this.trimString(this.poi.name) === ''))
......
......@@ -2,9 +2,14 @@
<div class="hello">
<h1>{{ msg }}</h1>
<div class="container">
<router-link class="row fw-bold" ref='linkMapPoi' :to="{name:'MapPOI', params: {pointOfInterestId:poi.pointOfInterestId}}" v-for="poi in listPOI" v-bind:key="poi.pointOfInterestId">
<div class='col-10 '><h5>{{poi.name}}</h5></div>
<div class='col'><i class="fas fa-plus-circle fa-2x"></i></div>
<router-link class="row fw-bold" ref='linkMapPoi' :to="{name:'MapPOI', params: {pointOfInterestId:poi.pointOfInterestId}}" v-bind:class="{'text-danger':poi.isNew, 'text-primary':poi.toUpload, 'text-secondary':poi.isDeleted}" v-for="poi in listPOI" v-bind:key="poi.pointOfInterestId">
<div v-if="poi.isDeleted">
<strike> <div ><h5>{{poi.name}}</h5></div> </strike>
</div>
<div v-else>
<div ><h5>{{poi.name}}</h5></div>
</div>
</router-link>
<div class="clearfix" />
</div>
......@@ -56,7 +61,26 @@ export default {
getPlacesList()
{
let lstPOI = JSON.parse(localStorage.getItem(CommonUtil.CONST_STORAGE_POI_LIST));
lstPOI.forEach(function(poi){
if(poi.uploaded===false)
{
if(poi.deleted)
{
poi.isDeleted = true;
}
else{
if(poi.pointOfInterestId < 0)
{
poi.isNew = true;
}
else{
poi.toUpload = true;
}
}
}
});
return lstPOI;
}
......
......@@ -34,6 +34,7 @@ export default {
],
arrSyncTwoWay : [
{"name":CommonUtil.CONST_STORAGE_OBSERVATION_LIST,"complete":false} ,
{"name":CommonUtil.CONST_STORAGE_POI_LIST,"complete":false} ,
],
appUser : {},
......@@ -172,8 +173,11 @@ export default {
switch(value.name) {
case CommonUtil.CONST_STORAGE_OBSERVATION_LIST :
strUrl = This.CONST_URL_DOMAIN +CommonUtil.CONST_URL_USER_OBSERVATION_LIST;
break;
case CommonUtil.CONST_STORAGE_POI_LIST :
strUrl = This.CONST_URL_DOMAIN +CommonUtil.CONST_URL_USER_POI;
break;
default :
}
......@@ -330,18 +334,255 @@ export default {
switch(value.name)
{
case CommonUtil.CONST_STORAGE_OBSERVATION_LIST :
this.syncTwoWayObservation(value,strUrl);
break;
case CommonUtil.CONST_STORAGE_POI_LIST :
//this.syncTwoWayPOI(value,strUrl);
break;
default:
}
},
/** Two way Sync POI */
syncTwoWayPOI(value,strUrl)
{
this.syncPOISendPrepare(value);
},
syncPOISendPrepare(value)
{
let This = this;
let lstPOI = JSON.parse(localStorage.getItem(value.name));
if(lstPOI)
{
let lstPOIUpload = lstPOI.filter(poi => poi.uploaded === false);
this.totalTwoWaySyncPOST = lstPOIUpload.length;
if(lstPOIUpload && lstPOIUpload.length != 0)
{
lstPOIUpload.forEach(function(poi){
this.syncPOIPOST(poi,this.totalTwoWaySyncPOST);
})
}
else{
/** Create the list using GET */
let totalTwoWaySyncPOST = 0;
let updatedObservation = {};
this.getPOIFromServerTwowaySync(totalTwoWaySyncPOST,updatedPOI);
}
}
else{
/** Create the list using GET */
this.getPOIFromServerTwowaySync(0,undefined);
}
},
syncPOIPOST(poi,totalTwoWaySyncPOST)
{
let This = this;
let userUUID = localStorage.getItem(CommonUtil.CONST_STORAGE_UUID);
let jsonBody = null;
if(poi.deleted)
{
/** prepare POI object for server Delete Operation */
let delPOI = {};
delPOI.pointOfInterestId = poi.pointOfInterestId;
delPOI.deleted = poi.deleted;
jsonBody = JSON.stringify(delPOI);
}
else
{
jsonBody = JSON.stringify(poi);
}
fetch(
CommonUtil.CONST_URL_DOMAIN + CommonUtil.CONST_URL_SYNC_UPDATE_POI,
{
method: "POST",
headers: {
"Content-Type": "application/json",
'Authorization' : userUUID
},
body : jsonBody
})
.then(function(response){
if(response.status === 200) {
}
else{
/** Even if the response is not success, still need to increase the counter,
* to decide for next action after all PUSH */
This.counterTwoWaySyncPOST = This.counterTwoWaySyncPOST + 1;
}
return response.text()
})
.then((data) => {
if(data) {
let updatedPOI = JSON.parse(data);
if(poi.pointOfInterestId < 0)
{
let indexPosition = null;
let lstPOI = JSON.parse(localStorage.getItem(CommonUtil.CONST_STORAGE_POI_LIST));
$.each(lstPOI, function(index, jsonPOI){
if(poi.pointOfInterestId == jsonPOI.pointOfInterestId)
{
indexPosition = index;
return false;
}
})
if(indexPosition)
{
/** Remove/delete the POI with nagative number (localy created ) */
lstPOI.splice(indexPosition,1);
localStorage.setItem(CommonUtil.CONST_STORAGE_POI_LIST,JSON.stringify(lstPOI));
this.getPOIFromServerTwowaySync(1,updatedPOI);
}
}
if(poi.pointOfInterestId === updatedPOI.pointOfInterestId)
{
this.updatePOIPOST(updatedPOI,totalTwoWaySyncPOST);
}
}
})
},
/** Update POI after response from server */
updatePOIPOST(updatedPOI,totalTwoWaySyncPOST)
{
let lstPOI = JSON.parse(localStorage.getItem(CommonUtil.CONST_STORAGE_POI_LIST));
let counter = undefined;
$.each(lstPOI, function(index, jsonPOI){
if(jsonPOI.pointOfInterestId === updatedPOI.pointOfInterestId)
{
counter = index;
return false;
}
});
if(counter)
{
lstPOI[counter]=updatedPOI;
localStorage.setItem(CommonUtil.CONST_STORAGE_POI_LIST, JSON.stringify(lstPOI) );
this.counterTwoWaySyncPOST = this.counterTwoWaySyncPOST + 1;
console.log('total number of upload : '+totalTwoWaySyncPOST+' ---- counter value : '+this.counterTwoWaySyncPOST);
if(this.counterTwoWaySyncPOST === totalTwoWaySyncPOST)
{
this.counterTwoWaySyncPOST = 0;
this.getPOIFromServerTwowaySync(totalTwoWaySyncPOST,updatedPOI);
}
}
},
/** GET POIs */
getPOIFromServerTwowaySync(totalTwoWaySyncPOST,updatedPOI)
{
let This = this;
let strUUID = localStorage.getItem(CommonUtil.CONST_STORAGE_UUID);
let jsonHeader = { Authorization: strUUID };
fetch(CommonUtil.CONST_URL_DOMAIN + CommonUtil.CONST_URL_USER_POI, {
method: "GET",
headers: jsonHeader,
}).then((response) => response.json())
.then((data) => {
let serverPOIs = data;
if(localStorage.getItem(CommonUtil.CONST_STORAGE_POI_LIST))
{
let lstLocalPOI = JSON.parse(localStorage.getItem(CommonUtil.CONST_STORAGE_POI_LIST));
serverPOIs.forEach(function(serverPOI){
let arrIndex = undefined;
let booNoRecordFound = false;
let booRecordFound = false;
$.each(lstLocalPOI,function(index, localPOI){
if(serverPOI.pointOfInterestId === localPOI.pointOfInterestId) {
booRecordFound = true;
if(updatedPOI && (totalTwoWaySyncPOST === 1 && updatedPOI.pointOfInterestId === serverPOI.pointOfInterestId ))
{
}
else
{
if(srvObservation.lastEditedTime)
{
let srvDate = new Date(serverPOI.lastEditedTime);
let localDate = new Date(localPOI.lastEditedTime);
if(srvDate >= localDate)
{
arrIndex = index;
return false;
}
}
else{
arrIndex = index;
return false;
}
}
}
});
if(booRecordFound){}
else {
booNoRecordFound = true;
}
if(arrIndex)
{
lstLocalPOI[arrIndex]=serverPOIs;
}
if(booNoRecordFound)
{
lstLocalPOI.push(serverPOIs);
return false;
}
});
localStorage.setItem(CommonUtil.CONST_STORAGE_POI_LIST,JSON.stringify(lstLocalPOI));
}
else{
localStorage.setItem(CommonUtil.CONST_STORAGE_POI_LIST,JSON.stringify(serverPOI));
}
})
},
/** Remove local POI */
removeLocalPOI(id)
{
let lstPOI = JSON.parse(localStorage.getItem(CommonUtil.CONST_STORAGE_POI_LIST));
let indexPosition = null;
$.each(lstPOI, function(index, poi){
if(poi.pointOfInterestId===id)
{
indexPosition = index;
return false;
}
});
if(indexPosition)
{
lstPOI.splice(indexPosition,1);
localStorage.setItem(CommonUtil.CONST_STORAGE_POI_LIST,JSON.stringify(lstPOI));
}
},
/** Two way Sync - Observation */
syncTwoWayObservation(value,strUrl)
{
this.syncObservationSendPrepare(value);
},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment