refined search
minor bugfixes in other functionalities
This commit is contained in:
parent
65d9e8ea1f
commit
180770f28e
@ -1,4 +1,7 @@
|
||||
function fetchQuery(fetchString) {
|
||||
import {searchBarTimeout} from "./main.js"
|
||||
|
||||
export function fetchQuery(fetchString) {
|
||||
clearTimeout(searchBarTimeout);
|
||||
fetch(fetchString)
|
||||
.then(resp => resp.json())
|
||||
.then((data) => {
|
||||
|
@ -1,3 +1,5 @@
|
||||
import { fetchQuery } from "./contentUtility.js";
|
||||
|
||||
const baseURL = "http://" + window.location.host + "/api/v1/datasets";
|
||||
const defaultPagingValue = 20;
|
||||
const lastQuery = {
|
||||
@ -23,10 +25,20 @@ searchButton.addEventListener("click", () => {
|
||||
search(searchString);
|
||||
});
|
||||
const searchBar = document.getElementById("search-entry");
|
||||
export let searchBarTimeout;
|
||||
searchBar.addEventListener("input", () => {
|
||||
const searchString = searchBar.value;
|
||||
search(searchString);
|
||||
clearTimeout(searchBarTimeout);
|
||||
searchBarTimeout = setTimeout(() => {
|
||||
const searchString = searchBar.value;
|
||||
search(searchString);
|
||||
}, 1000);
|
||||
});
|
||||
searchBar.addEventListener('keypress', function (e) {
|
||||
if (e.key === 'Enter') {
|
||||
const searchString = searchBar.value;
|
||||
search(searchString);
|
||||
}
|
||||
})
|
||||
|
||||
const sortButton = document.getElementById("sort-btn");
|
||||
sortButton.addEventListener("change", () => {
|
||||
@ -58,19 +70,20 @@ function navigateToAdd() {
|
||||
|
||||
function filter(filterString) {
|
||||
filterString = filterString.toUpperCase();
|
||||
const fetchURL = baseURL + "?type=" + filterString + "&size=" + defaultPagingValue;
|
||||
const fetchURL = baseURL + "?type=" + encodeURIComponent(filterString) + "&size=" + defaultPagingValue;
|
||||
console.log(fetchURL)
|
||||
fetchQuery(fetchURL);
|
||||
}
|
||||
|
||||
function search(searchString) {
|
||||
const fetchURL = baseURL + "?search=" + encodeURIComponent(searchString.length === 0?"%":searchString);
|
||||
const fetchURL = baseURL + "/search" + "?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] === "↑") {
|
||||
if (query[1] === "a-z" || query[1] === "↑") {
|
||||
query[1] = "asc";
|
||||
} else {
|
||||
query[1] = "desc";
|
||||
|
@ -5,7 +5,7 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>DataDash</title>
|
||||
<link rel="stylesheet" href="main.css">
|
||||
<script type="text/javascript" src="main.js" defer></script>
|
||||
<script type="module" src="main.js" defer></script>
|
||||
</head>
|
||||
<body>
|
||||
<div onclick="console.log('add')" id="add-btn" title="Add a new API entry"></div>
|
||||
|
Loading…
Reference in New Issue
Block a user