diff --git a/examples/webPanel.js b/examples/webPanel.js index 75a0cf8..1b7e6a0 100644 --- a/examples/webPanel.js +++ b/examples/webPanel.js @@ -24,7 +24,7 @@ c : [1, 2, 3] }); - app.listen(8080, function () { - console.time().log('Server listening at port 8080'); + app.listen(3000, function () { + console.time().log('Server listening at port 3000'); }); }()); diff --git a/lib/logWriter.js b/lib/logWriter.js index 251ffba..dcea714 100644 --- a/lib/logWriter.js +++ b/lib/logWriter.js @@ -1,12 +1,12 @@ /* jshint -W098 */ -(function () { +(function() { 'use strict'; var moment = require('moment'), - fs = require('fs'), + fs = require('fs'), mkdirp = require('mkdirp'), - path = require('path'); + path = require('path'); /** @@ -27,7 +27,7 @@ * * @param {String} rootPath root logs folder */ - var LogWriter = function (rootPath) { + var LogWriter = function(rootPath) { this.rootPath = rootPath || 'logs'; @@ -47,20 +47,20 @@ * * Attach and init the history property */ - LogWriter.prototype.initHistory = function () { + LogWriter.prototype.initHistory = function() { this.history = { - dates : {} + dates: {} }; var historyPath = path.join(this.rootPath, 'history.json'); - if (!fs.existsSync(historyPath)) { //create file if doesn't exist yet + if (!fs.existsSync(historyPath)) { //create file if doesn't exist yet this.writeFile( historyPath, this.history, - function (err) { + function(err) { if (err) { throw err; } @@ -71,14 +71,14 @@ var self = this; - fs.readFile(historyPath, function (err, data) { + fs.readFile(historyPath, { + "encoding" : "utf-8" + }, function(err, data) { if (err) { throw err; } else { try { - self.history = JSON.parse(data); - } catch (e) { throw e; } @@ -95,8 +95,9 @@ * @param {String} path The dir * @param {Function} callback */ - LogWriter.prototype.createDir = function (path, callback) { - mkdirp(path, function (err) { + LogWriter.prototype.createDir = function(path, callback) { + + mkdirp(path, function(err) { callback(err); }); }; @@ -110,11 +111,11 @@ * @param {String} content * @param {Function} callback */ - LogWriter.prototype.appendFile = function (pathToFile, content, callback) { + LogWriter.prototype.appendFile = function(pathToFile, content, callback) { var self = this; - self.createDir(path.dirname(pathToFile), function (err) { + self.createDir(path.dirname(pathToFile), function(err) { if (err) { callback(err); @@ -122,7 +123,7 @@ var newFile = !fs.existsSync(pathToFile); - fs.appendFile(pathToFile, content, function (err) { + fs.appendFile(pathToFile, content, function(err) { if (err) { throw err; @@ -145,17 +146,19 @@ * @param {String} content * @param {Function} callback */ - LogWriter.prototype.writeFile = function (pathToFile, content, callback) { + LogWriter.prototype.writeFile = function(pathToFile, content, callback) { if (typeof content !== 'string') { content = JSON.stringify(content); } - this.createDir(path.dirname(pathToFile), function (err) { + this.createDir(path.dirname(pathToFile), function(err) { if (err) { callback(err); } else { - fs.writeFile(pathToFile, content, callback); + fs.writeFile(pathToFile, content, { + "encoding" : "utf-8" + }, callback); } }); }; @@ -167,12 +170,12 @@ * * @param {String} pathToFile */ - LogWriter.prototype.newFileHistory = function (pathToFile) { + LogWriter.prototype.newFileHistory = function(pathToFile) { var historyPath = path.join(this.rootPath, 'history.json'), - self = this; + self = this; - var today = moment().startOf('day').valueOf().toString(); + var today = moment().startOf('day').valueOf().toString(); //Save the path under today key @@ -184,7 +187,7 @@ self.history.dates[today].push(pathToFile); - self.writeFile(historyPath, self.history, function (err) { + self.writeFile(historyPath, self.history, function(err) { if (err) { throw err; } @@ -200,27 +203,22 @@ * * @return {String} */ - LogWriter.prototype.getUser = function () { + LogWriter.prototype.getUser = function() { var user = ''; try { - var platformKey = process.platform === 'win32' ? 'USERPROFILE' : 'HOME', + var platformKey = process.platform === 'win32' ? 'USERPROFILE' : 'HOME', platformDivider = process.platform === 'win32' ? '\\' : '/'; - var userDir = process.env[platformKey].toLowerCase(); user = userDir.slice(userDir.lastIndexOf(platformDivider) + 1); } catch (e) { - user = 'user'; //default - } finally { - return user; - } }; @@ -232,13 +230,13 @@ * * @return {String} The path to current folder (without rootPath) */ - LogWriter.prototype.getPath = function (opt) { + LogWriter.prototype.getPath = function(opt) { var now = moment(); return path.join( - now.format('YYYY'), - now.format('MMM') + now.format('YYYY'), + now.format('MMM') ); }; @@ -250,7 +248,7 @@ * * @return {String} the filname (with extension) */ - LogWriter.prototype.getFile = function (opt) { + LogWriter.prototype.getFile = function(opt) { var now = moment(); @@ -268,11 +266,11 @@ * * @return {String} the full path to file */ - LogWriter.prototype.path = function (opt) { + LogWriter.prototype.path = function(opt) { return path.join( - this.rootPath, - this.getPath(opt), - this.getFile(opt) + this.rootPath, + this.getPath(opt), + this.getFile(opt) ); }; @@ -286,13 +284,17 @@ * @param {Object} opt Options * @param {String} opt.logger logger options */ - LogWriter.prototype.save = function (log, opt) { + LogWriter.prototype.save = function(log, opt) { - delete log.opt; //we save logger options in rootPath/[logger].json + try { + delete log.opt; //we save logger options in rootPath/[logger].json + } catch(e){ + // ignore + } var json = JSON.stringify(log); - this.appendFile(this.path(opt), json + '\n', function (err) { + this.appendFile(this.path(opt), json + '\n', function(err) { if (err) { throw err; } @@ -306,16 +308,15 @@ * * @param {Object} logger Logger options. */ - LogWriter.prototype.saveOpt = function (logger) { + LogWriter.prototype.saveOpt = function(logger) { var filePath = path.join(this.rootPath, logger.name + '.json'); - this.writeFile(filePath, JSON.stringify(logger), function (err) { + this.writeFile(filePath, JSON.stringify(logger), function(err) { if (err) { throw err; } }); - }; /** @@ -326,15 +327,14 @@ * * @param {Object} logger Console2 logger options */ - LogWriter.prototype.addLogger = function (logger) { - + LogWriter.prototype.addLogger = function(logger) { this.saveOpt(logger); }; module.exports = { - LogWriter : LogWriter, - folders : rootPaths + LogWriter: LogWriter, + folders: rootPaths }; }()); diff --git a/lib/webPanel.js b/lib/webPanel.js index 1fbaa68..f3d1d94 100644 --- a/lib/webPanel.js +++ b/lib/webPanel.js @@ -1,13 +1,12 @@ /* jshint -W098 */ -(function () { +(function() { 'use strict'; - var express = require('express'), + var express = require('express'), serveStatic = require('serve-static'), - path = require('path'), - fs = require('fs'); - + path = require('path'), + fs = require('fs'); /** * map @@ -19,10 +18,11 @@ * @param {Function} callback * @return {Array} */ - var map = function (arr, callback) { + var map = function(arr, callback) { var result = arr.map(callback); - return result.filter(function (item) { + + return result.filter(function(item) { return item !== undefined && item !== null; }); }; @@ -38,13 +38,13 @@ * * @return {Express Router} */ - var initWebPanel = function (consoles) { + var initWebPanel = function(consoles) { var webPanel = express.Router(); //Static files - webPanel.use('/', serveStatic('./static')); + webPanel.use('/', serveStatic(path.join(__dirname, '..', 'static'))); //API @@ -56,18 +56,18 @@ * @param {String} dirPath A path * @param {Function} callback Function to chain with result array */ - var readDir = function (dirPath, callback) { + var readDir = function(dirPath, callback) { if (!dirPath || typeof dirPath !== 'string') { callback("dirPath must be a string"); } else { - fs.readdir(dirPath, function (err, list) { + fs.readdir(dirPath, function(err, list) { var dir = []; if (err) { callback(err, null); } else { - list.forEach(function (item) { + list.forEach(function(item) { dir.push(readNode(path.join(dirPath, item))); }); @@ -90,7 +90,7 @@ * @return {String} name * @return {String} path @see params */ - var readNode = function (itemPath) { + var readNode = function(itemPath) { var info = fs.statSync(itemPath), item = {}; @@ -107,8 +107,9 @@ * * @return {Array} logs folder in use */ - var getLogFolders = function () { - return map(consoles, function (elem) { + var getLogFolders = function() { + + return map(consoles, function(elem) { return elem.logWriter.rootPath || undefined; }); }; @@ -120,10 +121,11 @@ * * @return {LogWriter|false} If false, no logWriter with rootPath set to logFolder */ - var getLogWriter = function (logFolder) { + var getLogWriter = function(logFolder) { + var logWriter; - return consoles.some(function (item) { + return consoles.some(function(item) { if (item.logWriter && item.logWriter.rootPath === logFolder) { logWriter = item.logWriter; return true; @@ -138,7 +140,7 @@ * * Send logWriters */ - webPanel.get('/api', function (req, res) { + webPanel.get('/api', function(req, res) { var path = req.query.path; @@ -150,11 +152,11 @@ * * Send path content info */ - webPanel.get('/api/folderExplorer', function (req, res) { + webPanel.get('/api/folderExplorer', function(req, res) { var path = req.query.path; - readDir(path, function (err, dir) { + readDir(path, function(err, dir) { if (err) { res.status(400).end(); } else { @@ -169,10 +171,10 @@ * Send files according to history dates * With pagination */ - webPanel.get('/api/dateExplorer', function (req, res) { + webPanel.get('/api/dateExplorer', function(req, res) { - var from = req.query.from || Date.now(), - length = req.query.length || 10, + var from = req.query.from || Date.now(), + length = req.query.length || 10, logFolder = req.query.logFolder; var logWriter = getLogWriter(logFolder); @@ -182,27 +184,24 @@ } else { //Find the good dates - - var nb = 0, + var nb = 0, result = [], - dates = Object.keys(logWriter.history.dates).filter(function (date) { + dates = Object.keys(logWriter.history.dates).filter(function(date) { + if (date < from && nb <= length) { + nb++; + return date; + } else { + return null; + } + }); - if (date < from && nb <= length) { - nb++; - return date; - } else { - return null; - } - - }); - - dates.forEach(function (date) { + dates.forEach(function(date) { result.push({ - date : date, - files : map(logWriter.history.dates[date], function (item) { + date: date, + files: map(logWriter.history.dates[date], function(item) { return { - name : path.basename(item), - path : item + name: path.basename(item), + path: item }; }) }); @@ -217,33 +216,29 @@ * * Send stream of file content */ - webPanel.get('/api/log', function (req, res) { + webPanel.get('/api/log', function(req, res) { var path = req.query.path; if (fs.existsSync(path)) { var stream = fs.createReadStream(path); - res.writeHead(200, { - 'Content-Length': fs.statSync(path).size, - 'Content-Type' : 'text/plain' - }); - - res.status(200); - stream.pipe(res); + res.writeHead(200, { + 'Content-Length': fs.statSync(path).size, + 'Content-Type': 'text/plain' + }); + res.status(200); + stream.pipe(res); } else { res.status(400).send("Can't read path"); } }); - return webPanel; }; - module.exports = initWebPanel; - }()); diff --git a/static/fonts/fontello.eot b/static/fonts/fontello.eot new file mode 100644 index 0000000..ace1fbc Binary files /dev/null and b/static/fonts/fontello.eot differ diff --git a/static/fonts/fontello.svg b/static/fonts/fontello.svg new file mode 100644 index 0000000..e4ac19e --- /dev/null +++ b/static/fonts/fontello.svg @@ -0,0 +1,16 @@ + + + +Copyright (C) 2014 by original authors @ fontello.com + + + + + + + + + + + + \ No newline at end of file diff --git a/static/fonts/fontello.ttf b/static/fonts/fontello.ttf new file mode 100644 index 0000000..43e26a1 Binary files /dev/null and b/static/fonts/fontello.ttf differ diff --git a/static/fonts/fontello.woff b/static/fonts/fontello.woff new file mode 100644 index 0000000..dd799bf Binary files /dev/null and b/static/fonts/fontello.woff differ diff --git a/static/index.html b/static/index.html index 37751f0..91fe95a 100644 --- a/static/index.html +++ b/static/index.html @@ -7,10 +7,11 @@ {{title}} - ScribeJS - + @@ -18,23 +19,23 @@ - +
- +
-

{{title}}

+

{{path}}

- Mode : {{mode}} + {{mode}}
- +
- +
- + @@ -42,13 +43,13 @@ - + - + diff --git a/static/js/app.js b/static/js/app.js index 270d37a..0579364 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -47,9 +47,10 @@ var from = $location.search().from || Date.now(), //timestamp length = $location.search().length || 10, //number of dates to show logWriter = $location.search().path; //which log writer to use ? - + $rootScope.title = logWriter + ' dates'; - + $rootScope.path = logWriter + ' · dates'; + //Get dates return ScribeAPI.dateExplorer({ logFolder : logWriter, @@ -64,7 +65,7 @@ .when('/folder/', { templateUrl : 'partials/folder.html', controller : 'folderController', - + //resolve folder content resolve : { folder : [ @@ -72,11 +73,12 @@ '$rootScope', '$location', function (ScribeAPI, $rootScope, $location) { - + //folder path var path = $location.search().path; $rootScope.title = path; + $rootScope.path = path; //Get folder content return ScribeAPI.folderExplorer({ @@ -102,6 +104,12 @@ 'ScribeAPI', function ($rootScope, $location, $q, $window, $document, ScribeAPI) { + $rootScope.$on('$routeChangeSuccess', function(ev,data) { + if (data.$$route && data.$$route.controller){ + $rootScope.controller = data.$$route.controller; + } + }); + /** * getAllLogsFiles * @@ -115,7 +123,7 @@ var deferred = $q.defer(), loggersHistory = []; - + //First, get all history files loggers.forEach(function (logger) { loggersHistory.push(ScribeAPI.log({ @@ -156,13 +164,13 @@ * * Page title * - * @type {String} + * @type {String} */ $rootScope.title = "ScribeJS"; /** * $rootScope.sidebar - * + * * Open/close sidebar * * @type {Boolean} @@ -233,6 +241,6 @@ } ]); - + }()); diff --git a/static/js/controllers/logsController.js b/static/js/controllers/logsController.js index c8f917f..f1bada7 100644 --- a/static/js/controllers/logsController.js +++ b/static/js/controllers/logsController.js @@ -15,7 +15,6 @@ //reset $rootScope.sidebar = false; - /** * attachCurrentFiles * @@ -43,7 +42,7 @@ var getCurrentLogs = function () { $scope.currentFiles.forEach(function (file) { - + $scope.lines = []; if (file.selected) { @@ -79,10 +78,10 @@ //ng-toggle values //3 states : 1 / null / 0 - $scope.showFile = null; - $scope.showTime = 1; - $scope.showDate = 0; - $scope.showTags = null; + $scope.showFile = 0; + $scope.showTime = 0; + $scope.showDate = 1; + $scope.showTags = 1; //Stores all lines (a line = a log) $scope.lines = []; @@ -96,7 +95,7 @@ * $scope.addFile * * Add a file to current files - * + * * @param {String} path Its path (with logWriter dir) * @type {Function} */ @@ -117,7 +116,7 @@ attachCurrentFiles(logs.getLogs()); getCurrentLogs(); }; - + $scope.reload(); @@ -132,7 +131,7 @@ getCurrentLogs(); } }, true); - + //watch selectAll checkbox //to select all current files $scope.$watch('selectAll', function (value, old) { diff --git a/static/lib/autocomplete.css b/static/lib/autocomplete.css index d83ba43..7dee209 100644 --- a/static/lib/autocomplete.css +++ b/static/lib/autocomplete.css @@ -6,9 +6,13 @@ } .autocomplete input{ - font-size: 1.2em; + font-size: 10px; width: 100%; - padding:0.4em; + padding: 8px; + background: #222; + border: 1px solid #2C2C2C; + color: #FFF; + font-family: "Open Sans"; } .autocomplete ul{ @@ -25,8 +29,11 @@ text-align: left; list-style:none; width: 100%; - padding:0.4em; - background-color: #fff; + padding: 7px; + background: #333; + font-family: "Open Sans"; + font-size: 10px; + color: #FFF; } .autocomplete li.active{ diff --git a/static/lib/ng-toggle.css b/static/lib/ng-toggle.css index 4f83100..4e57f66 100644 --- a/static/lib/ng-toggle.css +++ b/static/lib/ng-toggle.css @@ -2,7 +2,7 @@ display: inline-block; margin: 3px; position: relative; - width: 62px; + width: 46px; height: 36px; -webkit-backface-visibility: hidden; -webkit-transform: translateZ(0) scale(1.0, 1.0); @@ -36,10 +36,10 @@ cursor: pointer; } .ng-toggle-switch.true { - background-color: #68C527; + background-color: #21ce99; } .ng-toggle-switch.false { - background-color: #ff4d35; + background-color: #323232; } .ng-toggle-false { position: absolute; @@ -59,7 +59,7 @@ border-radius: 100%; background-color: white; position: absolute; - top: 3px; + top: 1px; left: 16px; -webkit-box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.15); box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.15); @@ -70,7 +70,7 @@ left: 29px; } .ng-toggle-switch.false .ng-toggle-handle { - left: 3px; + left: 2px; } .ng-toggle-tooltip { display: inline-block; diff --git a/static/partials/elements/blocks.html b/static/partials/elements/blocks.html index 9e8b115..4afc6e6 100644 --- a/static/partials/elements/blocks.html +++ b/static/partials/elements/blocks.html @@ -1,9 +1,9 @@ -

{{messageTop}}

{{message}}

-

{{messageBottom}}

+

·  {{messageBottom}}

diff --git a/static/partials/elements/log.html b/static/partials/elements/log.html index b6345c9..7d65706 100644 --- a/static/partials/elements/log.html +++ b/static/partials/elements/log.html @@ -1,10 +1,10 @@

- + {{log.context.time | date: 'EEE MMM dd yyyy'}} - + {{log.context.time | date: 'yyyy-MM-ddTHH:mm:ss:Z'}} diff --git a/static/partials/elements/menu.html b/static/partials/elements/menu.html index 37e2c0c..7a0fa2d 100644 --- a/static/partials/elements/menu.html +++ b/static/partials/elements/menu.html @@ -2,31 +2,31 @@