const SIZE = 60; let mimeMap = []; let tagMap = []; let mimeTree; let tagTree; let searchBar = document.getElementById("searchBar"); let pathBar = document.getElementById("pathBar"); let tagBar = document.getElementById("tagBar"); let currentDocToTag = null; let currentTagCallback = null; let lastDoc = null; let reachedEnd = false; let docCount = 0; let coolingDown = false; let searchBusy = true; let selectedIndices = []; let indexMap = {}; let size_min = 0; let size_max = 10000000000000; let date_min = null; let date_max = null; SORT_MODES = { score: { text: "Relevance", mode: [ {_score: {order: "desc"}}, {_tie: {order: "asc"}} ], key: hit => hit["_score"] }, date_asc: { text: "Date (Ascending)", mode: [ {mtime: {order: "asc"}}, {_tie: {order: "asc"}} ], key: hit => hit["_source"]["mtime"] }, date_desc: { text: "Date (Descending)", mode: [ {mtime: {order: "desc"}}, {_tie: {order: "asc"}} ], key: hit => hit["_source"]["mtime"] }, size_asc: { text: "Size (Ascending)", mode: [ {size: {order: "asc"}}, {_tie: {order: "asc"}} ], key: hit => hit["_source"]["size"] }, size_desc: { text: "Size (Descending)", mode: [ {size: {order: "desc"}}, {_tie: {order: "asc"}} ], key: hit => hit["_source"]["size"] }, }; function showEsError() { $.toast({ heading: "Elasticsearch connection error", text: "sist2 web module encountered an error while connecting " + "to Elasticsearch. See server logs for more information.", stack: false, bgColor: "#a94442", textColor: "#f2dede", position: 'bottom-right', hideAfter: false }); } window.onload = () => { CONF.load(); new autoComplete({ selector: '#pathBar', minChars: 1, delay: 400, renderItem: function (item) { return '
' + item + '
'; }, source: async function (term, suggest) { if (!CONF.options.suggestPath) { return [] } term = term.toLowerCase(); const choices = await getPathChoices(); let matches = []; for (let i = 0; i < choices.length; i++) { if (~choices[i].toLowerCase().indexOf(term)) { matches.push(choices[i]); } } suggest(matches.sort()); }, onSelect: function () { searchDebounced(); } }); searchBar.addEventListener("keyup", searchDebounced); pathBar.addEventListener("keyup", e => { if (e.key === "Enter") { searchDebounced(); } }); new autoComplete({ selector: '#tagBar', minChars: 1, delay: 200, renderItem: function (item) { return '
' + item.split("#")[0] + '
'; }, source: async function (term, suggest) { term = term.toLowerCase(); const choices = await getTagChoices(); let matches = []; for (let i = 0; i < choices.length; i++) { if (~choices[i].toLowerCase().indexOf(term)) { matches.push(choices[i]); } } suggest(matches.sort()); }, onSelect: function (e, item) { const name = item.split("#")[0]; const color = "#" + item.split("#")[1]; $("#tag-color").val(color); $("#tag-color").trigger("keyup", color); tagBar.value = name; e.preventDefault(); } }); [tagBar, document.getElementById("tag-color")].forEach(elem => { elem.addEventListener("keyup", e => { if (e.key === "Enter" && tagBar.value.length > 0) { const tag = tagBar.value + document.getElementById("tag-color").value; saveTag(tag, currentDocToTag).then(() => currentTagCallback(tag)); } }); }) $("#tag-color").colorpicker({ format: "hex", sliders: { saturation: { selector: '.colorpicker-saturation', callLeft: 'setSaturationRatio', callTop: 'setValueRatio' }, hue: { selector: '.colorpicker-hue', maxLeft: 0, callLeft: false, callTop: 'setHueRatio' } } }); }; function saveTag(tag, hit) { const relPath = hit["_source"]["path"] + (hit["_source"]["path"] ? "/" : "") + hit["_source"]["name"] + ext(hit); return $.jsonPost("/tag/" + hit["_source"]["index"], { delete: false, name: tag, doc_id: hit["_id"], path_md5: md5(relPath) }).then(() => { tagBar.blur(); $("#tagModal").modal("hide"); $.toast({ heading: "Tag added", text: "Tag saved to index storage and updated in ElasticSearch", stack: 3, bgColor: "#00a4bc", textColor: "#fff", position: 'bottom-right', hideAfter: 3000, loaderBg: "#08c7e8", }); }) } function deleteTag(tag, hit) { const relPath = hit["_source"]["path"] + "/" + hit["_source"]["name"] + ext(hit); return $.jsonPost("/tag/" + hit["_source"]["index"], { delete: true, name: tag, doc_id: hit["_id"], relpath: relPath }).then(() => { $.toast({ heading: "Tag deleted", text: "Tag deleted index storage and updated in ElasticSearch", stack: 3, bgColor: "#00a4bc", textColor: "#fff", position: 'bottom-right', hideAfter: 3000, loaderBg: "#08c7e8", }); }) } function toggleFuzzy() { searchDebounced(); } $.get("i").then(resp => { const urlIndices = (new URLSearchParams(location.search)).get("i"); resp["indices"].forEach(idx => { indexMap[idx.id] = idx.name; const opt = $("