From 07cf1ff77e2263c3eeaeee8f33187cf95b362e06 Mon Sep 17 00:00:00 2001 From: Guillaume Wuip Date: Thu, 1 Jan 2015 17:21:15 +0100 Subject: [PATCH 1/4] Add Gruntfile.js to gitignore for now --- .gitignore | 2 +- Gruntfile.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 Gruntfile.js diff --git a/.gitignore b/.gitignore index bc3e989..850254c 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,4 @@ logs*/ Thumbs.db -npm-debug.log \ No newline at end of file +npm-debug.logGruntfile.js diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..44125d4 --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,44 @@ +'use strict'; + +module.exports = function(grunt) { + + // Project configuration. + grunt.initConfig({ + jshint: { + options: { + jshintrc: '.jshintrc' + }, + gruntfile: { + src: ['scribe.js', 'Gruntfile.js'] + }, + lib: { + src: ['lib/**/*.js', 'examples/**/*.js', 'static/js/**/*.js'] + }, + test: { + src: ['test/**/*.js'] + }, + }, + watch: { + gruntfile: { + files: '<%= jshint.gruntfile.src %>', + tasks: ['jshint:gruntfile'] + }, + lib: { + files: '<%= jshint.lib.src %>', + tasks: ['jshint:lib'] + }, + test: { + files: '<%= jshint.test.src %>', + tasks: ['jshint:test'] + }, + }, + }); + + // These plugins provide necessary tasks. + grunt.loadNpmTasks('grunt-contrib-jshint'); + grunt.loadNpmTasks('grunt-contrib-watch'); + + // Default task. + grunt.registerTask('default', ['jshint']); + +}; From 233251916b3dc775be551d6fae1a1fd71894d965 Mon Sep 17 00:00:00 2001 From: Guillaume Wuip Date: Thu, 1 Jan 2015 19:55:03 +0100 Subject: [PATCH 2/4] Add /api/timezoneOffset --- lib/webPanel.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/webPanel.js b/lib/webPanel.js index bc4cc2e..5803c90 100644 --- a/lib/webPanel.js +++ b/lib/webPanel.js @@ -236,6 +236,20 @@ } }); + + /** + * /api/timezone + * + * Send the server timezone offset + */ + webPanel.get('/api/timezoneOffset', function (req, res) { + + res.status(200).json({ + timezoneOffset : (new Date()).getTimezoneOffset() + }); + + }); + return webPanel; }; From b08420a590bc93430098b28370ae259939de53d3 Mon Sep 17 00:00:00 2001 From: Guillaume Wuip Date: Thu, 1 Jan 2015 19:55:46 +0100 Subject: [PATCH 3/4] rootScope timezone offset variable and function --- static/js/app.js | 37 +++++++++++++++++++++++++++++++++ static/js/services/scribeAPI.js | 10 ++++++--- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/static/js/app.js b/static/js/app.js index 0579364..05789fc 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -204,6 +204,43 @@ }); }); + /** + * $rootScope.scribeTimezone + * + * Store the Scribe server timezoneOffset for showing good dates + * + * @type {Int} + */ + $rootScope.scribeTimezone = 0; + + ScribeAPI.timezoneOffset(function (result) { + $rootScope.scribeTimezone = result.timezoneOffset; + }); + + /** + * timezoneDate + * + * Add/remove minutes to the timestamp according to + * the timezone offset between server and browser time + * Because angular date filter print date with the browser timezone + * + * @param {Int|String} timestamp + * @return {Int} the new timestamp + * + * @type {Function} + */ + $rootScope.timezoneDate = function (timestamp) { + + timestamp = Number(timestamp); + + var serverOffset = $rootScope.scribeTimezone; + var localOffset = (new Date()).getTimezoneOffset(); + + var offset = serverOffset - localOffset; + + return timestamp + offset * 60; + }; + /** * $rootScope.back * diff --git a/static/js/services/scribeAPI.js b/static/js/services/scribeAPI.js index 013cae0..22c09ab 100644 --- a/static/js/services/scribeAPI.js +++ b/static/js/services/scribeAPI.js @@ -32,12 +32,12 @@ method : 'GET', url : 'api/log', isArray : true, - + //As logs are lines of JSON, we want to parse each lines one by one transformResponse : function (data) { - + var lines = data.match(/[^\r\n]+/g); //cut lines - + return lines.map(function (line) { try { return JSON.parse(line); @@ -46,6 +46,10 @@ } }); } + }, + timezoneOffset : { + methof : 'GET', + url : 'api/timezoneOffset' } } ); From b40c1fddf5abac37d2ff533372d6e1a01395cfba Mon Sep 17 00:00:00 2001 From: Guillaume Wuip Date: Thu, 1 Jan 2015 19:57:16 +0100 Subject: [PATCH 4/4] Update dates for timezone --- static/js/controllers/dateController.js | 18 +++++++++++------- static/js/controllers/folderController.js | 6 +++--- static/js/controllers/homeController.js | 2 +- static/js/directives/log.js | 4 +++- static/partials/elements/log.html | 4 ++-- static/partials/elements/sidebarLoggers.html | 4 ++-- 6 files changed, 22 insertions(+), 16 deletions(-) diff --git a/static/js/controllers/dateController.js b/static/js/controllers/dateController.js index e634999..3cee847 100644 --- a/static/js/controllers/dateController.js +++ b/static/js/controllers/dateController.js @@ -24,7 +24,7 @@ * Go to to a next page * * @param {int} next if < 0, goes to older dates, if > 0 goes to newer dates - */ + */ $scope.nextPage = function (next) { var currentDate = $location.search().from || Date.now(), @@ -42,17 +42,21 @@ //build blocks $scope.blocks = dates.map(function (item) { - + + var itemDate = $rootScope.timezoneDate(item.date); + console.log(item.date); + console.log(itemDate); + return { type : 'date', - messageTop : $filter('date')(item.date, 'MMM'), - message : $filter('date')(item.date, 'd'), - messageBottom : $filter('date')(item.date, 'yyyy'), + messageTop : $filter('date')(itemDate, 'MMM'), + message : $filter('date')(itemDate, 'd'), + messageBottom : $filter('date')(itemDate, 'yyyy'), click : function () { //save files logs.setLogs(item.files.map(function (el, index) { return { - selected : index === 0, //select the first by default + selected : index === 0, //select the first by default name : el.name, path : el.path }; @@ -62,7 +66,7 @@ $rootScope.go('logs'); } }; - + }); } ]); diff --git a/static/js/controllers/folderController.js b/static/js/controllers/folderController.js index f2e59a2..d0f3bc3 100644 --- a/static/js/controllers/folderController.js +++ b/static/js/controllers/folderController.js @@ -12,14 +12,14 @@ 'logs', 'folder', function ($scope, $rootScope, logs, folder) { - + //reset $rootScope.sidebar = false; $scope.onlyFiles = true; //build each block $scope.blocks = folder.map(function (item) { - + if (item.type !== 'file') { $scope.onlyFiles = false; } @@ -28,7 +28,7 @@ message : item.name, click : function () { if (item.type === 'file') { - + //Save all current files of the folder //But select only the clicked one var newFiles = folder.map(function (file) { diff --git a/static/js/controllers/homeController.js b/static/js/controllers/homeController.js index c9a4d8d..a001f1a 100644 --- a/static/js/controllers/homeController.js +++ b/static/js/controllers/homeController.js @@ -17,7 +17,7 @@ //build block for each logWriter $scope.blocks = $rootScope.logWriters.map(function (item) { - + return { message : item, click : function () { diff --git a/static/js/directives/log.js b/static/js/directives/log.js index 25710b3..42e199f 100644 --- a/static/js/directives/log.js +++ b/static/js/directives/log.js @@ -69,7 +69,9 @@ templateUrl : 'partials/elements/log.html', replace : true, - controller : ['$scope', function ($scope) { + controller : ['$rootScope', '$scope', function ($rootScope, $scope) { + + $scope.timezoneDate = $rootScope.timezoneDate; /** * $scope.handleTags diff --git a/static/partials/elements/log.html b/static/partials/elements/log.html index 40c0225..ea7dfe1 100644 --- a/static/partials/elements/log.html +++ b/static/partials/elements/log.html @@ -13,13 +13,13 @@ - {{log.context.time | date: 'EEE MMM dd yyyy'}} + {{timezoneDate(log.context.time) | date: 'EEE MMM dd yyyy'}} - {{log.context.time | date: 'yyyy-MM-ddTHH:mm:ss:Z'}} + {{timezoneDate(log.context.time) | date: 'yyyy-MM-ddTHH:mm:ss:Z'}} diff --git a/static/partials/elements/sidebarLoggers.html b/static/partials/elements/sidebarLoggers.html index c676dd7..a31ac55 100644 --- a/static/partials/elements/sidebarLoggers.html +++ b/static/partials/elements/sidebarLoggers.html @@ -5,11 +5,11 @@