all repos — litestore @ 5bd7732f9da51834b49d3b51cfc06ec74b28ba20

A minimalist nosql document store.

Refactoring & minor fixes.
h3rald h3rald@h3rald.com
Sun, 15 Mar 2015 14:53:30 +0100
commit

5bd7732f9da51834b49d3b51cfc06ec74b28ba20

parent

a2a51a82cfc5c19dbf3ce164d23e54041f3be6ae

M app/index.htmlapp/index.html

@@ -34,7 +34,9 @@ <script src="js/utils.js"> </script>

<script src="js/models.js"> </script> <script src="js/components.js"> </script> <script src="js/navbar.js"> </script> - <script src="js/modules.js"> </script> + <script src="js/modules/info.js"> </script> + <script src="js/modules/tags.js"> </script> + <script src="js/modules/guide.js"> </script> <script src="js/modules/document.js"> </script> <script src="js/app.js"> </script> </body>
M app/js/components.jsapp/js/components.js

@@ -7,16 +7,12 @@

app.editor.config = function(obj){ return function(element, isInitialized, context){ var e = element; - var setHeight = function(){ - e.style.height = (window.innerHeight-210)+"px"; - }; if (!isInitialized) { var editor = ace.edit(e); obj.editor = editor; e.style.position = "relative"; - setHeight(); - window.addEventListener("resize", setHeight); + editor.setOptions({ maxLines: Infinity }); editor.setReadOnly(obj.readOnly); editor.setShowPrintMargin(false); editor.setTheme("ace/theme/github");

@@ -35,4 +31,4 @@ app.editor.view = function(obj) {

return m(".editor.panel.panal-default", {config: app.editor.config(obj)}, obj.content); }; -}());));+}());
M app/js/models.jsapp/js/models.js

@@ -46,6 +46,7 @@ };

Doc.put = function(doc, contentType){ xhrcfg = u.setContentType(doc, contentType); + console.log("Doc.put - Saving Document:", doc); return m.request({ method: "PUT", url: "/v1/docs/"+doc.id,
D app/js/modules.js

@@ -1,95 +0,0 @@

-(function(){ - 'use strict'; - var app = window.LS || (window.LS = {}); - var u = LS.utils; - - // Info Module - app.info = {vm: {}}; - app.info.vm.init = function() { - this.content = Info.get(); - }; - app.info.main = function(){ - var vm = app.info.vm; - var info = vm.content(); - var infolist = m("dl", [ - m("dt", "Version"), - m("dd", info.version), - m("dt", "Size"), - m("dd", info.size), - m("dt", "Loaded directory"), - m("dd", info.directory), - m("dt", "Mirroring"), - m("dd", info.mirror), - m("dt", "Read-only"), - m("dd", info.read_only), - m("dt", "Total Documents"), - m("dd", info.total_documents), - m("dt", "Total Tags"), - m("dd", info.total_tags) - ]); - var taglist = m("ul", info.tags.map(function(tag){ - var key = Object.keys(tag)[0]; - return m("li", [m("a", {href: "/tags/"+key, config: m.route}, key+" ("+tag[key]+")")]); - }) - ); - var v = m(".row", [ - m(".col-md-6", [u.panel({title: "Datastore Information", content: infolist})]), - m(".col-md-6", [u.panel({title: "Tags", content: taglist})]) - ]); - return v; - }; - - // Tags Module - app.tags = {vm: {}}; - app.tags.vm.init = function(){ - this.id = m.route.param("id"); - this.docs = Doc.getByTag(this.id); - }; - app.tags.main = function(){ - var docs = app.tags.vm.docs(); - var title = m("h2", ["Tag: ", m("em", docs.tags)]); - var table = m("table.table.table-bordered.table-hover", [ - m("thead", [ - m("tr", [ - m("th", "ID"), - m("th", "Created"), - m("th", "Modified"), - m("th", "Tags") - ]) - ]), - m("tbody", [ - docs.results.map(function(d){ - return m("tr", [ - m("td", u.doclink(d.id)), - m("td", u.date(d.created)), - m("td", u.date(d.modified)), - m("td", d.tags.map(function(t){return u.taglink(t);})), - ]); - }) - ]) - ]); - return m(".row", [ - title, - m("p", "Total: "+docs.total), - table - ]); - }; - - // Guide Module - app.guide = {vm: {}}; - app.guide.vm.init = function() { - this.id = m.route.param("id"); - this.content = Page.get(this.id); - }; - app.guide.main = function(){ - return m("article.row", m.trust(app.guide.vm.content())); - }; - - - u.layout(app.guide); - u.layout(app.info); - u.layout(app.tags); - -}());yout(app.document); - -}());
A app/js/modules/guide.js

@@ -0,0 +1,18 @@

+(function(){ + 'use strict'; + var app = window.LS || (window.LS = {}); + var u = LS.utils; + + // Guide Module + app.guide = {vm: {}}; + app.guide.vm.init = function() { + this.id = m.route.param("id"); + this.content = Page.get(this.id); + }; + app.guide.main = function(){ + return m("article.row", m.trust(app.guide.vm.content())); + }; + + u.layout(app.guide); + +}());
A app/js/modules/info.js

@@ -0,0 +1,43 @@

+(function(){ + 'use strict'; + var app = window.LS || (window.LS = {}); + var u = LS.utils; + + // Info Module + app.info = {vm: {}}; + app.info.vm.init = function() { + this.content = Info.get(); + }; + app.info.main = function(){ + var vm = app.info.vm; + var info = vm.content(); + var infolist = m("dl", [ + m("dt", "Version"), + m("dd", info.version), + m("dt", "Size"), + m("dd", info.size), + m("dt", "Loaded directory"), + m("dd", info.directory), + m("dt", "Mirroring"), + m("dd", info.mirror), + m("dt", "Read-only"), + m("dd", info.read_only), + m("dt", "Total Documents"), + m("dd", info.total_documents), + m("dt", "Total Tags"), + m("dd", info.total_tags) + ]); + var taglist = m("ul", info.tags.map(function(tag){ + var key = Object.keys(tag)[0]; + return m("li", [m("a", {href: "/tags/"+key, config: m.route}, key+" ("+tag[key]+")")]); + }) + ); + var v = m(".row", [ + m(".col-md-6", [u.panel({title: "Datastore Information", content: infolist})]), + m(".col-md-6", [u.panel({title: "Tags", content: taglist})]) + ]); + return v; + }; + u.layout(app.info); + +}());
A app/js/modules/tags.js

@@ -0,0 +1,44 @@

+(function(){ + 'use strict'; + var app = window.LS || (window.LS = {}); + var u = LS.utils; + + // Tags Module + app.tags = {vm: {}}; + app.tags.vm.init = function(){ + this.id = m.route.param("id"); + this.docs = Doc.getByTag(this.id); + }; + app.tags.main = function(){ + var docs = app.tags.vm.docs(); + var title = m("h2", ["Tag: ", m("em", docs.tags)]); + var table = m("table.table.table-bordered.table-hover", [ + m("thead", [ + m("tr", [ + m("th", "ID"), + m("th", "Created"), + m("th", "Modified"), + m("th", "Tags") + ]) + ]), + m("tbody", [ + docs.results.map(function(d){ + return m("tr", [ + m("td", u.doclink(d.id)), + m("td", u.date(d.created)), + m("td", u.date(d.modified)), + m("td", d.tags.map(function(t){return u.taglink(t);})), + ]); + }) + ]) + ]); + return m(".row", [ + title, + m("p", "Total: "+docs.total), + table + ]); + }; + + u.layout(app.tags); + +}());
M app/js/utils.jsapp/js/utils.js

@@ -27,7 +27,9 @@ mod.view = function(ctrl){

return m("div", [ m(".container", [ app.navbar.view(ctrl.navbar), - m("main", [mod.vm.flash(), mod.main()]) + m("main", [mod.vm.flash(), mod.main()]), + m("footer.footer.container.center", [ + m("p")]) ]) ]); };

@@ -108,4 +110,4 @@ return function(xhr) {

xhr.setRequestHeader("Content-Type", contentType); }; }; -}());+}());
M lib/api_v1.nimlib/api_v1.nim

@@ -18,7 +18,7 @@ var pair = fragment.split('=')

if pair.len < 2 or pair[1] == "": raise newException(EInvalidRequest, "Invalid query string fragment '$1'" % fragment) try: - pair[1] = pair[1].decodeURL + pair[1] = pair[1].replace("+", "%2B").decodeURL except: raise newException(EInvalidRequest, "Unable to decode query string fragment '$1'" % fragment) case pair[0]:

@@ -160,7 +160,7 @@ if options.search != "":

content["search"] = %(options.search.decodeURL) if options.tags != "": content["tags"] = newJArray() - for tag in options.tags.decodeURL.split(","): + for tag in options.tags.replace("+", "%2B").decodeURL.split(","): content["tags"].add(%tag) if orig_limit > 0: content["limit"] = %orig_limit
M lib/types.nimlib/types.nim

@@ -50,11 +50,11 @@ version: string

] let PEG_TAG* = peg""" -^\$? [a-zA-Z0-9_\-?~:.@#^!]+$ +^\$? [a-zA-Z0-9_\-?~:.@#^!+]+$ """ let PEG_USER_TAG* = peg""" -^[a-zA-Z0-9_\-?~:.@#^!]+$ +^[a-zA-Z0-9_\-?~:.@#^!+]+$ """ let PEG_URL* = peg"""
M litestore.nimlitestore.nim

@@ -8,7 +8,8 @@ times,

json, pegs, strtabs, - base64 + base64, + logging import lib/types, lib/utils,

@@ -31,7 +32,11 @@ fail(200, "Unable to create datastore '$1'" % [LS.file])

try: LS.store = LS.file.openDatastore() if LS.mirror: - LS.store.mountDir(LS.directory) + try: + LS.store.mountDir(LS.directory) + except: + echo(getCurrentExceptionMsg()) + fail(202, "Unable to mount directory '$1'" % [LS.directory]) except: fail(201, "Unable to open datastore '$1'" % [LS.file]) case LS.operation: