Trees can now do selection

This commit is contained in:
Stefan Zermatten
2019-08-01 12:03:15 +02:00
parent 549418b395
commit 4ccf999fc7
4 changed files with 63 additions and 14 deletions

View File

@@ -1,18 +1,41 @@
<template lang="html"> <template lang="html">
<div :class="!hasChildren ? 'empty' : null" :data-id="node._id"> <div
<div class="layout row align-center"> class="tree-node"
:class="!hasChildren ? 'empty' : null"
:data-id="node._id"
>
<div
class="layout row align-center justify-start tree-node-title"
style="cursor: pointer;"
:class="selected && 'primary--text'"
@click.stop="$emit('selected', node._id)"
>
<v-btn <v-btn
small icon small icon
:class="showExpanded ? 'rotate-90' : null" :class="showExpanded ? 'rotate-90' : null"
@click="expanded = !expanded" @click.stop="expanded = !expanded"
:disabled="!hasChildren && !organize" :disabled="!hasChildren && !organize"
> >
<v-icon v-if="hasChildren || organize">chevron_right</v-icon> <v-icon v-if="hasChildren || organize">chevron_right</v-icon>
</v-btn> </v-btn>
<v-icon class="handle mr-2" v-if="organize" :disabled="expanded">drag_handle</v-icon> <div
<div class="layout row center" style="align-items: center"> class="layout row align-center justify-start"
<v-icon v-if="node.type" class="mr-2">{{icon(node.type)}}</v-icon> style="flex-grow: 0;"
{{node && node.name}} >
<v-icon
class="handle mr-2"
v-if="organize"
:class="selected && 'primary--text'"
:disabled="expanded"
>drag_handle</v-icon>
<v-icon
v-if="node.type"
class="mr-2"
:class="selected && 'primary--text'"
>{{icon(node.type)}}</v-icon>
<div class="text-no-wrap text-truncate">
{{node && node.name}}
</div>
</div> </div>
</div> </div>
<v-expand-transition> <v-expand-transition>
@@ -22,8 +45,10 @@
:children="computedChildren" :children="computedChildren"
:group="group" :group="group"
:organize="organize" :organize="organize"
:selected-node-id="selectedNodeId"
@reordered="e => $emit('reordered', e)" @reordered="e => $emit('reordered', e)"
@reorganized="e => $emit('reorganized', e)" @reorganized="e => $emit('reorganized', e)"
@selected="e => $emit('selected', e)"
/> />
</div> </div>
</v-expand-transition> </v-expand-transition>
@@ -52,6 +77,8 @@
organize: Boolean, organize: Boolean,
children: Array, children: Array,
getChildren: Function, getChildren: Function,
selectedNodeId: String,
selected: Boolean,
}, },
computed: { computed: {
hasChildren(){ hasChildren(){
@@ -73,7 +100,6 @@
}, },
methods: { methods: {
icon(type){ icon(type){
console.log({icon: PROPERTY_ICONS[type],PROPERTY_ICONS})
return PROPERTY_ICONS[type]; return PROPERTY_ICONS[type];
}, },
} }
@@ -102,7 +128,10 @@
opacity: 0.5; opacity: 0.5;
background: #c8ebfb; background: #c8ebfb;
} }
.v-icon--disabled { .v-icon.v-icon--disabled {
opacity: 0; opacity: 0;
} }
.theme--light .tree-node-title:hover {
background: rgba(0,0,0,.04);
}
</style> </style>

View File

@@ -1,7 +1,7 @@
<template lang="html"> <template lang="html">
<draggable <draggable
:value="children" :value="children"
class="drag-area layout column" class="drag-area"
@change="change" @change="change"
:group="group" :group="group"
:animation="200" :animation="200"
@@ -10,14 +10,17 @@
handle=".handle" handle=".handle"
> >
<tree-node <tree-node
class="item"
v-for="child in children" v-for="child in children"
:node="child.node" :node="child.node"
:children="child.children" :children="child.children"
:group="group" :group="group"
:key="child.node && (child.node._id || child.node.name)" :key="child.node._id"
:selected-node-id="selectedNodeId"
:selected="selectedNodeId === child.node._id"
:organize="organize" :organize="organize"
:lazy="lazy" :lazy="lazy"
class="item" @selected="e => $emit('selected', e)"
@reordered="e => $emit('reordered', e)" @reordered="e => $emit('reordered', e)"
@reorganized="e => $emit('reorganized', e)" @reorganized="e => $emit('reorganized', e)"
@dragstart.native="e => e.dataTransfer.setData('cow', child.node && child.node.name)" @dragstart.native="e => e.dataTransfer.setData('cow', child.node && child.node.name)"
@@ -45,6 +48,7 @@
type: Array, type: Array,
required: true, required: true,
}, },
selectedNodeId: String,
}, },
computed: { computed: {
hasChildren(){ hasChildren(){

View File

@@ -1,10 +1,12 @@
<template lang="html"> <template lang="html">
<v-card-text> <v-card-text style="width: initial; max-width: 50%; min-width: 320px;">
<tree-node-list <tree-node-list
v-if="libraryChildren" v-if="libraryChildren"
:children="libraryChildren" :children="libraryChildren"
:group="library && library._id" :group="library && library._id"
:organize="organize" :organize="organize"
:selected-node-id="selectedNodeId"
@selected="e => $emit('selected', e)"
@reordered="reordered" @reordered="reordered"
@reorganized="reorganized" @reorganized="reorganized"
/> />
@@ -24,6 +26,7 @@
props: { props: {
libraryId: String, libraryId: String,
organize: Boolean, organize: Boolean,
selectedNodeId: String,
}, },
meteor: { meteor: {
$subscribe: { $subscribe: {

View File

@@ -13,11 +13,19 @@
</v-btn> </v-btn>
</v-btn-toggle> </v-btn-toggle>
</template> </template>
<v-card class="ma-4"> <v-card class="ma-4 layout row">
<library-contents-container <library-contents-container
:library-id="$route.params.id" :library-id="$route.params.id"
:organize="organize" :organize="organize"
@selected="e => selected = e"
:selected-node-id="selected"
/> />
<v-divider vertical/>
<v-card-text
style="flex-grow: 1;"
>
<pre>{{selectedNode}}</pre>
</v-card-text>
</v-card> </v-card>
<v-btn fixed fab bottom right <v-btn fixed fab bottom right
color="primary" color="primary"
@@ -43,6 +51,7 @@
}, },
data(){ return { data(){ return {
organize: false, organize: false,
selected: undefined,
};}, };},
methods: { methods: {
insertLibraryNode(){ insertLibraryNode(){
@@ -70,6 +79,10 @@
}, },
library(){ library(){
return Libraries.findOne(this.$route.params.id); return Libraries.findOne(this.$route.params.id);
},
selectedNode(){
let node = LibraryNodes.findOne(this.selected);
return JSON.stringify(node, null, 2);
} }
} }
}; };