Skip to content

Commit

Permalink
Hide Project bookmarks section when no bookmarks is set on QGIS Proje…
Browse files Browse the repository at this point in the history
…ct (ref: left sidebar menu items) (#384)

* Hide Project bookmark sub menu if no bookmarks is set on QGIS project

* add computed property `hasProjectbookmarks`

---------

Co-authored-by: Raruto <Raruto@users.noreply.github.com>
  • Loading branch information
volterra79 and Raruto authored Mar 22, 2023
1 parent c6b8053 commit 5157386
Showing 1 changed file with 58 additions and 28 deletions.
86 changes: 58 additions & 28 deletions src/components/SpatialBookMarks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
class="treeview-menu g3w-spatial-bookmarks menu-items"
:class="{'g3w-tools': !showaddform}"
>

<!-- ADD NEW BOOKMARK (FORM) -->
<template v-if="showaddform">

<li>
Expand All @@ -26,12 +28,8 @@
</div>

<helpdiv message="sdk.spatialbookmarks.helptext"/>
<div
class="container add-bookmark-input"
style="padding: 5px; width: 100%"
>
<input-text
:state="addbookmarkinput"/>
<div class="container add-bookmark-input" style="padding: 5px; width: 100%">
<input-text :state="addbookmarkinput" />
</div>
<div style="margin-top: 5px;">
<button
Expand All @@ -42,16 +40,19 @@
</div>
</li>
</template>

<!-- BOOKMARS LIST -->
<template v-else>
<div class="content-bookmarks">
<span v-t="'sdk.spatialbookmarks.sections.project.title'"></span>
</div>
<template v-for="bookmark in project.bookmarks">
<spatial-book-mark-group
v-if="bookmark.nodes"
:group="bookmark"/>
<spatial-book-mark-item v-else :bookmark="bookmark"/>
<template v-if="hasProjectbookmarks">
<div class="content-bookmarks">
<span v-t="'sdk.spatialbookmarks.sections.project.title'"></span>
</div>
<template v-for="bookmark in project.bookmarks">
<spatial-book-mark-group v-if="bookmark.nodes" :group="bookmark" />
<spatial-book-mark-item v-else :bookmark="bookmark" />
</template>
</template>

<div
class="content-bookmarks"
style="display: flex; justify-content: space-between; align-items: center; margin-top: 10px;">
Expand All @@ -70,15 +71,15 @@
</span>
</div>
<spatial-book-mark-item
@remove-bookmark="removeBookMark"
v-for="bookmark in user.bookmarks"
@remove-bookmark="removeBookMark"
:bookmark="bookmark"/>
</template>
</ul>
</template>

<script>
import {LOCAL_ITEM_IDS} from 'app/constant';
import { LOCAL_ITEM_IDS } from 'app/constant';
import GUI from 'services/gui';
import ApplicationService from 'services/application';
import ProjectsRegistry from 'store/projects';
Expand All @@ -93,17 +94,27 @@
const SPATIAL_BOOKMARKS_LOCALITEMS = ApplicationService.getLocalItem(LOCAL_ITEM_IDS.SPATIALBOOKMARKS.id);

export default {

components: {
SpatialBookMarkGroup,
SpatialBookMarkItem,
InputText,
},

data() {
if ("undefined" === typeof SPATIAL_BOOKMARKS_LOCALITEMS[ProjectsRegistry.getCurrentProject().getId()]) {
SPATIAL_BOOKMARKS_LOCALITEMS[ProjectsRegistry.getCurrentProject().getId()] = []
const project = ProjectsRegistry.getCurrentProject();

if ("undefined" === typeof SPATIAL_BOOKMARKS_LOCALITEMS[project.getId()]) {
SPATIAL_BOOKMARKS_LOCALITEMS[project.getId()] = []
}

return {
showaddform: false, // property to show or not add dialog menu

/**
* true = show add dialog menu
*/
showaddform: false,

/** bookmark is an array of Object with follow structure:
* {
* name: <String> Unique identifier of spatial bootmark,
Expand All @@ -113,13 +124,13 @@
*/

project: {
show: true,
bookmarks: ProjectsRegistry.getCurrentProject().getSpatialBookmarks()
bookmarks: project.getSpatialBookmarks() || []
},

user: {
show: true,
bookmarks: SPATIAL_BOOKMARKS_LOCALITEMS[ProjectsRegistry.getCurrentProject().getId()]
bookmarks: SPATIAL_BOOKMARKS_LOCALITEMS[project.getId()]
},

addbookmarkinput: {
name: 'add-bookmark',
label: t('sdk.spatialbookmarks.input.name'),
Expand All @@ -136,10 +147,21 @@
required: true
}
}

}
},

computed: {

hasProjectbookmarks() {
return this.project.bookmarks.length > 0;
}

},

methods: {
addBookMark(){

addBookMark() {
this.user.bookmarks.push({
id: uniqueId(),
name: this.addbookmarkinput.value,
Expand All @@ -152,28 +174,36 @@
this.saveUserBookMarks();
this.showaddform = false;
},
removeBookMark(id){

removeBookMark(id) {
this.user.bookmarks = this.user.bookmarks.filter(bookmark => bookmark.id !== id);
this.saveUserBookMarks();
},
saveUserBookMarks(){

saveUserBookMarks() {
SPATIAL_BOOKMARKS_LOCALITEMS[ProjectsRegistry.getCurrentProject().getId()] = this.user.bookmarks;
ApplicationService.setLocalItem({
id: LOCAL_ITEM_IDS.SPATIALBOOKMARKS.id,
data: SPATIAL_BOOKMARKS_LOCALITEMS
});
},
showAddForm(){

showAddForm() {
this.addbookmarkinput.value = null;
this.showaddform = true;
}

},
created(){

created() {
this.$on('close', ()=>{
this.showaddform = false
})
},

/** @FIXME remove unusued method ? */
async mounted() {}

};
</script>

Expand Down

0 comments on commit 5157386

Please sign in to comment.