all repos — litestore @ 343ed9059c45739848f7c3215b4e88cde40b2ba5

A minimalist nosql document store.

Fixed JSHint warnings + refactoring.
h3rald h3rald@h3rald.com
Sun, 08 Mar 2015 19:15:14 +0100
commit

343ed9059c45739848f7c3215b4e88cde40b2ba5

parent

53b8b9dd28dd82ebd27930e4e19cb3ce38161531

6 files changed, 111 insertions(+), 112 deletions(-)

jump to
M app/js/app.jsapp/js/app.js

@@ -1,6 +1,6 @@

-var app = app || {}; (function(){ 'use strict'; + var app = window.LS || (window.LS = {}); m.route.mode = "hash";
M app/js/components.jsapp/js/components.js

@@ -1,9 +1,8 @@

-var app = app || {}; - -app.editor = {}; - (function(){ 'use strict'; + var app = window.LS || (window.LS = {}); + app.editor = {}; + app.editor.config = function(obj){ return function(element, isInitialized, context){

@@ -24,7 +23,7 @@ editor.setTheme("ace/theme/github");

editor.getSession().setMode("ace/mode/"+obj.mode); editor.getSession().setUseWrapMode(true); } - } + }; }; /**

@@ -32,8 +31,8 @@ * @param obj

* - content The content of the editor */ app.editor.view = function(obj) { - return m(".editor.panel.panal-default", {config: app.editor.config(obj)}, obj.content) + return m(".editor.panel.panal-default", {config: app.editor.config(obj)}, obj.content); - } + }; -}()) +}());
M app/js/models.jsapp/js/models.js

@@ -1,49 +1,49 @@

-var Page = {}; - -Page.get = function(id) { - var content = m.prop(""); - return m.request({ - method: "GET", - url: "md/"+id+".md", - deserialize: function(value) {return value;} - }).then(function(content){ return marked(content)}); -} - -var Info = {}; - -Info.get = function(){ - var content = m.prop(""); - return m.request({ - method: "GET", - url: "/v1/info" - }).then(content); -} - -var Doc = {}; - -Doc.getByTag = function(tag) { - var docs = m.prop(""); - return m.request({ - method: "GET", - url: "/v1/docs?contents=false&tags="+tag - }).then(docs); -} - -Doc.get = function(id) { - var doc = m.prop(""); - return m.request({ - method: "GET", - url: "/v1/docs/"+id+"?raw=true" - }).then(doc); -} - -Doc.put = function(doc){ - xhrcfg = u.getContentType(doc); - return m.request({ - method: "PUT", - url: "/v1/docs/"+doc.id, - data: doc.data, - serialize: function(data){return data}, - config: xhrcfg - }); -} +(function(){ + window.Page = {}; + window.Info = {}; + window.Doc = {}; + + Page.get = function(id) { + var content = m.prop(""); + return m.request({ + method: "GET", + url: "md/"+id+".md", + deserialize: function(value) {return value;} + }).then(function(content){ return marked(content);}); + }; + + Info.get = function(){ + var content = m.prop(""); + return m.request({ + method: "GET", + url: "/v1/info" + }).then(content); + }; + + Doc.getByTag = function(tag) { + var docs = m.prop(""); + return m.request({ + method: "GET", + url: "/v1/docs?contents=false&tags="+tag + }).then(docs); + }; + + Doc.get = function(id) { + var doc = m.prop(""); + return m.request({ + method: "GET", + url: "/v1/docs/"+id+"?raw=true" + }).then(doc); + }; + + Doc.put = function(doc){ + xhrcfg = u.getContentType(doc); + return m.request({ + method: "PUT", + url: "/v1/docs/"+doc.id, + data: doc.data, + serialize: function(data){return data;}, + config: xhrcfg + }); + }; +}());
M app/js/modules.jsapp/js/modules.js

@@ -1,7 +1,7 @@

-var app = app || {}; - (function(){ 'use strict'; + var app = window.LS || (window.LS = {}); + var u = LS.utils; // Info Module app.info = {vm: {}};

@@ -22,13 +22,13 @@ 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]+")")]) + 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; };

@@ -56,17 +56,17 @@ 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)})), - ]) + m("td", d.tags.map(function(t){return u.taglink(t);})), + ]); }) ]) - ]) + ]); return m(".row", [ title, m("p", "Total: "+docs.total), table ]); - } + }; app.document = {vm: {}}; app.document.vm.init = function() {

@@ -78,7 +78,7 @@ vm.doc = Doc.get(vm.id);

vm.doc.then(function(doc){ vm.content = doc.data; }); - } + }; this.getDoc(); this.state = "view"; switch (this.ext){

@@ -99,14 +99,14 @@ this.mode = "markdown";

break; default: this.mode = "text"; - }; + } this.edit = function(){ vm.state = "edit"; vm.editor.setReadOnly(false); }; this.save = function(){ var doc = {}; - doc.id = vm.doc().id + doc.id = vm.doc().id; doc.tags = vm.doc().tags; doc.data = vm.editor.getValue(); Doc.put(doc).then(function(){

@@ -123,23 +123,23 @@ switch (vm.state){

case "view": return [ {title: "Edit", icon: "edit", action: vm.edit} - ] + ]; default: return [ {title: "Save", icon: "save", action: vm.save}, {title: "Cancel", icon: "times-circle", action: vm.cancel} - ] + ]; } - } - } + }; + }; app.document.main = function(){ var vm = app.document.vm; - var title = m("span",[vm.id, m("span.pull-right", vm.doc().tags.map(function(t){return u.taglink(t)}))]); + var title = m("span",[vm.id, m("span.pull-right", vm.doc().tags.map(function(t){return u.taglink(t);}))]); return m("div", [ m(".row", [u.toolbar({links: vm.tools()})]), m(".row", [u.panel({title: title, content:app.editor.view(vm)})]) - ]) - } + ]); + }; // Guide Module
M app/js/navbar.jsapp/js/navbar.js

@@ -1,7 +1,7 @@

- var app = app || {}; - (function(){ 'use strict'; + var app = window.LS || (window.LS = {}); + var u = app.utils; app.navlinks = { controller: function(){

@@ -11,7 +11,7 @@ vm: {

init: function(){ this.info = Info.get(); this.activelink = function(url){ - return (m.route().match(RegExp("^\/"+url))) ? "active" : ""; + return (m.route().match(new RegExp("^\/"+url))) ? "active" : ""; }; this.guidelinks = [ {path: "/guide/overview", title: "Overview"},

@@ -24,8 +24,8 @@ this.taglinks = function(info){

return info.tags.map(function(tag){ var key = Object.keys(tag)[0]; return {path: "/tags/"+key, title: key+" ("+tag[key]+")"}; - }) - } + }); + }; } }, view: function(ctrl){

@@ -34,9 +34,9 @@ return m("ul.nav.navbar-nav", [

m("li", {class: vm.activelink("info")}, [m("a", {href: "/info", config: m.route}, "Info")]), u.dropdown({title: "Tags", links: vm.taglinks(vm.info()), active: vm.activelink("tags")}), u.dropdown({title: "Guide", links: vm.guidelinks, active: vm.activelink("guide")}) - ]) + ]); } - } + }; app.navheader = { controller: function() {},

@@ -49,9 +49,9 @@ m("span.icon-bar"),

m("span.icon-bar") ]), m("a.navbar-brand", {href: "/", config:m.route}, "LiteStore") - ]) + ]); } - } + }; app.searchbox = { controller: function() {},

@@ -63,9 +63,9 @@ m("span.input-group-btn",

m("button.btn.btn-default[type='button']", [m("i.fa.fa-search")])) ]) ] - ) + ); } - } + }; app.navbar = { controller: function() {

@@ -82,7 +82,7 @@ app.navlinks.view(ctrl.navlinks),

app.searchbox.view(ctrl.searchbox) ]) ]) - ]) + ]); } - } + }; }());
M app/js/utils.jsapp/js/utils.js

@@ -1,8 +1,8 @@

-var app = app || {}; -var u = {}; - (function(){ 'use strict'; + var app = window.LS || (window.LS = {}); + var u = app.utils = {}; + /** * @param mod a module * @param vm a view-model (with init function)

@@ -13,7 +13,7 @@

mod.controller = mod.controller || function(){ this.navbar = new app.navbar.controller(); mod.vm.init(); - } + }; mod.view = function(ctrl){ return m("div", [

@@ -21,9 +21,9 @@ m(".container", [

app.navbar.view(ctrl.navbar), m("main", [mod.main()]) ]) - ]) - } - } + ]); + }; + }; u.panel = function(obj){ return m(".panel.panel-default", [

@@ -33,8 +33,8 @@ ]),

m(".panel-body", [ obj.content ]) - ]) - } + ]); + }; u.dropdown = function(obj) { var el = "li.dropdown"; if (obj.active.length > 0) {

@@ -46,44 +46,44 @@ [m("span", obj.title+" "), m("span.caret")]),

m("ul.dropdown-menu[role='menu']", obj.links.map(function(e){ return m("li", - [m("a", {href: e.path, config: m.route}, e.title)])})) - ]) + [m("a", {href: e.path, config: m.route}, e.title)]);})) + ]); }; u.taglink = function(tag) { - return m("span.label.label-primary", [m("a", {href: "/tags/"+tag, config:m.route}, tag)]) + return m("span.label.label-primary", [m("a", {href: "/tags/"+tag, config:m.route}, tag)]); }; u.doclink = function(id) { return m("a", {href: "/document/"+id, config: m.route}, id); - } + }; u.date = function(date) { - if (date == ""){ + if (date === ""){ return ""; } else { return new Date(Date.parse(date)).toUTCString(); } - } + }; u.toolbar = function(obj){ return m("nav.toolbar.btn-group[role='group'][aria-label='...'].pull-right", obj.links.map(function(l){ - return m("a.btn.btn-default", {onclick:l.action}, [m("i.fa.fa-"+l.icon), " "+l.title]) + return m("a.btn.btn-default", {onclick:l.action}, [m("i.fa.fa-"+l.icon), " "+l.title]); }) - ) - } + ); + }; u.getContentType = function(doc){ var type = ""; var subtype = ""; doc.tags.forEach(function(tag){ - var t = tag.match(/^\$type:(.+)/) - var s = tag.match(/^\$subtype:(.+)/) + var t = tag.match(/^\$type:(.+)/); + var s = tag.match(/^\$subtype:(.+)/); if (t) type = t[1]; if (s) subtype = s[1]; - }) + }); return function(xhr) { xhr.setRequestHeader("Content-Type", type+"/"+subtype); - } - } + }; + }; }());