Skip to content

Commit

Permalink
Document info modal #19
Browse files Browse the repository at this point in the history
  • Loading branch information
simon987 committed Jan 16, 2020
1 parent d42129c commit 919f45c
Show file tree
Hide file tree
Showing 12 changed files with 198 additions and 24 deletions.
2 changes: 1 addition & 1 deletion scripts/get_static_libs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ THREADS=$(nproc)
cd lib

cd mupdf
make USE_SYSTEM_HARFBUZZ=yes USE_SYSTEM_OPENJPEG=yes HAVE_X11=no HAVE_GLUT=no CFLAGS=-fPIC -j $THREADS
CFLAGS=-fPIC make USE_SYSTEM_HARFBUZZ=yes USE_SYSTEM_OPENJPEG=yes HAVE_X11=no HAVE_GLUT=no -j $THREADS
cd ..

mv mupdf/build/release/libmupdf.a .
Expand Down
2 changes: 1 addition & 1 deletion src/index/elastic.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void elastic_flush() {
LOG_FATALF("elastic.c", "Could not connect to %s, make sure that elasticsearch is running!\n", IndexCtx.es_url)
}

LOG_INFOF("elastic.c", "Indexed %3d documents (%zukB) <%d>", count, buf_cur / 1024, r->status_code);
LOG_INFOF("elastic.c", "Indexed %d documents (%zukB) <%d>", count, buf_cur / 1024, r->status_code);

cJSON *ret_json = cJSON_Parse(r->body);
if (cJSON_GetObjectItem(ret_json, "errors")->valueint != 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#define EPILOG "Made by simon987 <me@simon987.net>. Released under GPL-3.0"


static const char *const Version = "1.2.1";
static const char *const Version = "1.2.2";
static const char *const usage[] = {
"sist2 scan [OPTION]... PATH",
"sist2 index [OPTION]... INDEX",
Expand Down
1 change: 0 additions & 1 deletion src/parsing/pdf.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define SIST2_PDF_H

#include "src/sist.h"
#include <tesseract/capi.h>


void parse_pdf(void *buf, size_t buf_len, document_t *doc);
Expand Down
2 changes: 2 additions & 0 deletions src/sist.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#include <archive_entry.h>
#include <opc/opc.h>
#include <libxml/xmlstring.h>
#define BOOL int
#include <tesseract/capi.h>

#include <onion/onion.h>
#include <onion/handler.h>
Expand Down
46 changes: 40 additions & 6 deletions src/web/serve.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ int thumbnail(void *p, onion_request *req, onion_response *res) {
int written = onion_response_write(res, data, data_len);
onion_response_flush(res);
if (written != data_len || data_len == 0) {
printf("Couldn't write thumb\n");
LOG_DEBUG("serve.c", "Couldn't write thumbnail");
}
free(data);

Expand Down Expand Up @@ -214,7 +214,7 @@ int chunked_response_file(const char *filename, const char *mime,
return OCS_PROCESSED;
}

int search(void *p, onion_request *req, onion_response *res) {
int search(UNUSED(void *p), onion_request *req, onion_response *res) {

int flags = onion_request_get_flags(req);
if ((flags & OR_METHODS) != OR_POST) {
Expand Down Expand Up @@ -254,7 +254,7 @@ int search(void *p, onion_request *req, onion_response *res) {
return OCS_PROCESSED;
}

int scroll(void *p, onion_request *req, onion_response *res) {
int scroll(UNUSED(void *p), onion_request *req, onion_response *res) {

int flags = onion_request_get_flags(req);
if ((flags & OR_METHODS) != OR_GET) {
Expand Down Expand Up @@ -327,7 +327,7 @@ int serve_file_from_disk(cJSON *json, index_t *idx, onion_request *req, onion_re
return chunked_response_file(full_path, mime, 1, req, res);
}

int index_info(void *p, onion_request *req, onion_response *res) {
int index_info(UNUSED(void *p), onion_request *req, onion_response *res) {
cJSON *json = cJSON_CreateObject();
cJSON *arr = cJSON_AddArrayToObject(json, "indices");

Expand All @@ -353,14 +353,47 @@ int index_info(void *p, onion_request *req, onion_response *res) {
return OCS_PROCESSED;
}

int file(void *p, onion_request *req, onion_response *res) {

int document_info(UNUSED(void *p), onion_request *req, onion_response *res) {

const char *arg_uuid = onion_request_get_query(req, "1");
if (arg_uuid == NULL) {
return OCS_PROCESSED;
}

cJSON *doc = elastic_get_document(arg_uuid);
cJSON *source = cJSON_GetObjectItem(doc, "_source");

cJSON *index_id = cJSON_GetObjectItem(source, "index");
if (index_id == NULL) {
cJSON_Delete(doc);
return OCS_NOT_PROCESSED;
}

index_t *idx = get_index_by_id(index_id->valuestring);
if (idx == NULL) {
cJSON_Delete(doc);
return OCS_NOT_PROCESSED;
}

onion_response_set_header(res, "Content-Type", "application/json");

char *json_str = cJSON_PrintUnformatted(source);
onion_response_write0(res, json_str);
free(json_str);
cJSON_Delete(doc);

return OCS_PROCESSED;
}

int file(UNUSED(void *p), onion_request *req, onion_response *res) {

const char *arg_uuid = onion_request_get_query(req, "1");
if (arg_uuid == NULL) {
return OCS_PROCESSED;
}

char *next = arg_uuid;
const char *next = arg_uuid;
cJSON *doc = NULL;
cJSON *index_id = NULL;
cJSON *source = NULL;
Expand Down Expand Up @@ -424,6 +457,7 @@ void serve(const char *hostname, const char *port) {
thumbnail
);
onion_url_add(urls, "^f/([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12})$", file);
onion_url_add(urls, "^d/([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12})$", document_info);
onion_url_add(urls, "i", index_info);


Expand Down
8 changes: 4 additions & 4 deletions src/web/static_generated.c

Large diffs are not rendered by default.

45 changes: 44 additions & 1 deletion web/css/dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@
outline: 0;
}

.info-icon {
width: 1rem;
margin-right: 0.2rem;
cursor: pointer;
color: #757575;
line-height: 1rem;
height: 1.1rem;
}

.info-icon:hover {
color: inherit;
}

.modal-title {
max-width: calc(100% - 2rem);
overflow: hidden;
text-overflow: ellipsis;
}


.path-row {
display: -ms-flexbox;
display: flex;
Expand Down Expand Up @@ -32,14 +52,35 @@ body {
margin-top: 1em;
}

.card {
.card, .modal-content {
margin-top: 1em;
background: #212121;
color: #e0e0e0;
border-radius: 1px;
border: none;
}

.table {
color: #e0e0e0;
}

.table td, .table th {
border: none;
}

.table thead th {
border-bottom: 1px solid #646464;
}

.modal-header .close {
color: #e0e0e0;
text-shadow: none;
}

.modal-header {
border-bottom: 1px solid #646464;
}

.sub-document {
background: #37474F !important;
}
Expand Down Expand Up @@ -134,6 +175,8 @@ body {

.file-title {
width: 100%;
line-height: 1rem;
height: 1.1rem;
font-size: 10pt;
white-space: nowrap;
text-overflow: ellipsis;
Expand Down
21 changes: 21 additions & 0 deletions web/css/light.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@
outline: 0;
}

.info-icon {
width: 1rem;
margin-right: 0.2rem;
cursor: pointer;
color: #757575;
line-height: 1rem;
height: 1rem;
}

.info-icon:hover {
color: inherit;
}

.modal-title {
max-width: calc(100% - 2rem);
overflow: hidden;
text-overflow: ellipsis;
}

.path-row {
display: -ms-flexbox;
display: flex;
Expand Down Expand Up @@ -100,6 +119,8 @@ body {

.file-title {
width: 100%;
line-height: 1rem;
height: 1.1rem;
font-size: 10pt;
white-space: nowrap;
text-overflow: ellipsis;
Expand Down
73 changes: 65 additions & 8 deletions web/js/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,44 @@ function getTags(hit, mimeCategory) {
return tags
}

/**
*
* @param hit
* @returns {Element}
*/
function infoButtonCb(hit) {
return () => {
getDocumentInfo(hit["_id"]).then(doc => {
$("#modal-title").text(doc["name"] + (doc["extension"] ? "." + doc["extension"] : ""));

const tbody = $("<tbody>");
$("#modal-body").empty()
.append($("<table class='table table-sm'>")
.append($("<thead>")
.append($("<tr>")
.append($("<th>").text("Field"))
.append($("<th>").text("Value"))
)
)
.append(tbody)
);

const displayFields = new Set([
"mime", "size", "mtime", "path", "title", "width", "height", "duration", "audioc", "videoc",
"bitrate", "artist", "album", "album_artist", "genre", "title", "font_name", "tag"
]);
Object.keys(doc)
.filter(key => key.startsWith("_keyword.") || key.startsWith("_text.") || displayFields.has(key))
.forEach(key => {
tbody.append($("<tr>")
.append($("<td>").text(key))
.append($("<td>").text(doc[key]))
);
});
if (doc.hasOwnProperty("content") && doc["content"]) {
$("#modal-body").append($("<div class='content-div'>").text(doc["content"]))
}

$("#modal").modal();
});
}
}

function createDocCard(hit) {
let docCard = document.createElement("div");
docCard.setAttribute("class", "card");
Expand All @@ -172,6 +205,7 @@ function createDocCard(hit) {
let link = document.createElement("a");
link.setAttribute("href", "f/" + hit["_id"]);
link.setAttribute("target", "_blank");
link.style.maxWidth = "calc(100% - 1.2rem)";
link.appendChild(title);

if (hit["_source"].hasOwnProperty("parent")) {
Expand Down Expand Up @@ -271,7 +305,15 @@ function createDocCard(hit) {
sizeTag.setAttribute("class", "text-muted");
tagContainer.appendChild(sizeTag);

docCardBody.appendChild(link);
const titleWrapper = document.createElement("div");
titleWrapper.style.display = "flex";

const infoButton = makeInfoButton(hit);

titleWrapper.appendChild(infoButton);
titleWrapper.appendChild(link);

docCardBody.appendChild(titleWrapper);
docCard.appendChild(docCardBody);

docCardBody.appendChild(tagContainer);
Expand Down Expand Up @@ -352,6 +394,14 @@ function makeThumbnail(mimeCategory, hit, imgWrapper, small) {
return thumbnail;
}

function makeInfoButton(hit) {
const infoButton = document.createElement("span");
infoButton.appendChild(document.createTextNode("🛈"));
infoButton.setAttribute("class", "info-icon");
infoButton.addEventListener("click", infoButtonCb(hit));
return infoButton;
}

function createDocLine(hit) {

const mime = hit["_source"]["mime"];
Expand All @@ -372,6 +422,8 @@ function createDocLine(hit) {
isSubDocument = true;
}

const infoButton = makeInfoButton(hit);

const title = makeTitle(hit);

let link = document.createElement("a");
Expand All @@ -380,8 +432,13 @@ function createDocLine(hit) {
link.appendChild(title);

const titleDiv = document.createElement("div");
titleDiv.setAttribute("class", "file-title");
titleDiv.appendChild(link);

const titleWrapper = document.createElement("div");
titleWrapper.style.display = "flex";
titleWrapper.appendChild(infoButton);
titleWrapper.appendChild(link);

titleDiv.appendChild(titleWrapper);

line.appendChild(media);

Expand Down
4 changes: 4 additions & 0 deletions web/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ $.jsonPost("i").then(resp => {
});
});

function getDocumentInfo(id) {
return $.getJSON("d/" + id)
}

function handleTreeClick(tree) {
return (event, node, handler) => {
event.preventTreeDefault();
Expand Down
Loading

0 comments on commit 919f45c

Please sign in to comment.