-
Notifications
You must be signed in to change notification settings - Fork 38
Adding readonlymode and db filtering for the data explorer #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,7 +45,9 @@ module.exports = function(config) { | |
| }) | ||
| } | ||
| else { | ||
| r.dbList().forEach(function(db) { | ||
| r.dbList().filter(function(dbName) { | ||
| return dbName.match(config.filterDB || '.*'); | ||
| }).forEach(function(db) { | ||
| return r.expr({ | ||
| x: [{ | ||
| db: db, | ||
|
|
@@ -72,7 +74,9 @@ module.exports = function(config) { | |
| }) | ||
| } | ||
| exports.databases = function (req, res) { | ||
| r.dbList().run( connection, {timeFormat: 'raw'}, function(error, dbs) { | ||
| r.dbList().filter(function(dbName) { | ||
| return dbName.match(config.filterDB || '.*'); | ||
| }).run( connection, {timeFormat: 'raw'}, function(error, dbs) { | ||
| if (error) handleError(error); | ||
| res.json({ | ||
| error: error, | ||
|
|
@@ -867,64 +871,68 @@ module.exports = function(config) { | |
| function flattenKeys(keys, prefix, numDocs) { | ||
| var result = []; | ||
|
|
||
| for(var i=0; i<keys.sorted_keys.length; i++) { | ||
| var hasNestedKeys; | ||
| if (keys.keys[keys.sorted_keys[i]].keys == null) { | ||
| hasNestedKeys = false; | ||
| } | ||
| else { | ||
| for(var key in keys.keys[keys.sorted_keys[i]].keys) { | ||
| hasNestedKeys = true; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| // Save the field if it's a primitive (at least once) or if it's an empty object | ||
| if ((keys.keys[keys.sorted_keys[i]].primitiveValueCount > 0) || (hasNestedKeys === false)) { | ||
| result.push(prefix.concat(keys.sorted_keys[i])) | ||
| } | ||
| else { | ||
| var count = 0; | ||
| for(var type in keys.keys[keys.sorted_keys[i]].type) { | ||
| count += keys.keys[keys.sorted_keys[i]].type[type] | ||
| } | ||
| if (typeof keys.keys[keys.sorted_keys[i]].primitiveCount === 'number') { | ||
| count += keys.keys[keys.sorted_keys[i]].primitiveCount; | ||
| } | ||
|
|
||
| if (count < numDocs) { | ||
| result.push(prefix.concat(keys.sorted_keys[i])) | ||
| } | ||
| } | ||
|
|
||
| // Recursively add more fields | ||
| if ((keys.keys[keys.sorted_keys[i]].type.object != null) | ||
| && (keys.keys[keys.sorted_keys[i]].type.object > 0)) { | ||
| result.push.apply(result, flattenKeys(keys.keys[keys.sorted_keys[i]], prefix.concat([keys.sorted_keys[i]]), numDocs)) | ||
| } | ||
| if(keys.sorted_keys){ | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you need keys.sorted_keys? Isn't it always an array?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One of the errors, where keys.sorted_keys is undefined, as the some of the keys in the document, are guids. Just to unblock on the error, added the check for keys.sorted_keys. an example document. |
||
| for(var i=0; i<keys.sorted_keys.length; i++) { | ||
| var hasNestedKeys; | ||
| if (keys.keys[keys.sorted_keys[i]].keys == null) { | ||
| hasNestedKeys = false; | ||
| } | ||
| else { | ||
| for(var key in keys.keys[keys.sorted_keys[i]].keys) { | ||
| hasNestedKeys = true; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| // Save the field if it's a primitive (at least once) or if it's an empty object | ||
| if ((keys.keys[keys.sorted_keys[i]].primitiveValueCount > 0) || (hasNestedKeys === false)) { | ||
| result.push(prefix.concat(keys.sorted_keys[i])) | ||
| } | ||
| else { | ||
| var count = 0; | ||
| for(var type in keys.keys[keys.sorted_keys[i]].type) { | ||
| count += keys.keys[keys.sorted_keys[i]].type[type] | ||
| } | ||
| if (typeof keys.keys[keys.sorted_keys[i]].primitiveCount === 'number') { | ||
| count += keys.keys[keys.sorted_keys[i]].primitiveCount; | ||
| } | ||
|
|
||
| if (count < numDocs) { | ||
| result.push(prefix.concat(keys.sorted_keys[i])) | ||
| } | ||
| } | ||
|
|
||
| // Recursively add more fields | ||
| if ((keys.keys[keys.sorted_keys[i]].type.object != null) | ||
| && (keys.keys[keys.sorted_keys[i]].type.object > 0)) { | ||
| result.push.apply(result, flattenKeys(keys.keys[keys.sorted_keys[i]], prefix.concat([keys.sorted_keys[i]]), numDocs)) | ||
| } | ||
| } | ||
| } | ||
| return result | ||
| } | ||
| function nestedKeys(keys, prefix) { | ||
| var result = []; | ||
| prefix = prefix || [] | ||
|
|
||
| for(var i=0; i<keys.sorted_keys.length; i++) { | ||
| if ((keys.keys[keys.sorted_keys[i]].type.object != null) | ||
| && (keys.keys[keys.sorted_keys[i]].type.object > 0)) { | ||
|
|
||
| result.push({ | ||
| field: keys.sorted_keys[i], | ||
| prefix: prefix, | ||
| nested: nestedKeys( keys.keys[keys.sorted_keys[i]], prefix.concat([keys.sorted_keys[i]])) | ||
| }) | ||
| } | ||
| else { | ||
| result.push({ | ||
| field: keys.sorted_keys[i], | ||
| prefix: prefix | ||
| }) | ||
| } | ||
| if(keys.sorted_keys){ | ||
| for(var i=0; i<keys.sorted_keys.length; i++) { | ||
| if ((keys.keys[keys.sorted_keys[i]].type.object != null) | ||
| && (keys.keys[keys.sorted_keys[i]].type.object > 0)) { | ||
|
|
||
| result.push({ | ||
| field: keys.sorted_keys[i], | ||
| prefix: prefix, | ||
| nested: nestedKeys( keys.keys[keys.sorted_keys[i]], prefix.concat([keys.sorted_keys[i]])) | ||
| }) | ||
| } | ||
| else { | ||
| result.push({ | ||
| field: keys.sorted_keys[i], | ||
| prefix: prefix | ||
| }) | ||
| } | ||
| } | ||
| } | ||
| return result | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,14 @@ | ||
| var appConfig = null; | ||
|
|
||
| exports.config = function(config){ | ||
| appConfig = config; | ||
| }; | ||
|
|
||
| exports.index = function(req, res){ | ||
| res.render('index'); | ||
| res.render('index', {"isReadOnlyMode": appConfig.isReadOnlyMode}); | ||
| }; | ||
|
|
||
| exports.partials = function (req, res) { | ||
| var name = req.params.name; | ||
| res.render('partials/' + name); | ||
| res.render('partials/' + name , {"isReadOnlyMode": appConfig.isReadOnlyMode}); | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably want:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will change it undefined check, rather than typeof. Will send a new pull with the changes.