Skip to content

Commit

Permalink
Merge pull request #112 from opentable/WebInterfacePublishedDate
Browse files Browse the repository at this point in the history
Added 'Updated' date field in web interface (#110)
  • Loading branch information
matteofigus committed Sep 21, 2015
2 parents 6ee00dd + 1d71f5e commit 3eca46b
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 13 deletions.
9 changes: 7 additions & 2 deletions registry/routes/list-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
var async = require('async');
var _ = require('underscore');

var dateStringified = require('../../utils/date-stringify');
var packageInfo = require('../../package.json');
var urlBuilder = require('../domain/url-builder');

Expand All @@ -26,6 +27,10 @@ module.exports = function(repository){
return repository.getComponent(component, function(err, result){
if(err){ return callback(err); }

if(result.oc && result.oc.date) {
result.oc.stringifiedDate = dateStringified(new Date(result.oc.date));
}

componentsInfo.push(result);
componentsReleases += result.allVersions.length;
callback();
Expand All @@ -36,7 +41,7 @@ module.exports = function(repository){
componentsInfo = _.sortBy(componentsInfo, function(componentInfo){
return componentInfo.name;
});

return res.render('list-components', {
availableDependencies: res.conf.dependencies,
availablePlugins: res.conf.plugins,
Expand All @@ -60,4 +65,4 @@ module.exports = function(repository){
}
});
};
};
};
16 changes: 8 additions & 8 deletions registry/views/css.jade
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,20 @@ style.
width: 100%;
float: left;
}

.t-80 {
width: 76%;
padding: 0 0 0 9px;
.t-55 {
width: 50%;
padding: 0 1% 0 9px;
}

.t-25 {
width: 23%;
padding: 1%
width: 20%;
padding: 2% 1% 2% 1%
}

.t-10 {
width: 6%;
padding: 2%;
padding: 2% 1% 2% 1%;
}

.w-100 {
Expand Down Expand Up @@ -153,4 +153,4 @@ style.

.hide {
display: none !important;
}
}
8 changes: 5 additions & 3 deletions registry/views/list-components.jade
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,21 @@ block content
input.search(placeholder="Filter by component name")

.row.double.header.componentRow.table
.t-80 Component
.t-55 Component
.version.t-10 Latest version
- if(!isLocal)
.date.t-25 Updated
.activity.t-10 Activity

each component in components
a(href=component.name + '/' + component.version + '/~info')
.componentRow.row.double.table(id="component-" + component.name)
.t-80.title
.t-55.title
p.name= component.name
span.description= component.description
.version.t-10= component.version
- if(!isLocal)
.date.t-25= component.oc.stringifiedDate
.activity.t-10= component.allVersions.length

block scripts
Expand Down Expand Up @@ -56,4 +58,4 @@ block scripts
};

$('#filter-components').submit(changed).keyup(changed);
});
});
39 changes: 39 additions & 0 deletions test/unit/utils-date-stringify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use strict';

var expect = require('chai').expect;
var sinon = require('sinon');

describe('utils : dateStringify', function(){

var dateStringified = require('../../utils/date-stringify');

describe('when the date is provided', function(){
var anyValidDate = new Date(1442592664035);
var dateString;

before(function(){
var mockedDate = new Date();
sinon.stub(mockedDate, 'getFullYear').returns(2015);
sinon.stub(mockedDate, 'getMonth').returns(8);
sinon.stub(mockedDate, 'getDate').returns(18);
sinon.stub(mockedDate, 'getHours').returns(17);
sinon.stub(mockedDate, 'getMinutes').returns(11);
sinon.stub(mockedDate, 'getSeconds').returns(4);

dateString = dateStringified(mockedDate);
});

it('should return the correct stringified date', function(){
expect(dateString).to.equal('2015/09/18 17:11:04');
});
});

describe('when the provided data is not valid', function(){
var anyNotValidData = 'Not a date';
var dateString = dateStringified(anyNotValidData);

it('should return empty string', function(){
expect(dateString).to.be.empty;
});
});
});
28 changes: 28 additions & 0 deletions test/unit/utils-pad-zero.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';

var expect = require('chai').expect;

describe('utils : padZero', function(){

var padZero = require('../../utils/pad-zero');

describe('when the correct parameters are provided', function(){
var anyData = 3;
var anyValidStringLength = 5;
var paddedValue = padZero(anyValidStringLength, anyData);

it('should return the correct padded string', function(){
expect(paddedValue).to.equal('00003');
});
});

describe('when the provided string length is shorter/equal than the length of the data', function(){
var anyData = 3;
var anyToShortStringLength = 1;
var paddedValue = padZero(anyToShortStringLength, anyData);

it('should return original data as a string', function(){
expect(paddedValue).to.be.equal(anyData.toString());
});
});
});
12 changes: 12 additions & 0 deletions utils/date-stringify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

var padZero = require('./pad-zero');

module.exports = function(date){
if(date instanceof Date) {
return date.getFullYear() + '/' + padZero(2, date.getMonth() + 1) + '/' + padZero(2, date.getDate()) +
' ' + padZero(2, date.getHours()) + ':' + padZero(2, date.getMinutes()) + ':' + padZero(2, date.getSeconds());
}

return '';
};
5 changes: 5 additions & 0 deletions utils/pad-zero.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

module.exports = function(length, data){
return Array(length - String(data).length + 1).join('0') + data;
};

0 comments on commit 3eca46b

Please sign in to comment.