-
+
diff --git a/public/main.js b/public/main.js index 388af6b..a5fc0dd 100644 --- a/public/main.js +++ b/public/main.js @@ -2,11 +2,14 @@ var requestsDiv = document.getElementById("requests"); var cronJobs = ['processBans']; var currentPage = 1; var totalPages = 1; +var count = document.getElementById("count").value; +var sortBy = document.getElementById("sortBy").value; +var sortDir = "desc"; -function getRequests(count,offset,allRequests) { +function getRequests(offset,allRequests) { if (allRequests) var reqUrl = "/api/getAllRequests"; else var reqUrl = "/api/getRequests"; - reqUrl += `?count=${count}&offset=${offset}`; + reqUrl += `?count=${count}&offset=${offset}&sort=${sortBy}&sortDirection=${sortDir}`; fetch(reqUrl) .then(response => response.json()) .then(requests => { @@ -38,7 +41,7 @@ function buildTable(requests) { document.getElementById("page").innerHTML += ``; } document.getElementById("page").value = currentPage; - var requestsDivHTML = '
Song | Requester | Score | '; + var requestsDivHTML = '
---|
Song Title | Requester | Score | '; requestsDivHTML += 'State'; if (window.loggedIn) requestsDivHTML += ' | Vote'; if (window.isStreamer) requestsDivHTML += ' | Update | ' @@ -65,10 +68,9 @@ function buildTable(requests) { } function updateTable() { - var count = document.getElementById("count").value; var offset = (currentPage - 1) * count; var allRequests = document.getElementById("allRequests").checked; - getRequests(count,offset,allRequests); + getRequests(offset,allRequests); } function applyUrlTransforms(url) { @@ -375,5 +377,16 @@ for(state of validStates) { var opt = document.createElement("option"); opt.text = state; opt.value = state; - updateRequestStateSelect.add(opt) + updateRequestStateSelect.add(opt); +} + +function toggleSortDir() { + if (window.sortDir == "desc") { + document.getElementById("sortDir").innerText = "↑"; + window.sortDir = "asc"; + } else { + document.getElementById("sortDir").innerText = "↓"; + window.sortDir = "desc"; + } + updateTable(); } diff --git a/public/style.css b/public/style.css index 6be863d..ccea461 100644 --- a/public/style.css +++ b/public/style.css @@ -111,11 +111,20 @@ div#nav-userpic { text-align: right; } -#tableSettings { +.tableSettings { display: flex; + align-items: center; justify-content: space-between; } +.tableSettings > span { + margin: auto; +} + +#tableSettingsTop { + margin-bottom: 10px; +} + #modalBackground { display: none; position: fixed; @@ -128,6 +137,7 @@ div#nav-userpic { height: 100%; background-color: #444; background-color: #444a; + margin: 5px; } .modal { @@ -201,3 +211,7 @@ div#nav-userpic { display: flex; justify-content: space-between; } + +#sortDir { + padding: 0; +} diff --git a/src/app.ts b/src/app.ts index ee577a3..583a56e 100644 --- a/src/app.ts +++ b/src/app.ts @@ -47,23 +47,26 @@ app.get("/api/getRequests", async (request, response) => { var requestCount = ( request.query.count ? parseInt(request.query.count as string, 10) : 5 ); var requestOffset = ( request.query.offset ? parseInt(request.query.offset as string, 10) : 0 ); var sortDirection = ( request.query.sortDirection == "asc" ? "ASC" : "DESC" ); + var inverseSortDirection = ( sortDirection == "ASC" ? "DESC" : "ASC" ); switch (request.query.sort) { - case undefined: - case "score": - var requestSort = `score ${sortDirection}, reqTimestamp ASC`; - break; + case undefined: // Default sort by newest case "timestamp": var requestSort = `reqTimestamp ${sortDirection}`; break; - case "alpha": + case "score": + var requestSort = `score ${sortDirection}, reqTimestamp ${inverseSortDirection}`; + break; + case "title": var requestSort = `title ${sortDirection}` break; + case "requester": + var requestSort = `requester ${sortDirection}, title ${sortDirection}` + break; default: response.status(400); response.send("Invalid sort"); return; }; - console.log('foo') var requestsTotal = await requests.getRequestsTotal(); if (request.session.user) { requests.getRequestsVoted(requestCount,requestOffset,requestSort,request.session.user.id) diff --git a/views/main.eta b/views/main.eta index 9f986d1..ce7d520 100644 --- a/views/main.eta +++ b/views/main.eta @@ -29,11 +29,10 @@ <%- } %>
---|