Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add delete button for the tree widget #69

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ For `type="tree"`, you can pass a tree with nodes and set callback for the doubl
- `node_dbclick_callback`: Function, a callback function triggered when the user double click on a node, one argument with the node object will be passed to the function
- `node_drop_callback`: Function, a callback function triggered when the user drag and drop a node, two arguments will be passed `nodes` (the ones that are being moved) and `position` (the reference node).
- `node_toggle_callback`: Function, a callback function triggered when the user toggle a node.
- `node_remove_callback`: Function, a callback function which will be called when the user try to remove an item. The function should return true if the node remove is actually performed, otherwise, the operation will be cancelled.
- `nodes`: Array, an array of node objects. One node is an object with some fixed fields, for example: `{"title": 'Item1', "isLeaf": True, "isExpanded": True}`, a node can also contain `children` which is an inner array of nodes.

**Returns**
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kaibu",
"version": "0.1.42",
"version": "0.1.43",
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
Expand Down
37 changes: 23 additions & 14 deletions src/components/widgets/TreeWidget.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
<template>
<div class="list-widget">
<!-- <p>{{ lastEvent }}</p> -->
<b-button
style="position: absolute; bottom: 0px; z-index: 1;"
v-if="
config.node_remove_callback && selectedNodes && selectedNodes.length > 0
"
@click="deleteNode()"
size="is-small"
icon-left="delete"
>Delete</b-button
>
<sl-vue-tree
style="margin-bottom: 10px;"
v-model="config.nodes"
ref="slVueTree"
:allow-multiselect="allowMultiselect"
Expand Down Expand Up @@ -59,9 +69,9 @@ export default {
},
data() {
return {
lastEvent: "No last event",
selectedNodesTitle: "",
allowMultiselect: false
allowMultiselect: false,
selectedNodes: null
};
},
created() {
Expand Down Expand Up @@ -92,14 +102,19 @@ export default {
event.stopPropagation();
const visible = !node.data || node.data.visible !== false;
slVueTree.updateNode(node.path, { data: { visible: !visible } });
this.lastEvent = `Node ${node.title} is ${
visible ? "visible" : "invisible"
} now`;
},

async deleteNode() {
if (!this.config.node_remove_callback) return;
if (await this.config.node_remove_callback(this.selectedNodes)) {
const paths = this.selectedNodes.map(node => node.path);
const slVueTree = this.$refs.slVueTree;
slVueTree.remove(paths);
this.selectedNodes = null;
}
},
async nodeSelected(nodes) {
this.selectedNodes = nodes;
this.selectedNodesTitle = nodes.map(node => node.title).join(", ");
this.lastEvent = `Select nodes: ${this.selectedNodesTitle}`;
if (this.config.node_select_callback) {
try {
this.$emit("loading", true);
Expand All @@ -111,9 +126,6 @@ export default {
},

async nodeToggled(node) {
this.lastEvent = `Node ${node.title} is ${
node.isExpanded ? "expanded" : "collapsed"
}`;
if (this.config.node_toggle_callback) {
try {
this.$emit("loading", true);
Expand All @@ -136,9 +148,6 @@ export default {
},

async nodeDropped(nodes, position) {
this.lastEvent = `Nodes: ${nodes
.map(node => node.title)
.join(", ")} are dropped ${position.placement} ${position.node.title}`;
if (this.config.node_drop_callback) {
try {
this.$emit("loading", true);
Expand Down