Folder sort and folder list generation fixed.

This commit is contained in:
Kasen IO 2020-04-23 23:23:53 -04:00
parent 14823d84d6
commit 14689bea87
3 changed files with 80 additions and 40 deletions

View file

@ -672,6 +672,14 @@ export default {
"folder": "No Folder", "folder": "No Folder",
"uuid": "54hgfhgf25fdfadeqwqeqf4354353", "uuid": "54hgfhgf25fdfadeqwqeqf4354353",
}, },
{
"hasChildren": false,
"type": "script",
"name": "123what",
"url": "https://googfdafsgaergale.com/vr.js",
"folder": "No Folder",
"uuid": "54hgfhgf25ffdafdWDQDdsadasQWWQdfadf4354353",
},
{ {
"hasChildren": false, "hasChildren": false,
"type": "script", "type": "script",
@ -1102,10 +1110,11 @@ export default {
]; ];
} }
var generateList = this.recursiveFolderPopulate(); var generateList = this.recursiveFolderPopulate(this.items, true);
if (generateList) { if (generateList) {
this.folderList.push(generateList); var combinedArray = this.folderList.concat(generateList);
this.folderList = combinedArray;
} }
}, },
moveItemToFolder: function(uuid, folderUUID) { moveItemToFolder: function(uuid, folderUUID) {
@ -1157,9 +1166,10 @@ export default {
); );
}, },
sortFolder: function(uuid) { sortFolder: function(uuid) {
for (var i = 0; i < this.items.length; i++) { var findFolder = this.searchForItem(uuid);
if (this.items[i].uuid == uuid) {
this.items[i].items.sort(function(a, b) { if (findFolder) {
findFolder.returnedItem.items.sort(function(a, b) {
var nameA = a.name.toUpperCase(); // ignore upper and lowercase var nameA = a.name.toUpperCase(); // ignore upper and lowercase
var nameB = b.name.toUpperCase(); // ignore upper and lowercase var nameB = b.name.toUpperCase(); // ignore upper and lowercase
if (nameA < nameB) { if (nameA < nameB) {
@ -1173,7 +1183,6 @@ export default {
return 0; return 0;
}); });
} }
}
}, },
searchForItem: function(uuid) { searchForItem: function(uuid) {
var foundItem = this.recursiveSingularSearch(uuid, this.items); var foundItem = this.recursiveSingularSearch(uuid, this.items);
@ -1196,20 +1205,20 @@ export default {
"parentArray": indexToSearch, "parentArray": indexToSearch,
} }
return foundItem; return foundItem;
} else if (Object.prototype.hasOwnProperty.call(indexToSearch[i], "items") && indexToSearch[i].length > 0) { } else if (Object.prototype.hasOwnProperty.call(indexToSearch[i], "items") && indexToSearch[i].items.length > 0) {
this.recursiveSingularSearch(uuid, indexToSearch[i]); this.recursiveSingularSearch(uuid, indexToSearch[i].items);
} }
} }
}, },
recursiveFolderPopulate: function(indexToSearch, firstIteration) { recursiveFolderPopulate: function(indexToSearch, firstIteration) {
for (var i = 0; i < indexToSearch.length; i++) { for (var i = 0; i < indexToSearch.length; i++) {
if (Object.prototype.hasOwnProperty.call(this.items[i], "hasChildren")) { if (Object.prototype.hasOwnProperty.call(indexToSearch[i], "items") && indexToSearch[i].items.length > 0) {
this.recursiveFolderHoldingList.push({ this.recursiveFolderHoldingList.push({
"name": indexToSearch[i].name, "name": indexToSearch[i].name,
"uuid": indexToSearch[i].uuid, "uuid": indexToSearch[i].uuid,
}); });
this.recursiveFolderPopulate(indexToSearch[i], false); this.recursiveFolderPopulate(indexToSearch[i].items, false);
} }
} }
@ -1352,10 +1361,7 @@ export default {
with: value with: value
}); });
}, },
}, }
triggerSortFolder: function () {
return this.$store.state.triggerSortFolder;
},
}, },
watch: { watch: {
// Whenever the item list changes, this will notice and then send it to the script to be saved. // Whenever the item list changes, this will notice and then send it to the script to be saved.
@ -1364,7 +1370,8 @@ export default {
handler() { handler() {
this.sendInventory(); this.sendInventory();
} }
}, // Whenever the settings change, we want to save that state. },
// Whenever the settings change, we want to save that state.
settings: { settings: {
deep: true, deep: true,
handler: function(newVal) { handler: function(newVal) {
@ -1381,13 +1388,8 @@ export default {
this.getFolderList('edit'); this.getFolderList('edit');
} }
} }
},
triggerSortFolder: {
handler: function(newVal) {
this.sortFolder(newVal);
} }
} }
},
}; };
</script> </script>

View file

@ -148,7 +148,7 @@
<v-icon>mdi-minus</v-icon> <v-icon>mdi-minus</v-icon>
</v-btn> </v-btn>
<v-btn medium tile color="blue" class="mx-1 folder-button" <v-btn medium tile color="blue" class="mx-1 folder-button"
@click="triggerSortFolder(item.uuid);" @click="sortFolder(item.uuid);"
> >
<v-icon>mdi-ab-testing</v-icon> <v-icon>mdi-ab-testing</v-icon>
</v-btn> </v-btn>
@ -313,12 +313,51 @@ export default {
return returnedItemIconColor; return returnedItemIconColor;
}, },
triggerSortFolder: function(uuid) { sortFolder: function(uuid) {
this.$store.commit('mutate', { var findFolder = this.searchForItem(uuid);
property: 'triggerSortFolder',
with: uuid if (findFolder) {
findFolder.returnedItem.items.sort(function(a, b) {
var nameA = a.name.toUpperCase(); // ignore upper and lowercase
var nameB = b.name.toUpperCase(); // ignore upper and lowercase
if (nameA < nameB) {
return -1;
}
if (nameA > nameB) {
return 1;
}
// names must be equal
return 0;
}); });
}
}, },
searchForItem: function(uuid) {
var foundItem = this.recursiveSingularSearch(uuid, this.itemsForIterator);
if (foundItem) {
return {
"returnedItem": foundItem.returnedItem,
"iteration": foundItem.iteration,
"parentArray": foundItem.parentArray,
"itemUUID": uuid,
}
}
},
recursiveSingularSearch: function(uuid, indexToSearch) {
for (var i = 0; i < indexToSearch.length; i++) {
if (indexToSearch[i].uuid == uuid) {
var foundItem = {
"returnedItem": indexToSearch[i],
"iteration": i,
"parentArray": indexToSearch,
}
return foundItem;
} else if (Object.prototype.hasOwnProperty.call(indexToSearch[i], "items") && indexToSearch[i].length > 0) {
this.recursiveSingularSearch(uuid, indexToSearch[i]);
}
}
}
} }
}; };
</script> </script>

View file

@ -123,7 +123,6 @@ export const store = new Vuex.Store({
"recipient": null, "recipient": null,
} }
}, },
triggerSortFolder: null,
}, },
mutations: { mutations: {
mutate (state, payload) { mutate (state, payload) {