2
0
mirror of https://github.com/frappe/books.git synced 2024-12-26 12:28:12 +00:00
books/ui/components/Tree/index.vue
Faris Ansari 110300005e Replace awesomplete with own component
- Add Tree View
2018-09-26 19:50:35 +05:30

54 lines
1.1 KiB
Vue

<template>
<div class="p-3 w-50" v-if="rootNode">
<tree-node :label="rootNode.label" :parentValue="''" :doctype="doctype" ref="rootNode"/>
</div>
</template>
<script>
import frappe from 'frappejs';
import TreeNode from './TreeNode';
import { setTimeout } from 'timers';
export default {
props: ['doctype'],
components: {
TreeNode,
},
data() {
return {
rootNode: null
}
},
mounted() {
setTimeout(() => {
this.$refs.rootNode.find('.tree-label').click();
}, 500);
},
async mounted() {
this.settings = frappe.getMeta(this.doctype).treeSettings;
this.rootNode = {
label: await this.settings.getRootLabel()
};
},
methods: {
async getChildren(parentValue) {
let filters = {
[this.settings.parentField]: parentValue
};
const children = await frappe.db.getAll({
doctype: this.doctype,
filters,
fields: [this.settings.parentField, 'isGroup', 'name'],
orderBy: 'name',
order: 'asc'
});
return children.map(c => {
c.label = c.name;
return c;
});
}
}
}
</script>