From 60c193fe23ef11d246169e1db94f221316071261 Mon Sep 17 00:00:00 2001 From: Irving Date: Thu, 7 Oct 2021 01:23:44 -0400 Subject: [PATCH] Fixed sorting under Folder View in Script Manager --- src/components/scripts/ScriptManager.vue | 34 +++++++++++++++++------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/src/components/scripts/ScriptManager.vue b/src/components/scripts/ScriptManager.vue index 92ffbf1..14a9d76 100644 --- a/src/components/scripts/ScriptManager.vue +++ b/src/components/scripts/ScriptManager.vue @@ -489,9 +489,24 @@ export default { // add Unassigned category categoriesTemp.push("Unassigned"); - const sorted = categoriesTemp.sort(); + const sortedCategories = categoriesTemp.sort(); - sorted.forEach(category => { + // sort by name property + const sortedScripts = scriptsTemp.sort(function (a, b) { + const nameA = a.name.toUpperCase(); + const nameB = b.name.toUpperCase(); + + if (nameA < nameB) { + return -1; + } + if (nameA > nameB) { + return 1; + } + // names must be equal + return 0; + }); + + sortedCategories.forEach(category => { let temp = { icon: "folder", iconColor: "yellow-9", @@ -500,13 +515,12 @@ export default { id: category, children: [], }; - for (var i = scriptsTemp.length - 1; i >= 0; i--) { - if (scriptsTemp[i].category === category) { - temp.children.push({ label: scriptsTemp[i].name, header: "script", ...scriptsTemp[i] }); - scriptsTemp.splice(i, 1); - } else if (category === "Unassigned" && !scriptsTemp[i].category) { - temp.children.push({ label: scriptsTemp[i].name, header: "script", ...scriptsTemp[i] }); - scriptsTemp.splice(i, 1); + + for (let x = 0; x < sortedScripts.length; x++) { + if (sortedScripts[x].category === category) { + temp.children.push({ label: sortedScripts[x].name, header: "script", ...sortedScripts[x] }); + } else if (category === "Unassigned" && !sortedScripts[x].category) { + temp.children.push({ label: sortedScripts[x].name, header: "script", ...sortedScripts[x] }); } } @@ -633,4 +647,4 @@ export default { }; }, }; - \ No newline at end of file + \ No newline at end of file