Fixes tsquillario/Jamstash#206
- We no longer use toString() if the album's artist info is missing. - Moved date formatting to utils-service.js and added TODOs to use angular filters instead - Cleaned up utils-service.js and remove unused functions - We no longer exclude vendor js files in karma, so we can test our call to jquery.dateFormat
This commit is contained in:
parent
c90eb9f211
commit
f1870f2f5b
6 changed files with 56 additions and 87 deletions
|
@ -270,9 +270,6 @@ angular.module('JamStash')
|
||||||
$scope.isActive = function (route) {
|
$scope.isActive = function (route) {
|
||||||
return route === $location.path();
|
return route === $location.path();
|
||||||
};
|
};
|
||||||
$rootScope.reloadRoute = function (reload) {
|
|
||||||
utils.reloadRoute(reload);
|
|
||||||
};
|
|
||||||
$rootScope.getSplitPosition = function (scope, elm) {
|
$rootScope.getSplitPosition = function (scope, elm) {
|
||||||
window.alert(elm.getBoundingClientRect().left);
|
window.alert(elm.getBoundingClientRect().left);
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
*/
|
*/
|
||||||
angular.module('jamstash.model', ['jamstash.utils'])
|
angular.module('jamstash.model', ['jamstash.utils'])
|
||||||
|
|
||||||
.service('model', ['utils', function (utils){
|
.service('model', ['utils', function (utils) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
this.Index = function (name, artist) {
|
this.Index = function (name, artist) {
|
||||||
|
@ -57,12 +57,12 @@ angular.module('jamstash.model', ['jamstash.utils'])
|
||||||
};
|
};
|
||||||
}])
|
}])
|
||||||
|
|
||||||
.service('map', ['$http', 'globals', 'utils', 'model', function ($http, globals, utils, model){
|
.service('map', ['$http', 'globals', 'utils', 'model', function ($http, globals, utils, model) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
this.mapAlbum = function (data) {
|
this.mapAlbum = function (data) {
|
||||||
var album = data;
|
var album = data;
|
||||||
var title, coverartthumb, coverartfull, starred;
|
var title, coverartthumb, coverartfull, starred, artist;
|
||||||
if (typeof album.coverArt != 'undefined') {
|
if (typeof album.coverArt != 'undefined') {
|
||||||
coverartthumb = globals.BaseURL() + '/getCoverArt.view?' + globals.BaseParams() + '&size=160&id=' + album.coverArt;
|
coverartthumb = globals.BaseURL() + '/getCoverArt.view?' + globals.BaseParams() + '&size=160&id=' + album.coverArt;
|
||||||
coverartfull = globals.BaseURL() + '/getCoverArt.view?' + globals.BaseParams() + '&id=' + album.coverArt;
|
coverartfull = globals.BaseURL() + '/getCoverArt.view?' + globals.BaseParams() + '&id=' + album.coverArt;
|
||||||
|
@ -75,7 +75,9 @@ angular.module('jamstash.model', ['jamstash.utils'])
|
||||||
} else {
|
} else {
|
||||||
type = 'bytag';
|
type = 'bytag';
|
||||||
}
|
}
|
||||||
return new model.Album(album.id, album.parent, title, album.artist.toString(), album.artistId, coverartthumb, coverartfull, $.format.date(new Date(album.created), "yyyy-MM-dd h:mm a"), starred, '', '', type);
|
artist = (album.artist !== undefined) ? album.artist.toString() : '';
|
||||||
|
//TODO: Hyz: we shouldn't format the date here but use a filter in the template
|
||||||
|
return new model.Album(album.id, album.parent, title, artist, album.artistId, coverartthumb, coverartfull, utils.formatDate(new Date(album.created), "yyyy-MM-dd h:mm a"), starred, '', '', type);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.mapAlbums = function (albums) {
|
this.mapAlbums = function (albums) {
|
||||||
|
|
|
@ -1,12 +1,18 @@
|
||||||
describe("model service", function() {
|
describe("model service", function() {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var model, map;
|
var model, map, utils;
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
module('jamstash.model');
|
module('jamstash.model', function ($provide) {
|
||||||
inject(function (_model_, _map_) {
|
$provide.decorator('utils', function ($delegate) {
|
||||||
|
$delegate.formatDate = jasmine.createSpy("formatDate");
|
||||||
|
return $delegate;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
inject(function (_model_, _map_, _utils_) {
|
||||||
model = _model_;
|
model = _model_;
|
||||||
map = _map_;
|
map = _map_;
|
||||||
|
utils = _utils_;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -52,6 +58,17 @@ describe("model service", function() {
|
||||||
expect(result).toEqual(episodes);
|
expect(result).toEqual(episodes);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("Given album data without artist info, when I map it to an Album, an Album with an empty artist name will be returned", function() {
|
||||||
|
var albumData = {
|
||||||
|
id: 584,
|
||||||
|
artist: undefined,
|
||||||
|
created: "2015-03-28T16:51:28.000Z"
|
||||||
|
};
|
||||||
|
|
||||||
|
var result = map.mapAlbum(albumData);
|
||||||
|
expect(result.artist).toEqual('');
|
||||||
|
});
|
||||||
|
|
||||||
it("Given multiple albums, when I map them, then mapAlbum is called for each album", function() {
|
it("Given multiple albums, when I map them, then mapAlbum is called for each album", function() {
|
||||||
var albums = [
|
var albums = [
|
||||||
{ id: 941 },
|
{ id: 941 },
|
||||||
|
|
|
@ -58,11 +58,6 @@ angular.module('jamstash.utils', ['jamstash.settings.service'])
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
this.makeBaseAuth = function (user, password) {
|
|
||||||
var tok = user + ':' + password;
|
|
||||||
var hash = $.base64Encode(tok);
|
|
||||||
return "Basic " + hash;
|
|
||||||
};
|
|
||||||
this.HexEncode = function (n) {
|
this.HexEncode = function (n) {
|
||||||
for (var u = "0123456789abcdef", i = [], r = [], t = 0; t < 256; t++) {
|
for (var u = "0123456789abcdef", i = [], r = [], t = 0; t < 256; t++) {
|
||||||
i[t] = u.charAt(t >> 4) + u.charAt(t & 15);
|
i[t] = u.charAt(t >> 4) + u.charAt(t & 15);
|
||||||
|
@ -129,12 +124,13 @@ angular.module('jamstash.utils', ['jamstash.settings.service'])
|
||||||
}
|
}
|
||||||
return time;
|
return time;
|
||||||
};
|
};
|
||||||
this.arrayObjectIndexOf = function (myArray, searchTerm, property) {
|
|
||||||
for (var i = 0, len = myArray.length; i < len; i++) {
|
//TODO: Hyz: replace with using an angular date filter in the template
|
||||||
if (myArray[i][property] === searchTerm) { return i; }
|
this.formatDate = function (date, format) {
|
||||||
}
|
var dateToformat = (angular.isDate(date)) ? date : new Date(date);
|
||||||
return -1;
|
return $.format.date(dateToformat, format);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.logObjectProperties = function (obj) {
|
this.logObjectProperties = function (obj) {
|
||||||
$.each(obj, function (key, value) {
|
$.each(obj, function (key, value) {
|
||||||
var parent = key;
|
var parent = key;
|
||||||
|
@ -147,25 +143,6 @@ angular.module('jamstash.utils', ['jamstash.settings.service'])
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
this.clickButton = function (el) {
|
|
||||||
var el = $(el);
|
|
||||||
if (el) {
|
|
||||||
var classes = $(el).attr('class').split(" ");
|
|
||||||
for (var i = 0, l = classes.length; i < l; ++i) {
|
|
||||||
var types = ['shuffle', 'mute'];
|
|
||||||
if (jQuery.inArray(classes[i], types) >= 0) {
|
|
||||||
var up = classes[i] + '_up';
|
|
||||||
if (el.hasClass(up)) {
|
|
||||||
el.removeClass(up);
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
el.addClass(up);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
this.findKeyForCode = function (code) {
|
this.findKeyForCode = function (code) {
|
||||||
var map = {
|
var map = {
|
||||||
'keymap': [
|
'keymap': [
|
||||||
|
@ -219,22 +196,6 @@ angular.module('jamstash.utils', ['jamstash.settings.service'])
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
this.getParameterByName = function (name) {
|
|
||||||
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
|
|
||||||
var regexS = "[\\?&]" + name + "=([^&#]*)";
|
|
||||||
var regex = new RegExp(regexS);
|
|
||||||
var results = regex.exec(window.location.search);
|
|
||||||
if (results === null) {
|
|
||||||
return "";
|
|
||||||
} else {
|
|
||||||
return decodeURIComponent(results[1].replace(/\+/g, " "));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
this.getPathFromUrl = function (url) {
|
|
||||||
var strurl = url.toString();
|
|
||||||
var u = strurl.substring(0, strurl.indexOf('?'));
|
|
||||||
return u;
|
|
||||||
};
|
|
||||||
|
|
||||||
this.parseVersionString = function (str) {
|
this.parseVersionString = function (str) {
|
||||||
if (typeof (str) !== 'string') { return false; }
|
if (typeof (str) !== 'string') { return false; }
|
||||||
|
@ -299,21 +260,4 @@ angular.module('jamstash.utils', ['jamstash.settings.service'])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.reloadRoute = function (date) {
|
|
||||||
if (reload) {
|
|
||||||
$window.location.reload();
|
|
||||||
} else {
|
|
||||||
$route.reload();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
this.parseDate = function (date) {
|
|
||||||
// input: "2012-09-23 20:00:00.0"
|
|
||||||
var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
||||||
var parts = date.split(" ");
|
|
||||||
var dateParts = parts[0].split("-");
|
|
||||||
var month = parseInt(dateParts[1], 10) - 1;
|
|
||||||
var newDate = months[month] + " " + dateParts[2] + ", " + dateParts[0];
|
|
||||||
return newDate;
|
|
||||||
};
|
|
||||||
}]);
|
}]);
|
||||||
|
|
|
@ -152,4 +152,13 @@ describe("utils service", function() {
|
||||||
expect(utils.checkVersionNewer(newer, older)).toBeTruthy();
|
expect(utils.checkVersionNewer(newer, older)).toBeTruthy();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("formatDate() - Given a Date and a text format, when I format a Date, jQuery's format date will be called and a formatted string will be returned", function() {
|
||||||
|
spyOn($.format, 'date');
|
||||||
|
var date = new Date('2015-03-28T16:54:40+01:00');
|
||||||
|
|
||||||
|
utils.formatDate(date, 'yyyy-MM-dd h:mm a');
|
||||||
|
|
||||||
|
expect($.format.date).toHaveBeenCalledWith(date, 'yyyy-MM-dd h:mm a');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
// Generated on 2014-10-26 using
|
// Generated on 2014-10-26 using
|
||||||
// generator-karma 0.8.3
|
// generator-karma 0.8.3
|
||||||
|
|
||||||
module.exports = function(config) {
|
module.exports = function (config) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
config.set({
|
config.set({
|
||||||
|
@ -43,7 +43,7 @@ module.exports = function(config) {
|
||||||
],
|
],
|
||||||
|
|
||||||
// list of files / patterns to exclude
|
// list of files / patterns to exclude
|
||||||
exclude: ['app/vendor/**/*.js'],
|
// exclude: ['app/vendor/**/*.js'],
|
||||||
|
|
||||||
preprocessors: {
|
preprocessors: {
|
||||||
'app/**/!(*_test).js': ['coverage']
|
'app/**/!(*_test).js': ['coverage']
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue