diff --git a/src/components/NavigationBar/ExamplesMenu.vue b/src/components/NavigationBar/ExamplesMenu.vue index 025819e7a..59f476b07 100644 --- a/src/components/NavigationBar/ExamplesMenu.vue +++ b/src/components/NavigationBar/ExamplesMenu.vue @@ -71,7 +71,7 @@ const examples = { }; function displaySwalPopupForUserExample(json, lkjgenwhikgu4ewkjn, selectedOption, SERVER, swal, workspace, toast) { - lkjgenwhikgu4ewkjn.innerHTML = `

${json.example[0].replaceAll("<", "").replaceAll("/", "").replaceAll("\\", "")}${json.example[5] == null || json.example[5] == "" ? "" : ` • `}

+ lkjgenwhikgu4ewkjn.innerHTML = `

${json.example[0].replaceAll("<", "").replaceAll("/", "").replaceAll("\\", "")}${json.example[5] == null || json.example[5] == "" ? "" : ` • `}

${json.example[6].replaceAll("\\", "").replaceAll("<", "").replaceAll(">", "").replaceAll("/", "")} ${Number(json.example[3])} @@ -393,9 +393,10 @@ ${blockCounts <= 5 ? `

Uploading ne }) /* eslint-disable */ let voteButtonSessionList = {} + let i = 0 names.forEach((name) => { voteButtonSessionList[String(name[2])] = {likes: name[8], dislikes: name[9]} - boxes += `

@@ -419,14 +420,14 @@ ${blockCounts <= 5 ? `

Uploading ne ${String(name[1])} blocks

- -
` +` + boxes; +i++ }) /* eslint-disable */ responseHTML.innerHTML = `
- + @@ -436,6 +437,17 @@ ${blockCounts <= 5 ? `

Uploading ne + +

-
@@ -592,6 +593,8 @@ fetch("${SERVER + 'api/examples/updateVotes'}", requestOptions) // console.log() // } let searchBox = document.getElementById("swal_dialog_box_searchForUserExamples") + let sortingType = document.getElementById("swal_dialog_box_sortUserExamples") + let sortingBy = "new" let caseSensitive = false let caseSensitiveButton = document.getElementById("swal_menu_CaseSensitiveUserExampleSearch") caseSensitiveButton.onclick = function () { @@ -602,6 +605,11 @@ fetch("${SERVER + 'api/examples/updateVotes'}", requestOptions) caseSensitiveButton.setAttribute("style", "background-color: Transparent;border: none;") searchBox.oninput() } + sortingType.onchange = (e) => { + sortingBy = e.target.value + console.log(sortingBy) + searchBox.oninput() + } let gridSize3 = false let gridSizeButton = document.getElementById("swal_menu_ChangeBoxSizeUserExamples") gridSizeButton.onclick = function () { @@ -623,6 +631,7 @@ fetch("${SERVER + 'api/examples/updateVotes'}", requestOptions) } let unsearchedHtml = document.getElementById("swal_user_examples_dialog_box-form_area").innerHTML searchBox.oninput = function () { + console.log("search changed") let area = document.getElementById("swal_user_examples_dialog_box-form_area") area.innerHTML = unsearchedHtml if (gridSize3) { @@ -631,6 +640,7 @@ fetch("${SERVER + 'api/examples/updateVotes'}", requestOptions) } let boxes = area.getElementsByTagName("label") let kept = boxes.length + let readyForSorting = [] for (let i = 0; i < boxes.length; i++) { let current = boxes.item(i) let name = current.getElementsByClassName("box").item(0) @@ -647,16 +657,141 @@ fetch("${SERVER + 'api/examples/updateVotes'}", requestOptions) current.setAttribute("style", "display: none") kept-- } + readyForSorting.push(current) } + console.log(kept) if (kept <= 0) { - area.innerHTML = `
+ area.innerHTML = `


No examples were found.
- +
` } + // sorting + if (kept > 0) { + console.log("sorting for", sortingBy) + const parent = area + switch (sortingBy) { + case 'new': + console.log("a") + for (let i = 0; i < boxes.length; i++) { + readyForSorting.forEach(box => { + if (String(box.getAttribute("storder")) == String(i)) { + parent.prepend(box) + } + }) + } + break; + case 'old': + console.log("b") + for (let i = 0; i < boxes.length; i++) { + readyForSorting.forEach(box => { + if (String(box.getAttribute("storder")) == String(i)) { + parent.append(box) + } + }) + } + break; + case 'liked': + console.log("c") + var likes = [] + readyForSorting.forEach(box => { + likes.push(Number(box.getAttribute("stlikes")) - Number(box.getAttribute("stdislikes"))) + }) + likes.sort((a, b) => { return b - a }) + for (let i = 0; i < likes.length; i++) { + readyForSorting.forEach(box => { + let like = Number(box.getAttribute("stlikes")) - Number(box.getAttribute("stdislikes")) + if (like == Number(likes[i])) { + parent.append(box) + } + }) + } + break; + case 'hated': + console.log("d") + var likes = [] + readyForSorting.forEach(box => { + likes.push(Number(box.getAttribute("stlikes")) - Number(box.getAttribute("stdislikes"))) + }) + likes.sort((a, b) => { return b - a }) + for (let i = 0; i < likes.length; i++) { + readyForSorting.forEach(box => { + let like = Number(box.getAttribute("stlikes")) - Number(box.getAttribute("stdislikes")) + if (like == Number(likes[i])) { + parent.prepend(box) + } + }) + } + break; + case 'mostImports': + console.log("e") + var likes = [] + readyForSorting.forEach(box => { + likes.push(Number(box.getAttribute("stloads"))) + }) + likes.sort((a, b) => { return b - a }) + for (let i = 0; i < likes.length; i++) { + readyForSorting.forEach(box => { + let like = Number(box.getAttribute("stloads")) + if (like == Number(likes[i])) { + parent.append(box) + } + }) + } + break; + case 'leastImports': + console.log("f") + var likes = [] + readyForSorting.forEach(box => { + likes.push(Number(box.getAttribute("stloads"))) + }) + likes.sort((a, b) => { return b - a }) + for (let i = 0; i < likes.length; i++) { + readyForSorting.forEach(box => { + let like = Number(box.getAttribute("stloads")) + if (like == Number(likes[i])) { + parent.prepend(box) + } + }) + } + break; + case 'mostBlocks': + console.log("g") + var likes = [] + readyForSorting.forEach(box => { + likes.push(Number(box.getAttribute("stblocks"))) + }) + likes.sort((a, b) => { return b - a }) + for (let i = 0; i < likes.length; i++) { + readyForSorting.forEach(box => { + let like = Number(box.getAttribute("stblocks")) + if (like == Number(likes[i])) { + parent.append(box) + } + }) + } + break; + case 'leastBlocks': + console.log("h") + var likes = [] + readyForSorting.forEach(box => { + likes.push(Number(box.getAttribute("stblocks"))) + }) + likes.sort((a, b) => { return b - a }) + for (let i = 0; i < likes.length; i++) { + readyForSorting.forEach(box => { + let like = Number(box.getAttribute("stblocks")) + if (like == Number(likes[i])) { + parent.prepend(box) + } + }) + } + break; + } + } } }) })