main.js mostly done,
started implmenting contentUtility.js added sort options to index.html
This commit is contained in:
@@ -1,3 +1,10 @@
|
||||
const baseURL = "http://" + window.location.host + "/api/v1/datasets";
|
||||
const defaultPagingValue = 20;
|
||||
const lastQuery = {
|
||||
url: "",
|
||||
totalPages: 0,
|
||||
currentPage: 0
|
||||
};
|
||||
|
||||
const addButton = document.getElementById("add-btn");
|
||||
addButton.addEventListener("click", () => {
|
||||
@@ -28,8 +35,8 @@ sortButton.addEventListener("change", () => {
|
||||
});
|
||||
|
||||
const upvoteButtons = document.getElementsByClassName("upvote-btn");
|
||||
const upvoteButtonClickListener = () => {
|
||||
const entryID = upvoteButton.parent.dataset.id;
|
||||
const upvoteButtonClickListener = e => {
|
||||
const entryID = e.target.parentElement.parentElement.dataset.id;
|
||||
vote(entryID, true);
|
||||
};
|
||||
for (const upvoteButton of upvoteButtons) {
|
||||
@@ -37,8 +44,8 @@ for (const upvoteButton of upvoteButtons) {
|
||||
}
|
||||
|
||||
const downvoteButtons = document.getElementsByClassName("downvote-btn");
|
||||
const downvoteButtonClickListener = () => {
|
||||
const entryID = downvoteButton.parent.dataset.id;
|
||||
const downvoteButtonClickListener = e => {
|
||||
const entryID = e.target.parentElement.parentElement.dataset.id;
|
||||
vote(entryID, false);
|
||||
};
|
||||
for (const downvoteButton of downvoteButtons) {
|
||||
@@ -50,17 +57,38 @@ function navigateToAdd() {
|
||||
}
|
||||
|
||||
function filter(filterString) {
|
||||
|
||||
filterString = filterString.toUpperCase();
|
||||
const fetchURL = baseURL + "?type=" + filterString + "&size=" + defaultPagingValue;
|
||||
fetchQuery(fetchURL);
|
||||
}
|
||||
|
||||
function search(searchString) {
|
||||
console.log(searchString);
|
||||
const fetchURL = baseURL + "?search=" + encodeURIComponent(searchString.length === 0?"%":searchString);
|
||||
console.log(fetchURL);
|
||||
fetchQuery(fetchURL);
|
||||
}
|
||||
|
||||
function sort(sortString) {
|
||||
|
||||
let query = sortString.toLowerCase().split(" ");
|
||||
if (query[1] === "A-Z" || query[1] === "↑") {
|
||||
query[1] = "asc";
|
||||
} else {
|
||||
query[1] = "desc";
|
||||
}
|
||||
const fetchURL = baseURL + "?sort=" + query[0] + "&direction=" + query[1];
|
||||
console.log(fetchURL);
|
||||
fetchQuery(fetchURL);
|
||||
}
|
||||
|
||||
function vote(entryID, up) {
|
||||
fetch()
|
||||
}
|
||||
console.log(baseURL + "/id/" + entryID + "/" + (up?"upvote":"downvote"));
|
||||
fetch(baseURL + "/id/" + entryID + "/" + up?"upvote":"downvote");
|
||||
}
|
||||
|
||||
function incrementPageCount() {
|
||||
lastQuery.currentPage++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user