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

View File

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

View File

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

View File

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