mirror of
https://github.com/mgerb/mywebsite
synced 2026-01-12 02:42:48 +00:00
updated bunch of file paths and changed the way posts are loaded
This commit is contained in:
105
node_modules/mongo-express/routes/collection.js
generated
vendored
105
node_modules/mongo-express/routes/collection.js
generated
vendored
@@ -1,8 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
var os = require('os');
|
||||
|
||||
var bson = require('../bson');
|
||||
var _ = require('underscore');
|
||||
var os = require('os');
|
||||
var bson = require('../bson');
|
||||
|
||||
var routes = function(config) {
|
||||
var exp = {};
|
||||
@@ -14,7 +14,7 @@ var routes = function(config) {
|
||||
var skip = parseInt(req.query.skip, 10) || 0;
|
||||
var query_options = {
|
||||
limit: limit,
|
||||
skip: skip
|
||||
skip: skip,
|
||||
};
|
||||
|
||||
// some query filter
|
||||
@@ -25,16 +25,34 @@ var routes = function(config) {
|
||||
var type = req.query.type || '';
|
||||
var jsonQuery = req.query.query || '';
|
||||
var jsonFields = req.query.fields || '';
|
||||
var dbName = req.params.database;
|
||||
var collectionName = req.params.collection;
|
||||
var defaultKey = (config.defaultKeyNames && config.defaultKeyNames[dbName] && config.defaultKeyNames[dbName][collectionName]) ?
|
||||
config.defaultKeyNames[dbName][collectionName] :
|
||||
'_id';
|
||||
var edKey = function(doc, defaultKey) {
|
||||
var defaultKeyAsArray = defaultKey.split('.');
|
||||
var val = doc;
|
||||
for (var i = 0; i < defaultKeyAsArray.length; i++) {
|
||||
if (val[defaultKeyAsArray[i]]) {
|
||||
val = val[defaultKeyAsArray[i]];
|
||||
}
|
||||
}
|
||||
|
||||
return val;
|
||||
};
|
||||
|
||||
if (key && value) {
|
||||
// If type == J, convert value as json document
|
||||
if (type.toUpperCase() === 'J') {
|
||||
value = JSON.parse(req.query.value);
|
||||
}
|
||||
|
||||
// If type == N, convert value to Number
|
||||
if (type.toUpperCase() === 'N') {
|
||||
value = Number(req.query.value);
|
||||
}
|
||||
|
||||
// If type == O, convert value to ObjectID
|
||||
// TODO: Add ObjectID validation to prevent error messages.
|
||||
if (type.toUpperCase() === 'O') {
|
||||
@@ -44,16 +62,18 @@ var routes = function(config) {
|
||||
return res.redirect('back');
|
||||
}
|
||||
}
|
||||
|
||||
query[key] = value;
|
||||
} else if (jsonQuery) {
|
||||
query = bson.toSafeBSON(jsonQuery);
|
||||
if (query === null) {
|
||||
req.session.error = 'Query entered is not valid';
|
||||
return res.redirect('back');
|
||||
}
|
||||
if (jsonFields) {
|
||||
fields = bson.toSafeBSON(jsonFields) || {};
|
||||
}
|
||||
query = bson.toSafeBSON(jsonQuery);
|
||||
if (query === null) {
|
||||
req.session.error = 'Query entered is not valid';
|
||||
return res.redirect('back');
|
||||
}
|
||||
|
||||
if (jsonFields) {
|
||||
fields = bson.toSafeBSON(jsonFields) || {};
|
||||
}
|
||||
} else {
|
||||
query = {};
|
||||
}
|
||||
@@ -63,38 +83,51 @@ var routes = function(config) {
|
||||
|
||||
//Pagination
|
||||
//Have to do this here, swig template doesn't allow any calculations :(
|
||||
var prev, prev2, here, next2, next, last;
|
||||
var prev;
|
||||
var prev2;
|
||||
var here;
|
||||
var next2;
|
||||
var next;
|
||||
var last;
|
||||
var pagination;
|
||||
|
||||
prev = {
|
||||
page: Math.round((skip - limit) / limit) + 1,
|
||||
skip: skip - limit
|
||||
skip: skip - limit,
|
||||
};
|
||||
prev2 = {
|
||||
page: Math.round((skip - limit * 2) / limit) + 1,
|
||||
skip: skip - limit * 2
|
||||
skip: skip - limit * 2,
|
||||
};
|
||||
next2 = {
|
||||
page: Math.round((skip + limit * 2) / limit) + 1,
|
||||
skip: skip + limit * 2
|
||||
skip: skip + limit * 2,
|
||||
};
|
||||
next = {
|
||||
page: Math.round((skip + limit) / limit) + 1,
|
||||
skip: skip + limit
|
||||
skip: skip + limit,
|
||||
};
|
||||
here = Math.round(skip / limit) + 1;
|
||||
last = (Math.ceil(stats.count / limit) - 1) * limit;
|
||||
pagination = stats.count > limit;
|
||||
|
||||
var docs = [];
|
||||
var docs = [];
|
||||
var columns = [];
|
||||
|
||||
for(var i in items) {
|
||||
for (var i in items) {
|
||||
docs[i] = items[i];
|
||||
columns.push(Object.keys(items[i]));
|
||||
items[i] = bson.toString(items[i]);
|
||||
}
|
||||
|
||||
// Generate an array of columns used by all documents visible on this page
|
||||
columns = _.uniq(_.flatten(columns));
|
||||
|
||||
var ctx = {
|
||||
title: 'Viewing Collection: ' + req.collectionName,
|
||||
documents: items, //Docs converted to strings
|
||||
docs: docs, //Original docs
|
||||
documents: items, // Docs converted to strings
|
||||
docs: docs, // Original docs
|
||||
columns: columns, // All used columns
|
||||
stats: stats,
|
||||
editorTheme: config.options.editorTheme,
|
||||
limit: limit,
|
||||
@@ -105,11 +138,14 @@ var routes = function(config) {
|
||||
next: next,
|
||||
here: here,
|
||||
last: last,
|
||||
pagination: pagination,
|
||||
key: key,
|
||||
value: value,
|
||||
type: type,
|
||||
query: jsonQuery,
|
||||
fields: jsonFields
|
||||
fields: jsonFields,
|
||||
defaultKey: defaultKey,
|
||||
edKey: edKey,
|
||||
};
|
||||
|
||||
res.render('collection', ctx);
|
||||
@@ -119,18 +155,28 @@ var routes = function(config) {
|
||||
|
||||
exp.exportCollection = function(req, res) {
|
||||
req.collection.find().toArray(function(err, items) {
|
||||
res.setHeader('Content-disposition', 'attachment; filename=' + req.collectionName + '.json');
|
||||
res.setHeader('Content-disposition', 'attachment; filename=' + req.collectionName + '.json');
|
||||
res.setHeader('Content-type', 'application/json');
|
||||
var aItems = [];
|
||||
for(var i in items) {
|
||||
var docStr = bson.toJsonString(items[i]);
|
||||
aItems.push(docStr);
|
||||
}
|
||||
for (var i in items) {
|
||||
var docStr = bson.toJsonString(items[i]);
|
||||
aItems.push(docStr);
|
||||
}
|
||||
|
||||
res.write(aItems.join(os.EOL));
|
||||
res.end();
|
||||
});
|
||||
};
|
||||
|
||||
exp.exportColArray = function(req, res) {
|
||||
req.collection.find().toArray(function(err, items) {
|
||||
res.setHeader('Content-disposition', 'attachment; filename=' + req.collectionName + '.json');
|
||||
res.setHeader('Content-type', 'application/json');
|
||||
res.write(bson.toJsonString(items));
|
||||
res.end();
|
||||
});
|
||||
};
|
||||
|
||||
exp.addCollection = function(req, res) {
|
||||
var name = req.body.collection;
|
||||
|
||||
@@ -159,7 +205,6 @@ var routes = function(config) {
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
exp.deleteCollection = function(req, res) {
|
||||
req.collection.drop(function(err) {
|
||||
if (err) {
|
||||
@@ -183,7 +228,6 @@ var routes = function(config) {
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
exp.renameCollection = function(req, res) {
|
||||
var name = req.body.collection;
|
||||
|
||||
@@ -198,7 +242,7 @@ var routes = function(config) {
|
||||
return res.redirect('back');
|
||||
}
|
||||
|
||||
req.collection.rename(name, function(err, collection) {
|
||||
req.collection.rename(name, function(err) {
|
||||
if (err) {
|
||||
req.session.error = 'Something went wrong: ' + err;
|
||||
console.error(err);
|
||||
@@ -216,6 +260,7 @@ var routes = function(config) {
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
return exp;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user