diff --git a/src/components/Observation.vue b/src/components/Observation.vue index ffec948997a8fce2f4b533d278e618cac3581b33..85ae03318307e08c665ce33259a9a75471f66f8d 100644 --- a/src/components/Observation.vue +++ b/src/components/Observation.vue @@ -1,4 +1,4 @@ - <!-- +<!-- Copyright (c) 2022 NIBIO <http://www.nibio.no/>. @@ -22,831 +22,772 @@ --> <template> - <div id="observation"> - <div><router-link class="vips-btn" to="/">{{ $t("back.label") }}</router-link></div> - - <div v-if="observation.deleted"> - <div class="alert alert-warning" role="alert"> - {{ $t("err.observation.remove.warn") }} - </div> - </div> + <div id="observation"> + <div> + <router-link class="vips-btn" to="/">{{ $t("back.label") }}</router-link> + </div> - <div class="form-group"> - <select required class="form-control" id="divCropId" ref='divCropId' v-model="selectedCropId" v-on:change="selectCrop($event)"> - <option v-for="crop in crops" :value='crop.organismId' >{{crop.localName}}</option> - </select> - </div> + <div v-if="observation.deleted"> + <div class="alert alert-warning" role="alert"> + {{ $t("err.observation.remove.warn") }} + </div> + </div> - <div class="form-group"> - <select :disabled="selectedCropId <= 0" required class="form-control" v-model="pest.pestId" id='divPestId' ref='divPestId'> - <option v-for="pest in pests" v-bind:value='pest.pestId'>{{pest.pestName}}</option> - </select> - </div> + <div class="form-group"> + <select required class="form-control" id="divCropId" ref='divCropId' v-model="selectedCropId" + v-on:change="selectCrop($event)"> + <option v-for="crop in crops" :value='crop.organismId'>{{crop.localName}}</option> + </select> + </div> + + <div class="form-group"> + <select :disabled="selectedCropId <= 0" required class="form-control" v-model="pest.pestId" id='divPestId' + ref='divPestId'> + <option v-for="pest in pests" v-bind:value='pest.pestId'>{{pest.pestName}}</option> + </select> + </div> - <div class="form-group row"> + <div class="form-group row"> - <label for="strDateObservation" class="col-1 col-form-label"><font-awesome-icon style="font-size: x-large;" icon="calendar-days" /></label> + <label for="strDateObservation" class="col-1 col-form-label"> + <font-awesome-icon style="font-size: x-large;" icon="calendar-days" /></label> <div class="col-7"> - <input class="form-control" id="strDateObservation" ref="strDateObservation" type="datetime-local" :max="maxObservationDate" :min="minObservationDate" v-model="strDateObservation" v-on:change="capturedTime($event)"/> + <input class="form-control" id="strDateObservation" ref="strDateObservation" type="datetime-local" + :max="maxObservationDate" :min="minObservationDate" v-model="strDateObservation" + v-on:change="capturedTime($event)" /> </div> - </div> - - <div v-if="pest.pestId" class="row"> - <div class="col-1"><font-awesome-icon style="font-size: x-large; margin-top: 7px;" icon="map-location" /></div> - <div class="col-7"> - <router-link - id="linkMap" - class="vips-btn" - ref='linkMap' - :to="{name:'MapObservation', params: {observationId:observation.observationId,geoinfo:mapGeoinfo,isMapPanelVisible:newMapPanel,locationPointOfInterestId:mapLocationPointOfInterestId, observation:observation}}" - >{{ $t("observation.map.label") }}</router-link> </div> - </div> - <div v-if="mapGeoinfo" id="divMapGeoInfo"> - <div class="col" style="margin-top: 15px;"> - <map-observation :geoinfo="mapGeoinfo" :isMapPanelVisible="isMapPanelVisible" :locationIsPrivate="observation.locationIsPrivate" :polygonService="observation.polygonService" v-on:visibilityObservationAction="visibilityObservationAction" ></map-observation> - </div> - </div> - - <div> - <div><font-awesome-icon style="font-size: x-large; vertical-align:middle;" icon="scale-balanced" /><a class="vips-btn" v-on:click="toggleShowQuantification">{{ $t("observation.quantification.label") }}</a></div> - <div v-if="isQuantification"> - <fieldset v-if="isMounted" id='divSchemaForm' class="form-group border" > - <legend style="font-size: 1em !important;">{{ $t("observation.quantification.form.label") }}</legend> - <quantification :isEditable="false" :observationId="observation.observationId" :organismId="observation.organismId" :schemaData="observation.observationData" v-on:updateQuntificationData="updateQuntificationData"> </quantification> - </fieldset> - </div> - </div> - - <observation-illustration-board - v-if="isMounted" - v-bind:initialObservationIllustrations="observation.observationIllustrationSet" - v-bind:observationId="observation.observationId" - @observationIllustrationSetUpdated = "handleObservationIllustrationSetUpdated" - /> - - - <div ref='divObservationText' class="form-group"> - <div><font-awesome-icon icon="fa-regular fa-file-lines" style="font-size: x-large;"/></div> - <div><input ref="observationHeader" type="text" class="form-control" v-model="observation.observationHeading" :placeholder="$t('observation.detail.heading.placeholder')"/></div> - <div><textarea v-model="observation.observationText" class="form-control" rows="4" :placeholder="$t('observation.detail.body.placeholder')"/></div> - </div> - <!--div v-show="isSync"><sync ref="sync" :isSyncNeeded="isSync"/></div--> + <div v-if="pest.pestId" class="row"> + <div class="col-1"> + <font-awesome-icon style="font-size: x-large; margin-top: 7px;" icon="map-location" /> + </div> + <div class="col-7"> + <router-link id="linkMap" class="vips-btn" ref='linkMap' + :to="{name:'MapObservation', params: {observationId:observation.observationId,geoinfo:mapGeoinfo,isMapPanelVisible:newMapPanel,locationPointOfInterestId:mapLocationPointOfInterestId, observation:observation}}"> + {{ $t("observation.map.label") }}</router-link> + </div> + </div> + <div v-if="mapGeoinfo" id="divMapGeoInfo"> + <div class="col" style="margin-top: 15px;"> + <map-observation :geoinfo="mapGeoinfo" :isMapPanelVisible="isMapPanelVisible" + :locationIsPrivate="observation.locationIsPrivate" :polygonService="observation.polygonService" + v-on:visibilityObservationAction="visibilityObservationAction"></map-observation> + </div> + </div> - + + <div> + <div> + <font-awesome-icon style="font-size: x-large; vertical-align:middle;" icon="scale-balanced" /><a + class="vips-btn" + v-on:click="toggleShowQuantification">{{ $t("observation.quantification.label") }}</a></div> + <div v-if="isQuantification"> + <fieldset v-if="isMounted" id='divSchemaForm' class="form-group border"> + <legend style="font-size: 1em !important;">{{ $t("observation.quantification.form.label") }} + </legend> + <quantification :isEditable="false" :observationId="observation.observationId" + :organismId="observation.organismId" :schemaData="observation.observationData" + v-on:updateQuntificationData="updateQuntificationData"> </quantification> + </fieldset> + </div> + </div> + + <observation-illustration-board v-if="isMounted" + v-bind:initialObservationIllustrations="observation.observationIllustrationSet" + v-bind:observationId="observation.observationId" + @observationIllustrationSetUpdated="handleObservationIllustrationSetUpdated" /> + + + <div ref='divObservationText' class="form-group"> + <div> + <font-awesome-icon icon="fa-regular fa-file-lines" style="font-size: x-large;" /> + </div> + <div><input ref="observationHeader" type="text" class="form-control" + v-model="observation.observationHeading" + :placeholder="$t('observation.detail.heading.placeholder')" /></div> + <div><textarea v-model="observation.observationText" class="form-control" rows="4" + :placeholder="$t('observation.detail.body.placeholder')" /></div> + </div> + <!--div v-show="isSync"><sync ref="sync" :isSyncNeeded="isSync"/></div--> - <div v-if="observation.deleted"></div> - <div v-else class="float-right"> - <a class="vips-btn" v-on:click="saveObservation">{{$t("save.label")}}</a> - <a v-show="isDeleteBttnVisible" class="vips-btn danger" v-on:click="callForRemoveObservation">{{$t("delete.label")}}</a> - </div> -<sync ref="sync"/> - </div> + + + <div v-if="observation.deleted"></div> + <div v-else class="float-right"> + <a class="vips-btn" v-on:click="saveObservation">{{$t("save.label")}}</a> + <a v-show="isDeleteBttnVisible" class="vips-btn danger" + v-on:click="callForRemoveObservation">{{$t("delete.label")}}</a> + </div> + <sync ref="sync" /> + </div> </template> <script> -import CommonUtil from '@/components/CommonUtil' -import { DateTime } from 'luxon' -import MapObservation from '@/components/MapObservation' -import Quantification from '@/components/Quantification.vue' -import Sync from '@/components/Sync' -import ObservationIllustrationBoard from "@/components/ObservationIllustrationBoard" - - - -export default { - name: 'Observation', - props: ['observationId','paramGeoinfo','locationPointOfInterestId','paramObservation'], - components: {MapObservation,Quantification,Sync,ObservationIllustrationBoard}, - data () { - return { - isGeoInfoNotAvailable : false, - isStrDateObservationEmpty : false, - isObservationHeaderEmpty : false, - isDeleteBttnVisible : true, - isQuantification : false, - isMounted : false, - msg : this.$i18n.t("observation.msg"), - observation : {}, - selectedCropId : -1, - crops : [], - pests : [], - crop : {'cropId':'','cropName':this.$i18n.t("observation.selectcrop")}, - pest : {'pestId':'','pestName':this.$i18n.t("observation.selectpest")}, - isActive : false, - //dateObservation : DateTime, - strDateObservation : null, - maxObservationDate : null, - minObservationDate : null, - mapGeoinfo : null, - mapLocationPointOfInterestId : '', - isMapPanelVisible : false, - newMapPanel : true, - observationForStore : - { - observationId: '', - timeOfObservation: '', - statusChangedTime: '', - organismId: '', - cropOrganismId: '', - observationHeading: '', - observationText: '', - uploaded:false - } - } - }, - methods:{ - handleObservationIllustrationSetUpdated(newList) - { - this.observation.observationIllustrationSet = newList; - }, - callForRemoveObservation() - { - if(confirm(this.$i18n.t("err.observation.remove.msg"))) - { - this.prepareForRemove(); - } - }, - prepareForRemove(){ - if(this.observationId) - { - if(this.observationId < 0) - { - /** Just remove it locally */ - this.removeLocalObservation(this.observationId); - this.$router.push('/'); - } - else - { - /** Mark the record - for sending to server */ - this.observationForStore.deleted=true; - this.saveObservation(); - } - } - }, - - /** Remove local Observation */ - removeLocalObservation(id) - { - let lstObservations = JSON.parse(localStorage.getItem(CommonUtil.CONST_STORAGE_OBSERVATION_LIST)); - let indexPosition = null; - $.each(lstObservations, function(index, observation){ - if(observation.observationId===id) - { - indexPosition = index; - return false; - } - }); - - if(indexPosition || indexPosition === 0) - { - this.removeImageRecord(id); - - lstObservations.splice(indexPosition,1); - localStorage.setItem(CommonUtil.CONST_STORAGE_OBSERVATION_LIST,JSON.stringify(lstObservations)); - } - }, - /** - * Remove image data from indexed DB - */ - removeImageRecord(observationId){ - let entityName = CommonUtil.CONST_DB_ENTITY_PHOTO; - let dbRequest = indexedDB.open(CommonUtil.CONST_DB_NAME, CommonUtil.CONST_DB_VERSION); - let indexName = CommonUtil.CONST_DB_INDEX_NAME_OBSERVATION_ID; - dbRequest.onsuccess = function(evt) { - let db = evt.target.result; - let transaction = db.transaction([entityName],'readwrite'); - let objectstore = transaction.objectStore(entityName); - let indexStore = objectstore.index(indexName); - let keyRange = IDBKeyRange.only(observationId); - let cursorRequest = indexStore.openCursor(keyRange); - cursorRequest.onsuccess = function(event){ - let cursor = event.target.result; - if(cursor) - { - cursor.delete(); - cursor.continue(); - } - } - - - } - - }, - /** Validation on save */ - validate() - { - let result = true; - let msg = ""; - - if(!this.strDateObservation) - { - msg += this.$i18n.t("err.observation.date.empty") + "\n"; - result = false; - } - - - if(!this.mapGeoinfo) - { - msg += this.$i18n.t("err.observation.geoinfo") + "\n"; - result = false; - } - - if(!this.observation.observationHeading) - { - msg += this.$i18n.t("err.observation.header.empty") + "\n"; - result = false; - } - if(! result) - { - alert(msg); - } - return result; - - }, - visibilityObservationAction(paramPrivate, paramPolygonService){ - this.observationForStore.locationIsPrivate=paramPrivate; - if(paramPolygonService) - { - this.observationForStore.polygonService=paramPolygonService; - } - else{ - this.observationForStore.polygonService=''; - } - }, - toggleShowQuantification() - { - this.isQuantification = ! this.isQuantification; - }, - /** Get observation from local storage system */ - getObservationFromStore(id) - { - // For existing observation - if(id) - { - - let jsonObservation = {}; - - let lstObservations = JSON.parse(localStorage.getItem(CommonUtil.CONST_STORAGE_OBSERVATION_LIST)); // Observation List - - /* - Check availability of observation object - - mainly from map component - - to hold crop, pest data - */ - - if(this.paramObservation) - { - - this.getObservationCrops(this.paramObservation); - this.getObservationPests(this.paramObservation); - - this.strDateObservation = DateTime.fromISO(this.paramObservation.timeOfObservation).toFormat('yyyy-MM-dd\'T\'HH:mm:ss'); - } - else - { - jsonObservation = lstObservations.find(({observationId})=> observationId === id); // Selection Observation - this.observation = jsonObservation; - this.observation.observationData = JSON.parse(jsonObservation.observationData); - if(jsonObservation.statusTypeId) {} - else - { - this.observation.statusTypeId = CommonUtil.CONST_STATUS_PENDING; - } - - /* For related Crop and Crop list */ - this.getObservationCrops(jsonObservation); - /* For related Pest and Pest list */ - this.getObservationPests(jsonObservation); - - this.strDateObservation = DateTime.fromISO(jsonObservation.timeOfObservation).toFormat('yyyy-MM-dd\'T\'HH:mm:ss'); - } - - if(this.paramGeoinfo) - { - this.mapGeoinfo = this.paramGeoinfo; - } - else if(jsonObservation.geoinfo) - { - this.mapGeoinfo = JSON.parse(jsonObservation.geoinfo); - } - else - { - - if(jsonObservation.location && jsonObservation.location.geoJSON) - { - this.mapGeoinfo = JSON.parse(jsonObservation.location.geoJSON); - this.mapLocationPointOfInterestId = jsonObservation.locationPointOfInterestId; - } - } - this.selectedCropId = this.observation.cropOrganismId; - } - else { - //TODO for new Observation - } - }, - - /** Get related crop and crop list for a selected Observation */ - getObservationCrops(jsonObservation){ - - //console.info(jsonObservation); - - let lstCrops = []; - let lstCropIds = []; - let lstCropList = JSON.parse(localStorage.getItem(CommonUtil.CONST_STORAGE_CROP_LIST)); - - /** Try to get list of crops from crop category ids */ - let lstCropCategories = JSON.parse(localStorage.getItem(CommonUtil.CONST_STORAGE_CROP_CATEGORY)); - - - /** For Selected Observation We require List of related crop ids for dropdown */ - // Iterating crop categories - $.each(lstCropCategories, function(index,category){ - // Iterating each category data - $.each(category, function(key, data){ - //find the key meant for crop id/ids - if(key === 'cropOrganismIds') - { - this.isActive = true; - // iterate and get the required cropids relaed to selected observation id - $.each (data, function(index, item){ - if(parseInt(item)===parseInt(jsonObservation.cropOrganismId)) - { - lstCropIds = data; - return false; - } - }); - } - }) - }); - /* Get list of related crops with their id and name */ - this.getCrops(lstCropIds); - - let jsonSelectedCrop= this.crops.find(({organismId}) => organismId === parseInt(jsonObservation.cropOrganismId)); - if(jsonSelectedCrop) - { - this.crop = {"cropId":jsonSelectedCrop.organismId, "cropName":jsonSelectedCrop.latinName}; - } - }, - - /** Get related pests for a particular crop of a observation */ - getObservationPests(jsonObservation){ - let lstPests = []; - let lstPestIds = []; - let lstPestList = JSON.parse(localStorage.getItem(CommonUtil.CONST_STORAGE_PEST_LIST)); - let lstCropPestList = JSON.parse(localStorage.getItem(CommonUtil.CONST_STORAGE_CROP_PEST_LIST)); - - $.each(lstCropPestList, function(index,cropPests){ - if(parseInt(cropPests.cropOrganismId) === parseInt(jsonObservation.cropOrganismId)) - { - lstPestIds = cropPests.pestOrganismIds; - } - - }); - this.getPests(lstPestIds); - - let jsonSelectedPest = this.pests.find(({pestId}) => pestId === jsonObservation.organismId); - if(jsonSelectedPest) - { - this.pest = {"pestId":jsonSelectedPest.pestId, "pestName":jsonSelectedPest.pestName}; - } - - - }, - - /** On selecting a particular crop */ - selectCrop(event) - { - this.observation.cropOrganismId=this.selectedCropId; - var selectedCropId = this.selectedCropId; - let crop = this.crop; - let lstPestIds = []; - let lstCropPestList = JSON.parse(localStorage.getItem(CommonUtil.CONST_STORAGE_CROP_PEST_LIST)); - $.each(lstCropPestList, function(cropId, cropPest){ - if(selectedCropId == cropId) - { - let jsonPestId = cropPest.pestOrganismIds; - lstPestIds = lstPestIds.concat(jsonPestId); - } - }); - this.getPests(lstPestIds); - }, - - capturedTime(event) - { - this.observation.timeOfObservation=this.strDateObservation; - }, - - /** Get New Observation */ - getNewObservation() - { - this.isDeleteBttnVisible = false; - let lstCropIds = []; - let cropCategoryIdProp = CommonUtil.CONST_CROP_CATEGORY_ID; - let jsonCrops = []; - let arrCropCatIds = localStorage.getItem(CommonUtil.CONST_STORAGE_CROP_ID_LIST).split(","); - let jsonCropCategoryList = JSON.parse(localStorage.getItem(CommonUtil.CONST_STORAGE_CROP_CATEGORY)); - - /* Iterate Selected Crop Ids */ - $.each(arrCropCatIds, function(index, cropCatId){ - if(cropCatId != "") - { - let jsonCropCategory = jsonCropCategoryList.find(({cropCategoryId}) => cropCategoryId === JSON.parse(cropCatId)); - let jsonCropIds = jsonCropCategory.cropOrganismIds; - lstCropIds = lstCropIds.concat(jsonCropIds); - } - }); - - this.getCrops(lstCropIds); - - this.pest = {"pestId":'', "pestName":this.$i18n.t("observation.selectpest")}; - this.pests = [this.pest]; - - this.getNewObservationId(); - }, - - /** Get Crops */ - getCrops(lstCropIds) - { - let This = this; - let lstCrops = []; - if(! this.observationId) - { - lstCrops.push({"organismId":-1, "localName":this.$i18n.t("observation.selectcrop")}); - } - let lstCropList = JSON.parse(localStorage.getItem(CommonUtil.CONST_STORAGE_CROP_LIST)); - $.each(lstCropIds, function(index, cropId){ - let jsonDetailCrop = lstCropList.find(({organismId}) => organismId === cropId); - let organismLocaleSet = jsonDetailCrop.organismLocaleSet; - let cropName = jsonDetailCrop.latinName; - - if(organismLocaleSet) - { - let strLocale = This.getSystemLocale(); - - organismLocaleSet.forEach(function(localObj) { - - if(localObj.organismLocalePK.locale === strLocale) - { - if(localObj.localName) - { - cropName = localObj.localName; - } - - return false; - - } - }); - - } - let jsonCrop = {'organismId':cropId, 'localName':cropName}; - lstCrops.push(jsonCrop); - }); - - this.crops = lstCrops; - }, - - /** Get Pests */ - getPests(lstPestIds) - { - let This = this; - let lstPests = []; - - if(! this.observationId) - { - lstPests.push({"pestId":'', "pestName":this.$i18n.t("observation.selectpest")}); - } - - if(lstPestIds.length===0) - { - lstPests.push({"pestId":-10, "pestName":this.$i18n.t("observation.unregisteredpest")}); - } - else{ - let lstPestList = JSON.parse(localStorage.getItem(CommonUtil.CONST_STORAGE_PEST_LIST)); - $.each(lstPestIds, function(index, pestId){ - let jsonDetailPest = lstPestList.find(({organismId}) => organismId === pestId); - let jsonPest = {}; - if(jsonDetailPest) - { - let pestName = jsonDetailPest.latinName; - let organismLocaleSet = jsonDetailPest.organismLocaleSet; - - if(organismLocaleSet) - { - let strLocale = This.getSystemLocale(); - organismLocaleSet.forEach(localObj => { - if(localObj.organismLocalePK.locale === strLocale) - { - if(localObj.localName) - { - pestName = localObj.localName; - } - return false; - } - }); - } - jsonPest = {"pestId":jsonDetailPest.organismId, "pestName":pestName}; - } - else - { - jsonPest = {"pestId":pestId, "pestName":'Not Available -- '+pestId}; - } - - lstPests.push(jsonPest); - - }); - - } - - - - this.pests = lstPests; - }, - - /** Get new observation Id */ - getNewObservationId(lstObservations) - { - let newId = 0; - let observationIds=[]; - - - if(lstObservations) - { - $.each(lstObservations, function(index, observation){ - if(observation.observationId < 0) - { - observationIds.push(Math.abs(observation.observationId)); - } - }); - if(observationIds.length === 0) - { - newId = CommonUtil.CONST_OBSERVATION_COUNT_START_ID; - } - else - { - let largestValue = Math.max.apply(null, observationIds); - newId = -Math.abs(largestValue + 1); - } - } - else - { - newId = CommonUtil.CONST_OBSERVATION_COUNT_START_ID; - } - - return newId; - }, - - /** Save Observation */ - saveObservation() - { - if(! this.validate()) { return false; } - //console.info("this.mapGeoinfo=" + this.mapGeoinfo); - let This = this; - - - let lstObservations = JSON.parse(localStorage.getItem(CommonUtil.CONST_STORAGE_OBSERVATION_LIST)); - /** Whether record to be updated */ - let isRecordAvailable = null; - if(lstObservations) - { - isRecordAvailable = lstObservations.find(({observationId})=> observationId === this.observationId); - } - - this.observationForStore.cropOrganismId = this.crop.cropId; - this.observationForStore.organismId = this.pest.pestId; - this.observationForStore.timeOfObservation = this.strDateObservation; - this.observationForStore.statusChangedTime = this.strDateObservation; - if(this.observation.statusTypeId) - { - this.observationForStore.statusTypeId = this.observation.statusTypeId; - } - else - { - this.observationForStore.statusTypeId = CommonUtil.CONST_STATUS_PENDING; - } - this.observationForStore.isQuantified = this.observation.isQuantified; - this.observationForStore.userId = this.observation.userId; - this.observationForStore.geoinfo = JSON.stringify(this.mapGeoinfo); //this.observation.geoinfo; - //console.info("this.mapGeoinfo=" + this.mapGeoinfo + ". this.observationForStore.geoinfo=" + this.observationForStore.geoinfo); - this.observationForStore.locationPointOfInterestId = this.observation.locationPointOfInterestId; - this.observationForStore.broadcastMessage = this.observation.broadcastMessage; - this.observationForStore.statusRemarks = this.observation.statusRemarks; - this.observationForStore.observationHeading = this.observation.observationHeading; - this.observationForStore.observationText = this.observation.observationText; - this.observationForStore.observationData = JSON.stringify(this.observation.observationData)//'{"number":0,"unit":"Number"}'; //"{\"number\":0,\"unit\":\"Number\"}"; - this.observationForStore.observationIllustrationSet = this.observation.observationIllustrationSet; - - // Update the record inside the list of observations - if(this.observationId && isRecordAvailable) - { - this.observationForStore.observationId = this.observationId; - let localObservationForStore = this.observationForStore; - let selectedObservationId = this.observationId; - - // Reference to this is lost in here - for(var i=0;i<lstObservations.length;i++) - //$.each(lstObservations, function(index, jobservation) - { - var jobservation = lstObservations[i]; - if(jobservation.observationId === selectedObservationId) - { - jobservation.cropOrganismId = localObservationForStore.cropOrganismId; - jobservation.organismId = localObservationForStore.organismId; - jobservation.timeOfObservation = localObservationForStore.timeOfObservation; - jobservation.statusChangedTime = localObservationForStore.statusChangedTime; - jobservation.statusTypeId = localObservationForStore.statusTypeId; - jobservation.isQuantified = localObservationForStore.isQuantified; - jobservation.userId = localObservationForStore.userId; - - jobservation.geoinfo = localObservationForStore.geoinfo; - //console.info("this.mapGeoinfo=" + this.mapGeoinfo + ". jobservation.geoinfo=" + jobservation.geoinfo + ". localObservationForStore.geoinfo = " + localObservationForStore.geoinfo); - jobservation.locationPointOfInterestId = localObservationForStore.locationPointOfInterestId; - jobservation.broadcastMessage = localObservationForStore.broadcastMessage; - jobservation.observationIllustrationSet = localObservationForStore.observationIllustrationSet; - - jobservation.observationData = localObservationForStore.observationData; - jobservation.observationHeading = localObservationForStore.observationHeading; - jobservation.observationText = localObservationForStore.observationText; - jobservation.locationIsPrivate = localObservationForStore.locationIsPrivate; - jobservation.polygonService = localObservationForStore.polygonService; - jobservation.uploaded = localObservationForStore.uploaded; - - if(localObservationForStore.deleted) - { - jobservation.deleted = localObservationForStore.deleted; - } - - break; - } - } - /*console.info("Here are the observations:" + JSON.stringify(lstObservations)); - console.info(lstObservations);*/ - } - else - { - this.observationForStore.observationId = this.getNewObservationId(lstObservations); - if(! lstObservations) - { - lstObservations = []; - - } - this.observationForStore.statusTypeId=CommonUtil.CONST_STATUS_PENDING; - //console.info("this.observationForStore=" + this.observationForStore); - lstObservations.push(this.observationForStore); - } - localStorage.setItem(CommonUtil.CONST_STORAGE_OBSERVATION_LIST, JSON.stringify(lstObservations) ); - //console.info("....and AFTER STORING: " + localStorage.getItem(CommonUtil.CONST_STORAGE_OBSERVATION_LIST)); - // Sync on save. saveObservation() is also called from the DELETE button - this.$refs.sync.syncTwoWay(); - this.$router.replace({path:'/'}); - - - }, - updateQuntificationData(schemaData){ - this.observation.observationData = schemaData; - }, - getSystemLocale() - { - var localePrefer = null; - var localePrefer2 = null; - if(typeof navigator.language != 'undefined') - { - localePrefer = navigator.language; - localePrefer2 = localePrefer.trim().substring(0,2); - } - - return localePrefer2; - }, - - }, - filters: { - dateFormat: function(timeStr) { - return DateTime.fromISO(timeStr).toFormat('yyyy-MM-dd\'T\'hh:mm:ss'); - } - }, - watch: { - - - - pest: { - - handler (val) - { - if(this.pest.pestId) - { - this.observation.organismId=this.pest.pestId; - this.isMounted = true; - } - }, - deep : true, - immediate : true - } - } , - mounted(){ - CommonUtil.setHeaderTitle(this.$i18n.t("observation.msg")); - - var dtToday = new Date(); - - var month = dtToday.getMonth() + 1; - var day = dtToday.getDate(); - var year = dtToday.getFullYear(); - var hh = dtToday.getHours(); - var min = dtToday.getMinutes(); - - if(month < 10) - month = '0' + month.toString(); - if(day < 10) - day = '0' + day.toString(); - if(hh<10) - hh = '0' + hh.toString(); - if(min<10) - min = '0' + min.toString(); - - - var maxDate = year + '-' + month + '-' + day; - var minDate = year + '-' + '01' + '-' + '01'; - - this.maxObservationDate = maxDate+'T00:00'; - this.minObservationDate = minDate+'T00:00'; - - this.strDateObservation = maxDate+'T'+hh+':'+min; - - this.observation.timeOfObservation=this.strDateObservation; - - /* Check existing Observation Object - Mainly from Map component - It helps to retain the data back to Observation from Map - */ - if(this.paramObservation) - { - this.observation = this.paramObservation; - } - if(this.paramGeoinfo) - { - this.mapGeoinfo = this.paramGeoinfo; - } - - - - /* Get details of existing Observation */ - if(this.observationId) - { - this.getObservationFromStore(this.observationId); - - this.observation.observationId=this.observationId; - } - else{ - let isCropIdsAvailable = false; - if(localStorage.getItem(CommonUtil.CONST_STORAGE_CROP_ID_LIST)) - { - - let lstCropIds = localStorage.getItem(CommonUtil.CONST_STORAGE_CROP_ID_LIST).split(","); - if(lstCropIds.length > 0) - { - isCropIdsAvailable = true; - } - } - - if(isCropIdsAvailable) - { - let newObservationId = 0; - let lstObservations = JSON.parse(localStorage.getItem(CommonUtil.CONST_STORAGE_OBSERVATION_LIST)); - newObservationId = this.getNewObservationId(lstObservations); - this.observation.observationId = newObservationId; - this.observation.observationData=''; - this.getNewObservation(); - } - else - { - this.$router.push('/cropCategory'); - } - if(this.locationPointOfInterestId) - { - this.mapLocationPointOfInterestId = this.locationPointOfInterestId; - + import CommonUtil from '@/components/CommonUtil' + import {DateTime} from 'luxon' + import MapObservation from '@/components/MapObservation' + import Quantification from '@/components/Quantification.vue' + import Sync from '@/components/Sync' + import ObservationIllustrationBoard from "@/components/ObservationIllustrationBoard" + + + + export default { + name: 'Observation', + props: ['observationId', 'paramGeoinfo', 'locationPointOfInterestId', 'paramObservation'], + components: {MapObservation, Quantification, Sync, ObservationIllustrationBoard}, + data() { + return { + isGeoInfoNotAvailable: false, + isStrDateObservationEmpty: false, + isObservationHeaderEmpty: false, + isDeleteBttnVisible: true, + isQuantification: false, + isMounted: false, + msg: this.$i18n.t("observation.msg"), + observation: {}, + selectedCropId: -1, + crops: [], + pests: [], + crop: {'cropId': '', 'cropName': this.$i18n.t("observation.selectcrop")}, + pest: {'pestId': '', 'pestName': this.$i18n.t("observation.selectpest")}, + isActive: false, + //dateObservation : DateTime, + strDateObservation: null, + maxObservationDate: null, + minObservationDate: null, + mapGeoinfo: null, + mapLocationPointOfInterestId: '', + isMapPanelVisible: false, + newMapPanel: true, + observationForStore: + { + observationId: '', + timeOfObservation: '', + statusChangedTime: '', + organismId: '', + cropOrganismId: '', + observationHeading: '', + observationText: '', + uploaded: false + } + } + }, + methods: { + handleObservationIllustrationSetUpdated(newList) { + this.observation.observationIllustrationSet = newList; + }, + callForRemoveObservation() { + if (confirm(this.$i18n.t("err.observation.remove.msg"))) { + this.prepareForRemove(); + } + }, + prepareForRemove() { + if (this.observationId) { + if (this.observationId < 0) { + /** Just remove it locally */ + this.removeLocalObservation(this.observationId); + this.$router.push('/'); + } + else { + /** Mark the record - for sending to server */ + this.observationForStore.deleted = true; + this.saveObservation(); + } + } + }, + + /** Remove local Observation */ + removeLocalObservation(id) { + let lstObservations = JSON.parse(localStorage.getItem(CommonUtil.CONST_STORAGE_OBSERVATION_LIST)); + let indexPosition = null; + $.each(lstObservations, function (index, observation) { + if (observation.observationId === id) { + indexPosition = index; + return false; + } + }); + + if (indexPosition || indexPosition === 0) { + this.removeImageRecord(id); + + lstObservations.splice(indexPosition, 1); + localStorage.setItem(CommonUtil.CONST_STORAGE_OBSERVATION_LIST, JSON.stringify(lstObservations)); + } + }, + /** + * Remove image data from indexed DB + */ + removeImageRecord(observationId) { + let entityName = CommonUtil.CONST_DB_ENTITY_PHOTO; + let dbRequest = indexedDB.open(CommonUtil.CONST_DB_NAME, CommonUtil.CONST_DB_VERSION); + let indexName = CommonUtil.CONST_DB_INDEX_NAME_OBSERVATION_ID; + dbRequest.onsuccess = function (evt) { + let db = evt.target.result; + let transaction = db.transaction([entityName], 'readwrite'); + let objectstore = transaction.objectStore(entityName); + let indexStore = objectstore.index(indexName); + let keyRange = IDBKeyRange.only(observationId); + let cursorRequest = indexStore.openCursor(keyRange); + cursorRequest.onsuccess = function (event) { + let cursor = event.target.result; + if (cursor) { + cursor.delete(); + cursor.continue(); + } + } + + + } + + }, + /** Validation on save */ + validate() { + let result = true; + let msg = ""; + + if (!this.strDateObservation) { + msg += this.$i18n.t("err.observation.date.empty") + "\n"; + result = false; + } + + + if (!this.mapGeoinfo) { + msg += this.$i18n.t("err.observation.geoinfo") + "\n"; + result = false; + } + + if (!this.observation.observationHeading) { + msg += this.$i18n.t("err.observation.header.empty") + "\n"; + result = false; + } + if (!result) { + alert(msg); + } + return result; + + }, + visibilityObservationAction(paramPrivate, paramPolygonService) { + this.observationForStore.locationIsPrivate = paramPrivate; + if (paramPolygonService) { + this.observationForStore.polygonService = paramPolygonService; + } + else { + this.observationForStore.polygonService = ''; + } + }, + toggleShowQuantification() { + this.isQuantification = !this.isQuantification; + }, + /** Get observation from local storage system */ + getObservationFromStore(id) { + // For existing observation + if (id) { + + let jsonObservation = {}; + + let lstObservations = JSON.parse(localStorage.getItem(CommonUtil.CONST_STORAGE_OBSERVATION_LIST)); // Observation List + + /* + Check availability of observation object + - mainly from map component + - to hold crop, pest data + */ + + if (this.paramObservation) { + + this.getObservationCrops(this.paramObservation); + this.getObservationPests(this.paramObservation); + + this.strDateObservation = DateTime.fromISO(this.paramObservation.timeOfObservation).toFormat('yyyy-MM-dd\'T\'HH:mm:ss'); + } + else { + jsonObservation = lstObservations.find(({observationId}) => observationId === id); // Selection Observation + this.observation = jsonObservation; + this.observation.observationData = JSON.parse(jsonObservation.observationData); + if (jsonObservation.statusTypeId) {} + else { + this.observation.statusTypeId = CommonUtil.CONST_STATUS_PENDING; + } + + /* For related Crop and Crop list */ + this.getObservationCrops(jsonObservation); + /* For related Pest and Pest list */ + this.getObservationPests(jsonObservation); + + this.strDateObservation = DateTime.fromISO(jsonObservation.timeOfObservation).toFormat('yyyy-MM-dd\'T\'HH:mm:ss'); + } + + if (this.paramGeoinfo) { + this.mapGeoinfo = this.paramGeoinfo; + } + else if (jsonObservation.geoinfo) { + this.mapGeoinfo = JSON.parse(jsonObservation.geoinfo); + } + else { + + if (jsonObservation.location && jsonObservation.location.geoJSON) { + this.mapGeoinfo = JSON.parse(jsonObservation.location.geoJSON); + this.mapLocationPointOfInterestId = jsonObservation.locationPointOfInterestId; + } + } + this.selectedCropId = this.observation.cropOrganismId; + } + else { + //TODO for new Observation + } + }, + + /** Get related crop and crop list for a selected Observation */ + getObservationCrops(jsonObservation) { + + //console.info(jsonObservation); + + let lstCrops = []; + let lstCropIds = []; + let lstCropList = JSON.parse(localStorage.getItem(CommonUtil.CONST_STORAGE_CROP_LIST)); + + /** Try to get list of crops from crop category ids */ + let lstCropCategories = JSON.parse(localStorage.getItem(CommonUtil.CONST_STORAGE_CROP_CATEGORY)); + + + /** For Selected Observation We require List of related crop ids for dropdown */ + // Iterating crop categories + $.each(lstCropCategories, function (index, category) { + // Iterating each category data + $.each(category, function (key, data) { + //find the key meant for crop id/ids + if (key === 'cropOrganismIds') { + this.isActive = true; + // iterate and get the required cropids relaed to selected observation id + $.each(data, function (index, item) { + if (parseInt(item) === parseInt(jsonObservation.cropOrganismId)) { + lstCropIds = data; + return false; + } + }); + } + }) + }); + /* Get list of related crops with their id and name */ + this.getCrops(lstCropIds); + + let jsonSelectedCrop = this.crops.find(({organismId}) => organismId === parseInt(jsonObservation.cropOrganismId)); + if (jsonSelectedCrop) { + this.crop = {"cropId": jsonSelectedCrop.organismId, "cropName": jsonSelectedCrop.latinName}; + } + }, + + /** Get related pests for a particular crop of a observation */ + getObservationPests(jsonObservation) { + let lstPests = []; + let lstPestIds = []; + let lstPestList = JSON.parse(localStorage.getItem(CommonUtil.CONST_STORAGE_PEST_LIST)); + let lstCropPestList = JSON.parse(localStorage.getItem(CommonUtil.CONST_STORAGE_CROP_PEST_LIST)); + + $.each(lstCropPestList, function (index, cropPests) { + if (parseInt(cropPests.cropOrganismId) === parseInt(jsonObservation.cropOrganismId)) { + lstPestIds = cropPests.pestOrganismIds; + } + + }); + this.getPests(lstPestIds); + + let jsonSelectedPest = this.pests.find(({pestId}) => pestId === jsonObservation.organismId); + if (jsonSelectedPest) { + this.pest = {"pestId": jsonSelectedPest.pestId, "pestName": jsonSelectedPest.pestName}; + } + + + }, + + /** On selecting a particular crop */ + selectCrop(event) { + this.observation.cropOrganismId = this.selectedCropId; + var selectedCropId = this.selectedCropId; + let crop = this.crop; + let lstPestIds = []; + let lstCropPestList = JSON.parse(localStorage.getItem(CommonUtil.CONST_STORAGE_CROP_PEST_LIST)); + $.each(lstCropPestList, function (cropId, cropPest) { + if (selectedCropId == cropId) { + let jsonPestId = cropPest.pestOrganismIds; + lstPestIds = lstPestIds.concat(jsonPestId); + } + }); + this.getPests(lstPestIds); + }, + + capturedTime(event) { + this.observation.timeOfObservation = this.strDateObservation; + }, + + /** Get New Observation */ + getNewObservation() { + this.isDeleteBttnVisible = false; + let lstCropIds = []; + let cropCategoryIdProp = CommonUtil.CONST_CROP_CATEGORY_ID; + let jsonCrops = []; + let arrCropCatIds = localStorage.getItem(CommonUtil.CONST_STORAGE_CROP_ID_LIST).split(","); + let jsonCropCategoryList = JSON.parse(localStorage.getItem(CommonUtil.CONST_STORAGE_CROP_CATEGORY)); + + /* Iterate Selected Crop Ids */ + $.each(arrCropCatIds, function (index, cropCatId) { + if (cropCatId != "") { + let jsonCropCategory = jsonCropCategoryList.find(({cropCategoryId}) => cropCategoryId === JSON.parse(cropCatId)); + let jsonCropIds = jsonCropCategory.cropOrganismIds; + lstCropIds = lstCropIds.concat(jsonCropIds); + } + }); + + this.getCrops(lstCropIds); + + this.pest = {"pestId": '', "pestName": this.$i18n.t("observation.selectpest")}; + this.pests = [this.pest]; + + this.getNewObservationId(); + }, + + /** Get Crops */ + getCrops(lstCropIds) { + let This = this; + let lstCrops = []; + if (!this.observationId) { + lstCrops.push({"organismId": -1, "localName": this.$i18n.t("observation.selectcrop")}); + } + let lstCropList = JSON.parse(localStorage.getItem(CommonUtil.CONST_STORAGE_CROP_LIST)); + $.each(lstCropIds, function (index, cropId) { + let jsonDetailCrop = lstCropList.find(({organismId}) => organismId === cropId); + let organismLocaleSet = jsonDetailCrop.organismLocaleSet; + let cropName = jsonDetailCrop.latinName; + + if (organismLocaleSet) { + let strLocale = This.getSystemLocale(); + + organismLocaleSet.forEach(function (localObj) { + + if (localObj.organismLocalePK.locale === strLocale) { + if (localObj.localName) { + cropName = localObj.localName; + } + + return false; + + } + }); + + } + let jsonCrop = {'organismId': cropId, 'localName': cropName}; + lstCrops.push(jsonCrop); + }); + + this.crops = lstCrops; + }, + + /** Get Pests */ + getPests(lstPestIds) { + let This = this; + let lstPests = []; + + if (!this.observationId) { + lstPests.push({"pestId": '', "pestName": this.$i18n.t("observation.selectpest")}); + } + + if (lstPestIds.length === 0) { + lstPests.push({"pestId": -10, "pestName": this.$i18n.t("observation.unregisteredpest")}); + } + else { + let lstPestList = JSON.parse(localStorage.getItem(CommonUtil.CONST_STORAGE_PEST_LIST)); + $.each(lstPestIds, function (index, pestId) { + let jsonDetailPest = lstPestList.find(({organismId}) => organismId === pestId); + let jsonPest = {}; + if (jsonDetailPest) { + let pestName = jsonDetailPest.latinName; + let organismLocaleSet = jsonDetailPest.organismLocaleSet; + + if (organismLocaleSet) { + let strLocale = This.getSystemLocale(); + organismLocaleSet.forEach(localObj => { + if (localObj.organismLocalePK.locale === strLocale) { + if (localObj.localName) { + pestName = localObj.localName; + } + return false; + } + }); + } + jsonPest = {"pestId": jsonDetailPest.organismId, "pestName": pestName}; + } + else { + jsonPest = {"pestId": pestId, "pestName": 'Not Available -- ' + pestId}; + } + + lstPests.push(jsonPest); + + }); + + } + + + + this.pests = lstPests; + }, + + /** Get new observation Id */ + getNewObservationId(lstObservations) { + let newId = 0; + let observationIds = []; + + + if (lstObservations) { + $.each(lstObservations, function (index, observation) { + if (observation.observationId < 0) { + observationIds.push(Math.abs(observation.observationId)); + } + }); + if (observationIds.length === 0) { + newId = CommonUtil.CONST_OBSERVATION_COUNT_START_ID; + } + else { + let largestValue = Math.max.apply(null, observationIds); + newId = -Math.abs(largestValue + 1); + } + } + else { + newId = CommonUtil.CONST_OBSERVATION_COUNT_START_ID; + } + + return newId; + }, + + /** Save Observation */ + saveObservation() { + if (!this.validate()) {return false;} + //console.info("this.mapGeoinfo=" + this.mapGeoinfo); + let This = this; + + + let lstObservations = JSON.parse(localStorage.getItem(CommonUtil.CONST_STORAGE_OBSERVATION_LIST)); + /** Whether record to be updated */ + let isRecordAvailable = null; + if (lstObservations) { + isRecordAvailable = lstObservations.find(({observationId}) => observationId === this.observationId); + } + + this.observationForStore.cropOrganismId = this.crop.cropId; + this.observationForStore.organismId = this.pest.pestId; + this.observationForStore.timeOfObservation = this.strDateObservation; + this.observationForStore.statusChangedTime = this.strDateObservation; + if (this.observation.statusTypeId) { + this.observationForStore.statusTypeId = this.observation.statusTypeId; + } + else { + this.observationForStore.statusTypeId = CommonUtil.CONST_STATUS_PENDING; + } + this.observationForStore.isQuantified = this.observation.isQuantified; + this.observationForStore.userId = this.observation.userId; + this.observationForStore.geoinfo = JSON.stringify(this.mapGeoinfo); //this.observation.geoinfo; + //console.info("this.mapGeoinfo=" + this.mapGeoinfo + ". this.observationForStore.geoinfo=" + this.observationForStore.geoinfo); + this.observationForStore.locationPointOfInterestId = this.observation.locationPointOfInterestId; + this.observationForStore.broadcastMessage = this.observation.broadcastMessage; + this.observationForStore.statusRemarks = this.observation.statusRemarks; + this.observationForStore.observationHeading = this.observation.observationHeading; + this.observationForStore.observationText = this.observation.observationText; + this.observationForStore.observationData = JSON.stringify(this.observation.observationData)//'{"number":0,"unit":"Number"}'; //"{\"number\":0,\"unit\":\"Number\"}"; + this.observationForStore.observationIllustrationSet = this.observation.observationIllustrationSet; + + // Update the record inside the list of observations + if (this.observationId && isRecordAvailable) { + this.observationForStore.observationId = this.observationId; + let localObservationForStore = this.observationForStore; + let selectedObservationId = this.observationId; + + // Reference to this is lost in here + for (var i = 0; i < lstObservations.length; i++) + //$.each(lstObservations, function(index, jobservation) + { + var jobservation = lstObservations[i]; + if (jobservation.observationId === selectedObservationId) { + jobservation.cropOrganismId = localObservationForStore.cropOrganismId; + jobservation.organismId = localObservationForStore.organismId; + jobservation.timeOfObservation = localObservationForStore.timeOfObservation; + jobservation.statusChangedTime = localObservationForStore.statusChangedTime; + jobservation.statusTypeId = localObservationForStore.statusTypeId; + jobservation.isQuantified = localObservationForStore.isQuantified; + jobservation.userId = localObservationForStore.userId; + + jobservation.geoinfo = localObservationForStore.geoinfo; + //console.info("this.mapGeoinfo=" + this.mapGeoinfo + ". jobservation.geoinfo=" + jobservation.geoinfo + ". localObservationForStore.geoinfo = " + localObservationForStore.geoinfo); + jobservation.locationPointOfInterestId = localObservationForStore.locationPointOfInterestId; + jobservation.broadcastMessage = localObservationForStore.broadcastMessage; + jobservation.observationIllustrationSet = localObservationForStore.observationIllustrationSet; + + jobservation.observationData = localObservationForStore.observationData; + jobservation.observationHeading = localObservationForStore.observationHeading; + jobservation.observationText = localObservationForStore.observationText; + jobservation.locationIsPrivate = localObservationForStore.locationIsPrivate; + jobservation.polygonService = localObservationForStore.polygonService; + jobservation.uploaded = localObservationForStore.uploaded; + + if (localObservationForStore.deleted) { + jobservation.deleted = localObservationForStore.deleted; + } + + break; + } + } + /*console.info("Here are the observations:" + JSON.stringify(lstObservations)); + console.info(lstObservations);*/ + } + else { + this.observationForStore.observationId = this.getNewObservationId(lstObservations); + if (!lstObservations) { + lstObservations = []; + + } + this.observationForStore.statusTypeId = CommonUtil.CONST_STATUS_PENDING; + //console.info("this.observationForStore=" + this.observationForStore); + lstObservations.push(this.observationForStore); + } + localStorage.setItem(CommonUtil.CONST_STORAGE_OBSERVATION_LIST, JSON.stringify(lstObservations)); + //console.info("....and AFTER STORING: " + localStorage.getItem(CommonUtil.CONST_STORAGE_OBSERVATION_LIST)); + // Sync on save. saveObservation() is also called from the DELETE button + this.$refs.sync.syncTwoWay(); + this.$router.replace({path: '/'}); + + + }, + updateQuntificationData(schemaData) { + this.observation.observationData = schemaData; + }, + getSystemLocale() { + var localePrefer = null; + var localePrefer2 = null; + if (typeof navigator.language != 'undefined') { + localePrefer = navigator.language; + localePrefer2 = localePrefer.trim().substring(0, 2); + } + + return localePrefer2; + }, + + }, + filters: { + dateFormat: function (timeStr) { + return DateTime.fromISO(timeStr).toFormat('yyyy-MM-dd\'T\'hh:mm:ss'); + } + }, + watch: { + + + + pest: { + + handler(val) { + if (this.pest.pestId) { + this.observation.organismId = this.pest.pestId; + this.isMounted = true; + } + }, + deep: true, + immediate: true + } + }, + mounted() { + CommonUtil.setHeaderTitle(this.$i18n.t("observation.msg")); + + var dtToday = new Date(); + + var month = dtToday.getMonth() + 1; + var day = dtToday.getDate(); + var year = dtToday.getFullYear(); + var hh = dtToday.getHours(); + var min = dtToday.getMinutes(); + + if (month < 10) + month = '0' + month.toString(); + if (day < 10) + day = '0' + day.toString(); + if (hh < 10) + hh = '0' + hh.toString(); + if (min < 10) + min = '0' + min.toString(); + + + var maxDate = year + '-' + month + '-' + day; + var minDate = year + '-' + '01' + '-' + '01'; + + this.maxObservationDate = maxDate + 'T00:00'; + this.minObservationDate = minDate + 'T00:00'; + + this.strDateObservation = maxDate + 'T' + hh + ':' + min; + + this.observation.timeOfObservation = this.strDateObservation; + + /* Check existing Observation Object - Mainly from Map component + It helps to retain the data back to Observation from Map + */ + if (this.paramObservation) { + this.observation = this.paramObservation; + } + if (this.paramGeoinfo) { + this.mapGeoinfo = this.paramGeoinfo; + } + + + + /* Get details of existing Observation */ + if (this.observationId) { + this.getObservationFromStore(this.observationId); + + this.observation.observationId = this.observationId; + } + else { + let isCropIdsAvailable = false; + if (localStorage.getItem(CommonUtil.CONST_STORAGE_CROP_ID_LIST)) { + + let lstCropIds = localStorage.getItem(CommonUtil.CONST_STORAGE_CROP_ID_LIST).split(","); + if (lstCropIds.length > 0) { + isCropIdsAvailable = true; + } + } + + if (isCropIdsAvailable) { + let newObservationId = 0; + let lstObservations = JSON.parse(localStorage.getItem(CommonUtil.CONST_STORAGE_OBSERVATION_LIST)); + newObservationId = this.getNewObservationId(lstObservations); + this.observation.observationId = newObservationId; + this.observation.observationData = ''; + this.getNewObservation(); + } + else { + this.$router.push('/cropCategory'); + } + if (this.locationPointOfInterestId) { + this.mapLocationPointOfInterestId = this.locationPointOfInterestId; + + } } - } - if(!this.paramObservation) - { - this.observationForStore.locationIsPrivate=this.observation.locationIsPrivate; - this.observationForStore.polygonService=this.observation.polygonService; - } - } - -} + if (!this.paramObservation) { + this.observationForStore.locationIsPrivate = this.observation.locationIsPrivate; + this.observationForStore.polygonService = this.observation.polygonService; + } + } + + } </script> <style scoped> - #btnCloseQuantification { - float: right; - top: 0px; - right: 0px; - } - - #divSchemaForm { - padding: 10px; - } -</style> + #btnCloseQuantification { + float: right; + top: 0px; + right: 0px; + } + + #divSchemaForm { + padding: 10px; + } +</style> \ No newline at end of file