From 3197ec12a5ffc22d850a67a463d2447e3a7cf99a Mon Sep 17 00:00:00 2001 From: Kasen IO Date: Fri, 24 Apr 2020 02:52:05 -0400 Subject: [PATCH] Basic folder moving functionality, missing safeguards. --- scripts/system/inventory/src/App.vue | 163 ++++++++++++------ .../inventory/src/components/ItemIterator.vue | 2 +- scripts/system/inventory/src/plugins/store.js | 1 + 3 files changed, 111 insertions(+), 55 deletions(-) diff --git a/scripts/system/inventory/src/App.vue b/scripts/system/inventory/src/App.vue index 369274c921..05575a3c62 100644 --- a/scripts/system/inventory/src/App.vue +++ b/scripts/system/inventory/src/App.vue @@ -255,6 +255,16 @@ :rules="[v => !!v || 'Name is required.']" required > + + @@ -272,7 +282,7 @@ color="blue" class="px-3" :disabled="!$store.state.editFolderDialog.valid" - @click="editFolderDialogStore.show = false; editFolder($store.state.editFolderDialog.uuid);" + @click="editFolderDialogStore.show = false; editFolder($store.state.editFolderDialog.data.uuid);" > Done @@ -643,13 +653,14 @@ export default { { "hasChildren": true, "name": "Test Folder", + "folder": "No Folder", "items": [ { "hasChildren": false, "type": "script", "name": "TESTFOLDERSCRIPT", "url": "https://googfdafsgaergale.com/vr.js", - "folder": "No Folder", + "folder": "Test Folder", "uuid": "54hgfhgf25fdfadf4354353", }, { @@ -657,19 +668,20 @@ export default { "type": "script", "name": "FOLDERSCRIPT2", "url": "https://googfdafsgaergale.com/vr.js", - "folder": "No Folder", + "folder": "Test Folder", "uuid": "54hgfhgf25ffdafddfadf4354353", }, { "hasChildren": true, "name": "FolderWithinAFolder", + "folder": "Test Folder", "items": [ { "hasChildren": false, "type": "script", "name": "inception1", "url": "https://googfdafsgaergale.com/vr.js", - "folder": "No Folder", + "folder": "FolderWithinAFolder", "uuid": "54hgfhgf25fdfadeqwqeqf4354353", }, { @@ -677,7 +689,7 @@ export default { "type": "script", "name": "123what", "url": "https://googfdafsgaergale.com/vr.js", - "folder": "No Folder", + "folder": "FolderWithinAFolder", "uuid": "54hgfhgf25ffdafdWDQDdsadasQWWQdfadf4354353", }, { @@ -685,7 +697,7 @@ export default { "type": "script", "name": "inception432", "url": "https://googfdafsgaergale.com/vr.js", - "folder": "No Folder", + "folder": "FolderWithinAFolder", "uuid": "54hgfhgf25ffdafdWDQDQWWQdfadf4354353", }, ], @@ -842,7 +854,7 @@ export default { this.items.push(itemToPush); if (folder !== null && folder !== "No Folder") { - this.moveItemToFolder(uuidToUse, folder); + this.moveItem(uuidToUse, folder); } }, pushFolderToItems: function(name) { @@ -909,11 +921,19 @@ export default { this.pushFolderToItems(name); }, editFolder: function(uuid) { - for (var i = 0; i < this.items.length; i++) { - if (this.items[i].uuid == uuid) { - this.items[i].name = this.editFolderDialog.data.name; - - return; + var findFolder = this.searchForItem(uuid); + + if (findFolder) { + findFolder.returnedItem.name = this.$store.state.editFolderDialog.data.name; + + if (this.$store.state.editFolderDialog.data.folder !== null && this.$store.state.editFolderDialog.data.folder !== "No Change") { + if (findFolder.returnedItem.folder !== this.$store.state.editFolderDialog.data.folder && this.$store.state.editFolderDialog.data.folder !== "No Folder") { + console.info("This folder?", this.$store.state.editFolderDialog.data.folder); + this.moveFolder(uuid, this.$store.state.editFolderDialog.data.folder); + } else if (this.$store.state.editFolderDialog.data.folder === "No Folder") { + console.info("This folder TOP?", this.$store.state.editFolderDialog.data.folder); + this.moveFolder(uuid, "top"); + } } } }, @@ -988,9 +1008,9 @@ export default { if (this.$store.state.editDialog.data.folder !== null) { if (folderName !== this.$store.state.editDialog.data.folder && this.$store.state.editDialog.data.folder !== "No Folder") { - this.moveItemToFolder(uuid, this.$store.state.editDialog.data.folder); + this.moveItem(uuid, this.$store.state.editDialog.data.folder); } else if (folderName === "No Folder") { - this.moveItemToTop(uuid); + this.moveItem(uuid, "top"); } } @@ -1111,54 +1131,79 @@ export default { this.folderList = combinedArray; } }, - moveItemToFolder: function(uuid, folderUUID) { - // This function is used to take an item one level deep, do not use it for any other purposes and check beforehand if you need to do this. - var itemToPush = { - "hasChildren": false, - 'type': null, - 'name': null, - 'folder': null, - 'url': null, - 'uuid': uuid, - }; - + moveItem: function(uuid, folderUUID) { var findItem = this.searchForItem(uuid); - itemToPush.type = findItem.returnedItem.type; - itemToPush.name = findItem.returnedItem.name; - itemToPush.url = findItem.returnedItem.url; + if (folderUUID === "top") { + // Remove the old item before placing down the copy, we already got the attributes that we had wanted. + this.removeItem(uuid); + + this.pushToItems( + findItem.returnedItem.type, + findItem.returnedItem.name, + "No Folder", + findItem.returnedItem.url, + uuid + ); + + } else { + + var itemToPush = { + "hasChildren": false, + 'type': null, + 'name': null, + 'folder': null, + 'url': null, + 'uuid': uuid, + }; - // Get the folder UUID. - for (var i = 0; i < this.folderList.length; i++) { - if (this.folderList[i].uuid === folderUUID) { - itemToPush.folder = this.folderList[i].name; + itemToPush.type = findItem.returnedItem.type; + itemToPush.name = findItem.returnedItem.name; + itemToPush.url = findItem.returnedItem.url; + + // Get the folder UUID. + for (var i = 0; i < this.folderList.length; i++) { + if (this.folderList[i].uuid === folderUUID) { + itemToPush.folder = this.folderList[i].name; + } + } + + // Remove the old item before placing down the copy, we already got the attributes that we had wanted. + this.removeItem(uuid); + + // Find that folder in our main items array. + var findFolder = this.searchForItem(folderUUID); + + if (findFolder) { + findFolder.returnedItem.items.push(itemToPush); } } - - // Remove the old item before placing down the copy, we already got the attributes that we had wanted. - this.removeItem(uuid); - // Find that folder in our main items array. - var findFolder = this.searchForItem(folderUUID); - - if (findFolder) { - findFolder.returnedItem.items.push(itemToPush); - } - }, - moveItemToTop: function(uuid) { - var findItem = this.searchForItem(uuid); - - // Remove the old item before placing down the copy, we already got the attributes that we had wanted. - this.removeItem(uuid); + moveFolder: function(uuid, parentFolderUUID) { + var findFolder = this.searchForItem(uuid); + console.info("WHAT", parentFolderUUID); + if (parentFolderUUID === "top") { + // Remove the old item before placing down the copy, we already got the attributes that we had wanted. + this.removeItem(uuid); + + findFolder.returnedItem.folder = "No Folder"; - this.pushToItems( - findItem.returnedItem.type, - findItem.returnedItem.name, - "No Folder", - findItem.returnedItem.url, - uuid - ); + this.items.push(findFolder.returnedItem); + + } else { + // Find the parent folder. + var findParentFolder = this.searchForItem(parentFolderUUID); + console.info("Going to push...", findFolder.returnedItem); + console.info("Into...", findParentFolder.returnedItem); + if (findParentFolder) { + // Remove the old item before placing down the copy, we already got the attributes that we had wanted. + this.removeItem(uuid); + + findFolder.returnedItem.folder = findParentFolder.name; + findParentFolder.returnedItem.items.push(findFolder.returnedItem); + } + } }, searchForItem: function(uuid) { var foundItem = this.recursiveSingularSearch(uuid, this.items); @@ -1286,6 +1331,9 @@ export default { }); }, }, + editFolderDialogShow: function() { + return this.$store.state.editFolderDialog.show; + }, createFolderDialogStore: { get() { return this.$store.state.createFolderDialog; @@ -1369,6 +1417,13 @@ export default { this.getFolderList('edit'); } } + }, + editFolderDialogShow: { + handler: function(newVal) { + if (newVal === true) { + this.getFolderList('edit'); + } + } } } }; diff --git a/scripts/system/inventory/src/components/ItemIterator.vue b/scripts/system/inventory/src/components/ItemIterator.vue index 5350f7e8f6..a19e4b1814 100644 --- a/scripts/system/inventory/src/components/ItemIterator.vue +++ b/scripts/system/inventory/src/components/ItemIterator.vue @@ -133,7 +133,7 @@ diff --git a/scripts/system/inventory/src/plugins/store.js b/scripts/system/inventory/src/plugins/store.js index d10ffc75f2..c7e8b2ccc6 100644 --- a/scripts/system/inventory/src/plugins/store.js +++ b/scripts/system/inventory/src/plugins/store.js @@ -101,6 +101,7 @@ export const store = new Vuex.Store({ uuid: null, // data: { "name": null, + "folder": null, }, }, receiveDialog: {