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