Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

insert and delete fixes

  • Loading branch information...
commit 122cb38139a307bac5f7990ffcc007e0ff7db6b6 1 parent cf098d6
Eric Schoffstall contra authored
Showing with 666 additions and 45 deletions.
  1. +8 −1 README.md
  2. +9 −2 client/css/styles.css
  3. +224 −0 client/js/ext/vein.js
  4. +3 −1 client/js/routes.coffee
  5. +1 −0  client/js/routes/connect.coffee
  6. +2 −1  client/js/routes/delete.coffee
  7. +7 −6 client/js/routes/edit.coffee
  8. +1 −1  client/js/routes/empty.coffee
  9. +13 −0 client/js/routes/home.coffee
  10. +31 −0 client/js/routes/insert.coffee
  11. +1 −2  client/js/server.coffee
  12. +1 −1  client/templates/admin.jade
  13. +3 −3 client/templates/connect.jade
  14. +6 −3 client/templates/edit.jade
  15. +13 −1 client/templates/editbar.jade
  16. +13 −3 lib/services/collection.coffee
  17. +9 −2 public/css/styles.css
  18. +224 −0 public/js/ext/vein.js
  19. +2 −1  public/js/routes.js
  20. +1 −0  public/js/routes/connect.js
  21. +2 −1  public/js/routes/delete.js
  22. +13 −10 public/js/routes/edit.js
  23. +1 −1  public/js/routes/empty.js
  24. +24 −0 public/js/routes/home.js
  25. +49 −0 public/js/routes/insert.js
  26. +1 −1  public/js/server.js
  27. +1 −1  public/templates/admin.js
  28. +1 −1  public/templates/connect.js
  29. +1 −1  public/templates/edit.js
  30. +1 −1  public/templates/editbar.js
9 README.md
View
@@ -16,9 +16,16 @@
</tr>
</table>
+## WARNING
+
+The document editor is NOT safe for BSON types yet.
+Any non-JSON types will be lost on save.
+If you need to edit any objects containing BSON types it needs to be done with the raw query form.
+You may experience some issues with editing if you use a non-ObjectID type for _id.
+
## Usage
-smog is visible at http://localhost:8080
+smog is started at http://localhost:8080
```
$ npm install smog -g
11 client/css/styles.css
View
@@ -2,6 +2,7 @@ body {
background-image: url('../img/bg6.jpg');
padding-bottom: 10px;
margin: 8px;
+ overflow: hidden;
}
code {
color: black;
@@ -10,6 +11,10 @@ code {
.small-modal {
width: 330px;
}
+.big-modal {
+ width: 900px;
+ height: 700px;
+}
.table {
table-layout: fixed;
@@ -27,11 +32,13 @@ code {
*/
.edit-body {
- height: 500px;
+ height: 596px;
+ padding: 0px;
max-height: 1000px;
}
.edit-editable {
- height: 490px;
+ height: 596px;
+ width: 900px;
}
.copy-body {
224 client/js/ext/vein.js
View
@@ -0,0 +1,224 @@
+// Generated by CoffeeScript 1.3.1
+(function() {
+ var Vein, cookies,
+ __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
+ __slice = [].slice;
+
+ cookies = {
+ getItem: function(key) {
+ if (!cookies.hasItem(key)) {
+ return;
+ }
+ return unescape(document.cookie.replace(new RegExp("(?:^|.*;\\s*)" + escape(key).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*((?:[^;](?!;))*[^;]?).*"), "$1"));
+ },
+ setItem: function(key, val, expires) {
+ var sExpires;
+ sExpires = "";
+ if (typeof expires === 'number') {
+ sExpires = "; max-age=" + expires;
+ }
+ if (typeof expires === 'string') {
+ sExpires = "; expires=" + expires;
+ }
+ if (typeof expires === 'object' ? expires.toGMTString : void 0) {
+ sExpires = "; expires=" + (expires.toGMTString());
+ }
+ document.cookie = "" + (escape(key)) + "=" + (escape(val)) + sExpires;
+ },
+ removeItem: function(key) {
+ document.cookie = "" + (escape(key)) + "=; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/";
+ },
+ hasItem: function(key) {
+ var ep;
+ ep = new RegExp("(?:^|;\\s*)" + (escape(key).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\="));
+ return ep.test(document.cookie);
+ }
+ };
+
+ Vein = (function() {
+
+ Vein.name = 'Vein';
+
+ function Vein(options) {
+ var _base, _base1, _base2;
+ this.options = options != null ? options : {};
+ this.getSender = __bind(this.getSender, this);
+
+ this.getListener = __bind(this.getListener, this);
+
+ this.handleMethods = __bind(this.handleMethods, this);
+
+ this.handleMessage = __bind(this.handleMessage, this);
+
+ this.handleClose = __bind(this.handleClose, this);
+
+ this.handleReady = __bind(this.handleReady, this);
+
+ this.clearSession = __bind(this.clearSession, this);
+
+ this.setSession = __bind(this.setSession, this);
+
+ this.getSession = __bind(this.getSession, this);
+
+ if ((_base = this.options).prefix == null) {
+ _base.prefix = 'vein';
+ }
+ if ((_base1 = this.options).host == null) {
+ _base1.host = location.origin;
+ }
+ if ((_base2 = this.options).sessionName == null) {
+ _base2.sessionName = "VEINSESSID-" + this.options.prefix;
+ }
+ this.socket = new SockJS("" + this.options.host + "/" + this.options.prefix, null, this.options);
+ this.callbacks['methods'] = this.handleMethods;
+ this.callbacks['session'] = this.setSession;
+ this.socket.onmessage = this.handleMessage;
+ this.socket.onclose = this.handleClose;
+ return;
+ }
+
+ Vein.prototype.connected = null;
+
+ Vein.prototype.callbacks = {
+ ready: [],
+ close: []
+ };
+
+ Vein.prototype.subscribe = {};
+
+ Vein.prototype.getSession = function() {
+ return cookies.getItem(this.options.sessionName);
+ };
+
+ Vein.prototype.setSession = function(sess) {
+ cookies.setItem(this.options.sessionName, sess, this.options.sessionLength);
+ return true;
+ };
+
+ Vein.prototype.clearSession = function() {
+ cookies.removeItem(this.options.sessionName);
+ };
+
+ Vein.prototype.ready = function(cb) {
+ this.callbacks['ready'].push(cb);
+ if (this.connected === true) {
+ return cb(this.methods);
+ }
+ };
+
+ Vein.prototype.close = function(cb) {
+ this.callbacks['close'].push(cb);
+ if (this.connected === false) {
+ return cb(this.methods);
+ }
+ };
+
+ Vein.prototype.handleReady = function(methods) {
+ var cb, _i, _len, _ref, _results;
+ this.methods = methods;
+ this.connected = true;
+ _ref = this.callbacks['ready'];
+ _results = [];
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ cb = _ref[_i];
+ _results.push(cb(methods));
+ }
+ return _results;
+ };
+
+ Vein.prototype.handleClose = function() {
+ var cb, _i, _len, _ref, _results;
+ this.connected = false;
+ _ref = this.callbacks['close'];
+ _results = [];
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ cb = _ref[_i];
+ _results.push(cb());
+ }
+ return _results;
+ };
+
+ Vein.prototype.handleMessage = function(e) {
+ var err, fn, id, keep, method, params, _i, _len, _ref, _ref1, _ref2;
+ _ref = JSON.parse(e.data), id = _ref.id, method = _ref.method, params = _ref.params, err = _ref.err;
+ if (!Array.isArray(params)) {
+ params = [params];
+ }
+ if (this.subscribe[method] && this.subscribe[method].listeners) {
+ _ref1 = this.subscribe[method].listeners;
+ for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
+ fn = _ref1[_i];
+ fn.apply(null, params);
+ }
+ }
+ if (!this.callbacks[id]) {
+ return;
+ }
+ keep = (_ref2 = this.callbacks)[id].apply(_ref2, params);
+ if (keep !== true) {
+ delete this.callbacks[id];
+ }
+ };
+
+ Vein.prototype.handleMethods = function() {
+ var method, methods, _i, _j, _len, _len1;
+ methods = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
+ for (_i = 0, _len = methods.length; _i < _len; _i++) {
+ method = methods[_i];
+ this[method] = this.getSender(method);
+ }
+ for (_j = 0, _len1 = methods.length; _j < _len1; _j++) {
+ method = methods[_j];
+ this.subscribe[method] = this.getListener(method);
+ }
+ this.handleReady(methods);
+ };
+
+ Vein.prototype.getListener = function(method) {
+ var _this = this;
+ return function(cb) {
+ var _base;
+ if ((_base = _this.subscribe[method]).listeners == null) {
+ _base.listeners = [];
+ }
+ _this.subscribe[method].listeners.push(cb);
+ };
+ };
+
+ Vein.prototype.getSender = function(method) {
+ var _this = this;
+ return function() {
+ var cb, id, params, _i;
+ params = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) : (_i = 0, []), cb = arguments[_i++];
+ id = _this.getId();
+ _this.callbacks[id] = cb;
+ _this.socket.send(JSON.stringify({
+ id: id,
+ method: method,
+ params: params,
+ session: _this.getSession()
+ }));
+ };
+ };
+
+ Vein.prototype.getId = function() {
+ var rand;
+ rand = function() {
+ return (((1 + Math.random()) * 0x10000000) | 0).toString(16);
+ };
+ return rand() + rand() + rand();
+ };
+
+ return Vein;
+
+ })();
+
+ if (typeof define === 'function') {
+ define(function() {
+ return Vein;
+ });
+ } else {
+ window.Vein = Vein;
+ }
+
+}).call(this);
4 client/js/routes.coffee
View
@@ -7,11 +7,12 @@ define ["routes/connect",
"routes/rename",
"routes/drop",
"routes/empty",
+ "routes/insert"
"routes/copy",
"routes/edit",
"routes/delete"],
- (connect, disconnect, home, nu, collection, rename, drop, empty, copy, edit, del) ->
+ (connect, disconnect, home, nu, collection, rename, drop, empty, insert, copy, edit, del) ->
'/': connect
'/connect': connect
'/disconnect': disconnect
@@ -23,6 +24,7 @@ define ["routes/connect",
'/rename/:name': rename
'/drop/:name': drop
'/empty/:name': empty
+ '/insert/:name': insert
# documents
'/copy/:name/:id': copy
1  client/js/routes/connect.coffee
View
@@ -11,6 +11,7 @@ define ["smog/server", "templates/connect", "smog/notify"], (server, templ, noti
server.connect host, port, database, (err, okay) ->
if err?
+ console.log err
notify.error "Connection error: #{err}"
else
$('#connect-modal').modal 'hide'
3  client/js/routes/delete.coffee
View
@@ -6,4 +6,5 @@ define ["smog/server", "smog/notify"], (server, notify) ->
query: _id: id
(err) ->
return notify.error "Error deleting document: #{err}" if err?
- notify.success "Document deleted"
+ notify.success "Document deleted"
+ window.location.hash = "#/collection/#{name}"
13 client/js/routes/edit.coffee
View
@@ -1,8 +1,8 @@
-define ["smog/notify", "smog/editor", "templates/edit"], (notify, editor, templ) ->
+define ["smog/server", "smog/notify", "smog/editor", "templates/edit"], (server, notify, editor, templ) ->
({name, id}) ->
realname = name.toLowerCase()
- $('#content').append templ id: id
+ $('#content').append templ title: 'Edit', id: id
edit = editor.create "#{id}-edit-view", "json"
edit.getSession().setUseWrapMode true
edit.getSession().setWrapLimitRange 100, 100
@@ -15,17 +15,18 @@ define ["smog/notify", "smog/editor", "templates/edit"], (notify, editor, templ)
edit.destroy()
$('#edit-modal').remove()
- handleChange = (value) ->
+ $('#edit-button').click ->
try
- val = JSON.parse value
- val._id = @getAttribute 'id'
+ val = JSON.parse edit.getSession().getValue()
+ val._id = id
server.collection
collection: realname
type: 'update'
query: val
(err) ->
return notify.error "Error saving document: #{err}" if err?
+ $('#edit-modal').modal 'hide'
notify.success "Document saved!"
- return value
+ window.location.hash = "#/collection/#{name}"
catch err
notify.error "Invalid JSON: #{err}"
2  client/js/routes/empty.coffee
View
@@ -17,4 +17,4 @@ define ["smog/server", "templates/confirm", "smog/notify"], (server, templ, noti
return notify.error "Error emptying collection: #{err}" if err?
$('#confirm-modal').modal 'hide'
notify.success "Collection emptied"
- window.location.hash = '#/home'
+ window.location.hash = "#/collection/#{name}"
13 client/js/routes/home.coffee
View
@@ -1,3 +1,15 @@
+prettySeconds = (secs) ->
+ days = Math.floor secs / 86400
+ hours = Math.floor (secs % 86400) / 3600
+ minutes = Math.floor ((secs % 86400) % 3600) / 60
+ seconds = ((secs % 86400) % 3600) % 60
+ out = ""
+ out += "#{days} days " if days > 0
+ out += "#{hours} hours " if hours > 0
+ out += "#{minutes} minutes" if minutes > 0
+ out += " #{seconds} seconds" if seconds > 0 and days <= 0
+ return out
+
define ["smog/server", "templates/sidebar", "templates/admin", "smog/notify"], (server, sidebar, admin, notify) ->
->
server.admin (err, info) ->
@@ -12,4 +24,5 @@ define ["smog/server", "templates/sidebar", "templates/admin", "smog/notify"],
info.serverStatus.network.bytesIn = Math.round info.serverStatus.network.bytesIn/1000/1000
info.serverStatus.network.bytesOut = Math.round info.serverStatus.network.bytesOut/1000/1000
info.serverStatus.connections.total = info.serverStatus.connections.current + info.serverStatus.connections.available
+ info.serverStatus.uptime = prettySeconds info.serverStatus.uptime
$('#content').html admin info
31 client/js/routes/insert.coffee
View
@@ -0,0 +1,31 @@
+define ["smog/server", "smog/notify", "smog/editor", "templates/edit"], (server, notify, editor, templ) ->
+ ({name}) ->
+ realname = name.toLowerCase()
+
+ $('#content').append templ title: 'Insert', id: realname
+ edit = editor.create "#{realname}-edit-view", "json"
+ edit.getSession().setUseWrapMode true
+ edit.getSession().setWrapLimitRange 100, 100
+ edit.getSession().setValue "{\r\n\r\n}"
+
+ $('#edit-modal').modal().css
+ 'margin-left': -> -($(@).width() / 2)
+
+ $('#edit-modal').on 'hidden', ->
+ edit.destroy()
+ $('#edit-modal').remove()
+
+ $('#edit-button').click ->
+ try
+ val = JSON.parse edit.getSession().getValue()
+ server.collection
+ collection: realname
+ type: 'insert'
+ query: val
+ (err) ->
+ return notify.error "Error inserting document: #{err}" if err?
+ $('#edit-modal').modal 'hide'
+ notify.success "Document inserted!"
+ window.location.hash = "#/collection/#{name}"
+ catch err
+ notify.error "Invalid JSON: #{err}"
3  client/js/server.coffee
View
@@ -1,2 +1 @@
-define ["https://raw.github.com/wearefractal/vein/master/vein.js"], (Vein) ->
- new Vein
+define ["ext/vein"], (Vein) -> new Vein
2  client/templates/admin.jade
View
@@ -17,7 +17,7 @@
b Host:
p #{serverStatus.host}
b Uptime:
- p #{serverStatus.uptime} seconds
+ p #{serverStatus.uptime}
b Collections:
p #{collections.length}
b Connections:
6 client/templates/connect.jade
View
@@ -3,9 +3,9 @@
h3 Connect
.modal-body
- input#host.span3(type="text", placeholder="Host", value="db.vsjs.mdcn.mobi")
- input#port.span3(type="text", placeholder="Port", value="27017")
- input#database.span3(type="text", placeholder="Database", value="squid")
+ input#host.span3(type="text", placeholder="Host")
+ input#port.span3(type="text", placeholder="Port")
+ input#database.span3(type="text", placeholder="Database")
.modal-footer
a#connect-button.btn.btn-primary Connect
9 client/templates/edit.jade
View
@@ -1,7 +1,10 @@
-#edit-modal.modal.fade.span8
+#edit-modal.modal.fade.big-modal
.modal-header
button.close(data-dismiss="modal") &times;
- h3 Edit
+ h3 #{title}
.modal-body.edit-body
- .span7.edit-editable(id="#{id}-edit-view")
+ .edit-editable(id="#{id}-edit-view")
+
+ .modal-footer
+ a#edit-button.btn.btn-primary Save
14 client/templates/editbar.jade
View
@@ -14,6 +14,18 @@
| Drop
li.divider
li
+ a(href="#/insert/#{name}")
+ i.icon-asterisk.icon-white
+ | Insert
+ li
a(href="#/find/#{name}")
+ i.icon-search.icon-white
+ | Find
+ li
+ a(href="#/mapreduce/#{name}")
i.icon-filter.icon-white
- | Find
+ | Map Reduce
+ li
+ a(href="#/aggregate/#{name}")
+ i.icon-tasks.icon-white
+ | Aggregate
16 lib/services/collection.coffee
View
@@ -10,8 +10,7 @@ tasks =
# collection tasks
rename: (col, command, cb) ->
return cb "Missing query" unless command.query?
- return cb "Missing name" unless command.query.name? and typeof command.query.name is 'string'
- return cb "Invalid name" unless command.query.name.length > 0
+ return cb "Missing name" unless command.query.name? and typeof command.query.name is 'string' and command.query.name.length > 0
col.rename command.query.name, (err, res) ->
return cb err if err?
return cb "Rename failed" unless res?
@@ -31,22 +30,33 @@ tasks =
# other
find: (col, command, cb) ->
+ # TODO: try objectid/non-id
return cb "Missing query" unless command.query?
col.find(command.query, command.options).toArray (err, res) ->
return cb err if err?
cb null, res
delete: (col, command, cb) ->
+ # TODO: try objectid/non-id
return cb "Missing query" unless command.query?
return cb "Missing _id" unless command.query._id?
+ command.query._id = getObjectID command.query._id if command.query._id?
col.remove {_id:command.query._id}, {safe:true}, (err, res) ->
return cb err if err?
return cb "Delete failed" unless res? and res > 0
cb()
+ insert: (col, command, cb) ->
+ # TODO: try objectid/non-id
+ return cb "Missing query" unless command.query?
+ command.query._id = getObjectID command.query._id if command.query._id?
+ col.insert command.query, {safe:true}, cb
+
update: (col, command, cb) ->
+ # TODO: try objectid/non-id
return cb "Missing query" unless command.query?
return cb "Missing _id" unless command.query._id?
+ command.query._id = getObjectID command.query._id
col.save command.query, cb
@@ -59,5 +69,5 @@ module.exports = (reply, socket, command) ->
return reply "Invalid command" unless tasks[command.type]?
socket.mongo.database.collection command.collection, {safe:true}, (err, col) ->
- return cb err if err?
+ return reply err if err?
tasks[command.type] col, command, reply
11 public/css/styles.css
View
@@ -2,6 +2,7 @@ body {
background-image: url('../img/bg6.jpg');
padding-bottom: 10px;
margin: 8px;
+ overflow: hidden;
}
code {
color: black;
@@ -10,6 +11,10 @@ code {
.small-modal {
width: 330px;
}
+.big-modal {
+ width: 900px;
+ height: 700px;
+}
.table {
table-layout: fixed;
@@ -27,11 +32,13 @@ code {
*/
.edit-body {
- height: 500px;
+ height: 596px;
+ padding: 0px;
max-height: 1000px;
}
.edit-editable {
- height: 490px;
+ height: 596px;
+ width: 900px;
}
.copy-body {
224 public/js/ext/vein.js
View
@@ -0,0 +1,224 @@
+// Generated by CoffeeScript 1.3.1
+(function() {
+ var Vein, cookies,
+ __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
+ __slice = [].slice;
+
+ cookies = {
+ getItem: function(key) {
+ if (!cookies.hasItem(key)) {
+ return;
+ }
+ return unescape(document.cookie.replace(new RegExp("(?:^|.*;\\s*)" + escape(key).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*((?:[^;](?!;))*[^;]?).*"), "$1"));
+ },
+ setItem: function(key, val, expires) {
+ var sExpires;
+ sExpires = "";
+ if (typeof expires === 'number') {
+ sExpires = "; max-age=" + expires;
+ }
+ if (typeof expires === 'string') {
+ sExpires = "; expires=" + expires;
+ }
+ if (typeof expires === 'object' ? expires.toGMTString : void 0) {
+ sExpires = "; expires=" + (expires.toGMTString());
+ }
+ document.cookie = "" + (escape(key)) + "=" + (escape(val)) + sExpires;
+ },
+ removeItem: function(key) {
+ document.cookie = "" + (escape(key)) + "=; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/";
+ },
+ hasItem: function(key) {
+ var ep;
+ ep = new RegExp("(?:^|;\\s*)" + (escape(key).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\="));
+ return ep.test(document.cookie);
+ }
+ };
+
+ Vein = (function() {
+
+ Vein.name = 'Vein';
+
+ function Vein(options) {
+ var _base, _base1, _base2;
+ this.options = options != null ? options : {};
+ this.getSender = __bind(this.getSender, this);
+
+ this.getListener = __bind(this.getListener, this);
+
+ this.handleMethods = __bind(this.handleMethods, this);
+
+ this.handleMessage = __bind(this.handleMessage, this);
+
+ this.handleClose = __bind(this.handleClose, this);
+
+ this.handleReady = __bind(this.handleReady, this);
+
+ this.clearSession = __bind(this.clearSession, this);
+
+ this.setSession = __bind(this.setSession, this);
+
+ this.getSession = __bind(this.getSession, this);
+
+ if ((_base = this.options).prefix == null) {
+ _base.prefix = 'vein';
+ }
+ if ((_base1 = this.options).host == null) {
+ _base1.host = location.origin;
+ }
+ if ((_base2 = this.options).sessionName == null) {
+ _base2.sessionName = "VEINSESSID-" + this.options.prefix;
+ }
+ this.socket = new SockJS("" + this.options.host + "/" + this.options.prefix, null, this.options);
+ this.callbacks['methods'] = this.handleMethods;
+ this.callbacks['session'] = this.setSession;
+ this.socket.onmessage = this.handleMessage;
+ this.socket.onclose = this.handleClose;
+ return;
+ }
+
+ Vein.prototype.connected = null;
+
+ Vein.prototype.callbacks = {
+ ready: [],
+ close: []
+ };
+
+ Vein.prototype.subscribe = {};
+
+ Vein.prototype.getSession = function() {
+ return cookies.getItem(this.options.sessionName);
+ };
+
+ Vein.prototype.setSession = function(sess) {
+ cookies.setItem(this.options.sessionName, sess, this.options.sessionLength);
+ return true;
+ };
+
+ Vein.prototype.clearSession = function() {
+ cookies.removeItem(this.options.sessionName);
+ };
+
+ Vein.prototype.ready = function(cb) {
+ this.callbacks['ready'].push(cb);
+ if (this.connected === true) {
+ return cb(this.methods);
+ }
+ };
+
+ Vein.prototype.close = function(cb) {
+ this.callbacks['close'].push(cb);
+ if (this.connected === false) {
+ return cb(this.methods);
+ }
+ };
+
+ Vein.prototype.handleReady = function(methods) {
+ var cb, _i, _len, _ref, _results;
+ this.methods = methods;
+ this.connected = true;
+ _ref = this.callbacks['ready'];
+ _results = [];
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ cb = _ref[_i];
+ _results.push(cb(methods));
+ }
+ return _results;
+ };
+
+ Vein.prototype.handleClose = function() {
+ var cb, _i, _len, _ref, _results;
+ this.connected = false;
+ _ref = this.callbacks['close'];
+ _results = [];
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ cb = _ref[_i];
+ _results.push(cb());
+ }
+ return _results;
+ };
+
+ Vein.prototype.handleMessage = function(e) {
+ var err, fn, id, keep, method, params, _i, _len, _ref, _ref1, _ref2;
+ _ref = JSON.parse(e.data), id = _ref.id, method = _ref.method, params = _ref.params, err = _ref.err;
+ if (!Array.isArray(params)) {
+ params = [params];
+ }
+ if (this.subscribe[method] && this.subscribe[method].listeners) {
+ _ref1 = this.subscribe[method].listeners;
+ for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
+ fn = _ref1[_i];
+ fn.apply(null, params);
+ }
+ }
+ if (!this.callbacks[id]) {
+ return;
+ }
+ keep = (_ref2 = this.callbacks)[id].apply(_ref2, params);
+ if (keep !== true) {
+ delete this.callbacks[id];
+ }
+ };
+
+ Vein.prototype.handleMethods = function() {
+ var method, methods, _i, _j, _len, _len1;
+ methods = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
+ for (_i = 0, _len = methods.length; _i < _len; _i++) {
+ method = methods[_i];
+ this[method] = this.getSender(method);
+ }
+ for (_j = 0, _len1 = methods.length; _j < _len1; _j++) {
+ method = methods[_j];
+ this.subscribe[method] = this.getListener(method);
+ }
+ this.handleReady(methods);
+ };
+
+ Vein.prototype.getListener = function(method) {
+ var _this = this;
+ return function(cb) {
+ var _base;
+ if ((_base = _this.subscribe[method]).listeners == null) {
+ _base.listeners = [];
+ }
+ _this.subscribe[method].listeners.push(cb);
+ };
+ };
+
+ Vein.prototype.getSender = function(method) {
+ var _this = this;
+ return function() {
+ var cb, id, params, _i;
+ params = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) : (_i = 0, []), cb = arguments[_i++];
+ id = _this.getId();
+ _this.callbacks[id] = cb;
+ _this.socket.send(JSON.stringify({
+ id: id,
+ method: method,
+ params: params,
+ session: _this.getSession()
+ }));
+ };
+ };
+
+ Vein.prototype.getId = function() {
+ var rand;
+ rand = function() {
+ return (((1 + Math.random()) * 0x10000000) | 0).toString(16);
+ };
+ return rand() + rand() + rand();
+ };
+
+ return Vein;
+
+ })();
+
+ if (typeof define === 'function') {
+ define(function() {
+ return Vein;
+ });
+ } else {
+ window.Vein = Vein;
+ }
+
+}).call(this);
3  public/js/routes.js
View
@@ -1,7 +1,7 @@
// Generated by CoffeeScript 1.3.1
(function() {
- define(["routes/connect", "routes/disconnect", "routes/home", "routes/new", "routes/collection", "routes/rename", "routes/drop", "routes/empty", "routes/copy", "routes/edit", "routes/delete"], function(connect, disconnect, home, nu, collection, rename, drop, empty, copy, edit, del) {
+ define(["routes/connect", "routes/disconnect", "routes/home", "routes/new", "routes/collection", "routes/rename", "routes/drop", "routes/empty", "routes/insert", "routes/copy", "routes/edit", "routes/delete"], function(connect, disconnect, home, nu, collection, rename, drop, empty, insert, copy, edit, del) {
return {
'/': connect,
'/connect': connect,
@@ -12,6 +12,7 @@
'/rename/:name': rename,
'/drop/:name': drop,
'/empty/:name': empty,
+ '/insert/:name': insert,
'/copy/:name/:id': copy,
'/edit/:name/:id': edit,
'/delete/:name/:id': del
1  public/js/routes/connect.js
View
@@ -16,6 +16,7 @@
database = $('#database').val();
return server.connect(host, port, database, function(err, okay) {
if (err != null) {
+ console.log(err);
return notify.error("Connection error: " + err);
} else {
$('#connect-modal').modal('hide');
3  public/js/routes/delete.js
View
@@ -15,7 +15,8 @@
if (err != null) {
return notify.error("Error deleting document: " + err);
}
- return notify.success("Document deleted");
+ notify.success("Document deleted");
+ return window.location.hash = "#/collection/" + name;
});
};
});
23 public/js/routes/edit.js
View
@@ -1,12 +1,13 @@
// Generated by CoffeeScript 1.3.1
(function() {
- define(["smog/notify", "smog/editor", "templates/edit"], function(notify, editor, templ) {
+ define(["smog/server", "smog/notify", "smog/editor", "templates/edit"], function(server, notify, editor, templ) {
return function(_arg) {
var edit, id, name, realname;
name = _arg.name, id = _arg.id;
realname = name.toLowerCase();
$('#content').append(templ({
+ title: 'Edit',
id: id
}));
edit = editor.create("" + id + "-edit-view", "json");
@@ -18,15 +19,16 @@
return -($(this).width() / 2);
}
});
- return $('#edit-modal').on('hidden', function() {
- var handleChange, val;
+ $('#edit-modal').on('hidden', function() {
edit.destroy();
- $('#edit-modal').remove();
- handleChange = function(value) {};
+ return $('#edit-modal').remove();
+ });
+ return $('#edit-button').click(function() {
+ var val;
try {
- val = JSON.parse(value);
- val._id = this.getAttribute('id');
- server.collection({
+ val = JSON.parse(edit.getSession().getValue());
+ val._id = id;
+ return server.collection({
collection: realname,
type: 'update',
query: val
@@ -34,9 +36,10 @@
if (err != null) {
return notify.error("Error saving document: " + err);
}
- return notify.success("Document saved!");
+ $('#edit-modal').modal('hide');
+ notify.success("Document saved!");
+ return window.location.hash = "#/collection/" + name;
});
- return value;
} catch (err) {
return notify.error("Invalid JSON: " + err);
}
2  public/js/routes/empty.js
View
@@ -27,7 +27,7 @@
}
$('#confirm-modal').modal('hide');
notify.success("Collection emptied");
- return window.location.hash = '#/home';
+ return window.location.hash = "#/collection/" + name;
});
});
};
24 public/js/routes/home.js
View
@@ -1,5 +1,28 @@
// Generated by CoffeeScript 1.3.1
(function() {
+ var prettySeconds;
+
+ prettySeconds = function(secs) {
+ var days, hours, minutes, out, seconds;
+ days = Math.floor(secs / 86400);
+ hours = Math.floor((secs % 86400) / 3600);
+ minutes = Math.floor(((secs % 86400) % 3600) / 60);
+ seconds = ((secs % 86400) % 3600) % 60;
+ out = "";
+ if (days > 0) {
+ out += "" + days + " days ";
+ }
+ if (hours > 0) {
+ out += "" + hours + " hours ";
+ }
+ if (minutes > 0) {
+ out += "" + minutes + " minutes";
+ }
+ if (seconds > 0 && days <= 0) {
+ out += " " + seconds + " seconds";
+ }
+ return out;
+ };
define(["smog/server", "templates/sidebar", "templates/admin", "smog/notify"], function(server, sidebar, admin, notify) {
return function() {
@@ -34,6 +57,7 @@
info.serverStatus.network.bytesIn = Math.round(info.serverStatus.network.bytesIn / 1000 / 1000);
info.serverStatus.network.bytesOut = Math.round(info.serverStatus.network.bytesOut / 1000 / 1000);
info.serverStatus.connections.total = info.serverStatus.connections.current + info.serverStatus.connections.available;
+ info.serverStatus.uptime = prettySeconds(info.serverStatus.uptime);
return $('#content').html(admin(info));
});
};
49 public/js/routes/insert.js
View
@@ -0,0 +1,49 @@
+// Generated by CoffeeScript 1.3.1
+(function() {
+
+ define(["smog/server", "smog/notify", "smog/editor", "templates/edit"], function(server, notify, editor, templ) {
+ return function(_arg) {
+ var edit, name, realname;
+ name = _arg.name;
+ realname = name.toLowerCase();
+ $('#content').append(templ({
+ title: 'Insert',
+ id: realname
+ }));
+ edit = editor.create("" + realname + "-edit-view", "json");
+ edit.getSession().setUseWrapMode(true);
+ edit.getSession().setWrapLimitRange(100, 100);
+ edit.getSession().setValue("{\r\n\r\n}");
+ $('#edit-modal').modal().css({
+ 'margin-left': function() {
+ return -($(this).width() / 2);
+ }
+ });
+ $('#edit-modal').on('hidden', function() {
+ edit.destroy();
+ return $('#edit-modal').remove();
+ });
+ return $('#edit-button').click(function() {
+ var val;
+ try {
+ val = JSON.parse(edit.getSession().getValue());
+ return server.collection({
+ collection: realname,
+ type: 'insert',
+ query: val
+ }, function(err) {
+ if (err != null) {
+ return notify.error("Error inserting document: " + err);
+ }
+ $('#edit-modal').modal('hide');
+ notify.success("Document inserted!");
+ return window.location.hash = "#/collection/" + name;
+ });
+ } catch (err) {
+ return notify.error("Invalid JSON: " + err);
+ }
+ });
+ };
+ });
+
+}).call(this);
2  public/js/server.js
View
@@ -1,7 +1,7 @@
// Generated by CoffeeScript 1.3.1
(function() {
- define(["https://raw.github.com/wearefractal/vein/master/vein.js"], function(Vein) {
+ define(["ext/vein"], function(Vein) {
return new Vein;
});
2  public/templates/admin.js
View
@@ -1 +1 @@
-define(["ext/jade"],function(jade){return function anonymous(locals,attrs,escape,rethrow){var attrs=jade.attrs,escape=jade.escape,rethrow=jade.rethrow,buf=[];with(locals||{}){var interp;buf.push("<div"),buf.push(attrs({"class":"well row"},{})),buf.push("><div"),buf.push(attrs({"class":"page-header"},{})),buf.push("><h1>Administration</h1></div><div"),buf.push(attrs({"class":"span3"},{})),buf.push("><h2>Build</h2><b>System: </b><p"),buf.push(attrs({title:""+buildInfo.sysInfo+"","class":"crop"},{title:!0})),buf.push(">"+escape((interp=buildInfo.sysInfo)==null?"":interp)+"</p><b>Version: </b><p>"+escape((interp=buildInfo.version)==null?"":interp)+"</p><b>Bits: </b><p>"+escape((interp=buildInfo.bits)==null?"":interp)+"</p><b>Debug: </b><p>"+escape((interp=buildInfo.debug)==null?"":interp)+"</p></div><div"),buf.push(attrs({"class":"span3"},{})),buf.push("><h2>System</h2><b>Host: </b><p>"+escape((interp=serverStatus.host)==null?"":interp)+"</p><b>Uptime: </b><p>"+escape((interp=serverStatus.uptime)==null?"":interp)+" seconds</p><b>Collections: </b><p>"+escape((interp=collections.length)==null?"":interp)+"</p><b>Connections: </b><p>"+escape((interp=serverStatus.connections.current)==null?"":interp)+"/"+escape((interp=serverStatus.connections.total)==null?"":interp)+"</p></div><div"),buf.push(attrs({"class":"span3"},{})),buf.push("><h2>Performance</h2><b>Requests: </b><p>"+escape((interp=serverStatus.network.numRequests)==null?"":interp)+"</p><b>Input: </b><p>"+escape((interp=serverStatus.network.bytesIn)==null?"":interp)+"mb</p><b>Output: </b><p>"+escape((interp=serverStatus.network.bytesOut)==null?"":interp)+"mb</p><b>Disk Memory:</b><p>"+escape((interp=serverStatus.mem.mapped)==null?"":interp)+"mb</p><b>Virtual Memory: </b><p>"+escape((interp=serverStatus.mem.virtual)==null?"":interp)+"mb</p></div></div>")}return buf.join("")}})
+define(["ext/jade"],function(jade){return function anonymous(locals,attrs,escape,rethrow){var attrs=jade.attrs,escape=jade.escape,rethrow=jade.rethrow,buf=[];with(locals||{}){var interp;buf.push("<div"),buf.push(attrs({"class":"well row"},{})),buf.push("><div"),buf.push(attrs({"class":"page-header"},{})),buf.push("><h1>Administration</h1></div><div"),buf.push(attrs({"class":"span3"},{})),buf.push("><h2>Build</h2><b>System: </b><p"),buf.push(attrs({title:""+buildInfo.sysInfo+"","class":"crop"},{title:!0})),buf.push(">"+escape((interp=buildInfo.sysInfo)==null?"":interp)+"</p><b>Version: </b><p>"+escape((interp=buildInfo.version)==null?"":interp)+"</p><b>Bits: </b><p>"+escape((interp=buildInfo.bits)==null?"":interp)+"</p><b>Debug: </b><p>"+escape((interp=buildInfo.debug)==null?"":interp)+"</p></div><div"),buf.push(attrs({"class":"span3"},{})),buf.push("><h2>System</h2><b>Host: </b><p>"+escape((interp=serverStatus.host)==null?"":interp)+"</p><b>Uptime: </b><p>"+escape((interp=serverStatus.uptime)==null?"":interp)+"</p><b>Collections: </b><p>"+escape((interp=collections.length)==null?"":interp)+"</p><b>Connections: </b><p>"+escape((interp=serverStatus.connections.current)==null?"":interp)+"/"+escape((interp=serverStatus.connections.total)==null?"":interp)+"</p></div><div"),buf.push(attrs({"class":"span3"},{})),buf.push("><h2>Performance</h2><b>Requests: </b><p>"+escape((interp=serverStatus.network.numRequests)==null?"":interp)+"</p><b>Input: </b><p>"+escape((interp=serverStatus.network.bytesIn)==null?"":interp)+"mb</p><b>Output: </b><p>"+escape((interp=serverStatus.network.bytesOut)==null?"":interp)+"mb</p><b>Disk Memory:</b><p>"+escape((interp=serverStatus.mem.mapped)==null?"":interp)+"mb</p><b>Virtual Memory: </b><p>"+escape((interp=serverStatus.mem.virtual)==null?"":interp)+"mb</p></div></div>")}return buf.join("")}})
2  public/templates/connect.js
View
@@ -1 +1 @@
-define(["ext/jade"],function(jade){return function anonymous(locals,attrs,escape,rethrow){var attrs=jade.attrs,escape=jade.escape,rethrow=jade.rethrow,buf=[];with(locals||{}){var interp;buf.push("<div"),buf.push(attrs({id:"connect-modal","class":"modal fade small-modal"},{})),buf.push("><div"),buf.push(attrs({"class":"modal-header"},{})),buf.push("><h3>Connect</h3></div><div"),buf.push(attrs({"class":"modal-body"},{})),buf.push("><input"),buf.push(attrs({id:"host",type:"text",placeholder:"Host",value:"db.vsjs.mdcn.mobi","class":"span3"},{type:!0,placeholder:!0,value:!0})),buf.push("/><input"),buf.push(attrs({id:"port",type:"text",placeholder:"Port",value:"27017","class":"span3"},{type:!0,placeholder:!0,value:!0})),buf.push("/><input"),buf.push(attrs({id:"database",type:"text",placeholder:"Database",value:"squid","class":"span3"},{type:!0,placeholder:!0,value:!0})),buf.push("/></div><div"),buf.push(attrs({"class":"modal-footer"},{})),buf.push("><a"),buf.push(attrs({id:"connect-button","class":"btn btn-primary"},{})),buf.push(">Connect</a></div></div>")}return buf.join("")}})
+define(["ext/jade"],function(jade){return function anonymous(locals,attrs,escape,rethrow){var attrs=jade.attrs,escape=jade.escape,rethrow=jade.rethrow,buf=[];with(locals||{}){var interp;buf.push("<div"),buf.push(attrs({id:"connect-modal","class":"modal fade small-modal"},{})),buf.push("><div"),buf.push(attrs({"class":"modal-header"},{})),buf.push("><h3>Connect</h3></div><div"),buf.push(attrs({"class":"modal-body"},{})),buf.push("><input"),buf.push(attrs({id:"host",type:"text",placeholder:"Host","class":"span3"},{type:!0,placeholder:!0})),buf.push("/><input"),buf.push(attrs({id:"port",type:"text",placeholder:"Port","class":"span3"},{type:!0,placeholder:!0})),buf.push("/><input"),buf.push(attrs({id:"database",type:"text",placeholder:"Database","class":"span3"},{type:!0,placeholder:!0})),buf.push("/></div><div"),buf.push(attrs({"class":"modal-footer"},{})),buf.push("><a"),buf.push(attrs({id:"connect-button","class":"btn btn-primary"},{})),buf.push(">Connect</a></div></div>")}return buf.join("")}})
2  public/templates/edit.js
View
@@ -1 +1 @@
-define(["ext/jade"],function(jade){return function anonymous(locals,attrs,escape,rethrow){var attrs=jade.attrs,escape=jade.escape,rethrow=jade.rethrow,buf=[];with(locals||{}){var interp;buf.push("<div"),buf.push(attrs({id:"edit-modal","class":"modal fade span8"},{})),buf.push("><div"),buf.push(attrs({"class":"modal-header"},{})),buf.push("><button"),buf.push(attrs({"data-dismiss":"modal","class":"close"},{"data-dismiss":!0})),buf.push(">&times;</button><h3>Edit</h3></div><div"),buf.push(attrs({"class":"modal-body edit-body"},{})),buf.push("><div"),buf.push(attrs({id:""+id+"-edit-view","class":"span7 edit-editable"},{id:!0})),buf.push("></div></div></div>")}return buf.join("")}})
+define(["ext/jade"],function(jade){return function anonymous(locals,attrs,escape,rethrow){var attrs=jade.attrs,escape=jade.escape,rethrow=jade.rethrow,buf=[];with(locals||{}){var interp;buf.push("<div"),buf.push(attrs({id:"edit-modal","class":"modal fade big-modal"},{})),buf.push("><div"),buf.push(attrs({"class":"modal-header"},{})),buf.push("><button"),buf.push(attrs({"data-dismiss":"modal","class":"close"},{"data-dismiss":!0})),buf.push(">&times;</button><h3>"+escape((interp=title)==null?"":interp)+"</h3></div><div"),buf.push(attrs({"class":"modal-body edit-body"},{})),buf.push("><div"),buf.push(attrs({id:""+id+"-edit-view","class":"edit-editable"},{id:!0})),buf.push("></div></div><div"),buf.push(attrs({"class":"modal-footer"},{})),buf.push("><a"),buf.push(attrs({id:"edit-button","class":"btn btn-primary"},{})),buf.push(">Save</a></div></div>")}return buf.join("")}})
2  public/templates/editbar.js
View
@@ -1 +1 @@
-define(["ext/jade"],function(jade){return function anonymous(locals,attrs,escape,rethrow){var attrs=jade.attrs,escape=jade.escape,rethrow=jade.rethrow,buf=[];with(locals||{}){var interp;buf.push("<div"),buf.push(attrs({"class":"well sidebar-nav"},{})),buf.push("><ul"),buf.push(attrs({"class":"nav nav-list"},{})),buf.push("><li><a"),buf.push(attrs({href:"#/rename/"+name+""},{href:!0})),buf.push("><i"),buf.push(attrs({"class":"icon-pencil icon-white"},{})),buf.push("></i>Rename</a></li><li><a"),buf.push(attrs({href:"#/empty/"+name+""},{href:!0})),buf.push("><i"),buf.push(attrs({"class":"icon-trash icon-white"},{})),buf.push("></i>Empty</a></li><li><a"),buf.push(attrs({href:"#/drop/"+name+""},{href:!0})),buf.push("><i"),buf.push(attrs({"class":"icon-fire icon-white"},{})),buf.push("></i>Drop</a></li><li"),buf.push(attrs({"class":"divider"},{})),buf.push("></li><li><a"),buf.push(attrs({href:"#/find/"+name+""},{href:!0})),buf.push("><i"),buf.push(attrs({"class":"icon-filter icon-white"},{})),buf.push("></i>Find</a></li></ul></div>")}return buf.join("")}})
+define(["ext/jade"],function(jade){return function anonymous(locals,attrs,escape,rethrow){var attrs=jade.attrs,escape=jade.escape,rethrow=jade.rethrow,buf=[];with(locals||{}){var interp;buf.push("<div"),buf.push(attrs({"class":"well sidebar-nav"},{})),buf.push("><ul"),buf.push(attrs({"class":"nav nav-list"},{})),buf.push("><li><a"),buf.push(attrs({href:"#/rename/"+name+""},{href:!0})),buf.push("><i"),buf.push(attrs({"class":"icon-pencil icon-white"},{})),buf.push("></i>Rename</a></li><li><a"),buf.push(attrs({href:"#/empty/"+name+""},{href:!0})),buf.push("><i"),buf.push(attrs({"class":"icon-trash icon-white"},{})),buf.push("></i>Empty</a></li><li><a"),buf.push(attrs({href:"#/drop/"+name+""},{href:!0})),buf.push("><i"),buf.push(attrs({"class":"icon-fire icon-white"},{})),buf.push("></i>Drop</a></li><li"),buf.push(attrs({"class":"divider"},{})),buf.push("></li><li><a"),buf.push(attrs({href:"#/insert/"+name+""},{href:!0})),buf.push("><i"),buf.push(attrs({"class":"icon-asterisk icon-white"},{})),buf.push("></i>Insert</a></li><li><a"),buf.push(attrs({href:"#/find/"+name+""},{href:!0})),buf.push("><i"),buf.push(attrs({"class":"icon-search icon-white"},{})),buf.push("></i>Find</a></li><li><a"),buf.push(attrs({href:"#/mapreduce/"+name+""},{href:!0})),buf.push("><i"),buf.push(attrs({"class":"icon-filter icon-white"},{})),buf.push("></i>Map Reduce</a></li><li><a"),buf.push(attrs({href:"#/aggregate/"+name+""},{href:!0})),buf.push("><i"),buf.push(attrs({"class":"icon-tasks icon-white"},{})),buf.push("></i>Aggregate</a></li></ul></div>")}return buf.join("")}})
Please sign in to comment.
Something went wrong with that request. Please try again.