Folder recursion safeguards established.

This commit is contained in:
Kasen IO 2020-04-24 03:16:31 -04:00
parent 3197ec12a5
commit d343589d16
2 changed files with 35 additions and 11 deletions

View file

@ -1104,6 +1104,9 @@ export default {
} }
}, },
getFolderList: function(request) { getFolderList: function(request) {
var generateList;
this.recursiveFolderHoldingList = []; // Clear that list before we do anything.
if (request == "edit") { if (request == "edit") {
this.folderList = [ this.folderList = [
{ {
@ -1115,6 +1118,9 @@ export default {
"uuid": "No Folder" "uuid": "No Folder"
}, },
]; ];
generateList = this.recursiveFolderPopulate(this.items, true, null);
} else if (request == "add") { } else if (request == "add") {
this.folderList = [ this.folderList = [
{ {
@ -1122,10 +1128,24 @@ export default {
"uuid": "No Folder" "uuid": "No Folder"
}, },
]; ];
generateList = this.recursiveFolderPopulate(this.items, true, null);
} else if (request == "editFolder") {
this.folderList = [
{
"name": "No Change",
"uuid": "No Change"
},
{
"name": "No Folder",
"uuid": "No Folder"
},
];
generateList = this.recursiveFolderPopulate(this.items, true, this.$store.state.editFolderDialog.data.uuid);
} }
var generateList = this.recursiveFolderPopulate(this.items, true);
if (generateList) { if (generateList) {
var combinedArray = this.folderList.concat(generateList); var combinedArray = this.folderList.concat(generateList);
this.folderList = combinedArray; this.folderList = combinedArray;
@ -1236,15 +1256,19 @@ export default {
return null; return null;
}, },
recursiveFolderPopulate: function(indexToSearch, firstIteration) { recursiveFolderPopulate: function(indexToSearch, firstIteration, avoidFolder) {
console.info(JSON.stringify(this.folderList));
for (var i = 0; i < indexToSearch.length; i++) { for (var i = 0; i < indexToSearch.length; i++) {
if (Object.prototype.hasOwnProperty.call(indexToSearch[i], "items") && indexToSearch[i].items.length > 0) { if (Object.prototype.hasOwnProperty.call(indexToSearch[i], "items") && indexToSearch[i].items.length > 0) {
this.recursiveFolderHoldingList.push({ // We want to avoid adding the folder itself and also any child folders it may have, putting a folder within its child folder will nuke it.
"name": indexToSearch[i].name, if (avoidFolder !== indexToSearch[i].uuid) {
"uuid": indexToSearch[i].uuid, this.recursiveFolderHoldingList.push({
}); "name": indexToSearch[i].name,
"uuid": indexToSearch[i].uuid,
this.recursiveFolderPopulate(indexToSearch[i].items, false); });
this.recursiveFolderPopulate(indexToSearch[i].items, false, avoidFolder);
}
} }
} }
@ -1421,7 +1445,7 @@ export default {
editFolderDialogShow: { editFolderDialogShow: {
handler: function(newVal) { handler: function(newVal) {
if (newVal === true) { if (newVal === true) {
this.getFolderList('edit'); this.getFolderList('editFolder');
} }
} }
} }

View file

@ -132,9 +132,9 @@
<div class="text-center my-2"> <div class="text-center my-2">
<v-btn medium tile color="purple" class="mx-1 folder-button" <v-btn medium tile color="purple" class="mx-1 folder-button"
@click=" @click="
editFolderDialogStore.show = true;
editFolderDialogStore.data.uuid = item.uuid; editFolderDialogStore.data.uuid = item.uuid;
editFolderDialogStore.data.name = item.name; editFolderDialogStore.data.name = item.name;
editFolderDialogStore.show = true;
" "
> >
<v-icon>mdi-pencil</v-icon> <v-icon>mdi-pencil</v-icon>