Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Moffat committed Jul 30, 2016
1 parent 6d6c744 commit 13f33f9
Show file tree
Hide file tree
Showing 13 changed files with 136 additions and 136 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Expand Up @@ -24,6 +24,7 @@
"space-before-function-paren": 0,
"space-before-blocks": ["error", "never"],
"camelcase": 0,
"handle-callback-err": ["error", "none"]
"handle-callback-err": ["error", "none"],
"object-curly-spacing": ["error", "never"]
}
}
14 changes: 7 additions & 7 deletions app.js
Expand Up @@ -35,11 +35,11 @@ var i18n = new (require('i18n-2'))({

// setup DB for server stats
var Datastore = require('nedb');
var db = new Datastore({ filename: path.join(dir_base, 'data/dbStats.db'), autoload: true });
var db = new Datastore({filename: path.join(dir_base, 'data/dbStats.db'), autoload: true});

// view engine setup
app.set('views', path.join(dir_base, 'views/'));
app.engine('hbs', handlebars({ extname: 'hbs', defaultLayout: path.join(dir_base, 'views/layouts/layout.hbs') }));
app.engine('hbs', handlebars({extname: 'hbs', defaultLayout: path.join(dir_base, 'views/layouts/layout.hbs')}));
app.set('view engine', 'hbs');

// helpers for the handlebars templating platform
Expand Down Expand Up @@ -99,8 +99,8 @@ if(fs.existsSync(config_connections, 'utf8')){

// setup the two conf. 'app' holds application config, and connections
// holds the mongoDB connections
nconf.add('connections', { type: 'file', file: config_connections });
nconf.add('app', { type: 'file', file: config_app });
nconf.add('connections', {type: 'file', file: config_connections});
nconf.add('app', {type: 'file', file: config_app});

// set app defaults
var app_host = '0.0.0.0';
Expand All @@ -127,8 +127,8 @@ if(nconf.stores.app.get('app:context') !== undefined){
}

app.use(logger('dev'));
app.use(bodyParser.json({ limit: '16mb' }));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json({limit: '16mb'}));
app.use(bodyParser.urlencoded({extended: false}));
app.use(cookieParser());

// setup session
Expand Down Expand Up @@ -227,7 +227,7 @@ async.forEachOf(connection_list, function (value, key, callback){

try{
uri = MongoURI.parse(value.connection_string);
connPool.addConnection({ connName: key, connString: value.connection_string, connOptions: value.connection_options }, app, function (err, data){
connPool.addConnection({connName: key, connString: value.connection_string, connOptions: value.connection_options}, app, function (err, data){
if(err)delete connection_list[key];
callback();
});
Expand Down
10 changes: 5 additions & 5 deletions connections.js
@@ -1,6 +1,6 @@
var MongoClient = require('mongodb').MongoClient;

exports.addConnection = function (connection, app, callback) {
exports.addConnection = function (connection, app, callback){
if(!app.locals.dbConnections){
app.locals.dbConnections = [];
}
Expand All @@ -9,23 +9,23 @@ exports.addConnection = function (connection, app, callback) {
connection.connOptions = {};
}

MongoClient.connect(connection.connString, connection.connOptions, function(err, database) {
MongoClient.connect(connection.connString, connection.connOptions, function(err, database){
if(err){
callback(err, null);
}else{
var dbObj = {};
dbObj.native = database;
dbObj.connString = connection.connString;
dbObj.connOptions = connection.connOptions;

app.locals.dbConnections[connection.connName] = null;
app.locals.dbConnections[connection.connName] = dbObj;
callback(null, null);
}
});
};

exports.removeConnection = function (connection, app) {
exports.removeConnection = function (connection, app){
if(!app.locals.dbConnections){
app.locals.dbConnections = [];
}
Expand All @@ -36,4 +36,4 @@ exports.removeConnection = function (connection, app) {

delete app.locals.dbConnections[connection];
return;
};
};
33 changes: 16 additions & 17 deletions electron.js
Expand Up @@ -4,18 +4,17 @@ const app = electron.app;
// Module to create native browser window.
const BrowserWindow = electron.BrowserWindow;

var express = require("./app.js");
var express = require('./app.js');

const {dialog} = require('electron');
const{dialog} = require('electron');

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow

function createWindow() {
let mainWindow;

function createWindow(){
// Create the browser window.
mainWindow = new BrowserWindow({ width: 1400, height: 800, 'node-integration': false })
mainWindow = new BrowserWindow({width: 1400, height: 800, 'node-integration': false});

// and load the index.html of the app.
mainWindow.loadURL('http://' + express.locals.app_host + ':' + express.locals.app_port);
Expand All @@ -24,39 +23,39 @@ function createWindow() {
mainWindow.maximize();

// Emitted when the window is closed.
mainWindow.on('closed', function () {
mainWindow.on('closed', function (){
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null;
})
});
}

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
//express.on('startedAdminMongo', createWindow);
app.on('ready', function () {
express.on('startedAdminMongo', function () {
// express.on('startedAdminMongo', createWindow);
app.on('ready', function (){
express.on('startedAdminMongo', function (){
createWindow();
});
});

var errorOnStartup = false;
express.on('errorAdminMongo', function () {
dialog.showErrorBox("Error","Error starting adminMongo. Please ensure no other instances are running before trying again.");
express.on('errorAdminMongo', function (){
dialog.showErrorBox('Error', 'Error starting adminMongo. Please ensure no other instances are running before trying again.');
app.quit();
});

// Quit when all windows are closed.
app.on('window-all-closed', function () {
app.on('window-all-closed', function (){
app.quit();
});

app.on('activate', function () {
app.on('activate', function (){
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (mainWindow === null) {
if(mainWindow === null){
createWindow();
}
});
});
2 changes: 1 addition & 1 deletion monitoring.js
Expand Up @@ -24,7 +24,7 @@ function serverMonitoringCleanup(db, conn){
idArray.push(value._id);
});

db.remove({'_id': {'$in': idArray}}, { multi: true }, function (err, newDoc){});
db.remove({'_id': {'$in': idArray}}, {multi: true}, function (err, newDoc){});
});
};

Expand Down
40 changes: 20 additions & 20 deletions routes/api.js
Expand Up @@ -16,12 +16,12 @@ router.post('/api/:conn/:db/:coll/:page', function (req, res, next){

// Check for existance of connection
if(connection_list[req.params.conn] === undefined){
res.status(400).json({ 'msg': req.i18n.__('Invalid connection name') });
res.status(400).json({'msg': req.i18n.__('Invalid connection name')});
}

// Validate database name
if(req.params.db.indexOf(' ') > -1){
res.status(400).json({ 'msg': req.i18n.__('Invalid database name') });
res.status(400).json({'msg': req.i18n.__('Invalid database name')});
}

// Get DB's form pool
Expand Down Expand Up @@ -54,12 +54,12 @@ router.post('/api/:conn/:db/:coll/:page', function (req, res, next){
}
}

mongo_db.collection(req.params.coll).find(query_obj, { skip: skip, limit: limit }).toArray(function (err, result){
mongo_db.collection(req.params.coll).find(query_obj, {skip: skip, limit: limit}).toArray(function (err, result){
if(err){
console.error(err);
res.status(500).json(err);
}else{
mongo_db.collection(req.params.coll).find({}, { skip: skip, limit: limit }).toArray(function (err, simpleSearchFields){
mongo_db.collection(req.params.coll).find({}, {skip: skip, limit: limit}).toArray(function (err, simpleSearchFields){
// get field names/keys of the Documents in collection
var fields = [];
for(var i = 0; i < simpleSearchFields.length; i++){
Expand Down Expand Up @@ -98,7 +98,7 @@ router.get('/api/monitoring/:conn', function (req, res, next){
// 24 hours worth of 30 sec blocks (data refresh interval)
var recordCount = (24 * 60) * 60 / 30;

req.db.find({ connectionName: req.params.conn }).sort({ eventDate: -1 }).limit(recordCount).exec(function (err, serverEvents){
req.db.find({connectionName: req.params.conn}).sort({eventDate: -1}).limit(recordCount).exec(function (err, serverEvents){
var connectionsCurrent = [];
var connectionsAvailable = [];
var connectionsTotalCreated = [];
Expand All @@ -122,28 +122,28 @@ router.get('/api/monitoring/:conn', function (req, res, next){
_.each(serverEvents, function (value, key){
// connections
if(value.connections){
connectionsCurrent.push({ x: value.eventDate, y: value.connections.current });
connectionsAvailable.push({ x: value.eventDate, y: value.connections.available });
connectionsTotalCreated.push({ x: value.eventDate, y: value.connections.totalCreated });
connectionsCurrent.push({x: value.eventDate, y: value.connections.current});
connectionsAvailable.push({x: value.eventDate, y: value.connections.available});
connectionsTotalCreated.push({x: value.eventDate, y: value.connections.totalCreated});
}
// clients
if(value.activeClients){
clientsTotal.push({ x: value.eventDate, y: value.activeClients.total });
clientsReaders.push({ x: value.eventDate, y: value.activeClients.readers });
clientsWriters.push({ x: value.eventDate, y: value.activeClients.writers });
clientsTotal.push({x: value.eventDate, y: value.activeClients.total});
clientsReaders.push({x: value.eventDate, y: value.activeClients.readers});
clientsWriters.push({x: value.eventDate, y: value.activeClients.writers});
}
// memory
if(value.memory){
memoryVirtual.push({ x: value.eventDate, y: value.memory.virtual });
memoryMapped.push({ x: value.eventDate, y: value.memory.mapped });
memoryCurrent.push({ x: value.eventDate, y: value.memory.resident });
memoryVirtual.push({x: value.eventDate, y: value.memory.virtual});
memoryMapped.push({x: value.eventDate, y: value.memory.mapped});
memoryCurrent.push({x: value.eventDate, y: value.memory.resident});
}

if(value.docCounts){
docsQueried.push({ x: value.eventDate, y: value.docCounts.queried });
docsInserted.push({ x: value.eventDate, y: value.docCounts.inserted });
docsDeleted.push({ x: value.eventDate, y: value.docCounts.deleted });
docsUpdated.push({ x: value.eventDate, y: value.docCounts.updated });
docsQueried.push({x: value.eventDate, y: value.docCounts.queried});
docsInserted.push({x: value.eventDate, y: value.docCounts.inserted});
docsDeleted.push({x: value.eventDate, y: value.docCounts.deleted});
docsUpdated.push({x: value.eventDate, y: value.docCounts.updated});
}
});
}
Expand Down Expand Up @@ -174,9 +174,9 @@ router.get('/api/monitoring/:conn', function (req, res, next){
}

if(err){
res.status(400).json({ 'msg': req.i18n.__('Could not get server monitoring') });
res.status(400).json({'msg': req.i18n.__('Could not get server monitoring')});
}else{
res.status(200).json({ data: returnedData, dataRetrieved: serverEvents[0].dataRetrieved, pid: serverEvents[0].pid, version: serverEvents[0].version, uptime: uptime });
res.status(200).json({data: returnedData, dataRetrieved: serverEvents[0].dataRetrieved, pid: serverEvents[0].pid, version: serverEvents[0].version, uptime: uptime});
}
}
});
Expand Down

0 comments on commit 13f33f9

Please sign in to comment.