main.js mostly done,
started implmenting contentUtility.js added sort options to index.html
This commit is contained in:
		
							
								
								
									
										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");
 | 
					const addButton = document.getElementById("add-btn");
 | 
				
			||||||
addButton.addEventListener("click", () => {
 | 
					addButton.addEventListener("click", () => {
 | 
				
			||||||
@@ -28,8 +35,8 @@ sortButton.addEventListener("change", () => {
 | 
				
			|||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const upvoteButtons = document.getElementsByClassName("upvote-btn");
 | 
					const upvoteButtons = document.getElementsByClassName("upvote-btn");
 | 
				
			||||||
const upvoteButtonClickListener = ()  => {
 | 
					const upvoteButtonClickListener = e  => {
 | 
				
			||||||
    const entryID = upvoteButton.parent.dataset.id;
 | 
					    const entryID = e.target.parentElement.parentElement.dataset.id;
 | 
				
			||||||
    vote(entryID, true);
 | 
					    vote(entryID, true);
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
for (const upvoteButton of upvoteButtons) {
 | 
					for (const upvoteButton of upvoteButtons) {
 | 
				
			||||||
@@ -37,8 +44,8 @@ for (const upvoteButton of upvoteButtons) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const downvoteButtons = document.getElementsByClassName("downvote-btn");
 | 
					const downvoteButtons = document.getElementsByClassName("downvote-btn");
 | 
				
			||||||
const downvoteButtonClickListener = ()  => {
 | 
					const downvoteButtonClickListener = e  => {
 | 
				
			||||||
    const entryID = downvoteButton.parent.dataset.id;
 | 
					    const entryID = e.target.parentElement.parentElement.dataset.id;
 | 
				
			||||||
    vote(entryID, false);
 | 
					    vote(entryID, false);
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
for (const downvoteButton of downvoteButtons) {
 | 
					for (const downvoteButton of downvoteButtons) {
 | 
				
			||||||
@@ -50,17 +57,38 @@ function navigateToAdd() {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function filter(filterString) {
 | 
					function filter(filterString) {
 | 
				
			||||||
 | 
					    filterString = filterString.toUpperCase();
 | 
				
			||||||
 | 
					    const fetchURL = baseURL + "?type=" + filterString + "&size=" + defaultPagingValue;
 | 
				
			||||||
 | 
					    fetchQuery(fetchURL);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function search(searchString) {
 | 
					function search(searchString) {
 | 
				
			||||||
    console.log(searchString);
 | 
					    const fetchURL = baseURL + "?search=" + encodeURIComponent(searchString.length === 0?"%":searchString);
 | 
				
			||||||
 | 
					    console.log(fetchURL);
 | 
				
			||||||
 | 
					    fetchQuery(fetchURL);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function sort(sortString) {
 | 
					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) {
 | 
					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">
 | 
					        <section id="tool-bar">
 | 
				
			||||||
            <select id="sort-btn" title="Sort entries">Sort by
 | 
					            <select id="sort-btn" title="Sort entries">Sort by
 | 
				
			||||||
                <option>Option 1</option>
 | 
					                <option>Author A-Z</option>
 | 
				
			||||||
                <option>Option 2</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>
 | 
					            </select>
 | 
				
			||||||
            <div class="divider"></div>
 | 
					            <div class="divider"></div>
 | 
				
			||||||
            <select class="btn" id="filter-btn" title="Filter entries">Filter
 | 
					            <select class="btn" id="filter-btn" title="Filter entries">Filter
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user