main.js mostly done,
started implmenting contentUtility.js added sort options to index.html
This commit is contained in:
parent
d5fd98a066
commit
65d9e8ea1f
11
src/main/resources/static/contentUtility.js
Normal file
11
src/main/resources/static/contentUtility.js
Normal file
@ -0,0 +1,11 @@
|
||||
function fetchQuery(fetchString) {
|
||||
fetch(fetchString)
|
||||
.then(resp => resp.json())
|
||||
.then((data) => {
|
||||
parseContent(data.content);
|
||||
});
|
||||
}
|
||||
|
||||
function parseContent(content) {
|
||||
|
||||
}
|
@ -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++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -17,8 +17,14 @@
|
||||
|
||||
<section id="tool-bar">
|
||||
<select id="sort-btn" title="Sort entries">Sort by
|
||||
<option>Option 1</option>
|
||||
<option>Option 2</option>
|
||||
<option>Author A-Z</option>
|
||||
<option>Author Z-A</option>
|
||||
<option>Title A-Z</option>
|
||||
<option>Title Z-A</option>
|
||||
<option>Stars ↑</option>
|
||||
<option>Stars ↓</option>
|
||||
<option>Votes ↑</option>
|
||||
<option>Votes ↓</option>
|
||||
</select>
|
||||
<div class="divider"></div>
|
||||
<select class="btn" id="filter-btn" title="Filter entries">Filter
|
||||
|
Loading…
Reference in New Issue
Block a user