From 152677b02366a00800ed364f0899e6be07f1e1ea Mon Sep 17 00:00:00 2001 From: Stefan Zermatten Date: Fri, 9 Apr 2021 12:36:14 +0200 Subject: [PATCH] Library nodes are now smarter about where in the tree they are inserted based on the currently selected node --- app/imports/ui/components/tree/TreeNode.vue | 2 +- .../ui/library/InsertLibraryNodeButton.vue | 84 +++++++++++++------ app/imports/ui/library/LibraryAndNode.vue | 4 + app/imports/ui/library/LibraryBrowser.vue | 42 +++++----- app/imports/ui/library/LibraryNodeDialog.vue | 10 ++- app/package-lock.json | 10 +-- 6 files changed, 94 insertions(+), 58 deletions(-) diff --git a/app/imports/ui/components/tree/TreeNode.vue b/app/imports/ui/components/tree/TreeNode.vue index 9022f898..321347df 100644 --- a/app/imports/ui/components/tree/TreeNode.vue +++ b/app/imports/ui/components/tree/TreeNode.vue @@ -100,7 +100,7 @@ }}, computed: { hasChildren(){ - return this.children && this.children.length || this.lazy && !this.expanded; + return this.children && !!this.children.length || this.lazy && !this.expanded; }, showExpanded(){ return this.expanded && (this.organize || this.hasChildren) diff --git a/app/imports/ui/library/InsertLibraryNodeButton.vue b/app/imports/ui/library/InsertLibraryNodeButton.vue index 45cf0466..a881d367 100644 --- a/app/imports/ui/library/InsertLibraryNodeButton.vue +++ b/app/imports/ui/library/InsertLibraryNodeButton.vue @@ -1,12 +1,14 @@ @@ -22,43 +24,73 @@ export default { type: String, required: true, }, - parentId: { - type: String, - default: undefined, - }, - parentCollection: { + selectedNodeId: { type: String, default: undefined, }, + fab: Boolean, }, methods: { insertLibraryNode(){ let libraryId = this.libraryId; - let tier = getUserTier(Meteor.userId()) - if (tier && tier.paidBenefits){ - let parentRef = { - id: this.parentId || libraryId, - collection: this.parentCollection || 'libraries', - }; - let {ancestors} = getAncestry({parentRef}); - this.$store.commit('pushDialogStack', { - component: 'library-node-creation-dialog', - elementId: 'insert-library-node-button', - callback(libraryNode){ - if (!libraryNode) return; - libraryNode.parent = parentRef; - libraryNode.ancestors = ancestors; - setDocToLastOrder({collection: LibraryNodes, doc: libraryNode}); - let libraryNodeId = insertNode.call(libraryNode); - return `tree-node-${libraryNodeId}`; - } - }); - } else { + + // Check tier has paid benefits + let tier = getUserTier(Meteor.userId()); + if (!(tier && tier.paidBenefits)){ this.$store.commit('pushDialogStack', { component: 'tier-too-low-dialog', elementId: 'insert-library-node-button', }); + return; } + + // Get ancestry reference + let order, parentRef; + let selectedComponent = document.querySelector( + `[data-id="tree-node-${this.selectedNodeId}"]` + ); + if (selectedComponent){ + let vueInstance = selectedComponent.__vue__.$parent; + if (vueInstance.showExpanded){ + parentRef = { + id: this.selectedNodeId, + collection: 'libraryNodes', + }; + } else { + parentRef = vueInstance.node.parent; + order = vueInstance.node.order + 0.5; + } + } else { + parentRef = { + id: libraryId, + collection: 'libraries', + }; + } + let {ancestors} = getAncestry({parentRef}); + + // Insert form dialog + let that = this; + this.$store.commit('pushDialogStack', { + component: 'library-node-creation-dialog', + elementId: 'insert-library-node-button', + callback(libraryNode){ + if (!libraryNode) return; + + // Set ancestry and order + libraryNode.parent = parentRef; + libraryNode.ancestors = ancestors; + if (order){ + libraryNode.order = order; + } else { + setDocToLastOrder({collection: LibraryNodes, doc: libraryNode}); + } + + // Insert doc + let libraryNodeId = insertNode.call(libraryNode); + that.$emit('selected', libraryNodeId); + return `tree-node-${libraryNodeId}`; + } + }); }, } } diff --git a/app/imports/ui/library/LibraryAndNode.vue b/app/imports/ui/library/LibraryAndNode.vue index 559a6e72..9e6063a9 100644 --- a/app/imports/ui/library/LibraryAndNode.vue +++ b/app/imports/ui/library/LibraryAndNode.vue @@ -28,7 +28,10 @@
diff --git a/app/imports/ui/library/LibraryBrowser.vue b/app/imports/ui/library/LibraryBrowser.vue index a3bfa7b6..0af63ee8 100644 --- a/app/imports/ui/library/LibraryBrowser.vue +++ b/app/imports/ui/library/LibraryBrowser.vue @@ -23,36 +23,32 @@ + + + + arrow_forward + + - - - add - New property - - - - arrow_forward - - @@ -76,10 +72,12 @@ import LibraryContentsContainer from '/imports/ui/library/LibraryContentsContain import Libraries, { insertLibrary } from '/imports/api/library/Libraries.js'; import { getUserTier } from '/imports/api/users/patreon/tiers.js'; import { assertEditPermission } from '/imports/api/sharing/sharingPermissions.js'; +import InsertLibraryNodeButton from '/imports/ui/library/InsertLibraryNodeButton.vue'; export default { components: { LibraryContentsContainer, + InsertLibraryNodeButton, }, props: { organizeMode: Boolean, diff --git a/app/imports/ui/library/LibraryNodeDialog.vue b/app/imports/ui/library/LibraryNodeDialog.vue index b6d4f76a..03e88fec 100644 --- a/app/imports/ui/library/LibraryNodeDialog.vue +++ b/app/imports/ui/library/LibraryNodeDialog.vue @@ -71,12 +71,12 @@