Tidying code and new gulp process to build compiled version on CF.

This commit is contained in:
Martin Donnelly 2016-09-06 12:23:48 +01:00
parent 8429b48f93
commit 5927c4433f
12 changed files with 14973 additions and 66 deletions

View File

@ -1,2 +1,3 @@
node_modules
/sql/
/dist/

14
app.js
View File

@ -75,8 +75,7 @@ app.use(function(req, res, next) {
// Run npm start --production to use dist
var staticDir = isProduction ? 'dist' : 'app';
staticDir = 'app';
var graphFile = isProduction ? 'graph-release' : 'test';
app.use(express.static(path.join(__dirname, staticDir)));
app.use(errorhandler({dumpExceptions: true, showStack: true}));
@ -96,7 +95,7 @@ app.get('/graph', authentication(({
file: 'htpasswd', // Path of file
suppress: true // Suppress throwing Error if wrong user
})), function(req, res) {
res.render('test',{delimiter: '^'});
res.render(graphFile,{delimiter: '^'});
});
app.get('/meeting', function(req, res) {
@ -113,15 +112,6 @@ meetingApi(app);
messageApi(app);
//var mqttClient = require('./lib/mqtt/mqttClient');
var mqtt;
if (isProduction) {
// mqtt = new mqttClient.mqttClient(busEmitter);
}
var port = (process.env.VCAP_APP_PORT || 3011);
var host = (process.env.VCAP_APP_HOST || 'localhost');

View File

@ -1,5 +1,5 @@
{
"name": "Censis Smart Office ",
"name": "Censis MQTT Grapher",
"icons": [
{
"src": "\/fav\/android-chrome-36x36.png",

View File

@ -6,19 +6,8 @@
(function($) {
var GraphView;
var mqttConfig = {
orgId: 'qz0da4',
userName: 'a-qz0da4-dfwwdkmkzr',
appKey: '9txJEf3Cjy7hkSOvkv',
prefix: 'iot-2/type/mDot/id/'
};
var sendAuthentication = function(xhr) {
var user = mqttConfig.userName; // Your actual username
var pass = mqttConfig.appKey; // Your actual password
var token = user.concat(':', pass);
xhr.setRequestHeader('Authorization', ('Basic '.concat(btoa(token))));
};
/*
@ -42,6 +31,21 @@
});
},
getBranch: function(ts) {
const y = ts.getFullYear().toString();
const m = ts.getMonth().toString();
const d = ts.getDate().toString();
if (this.dateTree.hasOwnProperty(y)) {
if (this.dateTree[y].hasOwnProperty(m)) {
return this.dateTree[y][m][d];
} else {
return null;
}
} else {
return null;
}
},
findOccupancy: function(ts) {
/*
Get a branch from the date tree and see if the reduced set of records has a matching timestamp..
@ -49,9 +53,9 @@
var count = 0;
var tsDate = new Date(ts);
var tsMS = tsDate.getTime();
var branch = this.dateTree[tsDate.getFullYear().toString()][tsDate.getMonth().toString()][tsDate.getDate().toString()];
var branch = this.getBranch(tsDate);
if (typeof branch === 'undefined') {
if (typeof branch === 'undefined' || branch === 'null') {
return count;
}
_(branch).each(function(item) {
@ -149,24 +153,8 @@
notification.notify('success', 'Data loaded');
}, decoder: function(data) {
var _obj = {};
var _data = window.atob(data).split('');
//var bytes = _data.map(i => i.charCodeAt());
/*
_obj.light = parseInt('0x' + ('0' + bytes[0]).substr(-2) + ('0' + bytes[1]).substr(
-2));
_obj.co2 = parseInt(_data[2] + _data[3] + _data[4] + _data[5] + _data[6],
10);
_obj.temp = (parseInt(_data[7] + _data[8] + _data[9] + _data[10] + _data[11],
10) - 1000) / 10;
_obj.humid = (parseInt(_data[12] + _data[13] + _data[14] + _data[15] + _data[16],
10) / 10);
_obj.noise = parseInt('0x' + ('0' + bytes[17]).substr(-2) + ('0' + bytes[18]).substr(
-2));
_obj.binData = bytes;*/
return _obj;
}, decoder: function() {
return {};
}, dateTime: function($date) {
var dateTime = new Date.create($date);
var date = dateTime.format('{yyyy}-{MM}-{dd}');

2142
app/lib/require.js Normal file

File diff suppressed because it is too large Load Diff

12628
app/lib/sugar.js Normal file

File diff suppressed because it is too large Load Diff

View File

@ -23,6 +23,7 @@
"backbone": "^1.3.3",
"base64": "^1.0.0",
"notification-js": "^1.1.1",
"amstock3": "^3.20.12"
"amstock3": "^3.20.12",
"requirejs": "^2.3.1"
}
}

View File

@ -28,8 +28,27 @@ gulp.task('appJS', function() {
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('default'))
.pipe(concat('app.js'))
.pipe(uglify({mangle: false}))
.pipe(gulp.dest('www/js'));
.pipe(uglify({mangle: true, compress: {sequences: true, // Join consecutive statemets with the “comma operator”
properties: true, // Optimize property access: a["foo"] → a.foo
dead_code: true, // Discard unreachable code
drop_debugger: true, // Discard “debugger” statements
unsafe: false, // Some unsafe optimizations (see below)
conditionals: true, // Optimize if-s and conditional expressions
comparisons: true, // Optimize comparisons
evaluate: true, // Evaluate constant expressions
booleans: true, // Optimize boolean expressions
loops: true, // Optimize loops
unused: true, // Drop unused variables/functions
hoist_funs: true, // Hoist function declarations
hoist_vars: false, // Hoist variable declarations
if_return: true, // Optimize if-s followed by return/continue
join_vars: true, // Join var declarations
cascade: true, // Try to cascade `right` into `left` in sequences
side_effects: true, // Drop side-effect-free statements
warnings: true, // Warn about potentially dangerous optimizations/code
global_defs: {} // global definitions
}}))
.pipe(gulp.dest('dist/js'));
});
gulp.task('vendor', function() {
@ -46,17 +65,17 @@ gulp.task('vendor', function() {
])
.pipe(concat('vendor.js'))
.pipe(uglify({mangle: false}))
.pipe(gulp.dest('www/libs'));
.pipe(gulp.dest('dist/js'));
});
gulp.task('styles', function() {
return gulp.src(['src/bower_modules/mui/packages/cdn/css/mui.min.css','app/css/test.css','app/css/style.css','src/bower_modules/notification-js/build/notification.min.js'])
return gulp.src(['src/bower_modules/mui/packages/cdn/css/mui.min.css','app/css/test.css','app/css/style.css','src/bower_modules/notification-js/build/notification.min.css'])
.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
.pipe(cssnano())
.pipe(concat('app.css'))
.pipe(gulp.dest('www/css'));
.pipe(gulp.dest('dist/css'));
});
@ -72,22 +91,23 @@ gulp.task('index', function() {
}))
.pipe(htmlmin({removeComments: true, collapseWhitespace: true, keepClosingSlash: true}))
.pipe(gulp.dest('www/'));
.pipe(gulp.dest('dist/'));
});
gulp.task('partials', function() {
gulp.src(['app/partials/**/*']).pipe(gulp.dest('www/partials'));
// gulp.src(['app/libs/ejs_production.js']).pipe(gulp.dest('dist/libs'));
gulp.src(['app/fav/**/*']).pipe(gulp.dest('dist/fav'));
gulp.src(['app/lib/images/**/*']).pipe(gulp.dest('dist/amcharts/images'));
// Gulp.src(['app/libs/ejs_production.js']).pipe(gulp.dest('dist/libs'));
// gulp.src(['app/libs/microevent.js']).pipe(gulp.dest('dist/libs'));
//gulp.src(['app/fav/**/*']).pipe(size({title: 'Partials'})).pipe(gulp.dest('dist/fav'));
gulp.src(['app/img/logo.png']).pipe(gulp.dest('www/img'));
gulp.src(['app/gfx/**/*']).pipe(gulp.dest('dist/gfx'));
});
gulp.task('copy', function() {
return gulp.src(['app/**/*'])
.pipe(gulp.dest('www'));
.pipe(gulp.dest('dist'));
});
gulp.task('buildJS', function() {
@ -95,7 +115,7 @@ gulp.task('buildJS', function() {
});
gulp.task('clean', function() {
return del(['www']);
return del(['dist']);
});
@ -105,7 +125,7 @@ gulp.task('normal', ['clean'], function() {
});
gulp.task('default', ['clean'], function() {
gulp.start('buildJS','styles','index');
gulp.start('buildJS','styles','index','partials');
});
gulp.task('watch',function() {

View File

@ -21,17 +21,17 @@ module.exports = function(app) {
res.status(500).json({});
return -1;
} else {
logger.debug(req.body.type, req.body.device);
logger.debug(req.body.type, req.body.device);
dbSave.addProcessedEvent(obj)
.then(function(d) {
'use strict';
// logger.info('Finished - Processed');
// Logger.info('Finished - Processed');
res.status(200).json({});
})
.catch(function(e) {
'use strict';
logger.error(e);
res.status(500).json({});
res.status(500).json({});
});
}

View File

@ -9,6 +9,7 @@
var pgp = require('pg-promise')();
/*
var cn = {
host: 'localhost',
port: 5432,
@ -16,16 +17,17 @@ var cn = {
user: 'postgres',
password: ''
};
*/
// ElephantSql settings
/*var cn = {
var cn = {
host: 'jumbo.db.elephantsql.com',
port: 5432,
database: 'vmlcokon',
user: 'vmlcokon',
password: 'PQUYLiIW4M6r7SWyZevrES_rRAULYFkp'
};*/
database: 'amlrxqev',
user: 'amlrxqev',
password: 'K11cvCplk0--oNafsYj4ISN-rVQmVS3y'
};
exports.dbConnection = pgp(cn);

View File

@ -78,7 +78,8 @@
},
"scripts": {
"test": "mocha --recursive --reporter spec --bail --check-leaks --timeout 3000",
"start": "node app.js"
"start": "node app.js",
"prepublish" : "gulp default"
},
"author": "Martin Donnelly",
"license": "ISC",

134
views/graph-release.ejs Normal file
View File

@ -0,0 +1,134 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Graph</title>
<meta name="viewport"
content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
<link href="css/app.css" rel="stylesheet" type="text/css"/>
<link rel="apple-touch-icon" sizes="57x57"
href="/fav/apple-touch-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60"
href="/fav/apple-touch-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72"
href="/fav/apple-touch-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76"
href="/fav/apple-touch-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114"
href="/fav/apple-touch-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120"
href="/fav/apple-touch-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144"
href="/fav/apple-touch-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152"
href="/fav/apple-touch-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180"
href="/fav/apple-touch-icon-180x180.png">
<link rel="icon" type="image/png" href="/fav/favicon-32x32.png" sizes="32x32">
<link rel="icon" type="image/png" href="/fav/android-chrome-192x192.png"
sizes="192x192">
<link rel="icon" type="image/png" href="/fav/favicon-96x96.png" sizes="96x96">
<link rel="icon" type="image/png" href="/fav/favicon-16x16.png" sizes="16x16">
<link rel="manifest" href="/fav/manifest.json">
<link rel="mask-icon" href="/fav/safari-pinned-tab.svg" color="#5bbad5">
<link rel="shortcut icon" href="/fav/favicon.ico">
<meta name="msapplication-TileColor" content="#da532c">
<meta name="msapplication-TileImage" content="/fav/mstile-144x144.png">
<meta name="msapplication-config" content="/fav/browserconfig.xml">
<meta name="theme-color" content="#00aeef">
</head>
<body style="background-color:#171d25" class="mui--no-user-select">
<div class="mui-container">
<div class='mui-row'>
<div class="mui-col-md-3 panel">
<div class='mui-panel' id="main"></div>
<div id="output"></div>
</div>
<div class="mui-col-md-9">
<div class="mui-container">
<div id="chartdiv" style="width:100%; height:600px;"></div>
</div>
</div>
</div>
<script type="text/template" id="loaded-template">
<div
style="background-color: darkred;color: white;font-weight: 900;text-align: center">Loaded
</div>
</script>
<script type="text/template" id="main-template">
<div class="mui-container">
<div class="mui-row">
<div class="mui-select">
<select id="device" name="device">
<option></option>
<option>
HIE-mobile-1
</option>
<option>
HIE-demo
</option>
<option>
HIE-mobile-2
</option>
<option>
HIE-smart-campus-1
</option>
<option>
HIE-smart-campus-2
</option>
<option>
HIE-smart-campus-3
</option>
<option>
HIE-smart-campus-4
</option>
<option>
HIE-smart-campus-5
</option>
<option>
HIE-smart-campus-6
</option>
<option>
HIE-smart-campus-7
</option>
<option>
CENSIS-LoRa-1
</option>
<option>
CENSIS-LoRa-2
</option>
<option>
CENSIS-LoRa-3
</option>
<option>
CENSIS-LoRa-4
</option>
<option>
HIE-mDot-1
</option>
</select> <label>Device</label>
</div>
</div>
</div>
<div class="mui-row">
<div class="mui-col-md-12">
<button id='refresh'
class="mui-btn mui-btn--small mui-btn--primary">Refresh
</button>
</div>
</div>
</script>
<script type="text/template" id="list-template">
<ul></ul>
</script>
<script src="js/vendor.js"></script>
<script src="js/app.js"></script>
</body>
</html>