Further separates services, directives and filters into individual files for a better organization.
Conflicts: js/app.js js/service.js js/services/utils-service.js test/services/model-service_test.js
This commit is contained in:
parent
a2747a633d
commit
3164f01407
14 changed files with 618 additions and 704 deletions
112
js/app.js
112
js/app.js
|
@ -1,61 +1,9 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
/* Declare app level module */
|
/* Declare app level module */
|
||||||
var JamStash = angular.module('JamStash', ['ngCookies', 'ngRoute', 'ngSanitize']);
|
var jamstash = angular.module('JamStash', ['ngCookies', 'ngRoute', 'ngSanitize']);
|
||||||
//var JamStash = angular.module('JamStash', ['ngCookies', 'ngRoute']);
|
|
||||||
|
|
||||||
/*
|
jamstash.config(function ($routeProvider) {
|
||||||
JamStash.config(function ($sceDelegateProvider) {
|
|
||||||
$sceDelegateProvider.resourceUrlWhitelist(['/^\s*(https?|file|ms-appx):/', 'self']);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Given:
|
|
||||||
// URL: http://server.com/index.html#/Chapter/1/Section/2?search=moby
|
|
||||||
// Route: /Chapter/:chapterId/Section/:sectionId
|
|
||||||
//
|
|
||||||
// Then
|
|
||||||
$routeParams ==> {chapterId:1, sectionId:2, search:'moby'}
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
JamStash.config(function ($stateProvider) {
|
|
||||||
$stateProvider
|
|
||||||
.state('root', {
|
|
||||||
url: '',
|
|
||||||
views: {
|
|
||||||
'settings': {
|
|
||||||
url: '/settings',
|
|
||||||
templateUrl: 'js/partials/settings.html',
|
|
||||||
controller: 'SettingsCtrl'
|
|
||||||
},
|
|
||||||
'library': {
|
|
||||||
url: '/library',
|
|
||||||
templateUrl: 'js/partials/library.html',
|
|
||||||
controller: 'SubsonicCtrl'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
JamStash.config(function ($stateProvider) {
|
|
||||||
$stateProvider
|
|
||||||
.state('root', {
|
|
||||||
url: '/',
|
|
||||||
templateUrl: 'js/partials/library.html',
|
|
||||||
controller: 'SubsonicCtrl'
|
|
||||||
})
|
|
||||||
.state('settings', {
|
|
||||||
url: '/settings',
|
|
||||||
templateUrl: 'js/partials/settings.html',
|
|
||||||
controller: 'SettingsCtrl'
|
|
||||||
})
|
|
||||||
.state('library', {
|
|
||||||
url: '/library',
|
|
||||||
templateUrl: 'js/partials/library.html',
|
|
||||||
controller: 'SubsonicCtrl'
|
|
||||||
});
|
|
||||||
})
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
JamStash.config(function ($routeProvider) {
|
|
||||||
$routeProvider
|
$routeProvider
|
||||||
.when('/index', { redirectTo: '/library' })
|
.when('/index', { redirectTo: '/library' })
|
||||||
.when('/settings', { templateUrl: 'js/partials/settings.html', controller: 'SettingsCtrl' })
|
.when('/settings', { templateUrl: 'js/partials/settings.html', controller: 'SettingsCtrl' })
|
||||||
|
@ -69,9 +17,9 @@ JamStash.config(function ($routeProvider) {
|
||||||
.when('/archive/:artist', { templateUrl: 'js/partials/archive.html', controller: 'ArchiveCtrl' })
|
.when('/archive/:artist', { templateUrl: 'js/partials/archive.html', controller: 'ArchiveCtrl' })
|
||||||
.when('/archive/:artist/:album', { templateUrl: 'js/partials/archive.html', controller: 'ArchiveCtrl' })
|
.when('/archive/:artist/:album', { templateUrl: 'js/partials/archive.html', controller: 'ArchiveCtrl' })
|
||||||
.otherwise({ redirectTo: '/index' });
|
.otherwise({ redirectTo: '/index' });
|
||||||
})
|
});
|
||||||
|
|
||||||
JamStash.config(function ($httpProvider) {
|
jamstash.config(function ($httpProvider) {
|
||||||
$httpProvider.interceptors.push(function ($rootScope, $location, $q, globals) {
|
$httpProvider.interceptors.push(function ($rootScope, $location, $q, globals) {
|
||||||
return {
|
return {
|
||||||
'request': function (request) {
|
'request': function (request) {
|
||||||
|
@ -101,51 +49,3 @@ JamStash.config(function ($httpProvider) {
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
JamStash.service('model', function (utils) {
|
|
||||||
this.Index = function (name, artist) {
|
|
||||||
this.name = name;
|
|
||||||
this.artist = artist;
|
|
||||||
}
|
|
||||||
this.Artist = function (id, name) {
|
|
||||||
this.id = id;
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
this.Album = function (id, parentid, name, artist, coverartthumb, coverartfull, date, starred, description, url) {
|
|
||||||
this.id = id;
|
|
||||||
this.parentid = parentid;
|
|
||||||
this.name = name;
|
|
||||||
this.artist = artist;
|
|
||||||
this.coverartthumb = coverartthumb;
|
|
||||||
this.coverartfull = coverartfull;
|
|
||||||
this.date = date;
|
|
||||||
this.starred = starred;
|
|
||||||
this.description = description;
|
|
||||||
this.url = url;
|
|
||||||
}
|
|
||||||
this.Song = function (id, parentid, track, name, artist, artistId, album, albumId, coverartthumb, coverartfull, duration, rating, starred, suffix, specs, url, position, description) {
|
|
||||||
this.id = id;
|
|
||||||
this.parentid = parentid;
|
|
||||||
this.track = track;
|
|
||||||
this.name = name;
|
|
||||||
this.artist = artist;
|
|
||||||
this.artistId = artistId;
|
|
||||||
this.album = album;
|
|
||||||
this.albumId = albumId;
|
|
||||||
this.coverartthumb = coverartthumb;
|
|
||||||
this.coverartfull = coverartfull;
|
|
||||||
this.duration = duration;
|
|
||||||
this.time = duration == '' ? '00:00' : utils.secondsToTime(duration);
|
|
||||||
this.rating = rating;
|
|
||||||
this.starred = starred;
|
|
||||||
this.suffix = suffix;
|
|
||||||
this.specs = specs;
|
|
||||||
this.url = url;
|
|
||||||
this.position = position;
|
|
||||||
this.selected = false;
|
|
||||||
this.playing = false;
|
|
||||||
this.description = description;
|
|
||||||
this.displayName = this.name + " - " + this.album + " - " + this.artist;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
134
js/directives/directives.js
Normal file
134
js/directives/directives.js
Normal file
|
@ -0,0 +1,134 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var jamstash = angular.module('JamStash');
|
||||||
|
|
||||||
|
jamstash.directive('sortable', function () {
|
||||||
|
return {
|
||||||
|
link: function (scope, elm, attrs) {
|
||||||
|
elm.sortable({
|
||||||
|
start: scope.dragStart,
|
||||||
|
update: scope.dragEnd
|
||||||
|
});
|
||||||
|
elm.disableSelection();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
/*
|
||||||
|
jamstash.directive('split', function () {
|
||||||
|
return {
|
||||||
|
link: function (scope, elm, attrs) {
|
||||||
|
elm.splitPane();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
*/
|
||||||
|
jamstash.directive('fancybox', function ($compile) {
|
||||||
|
return {
|
||||||
|
restrict: 'A',
|
||||||
|
replace: false,
|
||||||
|
link: function($scope, element, attrs) {
|
||||||
|
$scope.fancyboxOpen = function() {
|
||||||
|
var el = angular.element(element.html()),
|
||||||
|
compiled = $compile(el);
|
||||||
|
$.fancybox.open(el);
|
||||||
|
compiled($scope);
|
||||||
|
};
|
||||||
|
$scope.fancyboxOpenUrl = function () {
|
||||||
|
var el = angular.element(element.html()),
|
||||||
|
compiled = $compile(el);
|
||||||
|
$.fancybox.open(el);
|
||||||
|
compiled($scope);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
jamstash.directive('songpreview', function ($compile, subsonic) {
|
||||||
|
return {
|
||||||
|
restrict: 'E',
|
||||||
|
templateUrl: 'js/partials/songs.html',
|
||||||
|
replace: false,
|
||||||
|
// pass these two names from attrs into the template scope
|
||||||
|
scope: {
|
||||||
|
song: '@'
|
||||||
|
},
|
||||||
|
link: function (scope, element, attrs) {
|
||||||
|
subsonic.getSongTemplate(function (data) {
|
||||||
|
scope.song = data;
|
||||||
|
//var el = angular.element(element.html()),
|
||||||
|
//var el = element.html(),
|
||||||
|
//compiled = $compile(el);
|
||||||
|
$.fancybox.open(element);
|
||||||
|
//compiled($scope);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
jamstash.directive('stopEvent', function () {
|
||||||
|
return {
|
||||||
|
restrict: 'A',
|
||||||
|
link: function (scope, element, attr) {
|
||||||
|
element.bind(attr.stopEvent, function (e) {
|
||||||
|
e.stopPropagation();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
jamstash.directive('ngEnter', function () {
|
||||||
|
return {
|
||||||
|
scope: { onEnter: '&' },
|
||||||
|
link: function (scope, element) {
|
||||||
|
console.log(scope);
|
||||||
|
element.bind("keydown keypress", function (event) {
|
||||||
|
if (event.which === 13) {
|
||||||
|
scope.onEnter();
|
||||||
|
scope.$apply();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
jamstash.directive('ngDownload', function ($compile) {
|
||||||
|
return {
|
||||||
|
restrict: 'E',
|
||||||
|
scope: { data: '=' },
|
||||||
|
link: function (scope, elm, attrs) {
|
||||||
|
function getUrl() {
|
||||||
|
return URL.createObjectURL(new Blob([JSON.stringify(scope.data)], { type: "application/json" }));
|
||||||
|
}
|
||||||
|
|
||||||
|
elm.append($compile(
|
||||||
|
'<a class="button" download="backup.json"' +
|
||||||
|
'href="' + getUrl() + '">' +
|
||||||
|
'Download' +
|
||||||
|
'</a>'
|
||||||
|
)(scope));
|
||||||
|
|
||||||
|
scope.$watch(scope.data, function () {
|
||||||
|
elm.children()[0].href = getUrl();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
jamstash.directive('stopEvent', function () {
|
||||||
|
return {
|
||||||
|
restrict: 'A',
|
||||||
|
link: function (scope, element, attr) {
|
||||||
|
element.bind(attr.stopEvent, function (e) {
|
||||||
|
e.stopPropagation();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
jamstash.directive('ngEnter', function () {
|
||||||
|
return function (scope, element, attrs) {
|
||||||
|
element.bind("keydown keypress", function (event) {
|
||||||
|
if (event.which === 13) {
|
||||||
|
scope.$apply(function () {
|
||||||
|
scope.$eval(attrs.ngEnter);
|
||||||
|
});
|
||||||
|
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
});
|
20
js/filters/filters.js
Normal file
20
js/filters/filters.js
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var jamstash = angular.module('JamStash');
|
||||||
|
|
||||||
|
/* Filters */
|
||||||
|
jamstash.filter('capitalize', function () {
|
||||||
|
return function (input, scope) {
|
||||||
|
return input.substring(0, 1).toUpperCase() + input.substring(1);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
jamstash.filter('musicfolder', function () {
|
||||||
|
return function (items, scope) {
|
||||||
|
return items.slice(1, items.length);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
jamstash.filter('capitalize', function () {
|
||||||
|
return function (input, scope) {
|
||||||
|
return input.substring(0, 1).toUpperCase() + input.substring(1);
|
||||||
|
};
|
||||||
|
});
|
559
js/service.js
559
js/service.js
|
@ -1,559 +0,0 @@
|
||||||
JamStash.service('notifications', function ($rootScope, globals) {
|
|
||||||
var msgIndex = 1;
|
|
||||||
this.updateMessage = function (msg, autohide) {
|
|
||||||
if (msg != '') {
|
|
||||||
var id = msgIndex;
|
|
||||||
$('#messages').append('<span id=\"msg_' + id + '\" class="message">' + msg + '</span>');
|
|
||||||
$('#messages').fadeIn();
|
|
||||||
$("#messages").scrollTo('100%');
|
|
||||||
var el = '#msg_' + id;
|
|
||||||
if (autohide) {
|
|
||||||
setTimeout(function () {
|
|
||||||
$(el).fadeOut(function () { $(this).remove(); });
|
|
||||||
}, globals.settings.Timeout);
|
|
||||||
} else {
|
|
||||||
$(el).click(function () {
|
|
||||||
$(el).fadeOut(function () { $(this).remove(); });
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
msgIndex++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.requestPermissionIfRequired = function () {
|
|
||||||
if (window.Notify.isSupported() && window.Notify.needsPermission()) {
|
|
||||||
window.Notify.requestPermission();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.hasNotificationPermission = function () {
|
|
||||||
return (window.Notify.needsPermission() === false);
|
|
||||||
}
|
|
||||||
this.hasNotificationSupport = function () {
|
|
||||||
return window.Notify.isSupported();
|
|
||||||
}
|
|
||||||
var notifications = new Array();
|
|
||||||
|
|
||||||
this.showNotification = function (pic, title, text, type, bind) {
|
|
||||||
if (this.hasNotificationPermission()) {
|
|
||||||
//closeAllNotifications()
|
|
||||||
var settings = {}
|
|
||||||
if (bind = '#NextTrack') {
|
|
||||||
settings.notifyClick = function () {
|
|
||||||
$rootScope.nextTrack();
|
|
||||||
this.close();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
if (type == 'text') {
|
|
||||||
settings.body = text;
|
|
||||||
settings.icon = pic;
|
|
||||||
} else if (type == 'html') {
|
|
||||||
settings.body = text;
|
|
||||||
}
|
|
||||||
var notification = new Notify(title, settings);
|
|
||||||
notifications.push(notification);
|
|
||||||
setTimeout(function (notWin) {
|
|
||||||
notWin.close();
|
|
||||||
}, globals.settings.Timeout, notification);
|
|
||||||
notification.show();
|
|
||||||
} else {
|
|
||||||
console.log("showNotification: No Permission");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.closeAllNotifications = function () {
|
|
||||||
for (notification in notifications) {
|
|
||||||
notifications[notification].close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Directives
|
|
||||||
JamStash.directive('sortable', function () {
|
|
||||||
return {
|
|
||||||
link: function (scope, elm, attrs) {
|
|
||||||
elm.sortable({
|
|
||||||
start: scope.dragStart,
|
|
||||||
update: scope.dragEnd
|
|
||||||
});
|
|
||||||
elm.disableSelection();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
/*
|
|
||||||
JamStash.directive('split', function () {
|
|
||||||
return {
|
|
||||||
link: function (scope, elm, attrs) {
|
|
||||||
elm.splitPane();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
JamStash.directive('fancybox', function ($compile) {
|
|
||||||
return {
|
|
||||||
restrict: 'A',
|
|
||||||
replace: false,
|
|
||||||
link: function($scope, element, attrs) {
|
|
||||||
$scope.fancyboxOpen = function() {
|
|
||||||
var el = angular.element(element.html()),
|
|
||||||
compiled = $compile(el);
|
|
||||||
$.fancybox.open(el);
|
|
||||||
compiled($scope);
|
|
||||||
};
|
|
||||||
$scope.fancyboxOpenUrl = function () {
|
|
||||||
var el = angular.element(element.html()),
|
|
||||||
compiled = $compile(el);
|
|
||||||
$.fancybox.open(el);
|
|
||||||
compiled($scope);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
JamStash.directive('songpreview', function ($compile, subsonic) {
|
|
||||||
return {
|
|
||||||
restrict: 'E',
|
|
||||||
templateUrl: 'js/partials/songs.html',
|
|
||||||
replace: false,
|
|
||||||
// pass these two names from attrs into the template scope
|
|
||||||
scope: {
|
|
||||||
song: '@'
|
|
||||||
},
|
|
||||||
link: function (scope, element, attrs) {
|
|
||||||
subsonic.getSongTemplate(function (data) {
|
|
||||||
scope.song = data;
|
|
||||||
//var el = angular.element(element.html()),
|
|
||||||
//var el = element.html(),
|
|
||||||
//compiled = $compile(el);
|
|
||||||
$.fancybox.open(element);
|
|
||||||
//compiled($scope);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
JamStash.directive('stopEvent', function () {
|
|
||||||
return {
|
|
||||||
restrict: 'A',
|
|
||||||
link: function (scope, element, attr) {
|
|
||||||
element.bind(attr.stopEvent, function (e) {
|
|
||||||
e.stopPropagation();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
JamStash.directive('ngEnter', function () {
|
|
||||||
return {
|
|
||||||
scope: { onEnter: '&' },
|
|
||||||
link: function (scope, element) {
|
|
||||||
console.log(scope);
|
|
||||||
element.bind("keydown keypress", function (event) {
|
|
||||||
if (event.which === 13) {
|
|
||||||
scope.onEnter();
|
|
||||||
scope.$apply();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
JamStash.directive('ngDownload', function ($compile) {
|
|
||||||
return {
|
|
||||||
restrict: 'E',
|
|
||||||
scope: { data: '=' },
|
|
||||||
link: function (scope, elm, attrs) {
|
|
||||||
function getUrl() {
|
|
||||||
return URL.createObjectURL(new Blob([JSON.stringify(scope.data)], { type: "application/json" }));
|
|
||||||
}
|
|
||||||
|
|
||||||
elm.append($compile(
|
|
||||||
'<a class="button" download="backup.json"' +
|
|
||||||
'href="' + getUrl() + '">' +
|
|
||||||
'Download' +
|
|
||||||
'</a>'
|
|
||||||
)(scope));
|
|
||||||
|
|
||||||
scope.$watch(scope.data, function () {
|
|
||||||
elm.children()[0].href = getUrl();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
JamStash.directive('stopEvent', function () {
|
|
||||||
return {
|
|
||||||
restrict: 'A',
|
|
||||||
link: function (scope, element, attr) {
|
|
||||||
element.bind(attr.stopEvent, function (e) {
|
|
||||||
e.stopPropagation();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
JamStash.directive('ngEnter', function () {
|
|
||||||
return function (scope, element, attrs) {
|
|
||||||
element.bind("keydown keypress", function (event) {
|
|
||||||
if (event.which === 13) {
|
|
||||||
scope.$apply(function () {
|
|
||||||
scope.$eval(attrs.ngEnter);
|
|
||||||
});
|
|
||||||
|
|
||||||
event.preventDefault();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
/* Factory */
|
|
||||||
JamStash.factory('json', function ($http) { // Deferred loading
|
|
||||||
return {
|
|
||||||
getCollections: function (callback) {
|
|
||||||
$http.get('js/json_collections.js').success(callback);
|
|
||||||
},
|
|
||||||
getChangeLog: function (callback) {
|
|
||||||
$http.get('js/json_changelog.js').success(callback);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
/*
|
|
||||||
JamStash.factory('template', function ($http, $compile, $http, $templateCache) { // Deferred loading
|
|
||||||
return {
|
|
||||||
getCollections: function (callback) {
|
|
||||||
$http.get('js/json_collections.js', { cache: $templateCache }).success(callback);
|
|
||||||
},
|
|
||||||
getChangeLog: function (callback) {
|
|
||||||
$http.get('js/json_changelog.js', { cache: $templateCache }).success(callback);
|
|
||||||
},
|
|
||||||
getSongs: function (callback) {
|
|
||||||
templateUrl = 'js/partials/songs.html';
|
|
||||||
$http.get(templateUrl, { cache: $templateCache }).success(callback);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
|
|
||||||
JamStash.service('map', function ($http, globals, utils, model) {
|
|
||||||
this.mapArtist = function (data) {
|
|
||||||
var name = '';
|
|
||||||
var artist = data.artist;
|
|
||||||
var artists = [];
|
|
||||||
if (artist.length > 0) {
|
|
||||||
artists = artist;
|
|
||||||
} else {
|
|
||||||
artists[0] = artist;
|
|
||||||
}
|
|
||||||
angular.forEach(artists, function (item, key) {
|
|
||||||
if (typeof item.name !== 'undefined') { item.name = item.name.toString(); }
|
|
||||||
});
|
|
||||||
if (typeof data.name !== 'undefined') { name = data.name.toString(); }
|
|
||||||
return new model.Index(name, artists);
|
|
||||||
};
|
|
||||||
this.mapIndex = function (data) {
|
|
||||||
var name, id = '';
|
|
||||||
if (typeof data.id !== 'undefined') { id = data.id; }
|
|
||||||
if (typeof data.name !== 'undefined') { name = data.name.toString(); }
|
|
||||||
return new model.Artist(id, name);
|
|
||||||
};
|
|
||||||
this.mapAlbum = function (data) {
|
|
||||||
var album = data;
|
|
||||||
var title, coverartthumb, coverartfull, starred;
|
|
||||||
if (typeof album.coverArt != 'undefined') {
|
|
||||||
coverartthumb = globals.BaseURL() + '/getCoverArt.view?' + globals.BaseParams() + '&size=160&id=' + album.coverArt;
|
|
||||||
coverartfull = globals.BaseURL() + '/getCoverArt.view?' + globals.BaseParams() + '&id=' + album.coverArt;
|
|
||||||
}
|
|
||||||
if (typeof album.starred !== 'undefined') { starred = true; } else { starred = false; }
|
|
||||||
if (typeof album.title !== 'undefined') { title = album.title; } else { title = album.name; }
|
|
||||||
var type;
|
|
||||||
if (album.isDir) {
|
|
||||||
type = 'byfolder';
|
|
||||||
} else {
|
|
||||||
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);
|
|
||||||
};
|
|
||||||
this.mapSong = function (data) {
|
|
||||||
var song = data;
|
|
||||||
var url, title, artist, track, rating, starred, contenttype, suffix, description;
|
|
||||||
var specs = '', coverartthumb = '', coverartfull = '';
|
|
||||||
if (typeof song.coverArt != 'undefined') {
|
|
||||||
coverartthumb = globals.BaseURL() + '/getCoverArt.view?' + globals.BaseParams() + '&size=30&id=' + song.coverArt;
|
|
||||||
coverartfull = globals.BaseURL() + '/getCoverArt.view?' + globals.BaseParams() + '&id=' + song.coverArt;
|
|
||||||
} else {
|
|
||||||
coverartthumb = 'images/albumdefault_60.jpg';
|
|
||||||
coverartfull = 'images/albumdefault_160.jpg';
|
|
||||||
}
|
|
||||||
if (typeof song.description == 'undefined') { description = ''; } else { description = song.description; }
|
|
||||||
if (typeof song.artist == 'undefined') { artist = ' '; } else { artist = song.artist.toString(); }
|
|
||||||
if (typeof song.title == 'undefined') { title = ' '; } else { title = song.title.toString(); }
|
|
||||||
if (typeof song.track == 'undefined') { track = ' '; } else { track = song.track.toString(); }
|
|
||||||
if (typeof song.starred !== 'undefined') { starred = true; } else { starred = false; }
|
|
||||||
if (song.bitRate !== undefined) { specs += song.bitRate + ' Kbps'; }
|
|
||||||
if (song.transcodedSuffix !== undefined) { specs += ', transcoding:' + song.suffix + ' > ' + song.transcodedSuffix; } else { specs += ', ' + song.suffix; }
|
|
||||||
if (song.transcodedSuffix !== undefined) { suffix = song.transcodedSuffix; } else { suffix = song.suffix; }
|
|
||||||
if (suffix == 'ogg') { suffix = 'oga'; }
|
|
||||||
var salt = Math.floor(Math.random() * 100000);
|
|
||||||
url = globals.BaseURL() + '/stream.view?' + globals.BaseParams() + '&id=' + song.id + '&salt=' + salt;
|
|
||||||
return new model.Song(song.id, song.parent, track, title, artist, song.artistId, song.album, song.albumId, coverartthumb, coverartfull, song.duration, song.userRating, starred, suffix, specs, url, 0, description);
|
|
||||||
};
|
|
||||||
this.mapPlaylist = function (data) {
|
|
||||||
return new model.Artist(data.id, data.name);
|
|
||||||
};
|
|
||||||
this.mapPodcast = function (data) {
|
|
||||||
var song = data;
|
|
||||||
var url, track, rating, starred, contenttype, suffix, description, artist, album, title;
|
|
||||||
var specs = '', coverartthumb = '', coverartfull = '';
|
|
||||||
if (typeof song.coverArt != 'undefined') {
|
|
||||||
coverartthumb = globals.BaseURL() + '/getCoverArt.view?' + globals.BaseParams() + '&size=60&id=' + song.coverArt;
|
|
||||||
coverartfull = globals.BaseURL() + '/getCoverArt.view?' + globals.BaseParams() + '&id=' + song.coverArt;
|
|
||||||
}
|
|
||||||
if (typeof song.album == 'undefined') { album = ' '; } else { album = song.album.toString(); }
|
|
||||||
if (typeof song.artist == 'undefined') { artist = ' '; } else { artist = song.artist.toString(); }
|
|
||||||
if (typeof song.title == 'undefined') { title = ' '; } else { title = song.title.toString(); }
|
|
||||||
if (typeof song.description == 'undefined') { description = ''; } else { description = song.description; }
|
|
||||||
if (typeof song.track == 'undefined') { track = ' '; } else { track = song.track.toString(); }
|
|
||||||
if (typeof song.starred !== 'undefined') { starred = true; } else { starred = false; }
|
|
||||||
if (song.bitRate !== undefined) { specs += song.bitRate + ' Kbps'; }
|
|
||||||
if (song.transcodedSuffix !== undefined) { specs += ', transcoding:' + song.suffix + ' > ' + song.transcodedSuffix; } else { specs += ', ' + song.suffix; }
|
|
||||||
if (song.transcodedSuffix !== undefined) { suffix = song.transcodedSuffix; } else { suffix = song.suffix; }
|
|
||||||
if (suffix == 'ogg') { suffix = 'oga'; }
|
|
||||||
var salt = Math.floor(Math.random() * 100000);
|
|
||||||
url = globals.BaseURL() + '/stream.view?' + globals.BaseParams() + '&id=' + song.streamId + '&salt=' + salt;
|
|
||||||
return new model.Song(song.streamId, song.parent, track, title, artist, song.artistId, album, song.albumId, coverartthumb, coverartfull, song.duration, song.userRating, starred, suffix, specs, url, 0, description);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
JamStash.factory('archive', function ($rootScope, $http, $q, $sce, globals, model, utils, map, notifications) {
|
|
||||||
var index = { shortcuts: [], artists: [] };
|
|
||||||
var content = {
|
|
||||||
artist: [],
|
|
||||||
album: [],
|
|
||||||
song: [],
|
|
||||||
breadcrumb: [],
|
|
||||||
selectedArtist: null,
|
|
||||||
selectedAlbum: null,
|
|
||||||
selectedGenre: null,
|
|
||||||
selectedArchiveAlbumSort: "date desc"
|
|
||||||
};
|
|
||||||
var offset = 0;
|
|
||||||
|
|
||||||
var mapAlbum = function (data) {
|
|
||||||
var song = data;
|
|
||||||
var coverartthumb, coverartfull, starred, title, album, publisher, avg_rating, downloads, identifier;
|
|
||||||
var url = globals.archiveUrl + 'details/' + song.identifier;
|
|
||||||
coverartthumb = 'images/albumdefault_50.jpg';
|
|
||||||
coverartfull = 'images/albumdefault_160.jpg';
|
|
||||||
if (parseInt(song.avg_rating) == 5) { starred = true; } else { starred = false; }
|
|
||||||
if (typeof song.title == 'undefined') { title = ' '; } else { title = song.title.toString(); }
|
|
||||||
if (typeof song.identifier == 'undefined') { identifier = ' '; } else { identifier = song.identifier.toString(); }
|
|
||||||
if (typeof song.collection[0] == 'undefined') { album = ' '; } else { album = song.collection[0].toString(); }
|
|
||||||
if (typeof song.source == 'undefined') { source = ' '; } else { source = song.source.toString(); }
|
|
||||||
if (typeof song.date == 'undefined') { date = ' '; } else { date = song.date.toString(); }
|
|
||||||
if (typeof song.publisher == 'undefined') { publisher = ' '; } else { publisher = song.publisher.toString(); }
|
|
||||||
if (typeof song.avg_rating == 'undefined') { avg_rating = ' '; } else { avg_rating = song.avg_rating.toString(); }
|
|
||||||
if (typeof song.downloads == 'undefined') { downloads = ' '; } else { downloads = song.downloads.toString(); }
|
|
||||||
|
|
||||||
//var description = '<b>Details</b><br />';
|
|
||||||
var description = '<b>Source</b>: ' + source + '<br />';
|
|
||||||
description += '<b>Date</b>: ' + date + '<br />';
|
|
||||||
description += '<b>Transferer</b>: ' + publisher + '<br />';
|
|
||||||
description += '<b>Rating</b>: ' + avg_rating + '<br />';
|
|
||||||
description += '<b>Downloads</b>: ' + downloads + '<br />';
|
|
||||||
return new model.Album(identifier, null, title, album, '', coverartthumb, coverartfull, $.format.date(new Date(song.publicdate), "yyyy-MM-dd h:mm a"), starred, $sce.trustAsHtml(description), url);
|
|
||||||
};
|
|
||||||
var mapSong = function (key, song, server, dir, identifier, coverart) {
|
|
||||||
var url, time, track, title, rating, starred, contenttype, suffix;
|
|
||||||
var specs = '';
|
|
||||||
if (song.format == 'VBR MP3') {
|
|
||||||
url = 'http://' + server + dir + key;
|
|
||||||
if (typeof song.bitrate == 'undefined' || typeof song.format == 'undefined') { specs = ' '; } else { specs = song.bitrate + 'kbps, ' + song.format.toLowerCase(); }
|
|
||||||
if (typeof song.track == 'undefined') { track = ' '; } else { track = song.track; }
|
|
||||||
if (typeof song.title == 'undefined') { title = ' '; } else { title = song.title; }
|
|
||||||
if (typeof song.length == 'undefined') { time = ' '; } else { time = utils.timeToSeconds(song.length); }
|
|
||||||
return new model.Song(song.md5, identifier, song.track, title, song.creator, '', song.album, '', coverart, coverart, time, '', '', 'mp3', specs, url, 0, '');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
|
||||||
getArtists: function (query) {
|
|
||||||
var deferred = $q.defer();
|
|
||||||
if (globals.settings.Debug) { console.log("LOAD ARCHIVE.ORG COLLECTIONS"); }
|
|
||||||
var url = globals.archiveUrl + 'advancedsearch.php?q=';
|
|
||||||
if (query !== '') {
|
|
||||||
//url += 'collection:(' + collection + ') AND mediatype:(collection) AND identifier:(' + query + ')';
|
|
||||||
url += 'mediatype:(collection) AND identifier:(' + query + ')';
|
|
||||||
} else {
|
|
||||||
url += 'collection:(collection)';
|
|
||||||
}
|
|
||||||
url += '&fl[]=identifier&sort[]=&sort[]=&sort[]=&rows=50&page=1&output=json';
|
|
||||||
$.ajax({
|
|
||||||
url: url,
|
|
||||||
method: 'GET',
|
|
||||||
dataType: globals.settings.Protocol,
|
|
||||||
timeout: globals.settings.Timeout,
|
|
||||||
success: function (data) {
|
|
||||||
if (data.response.docs.length > 0) {
|
|
||||||
items = data.response.docs;
|
|
||||||
//alert(JSON.stringify(data["response"]));
|
|
||||||
content.artist = [];
|
|
||||||
angular.forEach(items, function (item, key) {
|
|
||||||
content.artist.push(item.identifier);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
notifications.updateMessage("Sorry :(", true);
|
|
||||||
}
|
|
||||||
deferred.resolve(content);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return deferred.promise;
|
|
||||||
},
|
|
||||||
getAlbums: function (name, filter) {
|
|
||||||
var deferred = $q.defer();
|
|
||||||
if (name) {
|
|
||||||
var url = globals.archiveUrl + 'advancedsearch.php?q=';
|
|
||||||
if (name !== '') {
|
|
||||||
content.selectedArtist = name;
|
|
||||||
url += 'collection:(' + name + ') AND format:(MP3)';
|
|
||||||
} else if (content.selectedArtist) {
|
|
||||||
name = content.selectedArtist;
|
|
||||||
url += 'collection:(' + content.selectedArtist + ') AND format:(MP3)';
|
|
||||||
} else {
|
|
||||||
url += 'collection:(' + name + ')';
|
|
||||||
}
|
|
||||||
content.breadcrumb = [];
|
|
||||||
content.breadcrumb.push({ 'type': 'artist', 'id': name, 'name': name });
|
|
||||||
|
|
||||||
if (filter.Source) {
|
|
||||||
url += ' AND source:(' + filter.Source + ')';
|
|
||||||
}
|
|
||||||
if (filter.Year) {
|
|
||||||
if (parseInt(filter.Year)) {
|
|
||||||
url += ' AND year:(' + filter.Year + ')';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (filter.Description) {
|
|
||||||
url += ' AND description:(' + filter.Description + ')';
|
|
||||||
}
|
|
||||||
if (content.selectedArtist) {
|
|
||||||
url += '&sort[]=' + globals.settings.DefaultArchiveAlbumSort;
|
|
||||||
}
|
|
||||||
url += '&fl[]=avg_rating,collection,date,description,downloads,headerImage,identifier,publisher,publicdate,source,subject,title,year';
|
|
||||||
url += '&rows=50&page=1&output=json';
|
|
||||||
$.ajax({
|
|
||||||
url: url,
|
|
||||||
method: 'GET',
|
|
||||||
dataType: globals.settings.Protocol,
|
|
||||||
timeout: globals.settings.Timeout,
|
|
||||||
success: function (data) {
|
|
||||||
var items = [];
|
|
||||||
if (data.response.docs.length > 0) {
|
|
||||||
items = data.response.docs;
|
|
||||||
//alert(JSON.stringify(data["response"]));
|
|
||||||
content.album = [];
|
|
||||||
content.song = [];
|
|
||||||
angular.forEach(items, function (item, key) {
|
|
||||||
content.album.push(mapAlbum(item));
|
|
||||||
});
|
|
||||||
notifications.updateMessage(content.album.length, true);
|
|
||||||
} else {
|
|
||||||
notifications.updateMessage("Sorry :(", true);
|
|
||||||
}
|
|
||||||
deferred.resolve(content);
|
|
||||||
},
|
|
||||||
error: function () {
|
|
||||||
notifications.updateMessage('Archive.org service down :(');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
deferred.resolve(content);
|
|
||||||
}
|
|
||||||
return deferred.promise;
|
|
||||||
},
|
|
||||||
getSongs: function (id, action) {
|
|
||||||
var deferred = $q.defer();
|
|
||||||
if (id) {
|
|
||||||
content.selectedAlbum = id;
|
|
||||||
if (content.breadcrumb.length > 0) { content.breadcrumb.splice(1, (content.breadcrumb.length - 1)); }
|
|
||||||
content.breadcrumb.push({ 'type': 'album', 'id': id, 'name': id });
|
|
||||||
var url = globals.archiveUrl + 'details/' + id + '?output=json';
|
|
||||||
$.ajax({
|
|
||||||
url: url,
|
|
||||||
method: 'GET',
|
|
||||||
dataType: globals.settings.Protocol,
|
|
||||||
timeout: globals.settings.Timeout,
|
|
||||||
success: function (data) {
|
|
||||||
var coverart = '';
|
|
||||||
var server = data.server;
|
|
||||||
var dir = data.dir;
|
|
||||||
var identifier = data.metadata.identifier[0];
|
|
||||||
if (typeof data.misc.image != 'undefined') {
|
|
||||||
coverart = data.misc.image;
|
|
||||||
}
|
|
||||||
var items = data.files;
|
|
||||||
if (action == 'add') {
|
|
||||||
angular.forEach(items, function (item, key) {
|
|
||||||
var song = mapSong(key, item, server, dir, identifier, coverart);
|
|
||||||
if (song) {
|
|
||||||
$rootScope.queue.push(song);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
notifications.updateMessage(Object.keys(items).length + ' Song(s) Added to Queue', true);
|
|
||||||
} else if (action == 'play') {
|
|
||||||
$rootScope.queue = [];
|
|
||||||
angular.forEach(items, function (item, key) {
|
|
||||||
var song = mapSong(key, item, server, dir, identifier, coverart);
|
|
||||||
if (song) {
|
|
||||||
$rootScope.queue.push(song);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
var next = $rootScope.queue[0];
|
|
||||||
$rootScope.playSong(false, next);
|
|
||||||
notifications.updateMessage(Object.keys(items).length + ' Song(s) Added to Queue', true);
|
|
||||||
} else {
|
|
||||||
content.album = [];
|
|
||||||
content.song = [];
|
|
||||||
angular.forEach(items, function (item, key) {
|
|
||||||
var song = mapSong(key, item, server, dir, identifier, coverart);
|
|
||||||
if (song) {
|
|
||||||
content.song.push(song);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
deferred.resolve(content);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
deferred.resolve(content);
|
|
||||||
}
|
|
||||||
return deferred.promise;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
JamStash.factory('json', function ($http, $q) { // Deferred loading
|
|
||||||
return {
|
|
||||||
getCollections: function (callback) {
|
|
||||||
//$http.get('js/json_collections.js').success(callback);
|
|
||||||
var deferred = $q.defer();
|
|
||||||
var collections = ['etree', 'dnalounge'];
|
|
||||||
deferred.resolve(collections);
|
|
||||||
return deferred.promise;
|
|
||||||
},
|
|
||||||
getChangeLog: function (callback) {
|
|
||||||
$http.get('js/json_changelog.js').success(callback);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
/* Filters */
|
|
||||||
JamStash.filter('capitalize', function () {
|
|
||||||
return function (input, scope) {
|
|
||||||
return input.substring(0, 1).toUpperCase() + input.substring(1);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
JamStash.filter('musicfolder', function () {
|
|
||||||
return function (items, scope) {
|
|
||||||
return items.slice(1, items.length);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
JamStash.filter('capitalize', function () {
|
|
||||||
return function (input, scope) {
|
|
||||||
return input.substring(0, 1).toUpperCase() + input.substring(1);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
210
js/services/archive-service.js
Normal file
210
js/services/archive-service.js
Normal file
|
@ -0,0 +1,210 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var jamstash = angular.module('JamStash');
|
||||||
|
|
||||||
|
jamstash.factory('archive', function ($rootScope, $http, $q, $sce, globals, model, utils, map, notifications) {
|
||||||
|
var index = { shortcuts: [], artists: [] };
|
||||||
|
var content = {
|
||||||
|
artist: [],
|
||||||
|
album: [],
|
||||||
|
song: [],
|
||||||
|
breadcrumb: [],
|
||||||
|
selectedArtist: null,
|
||||||
|
selectedAlbum: null,
|
||||||
|
selectedGenre: null,
|
||||||
|
selectedArchiveAlbumSort: "date desc"
|
||||||
|
};
|
||||||
|
var offset = 0;
|
||||||
|
|
||||||
|
var mapAlbum = function (data) {
|
||||||
|
var song = data;
|
||||||
|
var coverartthumb, coverartfull, starred, title, album, publisher, avg_rating, downloads, identifier;
|
||||||
|
var url = globals.archiveUrl + 'details/' + song.identifier;
|
||||||
|
coverartthumb = 'images/albumdefault_50.jpg';
|
||||||
|
coverartfull = 'images/albumdefault_160.jpg';
|
||||||
|
if (parseInt(song.avg_rating) == 5) { starred = true; } else { starred = false; }
|
||||||
|
if (typeof song.title == 'undefined') { title = ' '; } else { title = song.title.toString(); }
|
||||||
|
if (typeof song.identifier == 'undefined') { identifier = ' '; } else { identifier = song.identifier.toString(); }
|
||||||
|
if (typeof song.collection[0] == 'undefined') { album = ' '; } else { album = song.collection[0].toString(); }
|
||||||
|
if (typeof song.source == 'undefined') { source = ' '; } else { source = song.source.toString(); }
|
||||||
|
if (typeof song.date == 'undefined') { date = ' '; } else { date = song.date.toString(); }
|
||||||
|
if (typeof song.publisher == 'undefined') { publisher = ' '; } else { publisher = song.publisher.toString(); }
|
||||||
|
if (typeof song.avg_rating == 'undefined') { avg_rating = ' '; } else { avg_rating = song.avg_rating.toString(); }
|
||||||
|
if (typeof song.downloads == 'undefined') { downloads = ' '; } else { downloads = song.downloads.toString(); }
|
||||||
|
|
||||||
|
//var description = '<b>Details</b><br />';
|
||||||
|
var description = '<b>Source</b>: ' + source + '<br />';
|
||||||
|
description += '<b>Date</b>: ' + date + '<br />';
|
||||||
|
description += '<b>Transferer</b>: ' + publisher + '<br />';
|
||||||
|
description += '<b>Rating</b>: ' + avg_rating + '<br />';
|
||||||
|
description += '<b>Downloads</b>: ' + downloads + '<br />';
|
||||||
|
return new model.Album(identifier, null, title, album, '', coverartthumb, coverartfull, $.format.date(new Date(song.publicdate), "yyyy-MM-dd h:mm a"), starred, $sce.trustAsHtml(description), url);
|
||||||
|
};
|
||||||
|
var mapSong = function (key, song, server, dir, identifier, coverart) {
|
||||||
|
var url, time, track, title, rating, starred, contenttype, suffix;
|
||||||
|
var specs = '';
|
||||||
|
if (song.format == 'VBR MP3') {
|
||||||
|
url = 'http://' + server + dir + key;
|
||||||
|
if (typeof song.bitrate == 'undefined' || typeof song.format == 'undefined') { specs = ' '; } else { specs = song.bitrate + 'kbps, ' + song.format.toLowerCase(); }
|
||||||
|
if (typeof song.track == 'undefined') { track = ' '; } else { track = song.track; }
|
||||||
|
if (typeof song.title == 'undefined') { title = ' '; } else { title = song.title; }
|
||||||
|
if (typeof song.length == 'undefined') { time = ' '; } else { time = utils.timeToSeconds(song.length); }
|
||||||
|
return new model.Song(song.md5, identifier, song.track, title, song.creator, '', song.album, '', coverart, coverart, time, '', '', 'mp3', specs, url, 0, '');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
getArtists: function (query) {
|
||||||
|
var deferred = $q.defer();
|
||||||
|
if (globals.settings.Debug) { console.log("LOAD ARCHIVE.ORG COLLECTIONS"); }
|
||||||
|
var url = globals.archiveUrl + 'advancedsearch.php?q=';
|
||||||
|
if (query !== '') {
|
||||||
|
//url += 'collection:(' + collection + ') AND mediatype:(collection) AND identifier:(' + query + ')';
|
||||||
|
url += 'mediatype:(collection) AND identifier:(' + query + ')';
|
||||||
|
} else {
|
||||||
|
url += 'collection:(collection)';
|
||||||
|
}
|
||||||
|
url += '&fl[]=identifier&sort[]=&sort[]=&sort[]=&rows=50&page=1&output=json';
|
||||||
|
$.ajax({
|
||||||
|
url: url,
|
||||||
|
method: 'GET',
|
||||||
|
dataType: globals.settings.Protocol,
|
||||||
|
timeout: globals.settings.Timeout,
|
||||||
|
success: function (data) {
|
||||||
|
if (data.response.docs.length > 0) {
|
||||||
|
items = data.response.docs;
|
||||||
|
//alert(JSON.stringify(data["response"]));
|
||||||
|
content.artist = [];
|
||||||
|
angular.forEach(items, function (item, key) {
|
||||||
|
content.artist.push(item.identifier);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
notifications.updateMessage("Sorry :(", true);
|
||||||
|
}
|
||||||
|
deferred.resolve(content);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return deferred.promise;
|
||||||
|
},
|
||||||
|
getAlbums: function (name, filter) {
|
||||||
|
var deferred = $q.defer();
|
||||||
|
if (name) {
|
||||||
|
var url = globals.archiveUrl + 'advancedsearch.php?q=';
|
||||||
|
if (name !== '') {
|
||||||
|
content.selectedArtist = name;
|
||||||
|
url += 'collection:(' + name + ') AND format:(MP3)';
|
||||||
|
} else if (content.selectedArtist) {
|
||||||
|
name = content.selectedArtist;
|
||||||
|
url += 'collection:(' + content.selectedArtist + ') AND format:(MP3)';
|
||||||
|
} else {
|
||||||
|
url += 'collection:(' + name + ')';
|
||||||
|
}
|
||||||
|
content.breadcrumb = [];
|
||||||
|
content.breadcrumb.push({ 'type': 'artist', 'id': name, 'name': name });
|
||||||
|
|
||||||
|
if (filter.Source) {
|
||||||
|
url += ' AND source:(' + filter.Source + ')';
|
||||||
|
}
|
||||||
|
if (filter.Year) {
|
||||||
|
if (parseInt(filter.Year)) {
|
||||||
|
url += ' AND year:(' + filter.Year + ')';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (filter.Description) {
|
||||||
|
url += ' AND description:(' + filter.Description + ')';
|
||||||
|
}
|
||||||
|
if (content.selectedArtist) {
|
||||||
|
url += '&sort[]=' + globals.settings.DefaultArchiveAlbumSort;
|
||||||
|
}
|
||||||
|
url += '&fl[]=avg_rating,collection,date,description,downloads,headerImage,identifier,publisher,publicdate,source,subject,title,year';
|
||||||
|
url += '&rows=50&page=1&output=json';
|
||||||
|
$.ajax({
|
||||||
|
url: url,
|
||||||
|
method: 'GET',
|
||||||
|
dataType: globals.settings.Protocol,
|
||||||
|
timeout: globals.settings.Timeout,
|
||||||
|
success: function (data) {
|
||||||
|
var items = [];
|
||||||
|
if (data.response.docs.length > 0) {
|
||||||
|
items = data.response.docs;
|
||||||
|
//alert(JSON.stringify(data["response"]));
|
||||||
|
content.album = [];
|
||||||
|
content.song = [];
|
||||||
|
angular.forEach(items, function (item, key) {
|
||||||
|
content.album.push(mapAlbum(item));
|
||||||
|
});
|
||||||
|
notifications.updateMessage(content.album.length, true);
|
||||||
|
} else {
|
||||||
|
notifications.updateMessage("Sorry :(", true);
|
||||||
|
}
|
||||||
|
deferred.resolve(content);
|
||||||
|
},
|
||||||
|
error: function () {
|
||||||
|
notifications.updateMessage('Archive.org service down :(');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
deferred.resolve(content);
|
||||||
|
}
|
||||||
|
return deferred.promise;
|
||||||
|
},
|
||||||
|
getSongs: function (id, action) {
|
||||||
|
var deferred = $q.defer();
|
||||||
|
if (id) {
|
||||||
|
content.selectedAlbum = id;
|
||||||
|
if (content.breadcrumb.length > 0) { content.breadcrumb.splice(1, (content.breadcrumb.length - 1)); }
|
||||||
|
content.breadcrumb.push({ 'type': 'album', 'id': id, 'name': id });
|
||||||
|
var url = globals.archiveUrl + 'details/' + id + '?output=json';
|
||||||
|
$.ajax({
|
||||||
|
url: url,
|
||||||
|
method: 'GET',
|
||||||
|
dataType: globals.settings.Protocol,
|
||||||
|
timeout: globals.settings.Timeout,
|
||||||
|
success: function (data) {
|
||||||
|
var coverart = '';
|
||||||
|
var server = data.server;
|
||||||
|
var dir = data.dir;
|
||||||
|
var identifier = data.metadata.identifier[0];
|
||||||
|
if (typeof data.misc.image != 'undefined') {
|
||||||
|
coverart = data.misc.image;
|
||||||
|
}
|
||||||
|
var items = data.files;
|
||||||
|
if (action == 'add') {
|
||||||
|
angular.forEach(items, function (item, key) {
|
||||||
|
var song = mapSong(key, item, server, dir, identifier, coverart);
|
||||||
|
if (song) {
|
||||||
|
$rootScope.queue.push(song);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
notifications.updateMessage(Object.keys(items).length + ' Song(s) Added to Queue', true);
|
||||||
|
} else if (action == 'play') {
|
||||||
|
$rootScope.queue = [];
|
||||||
|
angular.forEach(items, function (item, key) {
|
||||||
|
var song = mapSong(key, item, server, dir, identifier, coverart);
|
||||||
|
if (song) {
|
||||||
|
$rootScope.queue.push(song);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
var next = $rootScope.queue[0];
|
||||||
|
$rootScope.playSong(false, next);
|
||||||
|
notifications.updateMessage(Object.keys(items).length + ' Song(s) Added to Queue', true);
|
||||||
|
} else {
|
||||||
|
content.album = [];
|
||||||
|
content.song = [];
|
||||||
|
angular.forEach(items, function (item, key) {
|
||||||
|
var song = mapSong(key, item, server, dir, identifier, coverart);
|
||||||
|
if (song) {
|
||||||
|
content.song.push(song);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
deferred.resolve(content);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
deferred.resolve(content);
|
||||||
|
}
|
||||||
|
return deferred.promise;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
|
@ -63,3 +63,14 @@ jamstash.service('globals', function () {
|
||||||
this.BaseURL = function () { return this.settings.Server + '/rest'; };
|
this.BaseURL = function () { return this.settings.Server + '/rest'; };
|
||||||
this.BaseParams = function () { return 'u=' + this.settings.Username + '&p=' + this.settings.Password + '&f=' + this.settings.Protocol + '&v=' + this.settings.ApiVersion + '&c=' + this.settings.ApplicationName; };
|
this.BaseParams = function () { return 'u=' + this.settings.Username + '&p=' + this.settings.Password + '&f=' + this.settings.Protocol + '&v=' + this.settings.ApiVersion + '&c=' + this.settings.ApplicationName; };
|
||||||
});
|
});
|
||||||
|
|
||||||
|
jamstash.factory('json', function ($http) { // Deferred loading
|
||||||
|
return {
|
||||||
|
getCollections: function (callback) {
|
||||||
|
$http.get('js/json_collections.js').success(callback);
|
||||||
|
},
|
||||||
|
getChangeLog: function (callback) {
|
||||||
|
$http.get('js/json_changelog.js').success(callback);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
|
@ -50,3 +50,93 @@ jamstash.service('model', function (utils) {
|
||||||
this.displayName = this.name + " - " + this.album + " - " + this.artist;
|
this.displayName = this.name + " - " + this.album + " - " + this.artist;
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
jamstash.service('map', function ($http, globals, utils, model) {
|
||||||
|
this.mapArtist = function (data) {
|
||||||
|
var name = '';
|
||||||
|
var artist = data.artist;
|
||||||
|
var artists = [];
|
||||||
|
if (artist.length > 0) {
|
||||||
|
artists = artist;
|
||||||
|
} else {
|
||||||
|
artists[0] = artist;
|
||||||
|
}
|
||||||
|
angular.forEach(artists, function (item, key) {
|
||||||
|
if (typeof item.name !== 'undefined') { item.name = item.name.toString(); }
|
||||||
|
});
|
||||||
|
if (typeof data.name !== 'undefined') { name = data.name.toString(); }
|
||||||
|
return new model.Index(name, artists);
|
||||||
|
};
|
||||||
|
this.mapIndex = function (data) {
|
||||||
|
var name, id = '';
|
||||||
|
if (typeof data.id !== 'undefined') { id = data.id; }
|
||||||
|
if (typeof data.name !== 'undefined') { name = data.name.toString(); }
|
||||||
|
return new model.Artist(id, name);
|
||||||
|
};
|
||||||
|
this.mapAlbum = function (data) {
|
||||||
|
var album = data;
|
||||||
|
var title, coverartthumb, coverartfull, starred;
|
||||||
|
if (typeof album.coverArt != 'undefined') {
|
||||||
|
coverartthumb = globals.BaseURL() + '/getCoverArt.view?' + globals.BaseParams() + '&size=160&id=' + album.coverArt;
|
||||||
|
coverartfull = globals.BaseURL() + '/getCoverArt.view?' + globals.BaseParams() + '&id=' + album.coverArt;
|
||||||
|
}
|
||||||
|
if (typeof album.starred !== 'undefined') { starred = true; } else { starred = false; }
|
||||||
|
if (typeof album.title !== 'undefined') { title = album.title; } else { title = album.name; }
|
||||||
|
var type;
|
||||||
|
if (album.isDir) {
|
||||||
|
type = 'byfolder';
|
||||||
|
} else {
|
||||||
|
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);
|
||||||
|
};
|
||||||
|
this.mapSong = function (data) {
|
||||||
|
var song = data;
|
||||||
|
var url, title, artist, track, rating, starred, contenttype, suffix, description;
|
||||||
|
var specs = '', coverartthumb = '', coverartfull = '';
|
||||||
|
if (typeof song.coverArt != 'undefined') {
|
||||||
|
coverartthumb = globals.BaseURL() + '/getCoverArt.view?' + globals.BaseParams() + '&size=30&id=' + song.coverArt;
|
||||||
|
coverartfull = globals.BaseURL() + '/getCoverArt.view?' + globals.BaseParams() + '&id=' + song.coverArt;
|
||||||
|
} else {
|
||||||
|
coverartthumb = 'images/albumdefault_60.jpg';
|
||||||
|
coverartfull = 'images/albumdefault_160.jpg';
|
||||||
|
}
|
||||||
|
if (typeof song.description == 'undefined') { description = ''; } else { description = song.description; }
|
||||||
|
if (typeof song.artist == 'undefined') { artist = ' '; } else { artist = song.artist.toString(); }
|
||||||
|
if (typeof song.title == 'undefined') { title = ' '; } else { title = song.title.toString(); }
|
||||||
|
if (typeof song.track == 'undefined') { track = ' '; } else { track = song.track.toString(); }
|
||||||
|
if (typeof song.starred !== 'undefined') { starred = true; } else { starred = false; }
|
||||||
|
if (song.bitRate !== undefined) { specs += song.bitRate + ' Kbps'; }
|
||||||
|
if (song.transcodedSuffix !== undefined) { specs += ', transcoding:' + song.suffix + ' > ' + song.transcodedSuffix; } else { specs += ', ' + song.suffix; }
|
||||||
|
if (song.transcodedSuffix !== undefined) { suffix = song.transcodedSuffix; } else { suffix = song.suffix; }
|
||||||
|
if (suffix == 'ogg') { suffix = 'oga'; }
|
||||||
|
var salt = Math.floor(Math.random() * 100000);
|
||||||
|
url = globals.BaseURL() + '/stream.view?' + globals.BaseParams() + '&id=' + song.id + '&salt=' + salt;
|
||||||
|
return new model.Song(song.id, song.parent, track, title, artist, song.artistId, song.album, song.albumId, coverartthumb, coverartfull, song.duration, song.userRating, starred, suffix, specs, url, 0, description);
|
||||||
|
};
|
||||||
|
this.mapPlaylist = function (data) {
|
||||||
|
return new model.Artist(data.id, data.name);
|
||||||
|
};
|
||||||
|
this.mapPodcast = function (data) {
|
||||||
|
var song = data;
|
||||||
|
var url, track, rating, starred, contenttype, suffix, description, artist, album, title;
|
||||||
|
var specs = '', coverartthumb = '', coverartfull = '';
|
||||||
|
if (typeof song.coverArt != 'undefined') {
|
||||||
|
coverartthumb = globals.BaseURL() + '/getCoverArt.view?' + globals.BaseParams() + '&size=60&id=' + song.coverArt;
|
||||||
|
coverartfull = globals.BaseURL() + '/getCoverArt.view?' + globals.BaseParams() + '&id=' + song.coverArt;
|
||||||
|
}
|
||||||
|
if (typeof song.album == 'undefined') { album = ' '; } else { album = song.album.toString(); }
|
||||||
|
if (typeof song.artist == 'undefined') { artist = ' '; } else { artist = song.artist.toString(); }
|
||||||
|
if (typeof song.title == 'undefined') { title = ' '; } else { title = song.title.toString(); }
|
||||||
|
if (typeof song.description == 'undefined') { description = ''; } else { description = song.description; }
|
||||||
|
if (typeof song.track == 'undefined') { track = ' '; } else { track = song.track.toString(); }
|
||||||
|
if (typeof song.starred !== 'undefined') { starred = true; } else { starred = false; }
|
||||||
|
if (song.bitRate !== undefined) { specs += song.bitRate + ' Kbps'; }
|
||||||
|
if (song.transcodedSuffix !== undefined) { specs += ', transcoding:' + song.suffix + ' > ' + song.transcodedSuffix; } else { specs += ', ' + song.suffix; }
|
||||||
|
if (song.transcodedSuffix !== undefined) { suffix = song.transcodedSuffix; } else { suffix = song.suffix; }
|
||||||
|
if (suffix == 'ogg') { suffix = 'oga'; }
|
||||||
|
var salt = Math.floor(Math.random() * 100000);
|
||||||
|
url = globals.BaseURL() + '/stream.view?' + globals.BaseParams() + '&id=' + song.streamId + '&salt=' + salt;
|
||||||
|
return new model.Song(song.streamId, song.parent, track, title, artist, song.artistId, album, song.albumId, coverartthumb, coverartfull, song.duration, song.userRating, starred, suffix, specs, url, 0, description);
|
||||||
|
};
|
||||||
|
});
|
71
js/services/notification-service.js
Normal file
71
js/services/notification-service.js
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var jamstash = angular.module('JamStash');
|
||||||
|
|
||||||
|
jamstash.service('notifications', function ($rootScope, globals) {
|
||||||
|
var msgIndex = 1;
|
||||||
|
this.updateMessage = function (msg, autohide) {
|
||||||
|
if (msg != '') {
|
||||||
|
var id = msgIndex;
|
||||||
|
$('#messages').append('<span id=\"msg_' + id + '\" class="message">' + msg + '</span>');
|
||||||
|
$('#messages').fadeIn();
|
||||||
|
$("#messages").scrollTo('100%');
|
||||||
|
var el = '#msg_' + id;
|
||||||
|
if (autohide) {
|
||||||
|
setTimeout(function () {
|
||||||
|
$(el).fadeOut(function () { $(this).remove(); });
|
||||||
|
}, globals.settings.Timeout);
|
||||||
|
} else {
|
||||||
|
$(el).click(function () {
|
||||||
|
$(el).fadeOut(function () { $(this).remove(); });
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
msgIndex++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.requestPermissionIfRequired = function () {
|
||||||
|
if (window.Notify.isSupported() && window.Notify.needsPermission()) {
|
||||||
|
window.Notify.requestPermission();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.hasNotificationPermission = function () {
|
||||||
|
return (window.Notify.needsPermission() === false);
|
||||||
|
}
|
||||||
|
this.hasNotificationSupport = function () {
|
||||||
|
return window.Notify.isSupported();
|
||||||
|
}
|
||||||
|
var notifications = new Array();
|
||||||
|
|
||||||
|
this.showNotification = function (pic, title, text, type, bind) {
|
||||||
|
if (this.hasNotificationPermission()) {
|
||||||
|
//closeAllNotifications()
|
||||||
|
var settings = {}
|
||||||
|
if (bind = '#NextTrack') {
|
||||||
|
settings.notifyClick = function () {
|
||||||
|
$rootScope.nextTrack();
|
||||||
|
this.close();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (type == 'text') {
|
||||||
|
settings.body = text;
|
||||||
|
settings.icon = pic;
|
||||||
|
} else if (type == 'html') {
|
||||||
|
settings.body = text;
|
||||||
|
}
|
||||||
|
var notification = new Notify(title, settings);
|
||||||
|
notifications.push(notification);
|
||||||
|
setTimeout(function (notWin) {
|
||||||
|
notWin.close();
|
||||||
|
}, globals.settings.Timeout, notification);
|
||||||
|
notification.show();
|
||||||
|
} else {
|
||||||
|
console.log("showNotification: No Permission");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.closeAllNotifications = function () {
|
||||||
|
for (notification in notifications) {
|
||||||
|
notifications[notification].close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
|
@ -1,4 +1,8 @@
|
||||||
JamStash.service('player', function ($rootScope, $window, utils, globals, model, notifications) {
|
'use strict';
|
||||||
|
|
||||||
|
var jamstash = angular.module('JamStash');
|
||||||
|
|
||||||
|
jamstash.service('player', function ($rootScope, $window, utils, globals, model, notifications) {
|
||||||
var player1 = globals.Player1;
|
var player1 = globals.Player1;
|
||||||
var player2 = '#playdeck_2';
|
var player2 = '#playdeck_2';
|
||||||
var scrobbled = false;
|
var scrobbled = false;
|
|
@ -1,7 +1,11 @@
|
||||||
JamStash.service('utils', function ($rootScope, $cookieStore, globals, model) {
|
'use strict';
|
||||||
|
|
||||||
|
var jamstash = angular.module('JamStash');
|
||||||
|
|
||||||
|
jamstash.service('utils', function ($rootScope, $cookieStore, globals) {
|
||||||
this.safeApply = function (fn) {
|
this.safeApply = function (fn) {
|
||||||
var phase = $rootScope.$root.$$phase;
|
var phase = $rootScope.$root.$$phase;
|
||||||
if (phase == '$apply' || phase == '$digest') {
|
if (phase === '$apply' || phase === '$digest') {
|
||||||
if (fn && (typeof (fn) === 'function')) {
|
if (fn && (typeof (fn) === 'function')) {
|
||||||
fn();
|
fn();
|
||||||
}
|
}
|
||||||
|
@ -9,16 +13,7 @@ JamStash.service('utils', function ($rootScope, $cookieStore, globals, model) {
|
||||||
this.$apply(fn);
|
this.$apply(fn);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
this.setValue = function (key, value, notify) {
|
this.setValue = function (key, value) {
|
||||||
/*
|
|
||||||
if (value !== null) {
|
|
||||||
$cookieStore.put(key, value);
|
|
||||||
} else {
|
|
||||||
$cookieStore.remove(key);
|
|
||||||
}
|
|
||||||
if (notify) {
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
try {
|
try {
|
||||||
localStorage.setItem(key, JSON.stringify(value));
|
localStorage.setItem(key, JSON.stringify(value));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -26,16 +21,9 @@ JamStash.service('utils', function ($rootScope, $cookieStore, globals, model) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
this.getValue = function (value) {
|
this.getValue = function (value) {
|
||||||
/*
|
|
||||||
if ($cookieStore.get(value)) {
|
|
||||||
return $cookieStore.get(value);
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
try {
|
try {
|
||||||
var item = localStorage.getItem(value);
|
var item = localStorage.getItem(value);
|
||||||
if (item !== '' && typeof item != 'undefined') {
|
if (item !== '' && typeof item !== 'undefined') {
|
||||||
return JSON.parse(item);
|
return JSON.parse(item);
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
@ -57,7 +45,7 @@ JamStash.service('utils', function ($rootScope, $cookieStore, globals, model) {
|
||||||
return parseInt(a.track) > parseInt(b.track) ? -1 : 1;
|
return parseInt(a.track) > parseInt(b.track) ? -1 : 1;
|
||||||
};
|
};
|
||||||
this.confirmDelete = function (text) {
|
this.confirmDelete = function (text) {
|
||||||
var question = confirm(text);
|
var question = window.confirm(text);
|
||||||
if (question) {
|
if (question) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -71,10 +59,12 @@ JamStash.service('utils', function ($rootScope, $cookieStore, globals, model) {
|
||||||
return "Basic " + hash;
|
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);
|
||||||
for (t = 0; t < n.length; t++)
|
}
|
||||||
|
for (t = 0; t < n.length; t++) {
|
||||||
r[t] = i[n.charCodeAt(t)];
|
r[t] = i[n.charCodeAt(t)];
|
||||||
|
}
|
||||||
return r.join("");
|
return r.join("");
|
||||||
};
|
};
|
||||||
this.switchTheme = function (theme) {
|
this.switchTheme = function (theme) {
|
||||||
|
@ -91,7 +81,7 @@ JamStash.service('utils', function ($rootScope, $cookieStore, globals, model) {
|
||||||
};
|
};
|
||||||
// HTML5
|
// HTML5
|
||||||
this.browserStorageCheck = function () {
|
this.browserStorageCheck = function () {
|
||||||
if (typeof (localStorage) == 'undefined') {
|
if (typeof (localStorage) === 'undefined') {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
|
@ -131,7 +121,7 @@ JamStash.service('utils', function ($rootScope, $cookieStore, globals, model) {
|
||||||
else if (tmp < 10) {
|
else if (tmp < 10) {
|
||||||
tmp = '0' + tmp;
|
tmp = '0' + tmp;
|
||||||
}
|
}
|
||||||
if (i === 0 && tmp == '00') {
|
if (i === 0 && tmp === '00') {
|
||||||
} else {
|
} else {
|
||||||
time += tmp;
|
time += tmp;
|
||||||
if (i < 2) {
|
if (i < 2) {
|
||||||
|
@ -144,7 +134,7 @@ JamStash.service('utils', function ($rootScope, $cookieStore, globals, model) {
|
||||||
};
|
};
|
||||||
this.arrayObjectIndexOf = function (myArray, searchTerm, property) {
|
this.arrayObjectIndexOf = function (myArray, searchTerm, property) {
|
||||||
for (var i = 0, len = myArray.length; i < len; i++) {
|
for (var i = 0, len = myArray.length; i < len; i++) {
|
||||||
if (myArray[i][property] === searchTerm) return i;
|
if (myArray[i][property] === searchTerm) { return i; }
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
};
|
};
|
||||||
|
@ -222,7 +212,7 @@ JamStash.service('utils', function ($rootScope, $cookieStore, globals, model) {
|
||||||
on: function (str) {
|
on: function (str) {
|
||||||
var a = [],
|
var a = [],
|
||||||
i = 0;
|
i = 0;
|
||||||
for (; i < str.length; ) a[i] = str.charCodeAt(i++);
|
for (; i < str.length; ) { a[i] = str.charCodeAt(i++); }
|
||||||
return "&#" + a.join(";&#") + ";";
|
return "&#" + a.join(";&#") + ";";
|
||||||
},
|
},
|
||||||
un: function (str) {
|
un: function (str) {
|
||||||
|
@ -237,10 +227,11 @@ JamStash.service('utils', function ($rootScope, $cookieStore, globals, model) {
|
||||||
var regexS = "[\\?&]" + name + "=([^&#]*)";
|
var regexS = "[\\?&]" + name + "=([^&#]*)";
|
||||||
var regex = new RegExp(regexS);
|
var regex = new RegExp(regexS);
|
||||||
var results = regex.exec(window.location.search);
|
var results = regex.exec(window.location.search);
|
||||||
if (results === null)
|
if (results === null) {
|
||||||
return "";
|
return "";
|
||||||
else
|
} else {
|
||||||
return decodeURIComponent(results[1].replace(/\+/g, " "));
|
return decodeURIComponent(results[1].replace(/\+/g, " "));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
this.getPathFromUrl = function (url) {
|
this.getPathFromUrl = function (url) {
|
||||||
var strurl = url.toString();
|
var strurl = url.toString();
|
||||||
|
@ -268,7 +259,7 @@ JamStash.service('utils', function ($rootScope, $cookieStore, globals, model) {
|
||||||
speed: 1200
|
speed: 1200
|
||||||
};
|
};
|
||||||
|
|
||||||
t = (opts.text || document.title).split("");
|
var t = (opts.text || document.title).split("");
|
||||||
if (!t) {
|
if (!t) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -281,16 +272,9 @@ JamStash.service('utils', function ($rootScope, $cookieStore, globals, model) {
|
||||||
document.title = t.join("");
|
document.title = t.join("");
|
||||||
}
|
}
|
||||||
}, opts.speed);
|
}, opts.speed);
|
||||||
/*
|
|
||||||
$.marqueeTitle({
|
|
||||||
text: text,
|
|
||||||
dir: "left",
|
|
||||||
speed: 1200
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
};
|
};
|
||||||
this.parseVersionString = function (str) {
|
this.parseVersionString = function (str) {
|
||||||
if (typeof (str) != 'string') { return false; }
|
if (typeof (str) !== 'string') { return false; }
|
||||||
var x = str.split('.');
|
var x = str.split('.');
|
||||||
// parse from string or default to 0 if can't parse
|
// parse from string or default to 0 if can't parse
|
||||||
var maj = parseInt(x[0]) || 0;
|
var maj = parseInt(x[0]) || 0;
|
4
test/services/archive-service_test.js
Normal file
4
test/services/archive-service_test.js
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
describe("archive service", function() {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
});
|
25
test/services/model-service_test.js
Normal file
25
test/services/model-service_test.js
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
describe("model service", function() {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var model;
|
||||||
|
beforeEach(module('JamStash'));
|
||||||
|
beforeEach(inject(function(_model_) {
|
||||||
|
model = _model_;
|
||||||
|
}));
|
||||||
|
|
||||||
|
it("given a name and artist, when calling Index() then the model name and artist are changed", function() {
|
||||||
|
model.Index("CoolAlbum", "HipArtist");
|
||||||
|
expect(model.name).toBe("CoolAlbum");
|
||||||
|
expect(model.artist).toBe("HipArtist");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("given all the arguments, when calling Song() then the composite attributes are computed", function() {
|
||||||
|
model.Song(21, 43, 3, "Know Your Enemy", "Yoko Kanno", "27", "Ghost in the Shell - Stand Alone Complex OST 3",
|
||||||
|
"51", "cover.jpg", "big-cover.jpg", "385", "5", true, "mp3", "specs", "url", "0", "Awesome track");
|
||||||
|
|
||||||
|
expect(model.selected).toBe(false);
|
||||||
|
expect(model.playing).toBe(false);
|
||||||
|
expect(model.time).toBe("06:25");
|
||||||
|
expect(model.displayName).toBe("Know Your Enemy - Ghost in the Shell - Stand Alone Complex OST 3 - Yoko Kanno");
|
||||||
|
});
|
||||||
|
});
|
15
test/services/subsonic-service_test.js
Normal file
15
test/services/subsonic-service_test.js
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
describe("subsonicService", function() {
|
||||||
|
'use strict';
|
||||||
|
/*
|
||||||
|
var Subsonic;
|
||||||
|
beforeEach(module('JamStash'));
|
||||||
|
beforeEach(inject(function (subsonic) {
|
||||||
|
Subsonic = subsonic;
|
||||||
|
}));
|
||||||
|
|
||||||
|
it("should exist", inject(function(subsonic) {
|
||||||
|
expect(subsonic).toBeDefined();
|
||||||
|
}));
|
||||||
|
*/
|
||||||
|
|
||||||
|
});
|
5
test/services/utils-service_test.js
Normal file
5
test/services/utils-service_test.js
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
describe("utils service", function() {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
|
});
|
Loading…
Add table
Add a link
Reference in a new issue