summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Kowalski <rok@kowalski.gd>2014-04-13 13:48:00 +0200
committerGarren Smith <garren.smith@gmail.com>2014-04-14 08:50:47 +0200
commit11f9d8af5da693a6ff3f8f33aa538caab5892869 (patch)
tree0645ae963b4bc5720bbae0c39151af96c19a3a97
parent198eb74752504dc62eba7d4232b5ebff9fbf988c (diff)
downloadcouchdb-11f9d8af5da693a6ff3f8f33aa538caab5892869.tar.gz
Fauxton: fix missing leading zeros in logs
This adds leading zeros to the times in the log view. Before that the times were displayed like 1:5:3 (if it were 01:05:03) because getHours() and friends are returning a Number and not a String with a leading 0. In the case of 1:5:3 the corrected time is now displayed as: 01:05:03. As d3 has a nice date formatter we do not have to roll our own.
-rw-r--r--src/Makefile.am3
-rw-r--r--src/fauxton/app/addons/logs/resources.js15
-rw-r--r--src/fauxton/app/addons/logs/tests/baseSpec.js (renamed from src/fauxton/app/addons/logs/tests/logSpec.js)0
-rw-r--r--src/fauxton/app/addons/logs/tests/resourcesSpec.js38
4 files changed, 47 insertions, 9 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 07ee5e150..ea1a11ba3 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -84,7 +84,8 @@ FAUXTON_FILES = \
fauxton/app/addons/logs/templates/dashboard.html \
fauxton/app/addons/logs/templates/filterItem.html \
fauxton/app/addons/logs/templates/sidebar.html \
- fauxton/app/addons/logs/tests/logSpec.js \
+ fauxton/app/addons/logs/tests/baseSpec.js \
+ fauxton/app/addons/logs/tests/resourcesSpec.js \
fauxton/app/addons/permissions/assets/less/permissions.less \
fauxton/app/addons/permissions/base.js \
fauxton/app/addons/permissions/resources.js \
diff --git a/src/fauxton/app/addons/logs/resources.js b/src/fauxton/app/addons/logs/resources.js
index 3a47b9261..5cfa673c3 100644
--- a/src/fauxton/app/addons/logs/resources.js
+++ b/src/fauxton/app/addons/logs/resources.js
@@ -13,22 +13,21 @@
define([
"app",
"api",
- "backbone"
+ "backbone",
+ "d3"
],
-function (app, FauxtonAPI, Backbone) {
+function (app, FauxtonAPI, Backbone, d3) {
var Log = FauxtonAPI.addon();
Log.Model = Backbone.Model.extend({
date: function () {
- var date = new Date(this.get('date'));
+ var date = new Date(this.get('date')),
+ formatter = d3.time.format("%b %e %H:%M%:%S");
- var formatted_time = date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
- var formatted_date = date.toDateString().slice(4, 10);
-
- return formatted_date + ' ' + formatted_time;
+ return formatter(date);
},
logLevel: function () {
@@ -51,7 +50,7 @@ function (app, FauxtonAPI, Backbone) {
initialize: function (options) {
this.params = {bytes: 5000};
},
-
+
documentation: "log",
url: function () {
diff --git a/src/fauxton/app/addons/logs/tests/logSpec.js b/src/fauxton/app/addons/logs/tests/baseSpec.js
index 621cc9b18..621cc9b18 100644
--- a/src/fauxton/app/addons/logs/tests/logSpec.js
+++ b/src/fauxton/app/addons/logs/tests/baseSpec.js
diff --git a/src/fauxton/app/addons/logs/tests/resourcesSpec.js b/src/fauxton/app/addons/logs/tests/resourcesSpec.js
new file mode 100644
index 000000000..d67c67718
--- /dev/null
+++ b/src/fauxton/app/addons/logs/tests/resourcesSpec.js
@@ -0,0 +1,38 @@
+// Licensed under the Apache License, Version 2.0 (the 'License'); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+
+define([
+ 'addons/logs/resources',
+ 'testUtils'
+], function (Log, testUtils) {
+ var assert = testUtils.assert;
+
+ describe('Log Resources', function () {
+
+ describe('Date Formatter', function () {
+ it('adds leading zeros to minutes', function () {
+ var model;
+
+ model = new Log.Model({
+ date: 'Sat, 12 Apr 2014 15:04:01 GMT',
+ log_level: 'info',
+ pid: '123',
+ args: 'ente ente'
+ });
+ // timezones with daylightsaving in JS are hard
+ // and we use the current local time here
+ // so do not test for hours and the exact day
+ assert.ok(/Apr \d\d \d\d:04:01/.test(model.date()));
+ });
+ });
+ });
+});