all repos — litestore @ e701cfec4b07f654ee64dda0d58f8378acfbfd7e

A minimalist nosql document store.

Displaying image previews.
* Closes #10.
h3rald h3rald@h3rald.com
Sat, 11 Apr 2015 20:22:41 +0200
commit

e701cfec4b07f654ee64dda0d58f8378acfbfd7e

parent

525f046ebc5da404a2ba993f3e5464a5e5dfef7d

2 files changed, 27 insertions(+), 13 deletions(-)

jump to
M admin/js/models.jsadmin/js/models.js

@@ -67,10 +67,8 @@ });

}; Doc.patch = function(id, updatedTags){ - console.log(updatedTags); return Doc.get(id).then(function(doc){ var tags = doc.tags; - console.log(tags); var count = 0; var ops = []; tags.forEach(function(tag){

@@ -91,6 +89,7 @@ // add tag

ops.push({"op": "add", "path": "/tags/"+i, "value": updatedTags[i]}); } } + console.log("Doc.patch - Saving Tags:", ops); return m.request({ method: "PATCH", url: "/v1/docs/"+id,
M admin/js/modules/document.jsadmin/js/modules/document.js

@@ -14,6 +14,8 @@ vm.readOnly = true;

vm.contentType = m.prop(""); vm.updatedTags = m.prop(""); vm.content = ""; + vm.binary = false; + vm.image = false; vm.tags = []; try { vm.ext = vm.id().match(/\.(.+)$/)[1];

@@ -21,13 +23,19 @@ } catch(e) {

vm.ext = ""; } - // Retrieve single document & populate + // Retrieve single document & update relevant variables vm.getDoc = function(cb){ vm.doc = Doc.get(vm.id()); vm.doc.then(function(doc){ vm.content = doc.data; vm.tags = doc.tags; vm.updatedTags(vm.tags.filter(function(t){return !/^\$/.test(t)}).join(", ")); + if (vm.tags.filter(function(t){return t === "$format:binary"}).length > 0) { + vm.binary = true; + if (vm.tags.filter(function(t){return t === "$type:image"}).length > 0) { + vm.image = true; + } + } }, vm.flashError); };

@@ -128,19 +136,20 @@ // Configure edit tags popover

var cfg = {}; cfg.title = "Edit Tags"; cfg.contentId = "#edit-tags-popover"; + var tools = []; switch (vm.action){ case "view": - return [ - {title: "Edit Content", icon: "edit", action: vm.edit}, - {title: "Edit Tags", icon: "tags", action: u.showModal("#edit-tags-modal")}, - {title: "Delete", icon: "trash", action: u.showModal("#delete-document-modal")} - ]; + if (!vm.binary) { + tools.push({title: "Edit Content", icon: "edit", action: vm.edit}); + } + tools.push({title: "Edit Tags", icon: "tags", action: u.showModal("#edit-tags-modal")}); + tools.push({title: "Delete", icon: "trash", action: u.showModal("#delete-document-modal")}); + break; default: - return [ - {title: "Save", icon: "save", action: vm.save}, - {title: "Cancel", icon: "times-circle", action: vm.cancel} - ]; + tools.push({title: "Save", icon: "save", action: vm.save}); + tools.push({title: "Cancel", icon: "times-circle", action: vm.cancel}); } + return tools; }; };

@@ -195,12 +204,18 @@ size: 25,

value: vm.contentType() })]); } + var panelContent; + if (vm.image){ + panelContent = m("div.text-center", [m("img", {src: "/docs/"+vm.id(), title: vm.id()})]); + } else { + panelContent = app.editor.view(vm); + } var title = m("span",[titleLeft, titleRight]); return m("div", [ u.modal(deleteDialogCfg), u.modal(editTagsDialogCfg), m(".row", [u.toolbar({links: vm.tools()})]), - m(".row", [u.panel({title: title, content:app.editor.view(vm)})]) + m(".row", [u.panel({title: title, content:panelContent})]) ]); };