UI tweaks, path autocomplete

This commit is contained in:
simon 2019-10-31 08:26:19 -04:00
parent 5661573b06
commit f8b081a3f4
7 changed files with 23 additions and 26 deletions

View File

@ -10,7 +10,7 @@
#define EPILOG "Made by simon987 <me@simon987.net>. Released under GPL-3.0" #define EPILOG "Made by simon987 <me@simon987.net>. Released under GPL-3.0"
static const char *const Version = "1.0.11"; static const char *const Version = "1.0.12";
static const char *const usage[] = { static const char *const usage[] = {
"sist2 scan [OPTION]... PATH", "sist2 scan [OPTION]... PATH",
"sist2 index [OPTION]... INDEX", "sist2 index [OPTION]... INDEX",

File diff suppressed because one or more lines are too long

View File

@ -15,6 +15,8 @@ body {
margin-top: 1em; margin-top: 1em;
background: #212121; background: #212121;
color: #e0e0e0; color: #e0e0e0;
border-radius: 1px;
border: none;
} }
.navbar-brand { .navbar-brand {

View File

@ -6,6 +6,7 @@ body {overflow-y:scroll;}
.card { .card {
margin-top: 1em; margin-top: 1em;
box-shadow: 0 .125rem .25rem rgba(0,0,0,.075) !important;
} }
.navbar-brand { .navbar-brand {
font-size: 1.75rem; font-size: 1.75rem;

View File

@ -82,7 +82,7 @@ function shouldPlayVideo(hit) {
*/ */
function createDocCard(hit) { function createDocCard(hit) {
let docCard = document.createElement("div"); let docCard = document.createElement("div");
docCard.setAttribute("class", "card shadow-sm"); docCard.setAttribute("class", "card");
let docCardBody = document.createElement("div"); let docCardBody = document.createElement("div");
docCardBody.setAttribute("class", "card-body document"); docCardBody.setAttribute("class", "card-body document");
@ -257,7 +257,7 @@ function makePreloader() {
function makePageIndicator(searchResult) { function makePageIndicator(searchResult) {
let pageIndicator = document.createElement("div"); let pageIndicator = document.createElement("div");
pageIndicator.setAttribute("class", "page-indicator shadow-sm font-weight-light"); pageIndicator.setAttribute("class", "page-indicator font-weight-light");
const totalHits = searchResult["hits"]["total"].hasOwnProperty("value") const totalHits = searchResult["hits"]["total"].hasOwnProperty("value")
? searchResult["hits"]["total"]["value"] : searchResult["hits"]["total"]; ? searchResult["hits"]["total"]["value"] : searchResult["hits"]["total"];
pageIndicator.appendChild(document.createTextNode(docCount + " / " + totalHits)); pageIndicator.appendChild(document.createTextNode(docCount + " / " + totalHits));

View File

@ -116,7 +116,7 @@ $.jsonPost("es", {
new autoComplete({ new autoComplete({
selector: '#pathBar', selector: '#pathBar',
minChars: 1, minChars: 1,
delay: 75, delay: 400,
renderItem: function (item) { renderItem: function (item) {
return '<div class="autocomplete-suggestion" data-val="' + item + '">' + item + '</div>'; return '<div class="autocomplete-suggestion" data-val="' + item + '">' + item + '</div>';
}, },
@ -279,14 +279,6 @@ function search() {
//Search stats //Search stats
searchResults.appendChild(makeStatsCard(searchResult)); searchResults.appendChild(makeStatsCard(searchResult));
//Autocomplete
if (searchResult.hasOwnProperty("suggest") && searchResult["suggest"].hasOwnProperty("path")) {
pathAutoComplete = [];
for (let i = 0; i < searchResult["suggest"]["path"][0]["options"].length; i++) {
pathAutoComplete.push(searchResult["suggest"]["path"][0]["options"][i].text)
}
}
//Setup page //Setup page
let resultContainer = makeResultContainer(); let resultContainer = makeResultContainer();
searchResults.appendChild(resultContainer); searchResults.appendChild(resultContainer);
@ -298,7 +290,6 @@ function search() {
}); });
} }
let pathAutoComplete = [];
let size_min = 0; let size_min = 0;
let size_max = 10000000000000; let size_max = 10000000000000;
@ -306,8 +297,8 @@ let searchDebounced = _.debounce(function () {
coolingDown = false; coolingDown = false;
search() search()
}, 500); }, 500);
searchBar.addEventListener("keyup", searchDebounced); searchBar.addEventListener("keyup", searchDebounced);
document.getElementById("pathBar").addEventListener("keyup", searchDebounced);
//Size slider //Size slider
$("#sizeSlider").ionRangeSlider({ $("#sizeSlider").ionRangeSlider({
@ -358,15 +349,18 @@ updateIndices();
//Suggest //Suggest
function getPathChoices() { function getPathChoices() {
return new Promise(getPaths => { return new Promise(getPaths => {
$.jsonPost("es", {
let xhttp = new XMLHttpRequest(); suggest: {
xhttp.onreadystatechange = function () { path: {
if (this.readyState === 4 && this.status === 200) { prefix: pathBar.value,
getPaths(JSON.parse(xhttp.responseText)) completion: {
field: "suggest-path",
skip_duplicates: true,
size: 10000
} }
}; }
xhttp.open("GET", "suggest?prefix=" + pathBar.value, true); }
xhttp.send(); }).then(resp => getPaths(resp["suggest"]["path"][0]["options"].map(opt => opt["_source"]["path"])));
}); })
} }