From 59308536f6cafab4c7817621a8f583d0d671b0e1 Mon Sep 17 00:00:00 2001 From: Matt Date: Tue, 12 Apr 2016 22:51:47 -0400 Subject: [PATCH] Start logging on client side --- app/.gitignore | 3 +- app/css/app.css | 22 ++++++++++---- app/css/app.less | 5 ++-- app/js/app.js | 44 ++++++++++++++++++++++----- app/main.js | 19 ++++++++++++ app/src/index.js | 78 +++++++++++++++++++++++++++++++++++------------- 6 files changed, 134 insertions(+), 37 deletions(-) diff --git a/app/.gitignore b/app/.gitignore index dbf0821..7ab50be 100644 --- a/app/.gitignore +++ b/app/.gitignore @@ -1 +1,2 @@ -node_modules/* \ No newline at end of file +node_modules/* +logs/* \ No newline at end of file diff --git a/app/css/app.css b/app/css/app.css index c192a1e..1057a19 100644 --- a/app/css/app.css +++ b/app/css/app.css @@ -1,6 +1,16 @@ -#log{ - position: fixed; - bottom: 0; - width: 100%; - height: 100px; -} \ No newline at end of file +#footer { + position: fixed; + bottom: 0; + width: 100%; + height: 150px; +} +#log { + position: fixed; + width: 600px; + height: 150px; +} +#status { + position: fixed; + width: 100px; + right: 0; +} diff --git a/app/css/app.less b/app/css/app.less index 3836ef7..a750c99 100644 --- a/app/css/app.less +++ b/app/css/app.less @@ -4,12 +4,13 @@ position: fixed; bottom: 0; width: 100%; - height: 100px; + height: 150px; } #log{ position: fixed; - width: 700px; + width: 600px; + height: 150px; } #status{ diff --git a/app/js/app.js b/app/js/app.js index 20e5a9d..c49884f 100644 --- a/app/js/app.js +++ b/app/js/app.js @@ -65,31 +65,61 @@ var ipcRenderer = require('electron').ipcRenderer, log = {}; //console.log(ipcRenderer.sendSync('light', { 'fuck' : true }) ); +log.time = 'MM/DD/YY-HH:mm:ss'; +log.count = 0; log.init = function () { 'use strict'; $('#log').w2grid({ name : 'log', columns: [ - { field: 'time', caption: 'Time', size: '20%' }, - { field: 'action', caption: 'Action', size: '60%' }, + { field: 'time', caption: 'Time', size: '22%' }, + { field: 'action', caption: 'Action', size: '58%' }, { field: 'service', caption: 'Service', size: '20%' }, { field: 'status', caption: 'Status', size: '10%' }, ], - records: [ - { recid: 1, time: '4/11/2016', action: 'Started app', service: 'MAIN', status: true } - ] + records: [] + }); + //{ recid: 1, time: moment().format(log.time), action: 'Started app', service: 'MAIN', status: true } + log.info('Started app', 'MAIN', true); +}; + +log.listen = function () { + ipcRender.on('log', function (event, arg) { + console.log(arg); + return event.returnValue = true; }); }; -log.display = function () { +log.display = function (action, service, status, time) { 'use strict'; + var obj = { + recid : log.count++, + time : time, + action : action, + service : service, + status : status + } + if (typeof time === 'undefined') { + obj.time = moment().format(log.time); + } + w2ui['log'].add(obj); + $('#log').animate({ scrollTop: $('#log').prop('scrollHeight')}, 100); + return obj; }; -log.report = function () { +log.report = function (obj) { 'use strict'; + ipcRenderer.sendSync('log', obj); }; +log.info = function (action, service, status, time) { + 'use strict'; + var obj = log.display(action, service, status, time); + log.report(obj); + console.log(obj); +}; +//color = [0,0,0] light.set = function (color) { 'use strict'; console.log('color: ' + color.join(',')); diff --git a/app/main.js b/app/main.js index 35f6c40..0566ffa 100644 --- a/app/main.js +++ b/app/main.js @@ -14,6 +14,7 @@ var mainWindow; var init = function () { createWindow(); + log.init(); mcopy.arduino.init(function (success) { if (success) { mcopy.arduino.connect(function () { @@ -54,3 +55,21 @@ ipcMain.on('light', function(event, arg) { // event.returnValue = true; }); + +var log = {}; +log.init = function () { + 'use strict'; + log.listen(); +}; +log.display = function () { + 'use strict'; + ipcMain.sendSync({}); +}; + +log.listen = function () { + 'use strict'; + ipcMain.on('log', function (event, arg) { + console.log(arg); + event.returnValue = true; + }); +}; \ No newline at end of file diff --git a/app/src/index.js b/app/src/index.js index 838a275..a5b5fb2 100644 --- a/app/src/index.js +++ b/app/src/index.js @@ -1,8 +1,63 @@ var ipcRenderer = require('electron').ipcRenderer, - light = {}; + light = {}, + log = {}; //console.log(ipcRenderer.sendSync('light', { 'fuck' : true }) ); +log.time = 'MM/DD/YY-HH:mm:ss'; +log.count = 0; +log.init = function () { + 'use strict'; + $('#log').w2grid({ + name : 'log', + columns: [ + { field: 'time', caption: 'Time', size: '22%' }, + { field: 'action', caption: 'Action', size: '58%' }, + { field: 'service', caption: 'Service', size: '20%' }, + { field: 'status', caption: 'Status', size: '10%' }, + ], + records: [] + }); + //{ recid: 1, time: moment().format(log.time), action: 'Started app', service: 'MAIN', status: true } + log.info('Started app', 'MAIN', true); +}; +log.listen = function () { + ipcRender.on('log', function (event, arg) { + console.log(arg); + return event.returnValue = true; + }); +}; + +log.display = function (action, service, status, time) { + 'use strict'; + var obj = { + recid : log.count++, + time : time, + action : action, + service : service, + status : status + } + if (typeof time === 'undefined') { + obj.time = moment().format(log.time); + } + w2ui['log'].add(obj); + $('#log').animate({ scrollTop: $('#log').prop('scrollHeight')}, 100); + return obj; +}; + +log.report = function (obj) { + 'use strict'; + ipcRenderer.sendSync('log', obj); +}; + +log.info = function (action, service, status, time) { + 'use strict'; + var obj = log.display(action, service, status, time); + log.report(obj); + console.log(obj); +}; + +//color = [0,0,0] light.set = function (color) { 'use strict'; console.log('color: ' + color.join(',')); @@ -23,24 +78,5 @@ var init = function () { { type: 'button', id: 'item5', group: '1', caption: 'Settings', icon: 'fa-home' } ] }); - $('#log').w2grid({ - name : 'myGrid', - columns: [ - { field: 'fname', caption: 'First Name', size: '30%' }, - { field: 'lname', caption: 'Last Name', size: '30%' }, - { field: 'email', caption: 'Email', size: '40%' }, - { field: 'sdate', caption: 'Start Date', size: '120px' }, - ], - records: [ - { recid: 1, fname: 'John', lname: 'Doe', email: 'jdoe@gmail.com', sdate: '4/3/2012' }, - { recid: 2, fname: 'Stuart', lname: 'Motzart', email: 'jdoe@gmail.com', sdate: '4/3/2012' }, - { recid: 3, fname: 'Jin', lname: 'Franson', email: 'jdoe@gmail.com', sdate: '4/3/2012' }, - { recid: 4, fname: 'Susan', lname: 'Ottie', email: 'jdoe@gmail.com', sdate: '4/3/2012' }, - { recid: 5, fname: 'Kelly', lname: 'Silver', email: 'jdoe@gmail.com', sdate: '4/3/2012' }, - { recid: 6, fname: 'Francis', lname: 'Gatos', email: 'jdoe@gmail.com', sdate: '4/3/2012' }, - { recid: 7, fname: 'Mark', lname: 'Welldo', email: 'jdoe@gmail.com', sdate: '4/3/2012' }, - { recid: 8, fname: 'Thomas', lname: 'Bahh', email: 'jdoe@gmail.com', sdate: '4/3/2012' }, - { recid: 9, fname: 'Sergei', lname: 'Rachmaninov', email: 'jdoe@gmail.com', sdate: '4/3/2012' } - ] - }); + log.init(); }; \ No newline at end of file