Skip to content
This repository has been archived by the owner on Jul 5, 2023. It is now read-only.

Commit

Permalink
Merge branch 'release/2.3.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
bobthecow committed Apr 17, 2013
2 parents 9ae7acc + a5a1e27 commit 228cf08
Show file tree
Hide file tree
Showing 9 changed files with 170 additions and 133 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.markdown
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
## v2.3.2

* [Fix #103][i103] — Properly encode and decode API URI components in Backbone v1.0.
* Clean up page title for non-ObjectId documents.

[i103]: https://github.com/bobthecow/genghis/issues/103


## v2.3.1

* [Fix #93][i93] — Skip `bson_ext` and `json` checks for JRuby, et. al.
* Use an explicit ISO date string when saving ISODate values.
* Update to the latest Backbone, Underscore, CodeMirror, jQuery, jQuery hoverIntent and Mousetrap library versions.
* Switch to Rob Garrison's fork of tablesorter.
* [Fix #96][i96] — Ensure document shows up in the editor in Opera.

[i93]: https://github.com/bobthecow/genghis/issues/93
[i96]: https://github.com/bobthecow/genghis/issues/96


## v2.3.0
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3.1
2.3.2
20 changes: 10 additions & 10 deletions genghis.php

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions genghis.rb

Large diffs are not rendered by default.

11 changes: 2 additions & 9 deletions src/js/genghis/models/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,9 @@ Genghis.Models.Document = Backbone.Model.extend({
initialize: function() {
_.bindAll(this, 'prettyId', 'prettyTime', 'prettyPrint', 'JSONish', 'isGridFile', 'isGridChunk', 'downloadUrl', 'fileUrl');
},
thunkId: function(id) {
if (_.isObject(id) && id.hasOwnProperty('$genghisType') && id.$genghisType == 'ObjectId') {
return id.$value;
} else if (typeof id !== 'undefined') {
return '~' + Genghis.Util.base64Encode(JSON.stringify(id));
}
},
parse: function(resp) {
// a little bitta id thunk.
var id = this.thunkId(resp._id);
var id = Genghis.Util.encodeDocumentId(resp._id);
if (id) {
this.id = id;
}
Expand Down Expand Up @@ -102,6 +95,6 @@ Genghis.Models.Document = Backbone.Model.extend({

return this.url()
.replace(/\.chunks\/documents\//, '.files/documents/')
.replace(this.id, this.thunkId(this.get('files_id')));
.replace(this.id, Genghis.Util.encodeDocumentId(this.get('files_id')));
}
});
6 changes: 3 additions & 3 deletions src/js/genghis/models/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Genghis.Models.Selection = Backbone.Model.extend({
this.servers.fetch({reset: true, error: showErrorMessage});

if (server) {
url = url + '/' + server;
url = url + '/' + encodeURIComponent(server);
this.currentServer.url = url;
this.currentServer.fetch({
reset: true,
Expand All @@ -62,7 +62,7 @@ Genghis.Models.Selection = Backbone.Model.extend({
}

if (database) {
url = url + '/' + database;
url = url + '/' + encodeURIComponent(database);
this.currentDatabase.url = url;
this.currentDatabase.fetch({
reset: true,
Expand All @@ -78,7 +78,7 @@ Genghis.Models.Selection = Backbone.Model.extend({
}

if (collection) {
url = url + '/' + collection;
url = url + '/' + encodeURIComponent(collection);
this.currentCollection.url = url;
this.currentCollection.fetch({
reset: true,
Expand Down
218 changes: 118 additions & 100 deletions src/js/genghis/router.js
Original file line number Diff line number Diff line change
@@ -1,103 +1,121 @@
Genghis.Router = Backbone.Router.extend({
routes: {
'': 'index',
'servers': 'redirectToIndex',
'servers/:server': 'server',
'servers/:server/databases': 'redirectToServer',
'servers/:server/databases/:database': 'database',
'servers/:server/databases/:database/collections': 'redirectToDatabase',
'servers/:server/databases/:database/collections/:collection': 'collection',
'servers/:server/databases/:database/collections/:collection/documents': 'collectionQueryOrRedirect',
'servers/:server/databases/:database/collections/:collection/documents?*query': 'collectionQueryOrRedirect',
'servers/:server/databases/:database/collections/:collection/documents/:documentId': 'document',
'*path': 'notFound'
},
index: function() {
document.title = 'Genghis';
app.selection.select();
app.showSection('servers');
},
redirectToIndex: function() {
this.navigate('', true);
},
server: function(server) {
document.title = this.buildTitle(server);
app.selection.select(server);
app.showSection('databases');
},
redirectToServer: function(server) {
this.navigate('servers/'+server, true);
},
database: function(server, database) {
document.title = this.buildTitle(server, database);
app.selection.select(server, database);
app.showSection('collections');
},
redirectToDatabase: function(server, database) {
this.navigate('servers/'+server+'/databases/'+database, true);
},
collection: function(server, database, collection) {
if (!!window.location.search) {
return this.collectionQueryOrRedirect(server, database, collection);
}
Genghis.Router = (function() {
var e = encodeURIComponent;

document.title = this.buildTitle(server, database, collection);
app.selection.select(server, database, collection);
app.showSection('documents');
},
redirectToCollection: function(server, database, collection) {
this.navigate('servers/'+server+'/databases/'+database+'/collections/'+collection, true);
},
collectionQueryOrRedirect: function(server, database, collection) {
if (!!window.location.search) {
return this.collectionQuery(server, database, collection, window.location.search.substr(1));
} else {
this.redirectToCollection(server, database, collection);
}
},
collectionQuery: function(server, database, collection, query) {
document.title = this.buildTitle(server, database, collection, 'Query results');
var params = Genghis.Util.parseQuery(query);
app.selection.select(server, database, collection, null, params.q, params.page);
app.showSection('documents');
},
redirectToQuery: function(server, database, collection, query) {
this.navigate('servers/'+server+'/databases/'+database+'/collections/'+collection+'/documents?'+Genghis.Util.buildQuery({q: encodeURIComponent(query)}), true);
},
document: function(server, database, collection, documentId) {
document.title = this.buildTitle(server, database, collection, decodeURIComponent(documentId));
app.selection.select(server, database, collection, decodeURIComponent(documentId));
app.showSection('document');
},
redirectToDocument: function(server, database, collection, document) {
this.navigate('servers/'+server+'/databases/'+database+'/collections/'+collection+'/documents/'+document, true);
},
redirectTo: function(server, database, collection, document, query) {
if (!server) return this.redirectToIndex();
if (!database) return this.redirectToServer(server);
if (!collection) return this.redirectToDatabase(server, database);

if (!document && !query) {
return this.redirectToCollection(server, database, collection);
} else if (!query) {
return this.redirectToDocument(server, database, collection, document);
} else {
return this.redirectToQuery(server, database, collection, query);
}
},
notFound: function(path) {
// fix a weird case where the Backbone router won't route if the root url == the current pathname.
if (path.replace(/(^\/|\/$)/g, '') == app.baseUrl.replace(/(^\/|\/$)/g, '')) return this.redirectToIndex();

document.title = this.buildTitle('404: Not Found');
app.showSection();
app.showMasthead('404: Not Found', "<p>If you think you've reached this message in error, please press <strong>0</strong> to speak with an operator. Otherwise, hang up and try again.</p>", {
error: true,
epic: true
});
},
buildTitle: function() {
function setTitle() {
var args = Array.prototype.slice.call(arguments);
return (args.length) ? 'Genghis \u2014 ' + args.join(' \u203A ') : 'Genghis';
document.title = (args.length) ? 'Genghis \u2014 ' + args.join(' \u203A ') : 'Genghis';
}
});

return Backbone.Router.extend({
routes: {
'': 'index',
'servers': 'redirectToIndex',
'servers/:server': 'server',
'servers/:server/databases': 'redirectToServer',
'servers/:server/databases/:database': 'database',
'servers/:server/databases/:database/collections': 'redirectToDatabase',
'servers/:server/databases/:database/collections/:collection': 'collection',
'servers/:server/databases/:database/collections/:collection/documents': 'collectionQueryOrRedirect',
'servers/:server/databases/:database/collections/:collection/documents?*query': 'collectionQueryOrRedirect',
'servers/:server/databases/:database/collections/:collection/documents/:documentId': 'document',
'*path': 'notFound'
},

index: function() {
setTitle();
app.selection.select();
app.showSection('servers');
},

redirectToIndex: function() {
this.navigate('', true);
},

server: function(server) {
setTitle(server);
app.selection.select(server);
app.showSection('databases');
},

redirectToServer: function(server) {
this.navigate('servers/' + e(server), true);
},

database: function(server, database) {
setTitle(server, database);
app.selection.select(server, database);
app.showSection('collections');
},

redirectToDatabase: function(server, database) {
this.navigate('servers/' + e(server) + '/databases/' + e(database), true);
},

collection: function(server, database, collection) {
if (!!window.location.search) {
return this.collectionQueryOrRedirect(server, database, collection);
}

setTitle(server, database, collection);
app.selection.select(server, database, collection);
app.showSection('documents');
},

redirectToCollection: function(server, database, collection) {
this.navigate('servers/' + e(server) + '/databases/' + e(database) + '/collections/' + e(collection), true);
},

collectionQueryOrRedirect: function(server, database, collection) {
if (!!window.location.search) {
return this.collectionQuery(server, database, collection, window.location.search.substr(1));
} else {
this.redirectToCollection(server, database, collection);
}
},

collectionQuery: function(server, database, collection, query) {
setTitle(server, database, collection, 'Query results');
var params = Genghis.Util.parseQuery(query);
app.selection.select(server, database, collection, null, params.q, params.page);
app.showSection('documents');
},

redirectToQuery: function(server, database, collection, query) {
this.navigate('servers/' + e(server) + '/databases/' + e(database) + '/collections/' + e(collection) + '/documents?' + Genghis.Util.buildQuery({q: e(query)}), true);
},

document: function(server, database, collection, documentId) {
setTitle(server, database, collection, Genghis.Util.decodeDocumentId(documentId));
app.selection.select(server, database, collection, documentId);
app.showSection('document');
},

redirectToDocument: function(server, database, collection, documentId) {
var e = encodeURIComponent;
this.navigate('servers/' + e(server) + '/databases/' + e(database) + '/collections/' + e(collection) + '/documents/' + e(documentId), true);
},

redirectTo: function(server, database, collection, documentId, query) {
if (!server) return this.redirectToIndex();
if (!database) return this.redirectToServer(server);
if (!collection) return this.redirectToDatabase(server, database);

if (!documentId && !query) {
return this.redirectToCollection(server, database, collection);
} else if (!query) {
return this.redirectToDocument(server, database, collection, documentId);
} else {
return this.redirectToQuery(server, database, collection, query);
}
},

notFound: function(path) {
setTitle('404: Not Found');
app.showSection();
app.showMasthead('404: Not Found', "<p>If you think you've reached this message in error, please press <strong>0</strong> to speak with an operator. Otherwise, hang up and try again.</p>", {
error: true,
epic: true
});
}
});
})();
16 changes: 16 additions & 0 deletions src/js/genghis/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,22 @@ Genghis.Util = {
return hex.join('');
},

encodeDocumentId: function(id) {
if (_.isObject(id) && id.hasOwnProperty('$genghisType') && id.$genghisType == 'ObjectId') {
return id.$value;
} else if (!_.isUndefined(id)) {
return '~' + this.base64Encode(JSON.stringify(id));
}
},

decodeDocumentId: function(id) {
if (_.isString(id) && id[0] === '~') {
return this.base64Decode(id.substr(1));
} else {
return id;
}
},

download: (function() {
var frame;
return function(url) {
Expand Down
4 changes: 2 additions & 2 deletions src/js/genghis/views/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ Genghis.Views.Search = Backbone.View.extend({
},
getDocumentQuery: function() {
var q = this.model.get('document');
if (typeof q === 'string' && q[0] === '~') {
q = Genghis.JSON.normalize('{"_id":' + Genghis.Util.base64Decode(q.substr(1)) + '}');
if (_.isString(q) && q[0] === '~') {
q = Genghis.JSON.normalize('{"_id":' + Genghis.Util.decodeDocumentId(q) + '}');
}

return q;
Expand Down

0 comments on commit 228cf08

Please sign in to comment.