User scripts, bug fixes, docker image

This commit is contained in:
2019-11-12 20:58:43 -05:00
parent 6931d320a2
commit ebfd7e03ce
21 changed files with 489 additions and 63 deletions

View File

@@ -76,8 +76,8 @@ function shouldPlayVideo(hit) {
}
function makePlaceholder(w, h) {
const calc = w > h
? (175 / w / h) >= 272
const calc = w > h
? (175 / w / h) >= 272
? (175 * w / h)
: 175
: 175;
@@ -195,7 +195,7 @@ function createDocCard(hit) {
if (hit["_source"].hasOwnProperty("duration")) {
thumbnailOverlay = document.createElement("div");
thumbnailOverlay.setAttribute("class", "card-img-overlay");
let durationBadge = document.createElement("span");
const durationBadge = document.createElement("span");
durationBadge.setAttribute("class", "badge badge-resolution");
durationBadge.appendChild(document.createTextNode(humanTime(hit["_source"]["duration"])));
thumbnailOverlay.appendChild(durationBadge);
@@ -207,7 +207,7 @@ function createDocCard(hit) {
case "video":
case "image":
if (hit["_source"].hasOwnProperty("videoc")) {
let formatTag = document.createElement("span");
const formatTag = document.createElement("span");
formatTag.setAttribute("class", "badge badge-pill badge-video");
formatTag.appendChild(document.createTextNode(hit["_source"]["videoc"].replace(" ", "")));
tags.push(formatTag);
@@ -227,7 +227,7 @@ function createDocCard(hit) {
//Content
let contentHl = getContentHighlight(hit);
if (contentHl !== undefined) {
let contentDiv = document.createElement("div");
const contentDiv = document.createElement("div");
contentDiv.setAttribute("class", "content-div");
contentDiv.insertAdjacentHTML('afterbegin', contentHl);
docCard.appendChild(contentDiv);
@@ -254,6 +254,26 @@ function createDocCard(hit) {
imgWrapper.appendChild(thumbnailOverlay);
}
// User tags
if (hit["_source"].hasOwnProperty("tag")) {
hit["_source"]["tag"].forEach(tag => {
const userTag = document.createElement("span");
userTag.setAttribute("class", "badge badge-pill badge-user");
const tokens = tag.split("#");
if (tokens.length > 1) {
const bg = "#" + tokens[1];
const fg = lum(tokens[1]) > 40 ? "#000" : "#fff";
userTag.setAttribute("style", `background-color: ${bg}; color: ${fg}`);
}
const name = tokens[0].split(".")[tokens[0].split(".").length - 1];
userTag.appendChild(document.createTextNode(name));
tags.push(userTag);
})
}
for (let i = 0; i < tags.length; i++) {
tagContainer.appendChild(tags[i]);
}

View File

@@ -1,6 +1,8 @@
const SIZE = 40;
let mimeMap = [];
let tree;
let tagMap = [];
let mimeTree;
let tagTree;
let searchBar = document.getElementById("searchBar");
let pathBar = document.getElementById("pathBar");
@@ -49,6 +51,23 @@ $.jsonPost("i").then(resp => {
});
});
function handleTreeClick (tree) {
return (event, node, handler) => {
event.preventTreeDefault();
if (node.id === "any") {
if (!node.itree.state.checked) {
tree.deselect();
}
} else {
tree.node("any").deselect();
}
handler();
searchDebounced();
}
}
$.jsonPost("es", {
aggs: {
mimeTypes: {
@@ -85,34 +104,86 @@ $.jsonPost("es", {
});
mimeMap.push({"text": "All", "id": "any"});
tree = new InspireTree({
mimeTree = new InspireTree({
selection: {
mode: 'checkbox'
},
data: mimeMap
});
new InspireTreeDOM(tree, {
target: '.tree'
new InspireTreeDOM(mimeTree, {
target: '#mimeTree'
});
tree.on("node.click", function (event, node, handler) {
event.preventTreeDefault();
mimeTree.on("node.click", handleTreeClick(mimeTree));
mimeTree.select();
mimeTree.node("any").deselect();
});
if (node.id === "any") {
if (!node.itree.state.checked) {
tree.deselect();
function leafTag(tag) {
const tokens = tag.split(".");
return tokens[tokens.length-1]
}
// Tags tree
$.jsonPost("es", {
aggs: {
tags: {
terms: {
field: "tag",
size: 10000
}
} else {
tree.node("any").deselect();
}
handler();
searchDebounced();
},
size: 0,
}).then(resp => {
resp["aggregations"]["tags"]["buckets"]
.sort((a, b) => a["key"].localeCompare(b["key"]))
.forEach(bucket => {
addTag(tagMap, bucket["key"], bucket["key"], bucket["doc_count"])
});
tree.select();
tree.node("any").deselect();
tagMap.push({"text": "All", "id": "any"});
tagTree = new InspireTree({
selection: {
mode: 'checkbox'
},
data: tagMap
});
new InspireTreeDOM(tagTree, {
target: '#tagTree'
});
tagTree.on("node.click", handleTreeClick(tagTree));
tagTree.node("any").select();
searchBusy = false;
});
function addTag(map, tag, id, count) {
let tags = tag.split("#")[0].split(".");
let child = {
id: id,
text: tags.length !== 1 ? tags[0] : `${tags[0]} (${count})`,
children: []
};
let found = false;
map.forEach(node => {
if (node.text === child.text) {
found = true;
if (tags.length !== 1) {
addTag(node.children, tags.slice(1).join("."), id, count);
}
}
});
if (!found) {
if (tags.length !== 1) {
addTag(child.children, tags.slice(1).join("."), id, count);
map.push(child);
} else {
map.push(child);
}
}
}
new autoComplete({
selector: '#pathBar',
minChars: 1,
@@ -181,8 +252,8 @@ function doScroll() {
})
}
function getSelectedMimeTypes() {
let mimeTypes = [];
function getSelectedNodes(tree) {
let selectedNodes = [];
let selected = tree.selected();
@@ -194,11 +265,11 @@ function getSelectedMimeTypes() {
//Only get children
if (selected[i].text.indexOf("(") !== -1) {
mimeTypes.push(selected[i].id);
selectedNodes.push(selected[i].id);
}
}
return mimeTypes
return selectedNodes
}
function search() {
@@ -239,11 +310,16 @@ function search() {
if (path !== "") {
filters.push([{term: {path: path}}])
}
let mimeTypes = getSelectedMimeTypes();
let mimeTypes = getSelectedNodes(mimeTree);
if (!mimeTypes.includes("any")) {
filters.push([{terms: {"mime": mimeTypes}}]);
}
let tags = getSelectedNodes(tagTree);
if (!tags.includes("any")) {
filters.push([{terms: {"tag": tags}}]);
}
$.jsonPost("es?scroll=1", {
"_source": {
excludes: ["content"]

View File

@@ -43,9 +43,9 @@ function humanTime(sec_num) {
function debounce(func, wait) {
let timeout;
return function() {
return function () {
let context = this, args = arguments;
let later = function() {
let later = function () {
timeout = null;
func.apply(context, args);
};
@@ -54,3 +54,13 @@ function debounce(func, wait) {
func.apply(context, args);
};
}
function lum(c) {
c = c.substring(1);
let rgb = parseInt(c, 16);
let r = (rgb >> 16) & 0xff;
let g = (rgb >> 8) & 0xff;
let b = (rgb >> 0) & 0xff;
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
}