Replaced Underscore with Lodash
Lodash has more useful functions and is more regularly updated.
This commit is contained in:
parent
0ba6b651b1
commit
5d35c2bd1a
11 changed files with 108 additions and 48 deletions
16
app/app.js
16
app/app.js
|
@ -1,8 +1,20 @@
|
|||
'use strict';
|
||||
|
||||
/* Declare app level module */
|
||||
angular.module('JamStash', ['ngCookies', 'ngRoute', 'ngSanitize', 'ui.keypress', 'angular-underscore/utils',
|
||||
'jamstash.subsonic.controller', 'jamstash.archive.controller', 'jamstash.player.controller', 'jamstash.queue.controller', 'jamstash.settings.controller', 'jamstash.persistence', 'jamstash.loading'])
|
||||
angular.module('JamStash', [
|
||||
'ngCookies',
|
||||
'ngRoute',
|
||||
'ngSanitize',
|
||||
'ngLodash',
|
||||
'ui.keypress',
|
||||
'jamstash.subsonic.controller',
|
||||
'jamstash.archive.controller',
|
||||
'jamstash.player.controller',
|
||||
'jamstash.queue.controller',
|
||||
'jamstash.settings.controller',
|
||||
'jamstash.persistence',
|
||||
'jamstash.loading'
|
||||
])
|
||||
|
||||
.config(['$routeProvider',function ($routeProvider) {
|
||||
$routeProvider
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
angular.module('JamStash')
|
||||
.controller('AppController', ['$scope', '$rootScope', '$document', '$window', '$location', '$cookieStore', '$http', 'utils', 'globals', 'model', 'notifications', 'player', 'persistence', 'Page', 'subsonic', 'Loading',
|
||||
function ($scope, $rootScope, $document, $window, $location, $cookieStore, $http, utils, globals, model, notifications, player, persistence, Page, subsonic, Loading) {
|
||||
.controller('AppController', ['$scope', '$rootScope', '$document', '$window', '$location', '$cookieStore', '$http', 'lodash', 'utils', 'globals', 'model', 'notifications', 'player', 'persistence', 'Page', 'subsonic', 'Loading',
|
||||
function ($scope, $rootScope, $document, $window, $location, $cookieStore, $http, _, utils, globals, model, notifications, player, persistence, Page, subsonic, Loading) {
|
||||
'use strict';
|
||||
|
||||
$rootScope.settings = globals.settings;
|
||||
|
@ -47,10 +47,10 @@ angular.module('JamStash')
|
|||
}
|
||||
var settings = persistence.getSettings();
|
||||
if (settings !== undefined) {
|
||||
var updSettings = _(settings).omit('Url');
|
||||
var updSettings = _.omit(settings, 'Url');
|
||||
// We can't just assign settings to globals.settings because it's on the scope
|
||||
// TODO: Hyz: remove $rootScope.settings and replace with individual settings
|
||||
_(updSettings).each(function(val, key) {
|
||||
_.each(updSettings, function(val, key) {
|
||||
globals.settings[key] = val;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ describe("Main controller", function() {
|
|||
"updateMessage"
|
||||
]);
|
||||
|
||||
inject(function (_$controller_, $rootScope, _$q_, _$document_, _$window_, _$location_, _$cookieStore_, _utils_, globals, _model_, _Page_) {
|
||||
inject(function (_$controller_, $rootScope, _$q_, _$document_, _$window_, _$location_, _$cookieStore_, lodash, _utils_, globals, _model_, _Page_) {
|
||||
scope = $rootScope.$new();
|
||||
utils = _utils_;
|
||||
$q = _$q_;
|
||||
|
@ -64,6 +64,7 @@ describe("Main controller", function() {
|
|||
$window: _$window_,
|
||||
$location: _$location_,
|
||||
$cookieStore: _$cookieStore_,
|
||||
lodash: lodash,
|
||||
utils: utils,
|
||||
globals: globals,
|
||||
model: _model_,
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* Provides load, save and delete operations for the current song and queue.
|
||||
* Data storage provided by HTML5 localStorage.
|
||||
*/
|
||||
angular.module('jamstash.persistence', ['angular-locker',
|
||||
angular.module('jamstash.persistence', ['ngLodash', 'angular-locker',
|
||||
'jamstash.settings.service', 'jamstash.player.service', 'jamstash.notifications', 'jamstash.utils'])
|
||||
|
||||
.config(['lockerProvider', function (lockerProvider) {
|
||||
|
@ -14,8 +14,8 @@ angular.module('jamstash.persistence', ['angular-locker',
|
|||
.setEventsEnabled(false);
|
||||
}])
|
||||
|
||||
.service('persistence', ['globals', 'player', 'notifications', 'locker', 'json', 'jamstashVersionChangesets', 'utils',
|
||||
function (globals, player, notifications, locker, json, jamstashVersionChangesets, utils) {
|
||||
.service('persistence', ['lodash', 'globals', 'player', 'notifications', 'locker', 'json', 'jamstashVersionChangesets', 'utils',
|
||||
function (_, globals, player, notifications, locker, json, jamstashVersionChangesets, utils) {
|
||||
/* Manage current track */
|
||||
this.loadTrackPosition = function () {
|
||||
// Load Saved Song
|
||||
|
@ -121,12 +121,12 @@ angular.module('jamstash.persistence', ['angular-locker',
|
|||
this.upgradeVersion = function (currentVersion, finalVersion) {
|
||||
var settings = locker.get('Settings');
|
||||
// Apply all upgrades older than the final version and newer than the current
|
||||
var allUpgrades = _(jamstashVersionChangesets.versions).filter(function (toApply) {
|
||||
var allUpgrades = _.filter(jamstashVersionChangesets.versions, function (toApply) {
|
||||
var olderOrEqualToFinal = utils.checkVersion(finalVersion, toApply.version);
|
||||
var newerThanCurrent = utils.checkVersionNewer(toApply.version, currentVersion);
|
||||
return olderOrEqualToFinal && newerThanCurrent;
|
||||
});
|
||||
_(allUpgrades).each(function (versionUpg) {
|
||||
_.forEach(allUpgrades, function (versionUpg) {
|
||||
versionUpg.changeset(settings);
|
||||
});
|
||||
this.saveSettings(settings);
|
||||
|
|
|
@ -92,10 +92,9 @@
|
|||
<script src="bower_components/notify.js/notify.js"></script>
|
||||
<script src="bower_components/jquery.scrollTo/jquery.scrollTo.js"></script>
|
||||
<script src="bower_components/jquery-dateFormat/dist/jquery-dateFormat.js"></script>
|
||||
<script src="bower_components/underscore/underscore.js"></script>
|
||||
<script src="bower_components/angular-underscore/angular-underscore.js"></script>
|
||||
<script src="bower_components/angular-locker/dist/angular-locker.min.js"></script>
|
||||
<script src="bower_components/angular-ui-utils/keypress.js"></script>
|
||||
<script src="bower_components/ng-lodash/build/ng-lodash.js"></script>
|
||||
<!-- endbower -->
|
||||
<!-- endbuild -->
|
||||
<!-- our scripts -->
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
*
|
||||
* Manages the player and playing queue. Use it to play a song, go to next track or add songs to the queue.
|
||||
*/
|
||||
angular.module('jamstash.player.service', ['angular-underscore/utils'])
|
||||
angular.module('jamstash.player.service', ['ngLodash'])
|
||||
|
||||
.factory('player', [function () {
|
||||
.factory('player', ['lodash', function (_) {
|
||||
'use strict';
|
||||
|
||||
var playerVolume = 1.0;
|
||||
|
@ -105,8 +105,8 @@ angular.module('jamstash.player.service', ['angular-underscore/utils'])
|
|||
},
|
||||
|
||||
shuffleQueue: function () {
|
||||
var shuffled = _(player.queue).without(player._playingSong);
|
||||
shuffled = _(shuffled).shuffle();
|
||||
var shuffled = _.without(player.queue, player._playingSong);
|
||||
shuffled = _.shuffle(shuffled);
|
||||
if(player._playingSong !== undefined) {
|
||||
shuffled.unshift(player._playingSong);
|
||||
player._playingIndex = 0;
|
||||
|
@ -132,7 +132,7 @@ angular.module('jamstash.player.service', ['angular-underscore/utils'])
|
|||
},
|
||||
|
||||
removeSongs: function (songs) {
|
||||
player.queue = _(player.queue).difference(songs);
|
||||
player.queue = _.difference(player.queue, songs);
|
||||
return player;
|
||||
},
|
||||
|
||||
|
|
|
@ -4,11 +4,30 @@
|
|||
* Provides access through $http to the Subsonic server's API.
|
||||
* Also offers more fine-grained functionality that is not part of Subsonic's API.
|
||||
*/
|
||||
angular.module('jamstash.subsonic.service', ['angular-underscore/utils',
|
||||
'jamstash.settings.service', 'jamstash.utils', 'jamstash.model'])
|
||||
angular.module('jamstash.subsonic.service', [
|
||||
'ngLodash',
|
||||
'jamstash.settings.service',
|
||||
'jamstash.utils',
|
||||
'jamstash.model'
|
||||
])
|
||||
|
||||
.factory('subsonic', ['$rootScope', '$http', '$q', 'globals', 'utils', 'map',
|
||||
function ($rootScope, $http, $q, globals, utils, map) {
|
||||
.factory('subsonic', [
|
||||
'$rootScope',
|
||||
'$http',
|
||||
'$q',
|
||||
'lodash',
|
||||
'globals',
|
||||
'utils',
|
||||
'map',
|
||||
function (
|
||||
$rootScope,
|
||||
$http,
|
||||
$q,
|
||||
_,
|
||||
globals,
|
||||
utils,
|
||||
map
|
||||
) {
|
||||
'use strict';
|
||||
|
||||
//TODO: Hyz: Remove when refactored
|
||||
|
@ -152,7 +171,7 @@ angular.module('jamstash.subsonic.service', ['angular-underscore/utils',
|
|||
var formattedResponse = {};
|
||||
formattedResponse.shortcut = [].concat(subsonicResponse.indexes.shortcut);
|
||||
formattedResponse.index = [].concat(subsonicResponse.indexes.index);
|
||||
_(formattedResponse.index).map(function (index) {
|
||||
_.map(formattedResponse.index, function (index) {
|
||||
var formattedIndex = index;
|
||||
formattedIndex.artist = [].concat(index.artist);
|
||||
return formattedIndex;
|
||||
|
@ -277,7 +296,7 @@ angular.module('jamstash.subsonic.service', ['angular-underscore/utils',
|
|||
// Make sure this is an array using concat because Madsonic will return an object when there's only one element
|
||||
var children = [].concat(subsonicResponse.directory.child);
|
||||
if (children.length > 0) {
|
||||
var allChildren = _(children).partition(function (item) {
|
||||
var allChildren = _.partition(children, function (item) {
|
||||
return item.isDir;
|
||||
});
|
||||
return {
|
||||
|
@ -315,7 +334,7 @@ angular.module('jamstash.subsonic.service', ['angular-underscore/utils',
|
|||
// since all of this is asynchronous, we need to wait for all the requests to finish by using $q.all()
|
||||
var allRequestsFinished = $q.all(promises).then(function (data) {
|
||||
// and since $q.all() wraps everything in another array, we use flatten() to end up with only one array of songs
|
||||
return _(data).flatten();
|
||||
return _.flatten(data);
|
||||
});
|
||||
deferred.resolve(allRequestsFinished);
|
||||
}
|
||||
|
@ -419,7 +438,7 @@ angular.module('jamstash.subsonic.service', ['angular-underscore/utils',
|
|||
var songArray = [].concat(starred.song);
|
||||
if (songArray.length > 0) {
|
||||
// Return random subarray of songs
|
||||
var songs = [].concat(_(songArray).sample(globals.settings.AutoPlaylistSize));
|
||||
var songs = [].concat(_.sample(songArray, globals.settings.AutoPlaylistSize));
|
||||
return map.mapSongs(songs);
|
||||
}
|
||||
}
|
||||
|
@ -437,7 +456,7 @@ angular.module('jamstash.subsonic.service', ['angular-underscore/utils',
|
|||
// Make sure this is an array using concat because Madsonic will return an object when there's only one element
|
||||
var playlistArray = [].concat(subsonicResponse.playlists.playlist);
|
||||
if (playlistArray.length > 0) {
|
||||
var allPlaylists = _(playlistArray).partition(function (item) {
|
||||
var allPlaylists = _.partition(playlistArray, function (item) {
|
||||
return item.owner === globals.settings.Username;
|
||||
});
|
||||
return {playlists: allPlaylists[0], playlistsPublic: allPlaylists[1]};
|
||||
|
@ -572,7 +591,7 @@ angular.module('jamstash.subsonic.service', ['angular-underscore/utils',
|
|||
if (channel !== null && channel.id === id) {
|
||||
// Make sure this is an array using concat because Madsonic will return an object when there's only one element
|
||||
var episodesArray = [].concat(channel.episode);
|
||||
episodes = _(episodesArray).filter(function (episode) {
|
||||
episodes = _.filter(episodesArray, function (episode) {
|
||||
return episode.status === "completed";
|
||||
});
|
||||
if(episodes.length > 0) {
|
||||
|
|
|
@ -4,10 +4,40 @@
|
|||
* Access and use the Subsonic Server. The Controller is in charge of relaying the Service's messages to the user through the
|
||||
* notifications.
|
||||
*/
|
||||
angular.module('jamstash.subsonic.controller', ['angular-underscore/utils', 'jamstash.subsonic.service', 'jamstash.player.service', 'jamstash.persistence'])
|
||||
angular.module('jamstash.subsonic.controller', [
|
||||
'ngLodash',
|
||||
'jamstash.subsonic.service',
|
||||
'jamstash.player.service',
|
||||
'jamstash.persistence'
|
||||
])
|
||||
|
||||
.controller('SubsonicController', ['$scope', '$rootScope', '$routeParams', '$window', 'utils', 'globals', 'map', 'subsonic', 'notifications', 'player', 'persistence',
|
||||
function ($scope, $rootScope, $routeParams, $window, utils, globals, map, subsonic, notifications, player, persistence) {
|
||||
.controller('SubsonicController', [
|
||||
'$scope',
|
||||
'$rootScope',
|
||||
'$routeParams',
|
||||
'$window',
|
||||
'lodash',
|
||||
'utils',
|
||||
'globals',
|
||||
'map',
|
||||
'subsonic',
|
||||
'notifications',
|
||||
'player',
|
||||
'persistence',
|
||||
function (
|
||||
$scope,
|
||||
$rootScope,
|
||||
$routeParams,
|
||||
$window,
|
||||
_,
|
||||
utils,
|
||||
globals,
|
||||
map,
|
||||
subsonic,
|
||||
notifications,
|
||||
player,
|
||||
persistence
|
||||
) {
|
||||
'use strict';
|
||||
|
||||
$scope.settings = globals.settings;
|
||||
|
|
|
@ -2,17 +2,18 @@ describe("Subsonic controller", function() {
|
|||
'use strict';
|
||||
|
||||
var scope, $rootScope, $controller, $window,
|
||||
subsonic, notifications, player, utils, persistence, controllerParams, deferred;
|
||||
_, subsonic, notifications, player, utils, persistence, controllerParams, deferred;
|
||||
|
||||
beforeEach(function() {
|
||||
jasmine.addCustomEqualityTester(angular.equals);
|
||||
|
||||
module('jamstash.subsonic.controller');
|
||||
|
||||
inject(function (_$controller_, _$rootScope_, globals, map, $q) {
|
||||
inject(function (_$controller_, _$rootScope_, globals, map, $q, lodash) {
|
||||
$rootScope = _$rootScope_;
|
||||
scope = $rootScope.$new();
|
||||
deferred = $q.defer();
|
||||
_ = lodash;
|
||||
|
||||
$window = jasmine.createSpyObj("$window", [
|
||||
"prompt",
|
||||
|
@ -43,11 +44,11 @@ describe("Subsonic controller", function() {
|
|||
"newPlaylist",
|
||||
"recursiveGetSongs",
|
||||
"savePlaylist",
|
||||
"search",
|
||||
"search"
|
||||
]);
|
||||
// We make them return different promises and use our deferred variable only when testing
|
||||
// a particular function, so that they stay isolated
|
||||
_.chain(subsonic).pluck('and').invoke("returnValue", $q.defer().promise);
|
||||
_.forIn(subsonic, _.method('and.returnValue', $q.defer().promise));
|
||||
subsonic.showIndex = false;
|
||||
|
||||
// Mock the player service
|
||||
|
@ -58,7 +59,7 @@ describe("Subsonic controller", function() {
|
|||
"play",
|
||||
"playFirstSong"
|
||||
]);
|
||||
_.chain(player).pluck('and').invoke("returnValue", player);
|
||||
_.forIn(player, _.method('and.returnValue', player));
|
||||
player.queue = [];
|
||||
|
||||
$controller = _$controller_;
|
||||
|
|
17
bower.json
17
bower.json
|
@ -26,11 +26,11 @@
|
|||
},
|
||||
"main": "app/index.html",
|
||||
"dependencies": {
|
||||
"angular": "~1.3.15",
|
||||
"angular-route": "~1.3.15",
|
||||
"angular-sanitize": "~1.3.15",
|
||||
"angular-cookies": "~1.3.15",
|
||||
"angular-resource": "~1.3.15",
|
||||
"angular": "~1.3.16",
|
||||
"angular-route": "~1.3.16",
|
||||
"angular-sanitize": "~1.3.16",
|
||||
"angular-cookies": "~1.3.16",
|
||||
"angular-resource": "~1.3.16",
|
||||
"jquery": "~2.0.0",
|
||||
"jquery-ui": "~1.10.0",
|
||||
"jplayer": "~2.9.0",
|
||||
|
@ -38,11 +38,10 @@
|
|||
"notify.js": "<=1.2.2",
|
||||
"jquery.scrollTo": "~1.4.5",
|
||||
"jquery-dateFormat": "~1.0.2",
|
||||
"underscore": "~1.8.3",
|
||||
"angular-underscore": "~0.5.0",
|
||||
"angular-locker": "~1.2.0",
|
||||
"angular-ui-utils": "bower-keypress",
|
||||
"open-iconic": "~1.1.1"
|
||||
"open-iconic": "~1.1.1",
|
||||
"ng-lodash": "~0.2.3"
|
||||
},
|
||||
"overrides": {
|
||||
"fancybox": {
|
||||
|
@ -53,7 +52,7 @@
|
|||
}
|
||||
},
|
||||
"devDependencies": {
|
||||
"angular-mocks": "~1.3.15",
|
||||
"angular-mocks": "~1.3.16",
|
||||
"jasmine-promise-matchers": "~1.1.1",
|
||||
"jasmine-fixture": "~1.2.2"
|
||||
},
|
||||
|
|
|
@ -31,10 +31,9 @@ module.exports = function (config) {
|
|||
'bower_components/notify.js/notify.js',
|
||||
'bower_components/jquery.scrollTo/jquery.scrollTo.js',
|
||||
'bower_components/jquery-dateFormat/dist/jquery-dateFormat.js',
|
||||
'bower_components/underscore/underscore.js',
|
||||
'bower_components/angular-underscore/angular-underscore.js',
|
||||
'bower_components/angular-locker/dist/angular-locker.min.js',
|
||||
'bower_components/angular-ui-utils/keypress.js',
|
||||
'bower_components/ng-lodash/build/ng-lodash.js',
|
||||
'bower_components/angular-mocks/angular-mocks.js',
|
||||
'bower_components/jasmine-promise-matchers/dist/jasmine-promise-matchers.js',
|
||||
'bower_components/jasmine-fixture/dist/jasmine-fixture.js',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue