diff --git a/src/components/PlacesList.vue b/src/components/PlacesList.vue index bf59adfdc219dd6a9be721d35e7854ed35e5570a..1e17cc34b442048b03219d3fde7c1e87e3a700e8 100644 --- a/src/components/PlacesList.vue +++ b/src/components/PlacesList.vue @@ -28,10 +28,20 @@ <button type="button" class="btn btn-primary">+</button> </router-link> </div> + <div class="alert alert-info"> + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> + <span aria-hidden="true">×</span> + </button> + {{ $t("placeslist.explanation") }} + </div> + <div class="form-group form-check"> + <input type="checkbox" class="form-check-input" v-model="showOnlyUsersPOIs" @change="handleFiltersChanged" id="showOnlyUsersPOIs"> + <label class="form-check-label" for="showOnlyUsersPOIs">Bare mine steder</label> + </div> <div> <div class="row form-group" style="margin-left:0px;"> <div><input class="form-control" type="text" v-model.trim="textSearch" - :placeholder="$t('places.search.label')" @input="search"> </div> + :placeholder="$t('places.search.label')" @input="handleFiltersChanged"> </div> </div> <!-- TODO: Remove the sync status classes (v-bind:class). Do it after sync has been automatized --> <router-link class="list-group-item list-group-item-action bg-light" ref='linkMapPoi' @@ -46,7 +56,7 @@ </div> <div v-else class="row"> <div class="col-9"> - <div>{{poi.name}}</div> + <div :style="poi.isOwnPOI?'font-weight:bold;':false">{{poi.name}}</div> </div> <div class="col-3"> <router-link @@ -72,12 +82,33 @@ return { CONST_URL_DOMAIN: '', listPOI: [], + listPOIAll: [], textSearch: null, + showOnlyUsersPOIs: true } }, - - methods: { + filterListPOI(){ + var userId = this.$root.sharedState.userId; + var candidateList = [];//this.listPOIAll; + if(this.showOnlyUsersPOIs) + { + candidateList = this.listPOIAll.filter((poi) =>{ + return userId == poi.userId; + }) + } + else + { + candidateList = this.listPOIAll; + } + if(this.textSearch){ + return candidateList.filter((poi) => { + let poiName = poi.name; + return poiName.toLowerCase().indexOf(this.textSearch.toLowerCase()) != -1; + }); + } + return candidateList; + }, fetchFromServer() { let strUUID = localStorage.getItem(CommonUtil.CONST_STORAGE_UUID); let jsonHeader = {Authorization: strUUID}; @@ -92,8 +123,13 @@ }) }, - getPlacesList(lstPOI) { - lstPOI.forEach(function (poi) { + handleFiltersChanged(){ + this.listPOI = this.filterListPOI(); + }, + getPOIListFromStore() { + var userId = this.$root.sharedState.userId; + this.listPOIAll = JSON.parse(localStorage.getItem(CommonUtil.CONST_STORAGE_POI_LIST)); + this.listPOIAll.forEach(function (poi) { if (poi.uploaded === false) { if (poi.deleted) { poi.isDeleted = true; @@ -108,40 +144,31 @@ } } - + poi.isOwnPOI = userId == poi.userId; + }); + + // Sorting own POIs first, then alphabetic + this.listPOIAll.sort((poi1, poi2)=>{ + if(poi1.userId == userId && poi2.userId != userId) + { + return -1; + } + if(poi1.userId != userId && poi2.userId == userId) + { + return 1; + } + if (poi1.name.toLowerCase() < poi2.name.toLowerCase()) {return -1;} + if (poi1.name.toLowerCase() > poi2.name.toLowerCase()) {return 1;} + return 0; }); - return lstPOI; - }, - /** Search POI */ - search() { - let lstPOI = JSON.parse(localStorage.getItem(CommonUtil.CONST_STORAGE_POI_LIST)); - if (this.textSearch) { - let This = this; - - let lstPOISearch = lstPOI.filter(function (poi) { - let poiName = poi.name; - return poiName.toLowerCase().indexOf(This.textSearch.toLowerCase()) != -1; - }); - this.listPOI = this.getPlacesList(lstPOISearch) - } - else { - this.listPOI = this.getPlacesList(lstPOI); - } - }, - getPOIListFromStore() { - let lstPOI = JSON.parse(localStorage.getItem(CommonUtil.CONST_STORAGE_POI_LIST)); - this.listPOI = this.getPlacesList(lstPOI); } }, mounted() { CommonUtil.setHeaderTitle(this.$i18n.t("placeslist.heading")); this.CONST_URL_DOMAIN = CommonUtil.CONST_URL_DOMAIN; - /* - let lstPOI = JSON.parse(localStorage.getItem(CommonUtil.CONST_STORAGE_POI_LIST)); - this.listPOI = this.getPlacesList(lstPOI); - */ this.getPOIListFromStore(); + this.listPOI = this.filterListPOI(); // Making it globally available, so that e.g. the Sync component can update the list // calling e.g. this.$root.sharedState.placesListComponent.fooBar(); this.$root.sharedState.placesListComponent = this; diff --git a/src/locales/en.json b/src/locales/en.json index 26c5647ba66ae78a09e14d36d0b7464d4754c7e4..4a98d4e7ad5a638bf2a973cab881304f6f7b4a58 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -49,6 +49,7 @@ "Weather station": "Weather station", "places.search.label": "Search", "placeslist.heading": "My places", + "placeslist.explanation" : "\"Places\" are predefined locations with their own name. Useful for registering several observations on the same location. Click the magnifying glass icon to add an observation on this place.", "crop.category.empty.alert": "Please select Crop category", "cropcategory": "Crop category", "alert.header.label": "!! ALERT !!", diff --git a/src/locales/nb.json b/src/locales/nb.json index 49e990ae4ae285e1483540902d26c5c60dced96c..bad43123153a91eadf00220971f45451736d7a9c 100644 --- a/src/locales/nb.json +++ b/src/locales/nb.json @@ -20,7 +20,7 @@ "observation.msg": "Registrer observasjon", "observation.selectcrop": "Velg kultur", "observation.selectpest": "Velg skadegjører", - "observation.unregisteredpest": "Ukjent for VIPS-databasen", + "observation.unregisteredpest": "Annet (Finnes ikke i VIPS-databasen)", "photo.label.takephoto": "Ta bilde", "photo.label.selectphoto": "Velg bilde", "photo.modal.deleteprompt": "Bildet vil bli slettet", @@ -35,7 +35,7 @@ "map.link.OK.label": "OK", "map.link.cancel.label": "Avbryt", "mapobservation.label.selectPOI": "Velg et sted", - "mapobservation.label.noPOIselected": "Sted ikke valgt", + "mapobservation.label.noPOIselected": "Velg et forhåndsdefinert sted", "mapPOI.poiName.label": "Stedsnavn", "mapPOI.modal.label.saveprompt": "Lagre informasjon for", "mapPOI.modal.label.pleasechoose": "Vennligst velg", @@ -49,6 +49,7 @@ "Weather station": "Målestasjon", "places.search.label": "Søk", "placeslist.heading": "Mine steder", + "placeslist.explanation" : "\"Steder\" er forhåndsdefinerte punkter med eget navn. Kjekt å bruke hvis man skal legge inn flere observasjoner over tid på samme sted. Klikk på forstørrelsesikonet for å legge inn en observasjon på dette stedet", "crop.category.empty.alert": "For å kunne registrere observasjoner, må du først velge de kulturgruppene du ønsker å jobbe med", "cropcategory": "Kulturgrupper", "alert.header.label": "!! ADVARSEL !!",