js-beautify all the controllers, services and directives (and jshint)

This commit is contained in:
Emory P 2014-02-12 01:18:36 -05:00
parent 95f7ef53f2
commit bb7d018de4
23 changed files with 2533 additions and 3446 deletions

View file

@ -1,288 +1,323 @@
JamStash.controller('ArchiveCtrl',
function ArchiveCtrl($scope, $rootScope, $location, $routeParams, $http, utils, globals, model, notifications, player, json) {
//$("#left-component").layout($scope.layoutThreeCol);
function ArchiveCtrl($scope, $rootScope, $location, $routeParams, $http, utils, globals, model, notifications, player, json) {
//$("#left-component").layout($scope.layoutThreeCol);
$scope.settings = globals.settings;
$scope.itemType = 'archive';
$rootScope.song = [];
$scope.Protocol = 'jsonp';
$scope.artist = [];
$scope.album = [];
$scope.selectedArtist;
$scope.selectedAlbum;
$scope.selectedSongs = [];
$scope.SavedCollections = globals.SavedCollections;
$scope.AllCollections = [];
$scope.loadedCollection = false;
json.getCollections(function (data) {
$scope.AllCollections = data;
$scope.loadedCollection = true;
});
$scope.writeSavedCollection = function () {
utils.setValue('SavedCollections', $scope.SavedCollections.join(), false);
/*
$scope.$apply(function () {
$scope.settings = globals.settings;
$scope.itemType = 'archive';
$rootScope.song = [];
$scope.Protocol = 'jsonp';
$scope.artist = [];
$scope.album = [];
$scope.selectedArtist = null;
$scope.selectedAlbum = null;
$scope.selectedSongs = [];
$scope.SavedCollections = globals.SavedCollections;
$scope.AllCollections = [];
$scope.loadedCollection = false;
json.getCollections(function(data) {
$scope.AllCollections = data;
$scope.loadedCollection = true;
});
*/
globals.SavedCollections = $scope.SavedCollections;
}
$scope.addSavedCollection = function (newValue) {
if ($scope.SavedCollections.indexOf(newValue) == -1) {
$scope.SavedCollections.push(newValue);
$scope.writeSavedCollection = function() {
utils.setValue('SavedCollections', $scope.SavedCollections.join(), false);
globals.SavedCollections = $scope.SavedCollections;
};
$scope.addSavedCollection = function(newValue) {
if ($scope.SavedCollections.indexOf(newValue) == -1) {
$scope.SavedCollections.push(newValue);
$scope.writeSavedCollection();
}
};
$scope.deleteSavedCollection = function(index) {
$scope.SavedCollections.splice(index, 1);
$scope.writeSavedCollection();
}
}
$scope.deleteSavedCollection = function (index) {
$scope.SavedCollections.splice(index, 1);
$scope.writeSavedCollection();
}
$scope.selectedCollection;
$scope.$watch("selectedCollection", function (newValue, oldValue) {
if (newValue !== oldValue) {
$scope.addSavedCollection(newValue);
}
});
$scope.setupDemoCollections = function () {
var demo = ["YonderMountainStringBand", "GreenskyBluegrass"];
angular.forEach(demo, function (item, key) {
if ($scope.SavedCollections.indexOf(item) == -1) {
$scope.SavedCollections.push(item);
};
$scope.selectedCollection = null;
$scope.$watch("selectedCollection", function(newValue, oldValue) {
if (newValue !== oldValue) {
$scope.addSavedCollection(newValue);
}
});
}
$scope.archiveUrl = 'https://archive.org/';
/* Filter */
$scope.selectedArchiveAlbumSort = "date desc";
$scope.ArchiveAlbumSort = [
'addeddate desc',
'addeddate asc',
'avg_rating desc',
'avg_rating asc',
'createdate desc',
'createdate asc',
'date desc',
'date asc',
'downloads desc',
'downloads asc',
'num_reviews desc',
'num_reviews asc',
'publicdate desc',
'publicdate asc',
'stars desc',
'stars asc'
],
$scope.$watch("selectedArchiveAlbumSort", function (newValue, oldValue) {
if (utils.getValue('AlbumSort') != newValue) {
if (typeof newValue != 'undefined') {
utils.setValue('AlbumSort', newValue, true);
$scope.setupDemoCollections = function() {
var demo = ["YonderMountainStringBand", "GreenskyBluegrass"];
angular.forEach(demo, function(item, key) {
if ($scope.SavedCollections.indexOf(item) == -1) {
$scope.SavedCollections.push(item);
}
});
};
$scope.archiveUrl = 'https://archive.org/';
/* Filter */
$scope.selectedArchiveAlbumSort = "date desc";
$scope.ArchiveAlbumSort = [
'addeddate desc',
'addeddate asc',
'avg_rating desc',
'avg_rating asc',
'createdate desc',
'createdate asc',
'date desc',
'date asc',
'downloads desc',
'downloads asc',
'num_reviews desc',
'num_reviews asc',
'publicdate desc',
'publicdate asc',
'stars desc',
'stars asc'
];
$scope.$watch("selectedArchiveAlbumSort", function(newValue, oldValue) {
if (utils.getValue('AlbumSort') != newValue) {
if (typeof newValue != 'undefined') {
utils.setValue('AlbumSort', newValue, true);
} else {
utils.setValue('AlbumSort', null, true);
}
//alert(newValue);
$scope.getAlbums('');
}
});
$scope.getYears = function(startYear) {
var currentYear = new Date().getFullYear(),
years = [];
startYear = startYear || 1950;
while (startYear <= currentYear) {
years.push(startYear++);
}
return years;
};
$scope.Years = $scope.getYears();
$scope.filter = {
Year: "",
Source: "",
Description: ""
};
$scope.filterSave = function() {
if ($scope.selectedArtist) {
$scope.getAlbums('', '');
}
};
/* End Filter */
$scope.getAlbums = function(name, identifier) {
var url = $scope.archiveUrl + 'advancedsearch.php?q=';
if (name !== '') {
$scope.selectedArtist = name;
url += 'collection:(' + name + ') AND format:(MP3)';
} else if ($scope.selectedArtist) {
url += 'collection:(' + $scope.selectedArtist + ') AND format:(MP3)';
} else {
utils.setValue('AlbumSort', null, true);
url += 'identifier:(' + identifier + ')';
}
//alert(newValue);
$scope.getAlbums('');
}
});
$scope.getYears = function (startYear) {
var currentYear = new Date().getFullYear(), years = [];
startYear = startYear || 1950;
while (startYear <= currentYear) {
years.push(startYear++);
}
return years;
}
$scope.Years = $scope.getYears(),
$scope.filter = {
Year: "",
Source: "",
Description: ""
};
$scope.filterSave = function () {
if ($scope.selectedArtist) {
$scope.getAlbums('', '');
}
}
/* End Filter */
/*
$scope.getArtists = function (data) {
var map = function (data) {
return new model.Artist('', data);
};
angular.forEach($scope.SavedCollections, function (item, key) {
$scope.artist.push(map(item));
});
};
*/
$scope.getAlbums = function (name, identifier) {
var url = $scope.archiveUrl + 'advancedsearch.php?q=';
if (name != '') {
$scope.selectedArtist = name;
url += 'collection:(' + name + ') AND format:(MP3)';
} else if ($scope.selectedArtist) {
url += 'collection:(' + $scope.selectedArtist + ') AND format:(MP3)';
} else {
url += 'identifier:(' + identifier + ')';
}
var map = function (data) {
var song = data;
var coverartthumb, coverartfull, starred;
var url = $scope.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; }
//var description = '<b>Details</b><br />';
var description = '<b>Source</b>: ' + song.source + '<br />';
description += '<b>Date</b>: ' + song.date + '<br />';
description += typeof song.publisher != 'undefined' ? '<b>Transferer</b>: ' + song.publisher + '<br />' : '';
description += typeof song.avg_rating != 'undefined' ? '<b>Rating</b>: ' + song.avg_rating + '<br />' : '';
description += typeof song.downloads != 'undefined' ? '<b>Downloads</b>: ' + song.downloads + '<br />' : '';
return new model.Album(song.identifier, null, song.title, song.collection[0], '', coverartthumb, coverartfull, $.format.date(new Date(song.publicdate), "yyyy-MM-dd h:mm a"), starred, description, url);
}
if ($scope.filter.Source) {
url += ' AND source:(' + $scope.filter.Source + ')';
}
if ($scope.filter.Year) {
if (parseInt($scope.filter.Year)) {
url += ' AND year:(' + $scope.filter.Year + ')';
}
}
if ($scope.filter.Description) {
url += ' AND description:(' + $scope.filter.Description + ')';
}
if ($scope.selectedArchiveAlbumSort) {
url += '&sort[]=' + $scope.selectedArchiveAlbumSort;
}
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: $scope.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"]));
$scope.album = [];
$rootScope.song = [];
angular.forEach(items, function (item, key) {
$scope.album.push(map(item));
});
$scope.$apply();
notifications.updateMessage($scope.album.length, true);
var map = function(data) {
var song = data;
var coverartthumb, coverartfull, starred;
var url = $scope.archiveUrl + 'details/' + song.identifier;
coverartthumb = 'images/albumdefault_50.jpg';
coverartfull = 'images/albumdefault_160.jpg';
if (parseInt(song.avg_rating) == 5) {
starred = true;
} else {
notifications.updateMessage("Sorry :(", true);
starred = false;
}
},
error: function () {
alert('Archive.org service down :(');
//var description = '<b>Details</b><br />';
var description = '<b>Source</b>: ' + song.source + '<br />';
description += '<b>Date</b>: ' + song.date + '<br />';
description += typeof song.publisher != 'undefined' ? '<b>Transferer</b>: ' + song.publisher + '<br />' : '';
description += typeof song.avg_rating != 'undefined' ? '<b>Rating</b>: ' + song.avg_rating + '<br />' : '';
description += typeof song.downloads != 'undefined' ? '<b>Downloads</b>: ' + song.downloads + '<br />' : '';
return new model.Album(song.identifier, null, song.title, song.collection[0], '', coverartthumb, coverartfull, $.format.date(new Date(song.publicdate), "yyyy-MM-dd h:mm a"), starred, description, url);
};
if ($scope.filter.Source) {
url += ' AND source:(' + $scope.filter.Source + ')';
}
});
};
utils.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 = '&nbsp;'; } else { specs = song.bitrate + 'kbps, ' + song.format.toLowerCase(); }
if (typeof song.track == 'undefined') { track = '&nbsp;'; } else { track = song.track; }
if (typeof song.title == 'undefined') { title = '&nbsp;'; } else { title = song.title; }
if (typeof song.length == 'undefined') { time = '&nbsp;'; } 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, '');
}
};
$scope.getSongs = function (id, action) {
$scope.selectedAlbum = id;
var url = $scope.archiveUrl + 'details/' + id + '?output=json';
$.ajax({
url: url,
method: 'GET',
dataType: $scope.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;
if ($scope.filter.Year) {
if (parseInt($scope.filter.Year)) {
url += ' AND year:(' + $scope.filter.Year + ')';
}
var items = data.files;
if (action == 'add') {
angular.forEach(items, function (item, key) {
var song = utils.mapSong(key, item, server, dir, identifier, coverart);
if (song) {
$rootScope.queue.push(song);
}
});
$rootScope.showQueue();
notifications.updateMessage(Object.keys(items).length + ' Song(s) Added to Queue', true);
$scope.$apply();
} else if (action == 'play') {
$rootScope.queue = [];
angular.forEach(items, function (item, key) {
var song = utils.mapSong(key, item, server, dir, identifier, coverart);
if (song) {
$rootScope.queue.push(song);
}
});
var next = $rootScope.queue[0];
$scope.$apply(function () {
$rootScope.playSong(false, next);
});
$rootScope.showQueue();
notifications.updateMessage(Object.keys(items).length + ' Song(s) Added to Queue', true);
}
if ($scope.filter.Description) {
url += ' AND description:(' + $scope.filter.Description + ')';
}
if ($scope.selectedArchiveAlbumSort) {
url += '&sort[]=' + $scope.selectedArchiveAlbumSort;
}
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: $scope.Protocol,
timeout: globals.settings.Timeout,
success: function(data) {
var items = [];
if (data.response.docs.length > 0) {
items = data.response.docs;
$scope.album = [];
$rootScope.song = [];
angular.forEach(items, function(item, key) {
$scope.album.push(map(item));
});
$scope.$apply();
notifications.updateMessage($scope.album.length, true);
} else {
notifications.updateMessage("Sorry :(", true);
}
},
error: function() {
alert('Archive.org service down :(');
}
});
};
utils.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 = '&nbsp;';
} else {
$scope.album = [];
$rootScope.song = [];
angular.forEach(items, function (item, key) {
var song = utils.mapSong(key, item, server, dir, identifier, coverart);
if (song) {
$rootScope.song.push(song);
}
});
$scope.$apply();
specs = song.bitrate + 'kbps, ' + song.format.toLowerCase();
}
if (typeof song.track == 'undefined') {
track = '&nbsp;';
} else {
track = song.track;
}
if (typeof song.title == 'undefined') {
title = '&nbsp;';
} else {
title = song.title;
}
if (typeof song.length == 'undefined') {
time = '&nbsp;';
} 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, '');
}
});
};
$scope.addSongsToQueue = function () {
if ($scope.selectedSongs.length > 0) {
angular.forEach($scope.selectedSongs, function (item, key) {
$scope.queue.push(item);
};
$scope.getSongs = function(id, action) {
$scope.selectedAlbum = id;
var url = $scope.archiveUrl + 'details/' + id + '?output=json';
$.ajax({
url: url,
method: 'GET',
dataType: $scope.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 = utils.mapSong(key, item, server, dir, identifier, coverart);
if (song) {
$rootScope.queue.push(song);
}
});
$rootScope.showQueue();
notifications.updateMessage(Object.keys(items).length + ' Song(s) Added to Queue', true);
$scope.$apply();
} else if (action == 'play') {
$rootScope.queue = [];
angular.forEach(items, function(item, key) {
var song = utils.mapSong(key, item, server, dir, identifier, coverart);
if (song) {
$rootScope.queue.push(song);
}
});
var next = $rootScope.queue[0];
$scope.$apply(function() {
$rootScope.playSong(false, next);
});
$rootScope.showQueue();
notifications.updateMessage(Object.keys(items).length + ' Song(s) Added to Queue', true);
} else {
$scope.album = [];
$rootScope.song = [];
angular.forEach(items, function(item, key) {
var song = utils.mapSong(key, item, server, dir, identifier, coverart);
if (song) {
$rootScope.song.push(song);
}
});
$scope.$apply();
}
}
});
};
$scope.addSongsToQueue = function() {
if ($scope.selectedSongs.length > 0) {
angular.forEach($scope.selectedSongs, function(item, key) {
$scope.queue.push(item);
item.selected = false;
});
$rootScope.showQueue();
notifications.updateMessage($scope.selectedSongs.length + ' Song(s) Added to Queue', true);
}
};
$scope.scrollToTop = function() {
$('#Artists').stop().scrollTo('#auto', 400);
};
$scope.selectAll = function() {
angular.forEach($rootScope.song, function(item, key) {
$scope.selectedSongs.push(item);
item.selected = true;
});
};
$scope.selectNone = function() {
angular.forEach($rootScope.song, function(item, key) {
$scope.selectedSongs = [];
item.selected = false;
});
$rootScope.showQueue();
notifications.updateMessage($scope.selectedSongs.length + ' Song(s) Added to Queue', true);
}
}
$scope.scrollToTop = function () {
$('#Artists').stop().scrollTo('#auto', 400);
}
$scope.selectAll = function () {
angular.forEach($rootScope.song, function (item, key) {
$scope.selectedSongs.push(item);
item.selected = true;
});
}
$scope.selectNone = function () {
angular.forEach($rootScope.song, function (item, key) {
$scope.selectedSongs = [];
item.selected = false;
});
}
};
/* Launch on Startup */
if ($routeParams.artist) {
if ($routeParams.album) {
//collection:(GreenskyBluegrass) AND format:(MP3) AND identifier:(gsbg2013-09-20.flac16)
$scope.getAlbums('', $routeParams.album);
} else {
$scope.getAlbums($routeParams.artist, '');
/* Launch on Startup */
if ($routeParams.artist) {
if ($routeParams.album) {
//collection:(GreenskyBluegrass) AND format:(MP3) AND identifier:(gsbg2013-09-20.flac16)
$scope.getAlbums('', $routeParams.album);
} else {
$scope.getAlbums($routeParams.artist, '');
}
$scope.addSavedCollection($routeParams.artist);
}
$scope.addSavedCollection($routeParams.artist);
}
/* End Startup */
});
/* End Startup */
});

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,52 +0,0 @@
JamStash.controller('PartialCtrl',
function PartialCtrl($scope, $rootScope, $location, $window, $routeParams, utils, globals) {
//$("#SubsonicAlbums").layout($scope.layoutThreeCol);
$scope.song = [];
$scope.itemType = 'ss';
$scope.index = [];
$scope.shortcut = [];
$scope.album = [];
$scope.Server = globals.settings.Server;
$scope.getSongs = function (id) {
var url = globals.BaseURL() + '/getMusicDirectory.view?' + globals.BaseParams() + '&id=' + id;
$.ajax({
url: url,
method: 'GET',
dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout,
success: function (data) {
var items = [];
if (typeof data["subsonic-response"].directory.child != 'undefined') {
if (data["subsonic-response"].directory.child.length > 0) {
items = data["subsonic-response"].directory.child;
} else {
items[0] = data["subsonic-response"].directory.child;
}
$scope.song = [];
var albums = [];
angular.forEach(items, function (item, key) {
if (item.isDir) {
//albums.push($scope.mapAlbum(item));
} else {
$rootScope.song.push(utils.mapSong(item));
}
});
//$location.path('/library/0/' + id);
$scope.$apply();
} else {
notifications.updateMessage('No Songs Returned :(', true);
}
}
});
};
/* Launch on Startup */
if ($routeParams.albumId) {
$scope.getSongs($routeParams.albumId);
}
/* End Startup */
});

View file

@ -1,231 +1,244 @@
JamStash.controller('PlaylistCtrl',
function PlaylistCtrl($scope, $rootScope, $location, utils, globals, model, notifications) {
//$("#left-component").layout($scope.layoutTwoCol);
function PlaylistCtrl($scope, $rootScope, $location, utils, globals, model, notifications) {
$rootScope.song = [];
$scope.itemType = 'pl';
$scope.playlists = [];
$scope.playlistsPublic = [];
$scope.playlistsGenre = globals.SavedGenres;
$scope.selectedGenre;
$scope.$watch("selectedGenre", function (newValue, oldValue) {
if (newValue !== oldValue) {
globals.SavedGenres.push(newValue);
//$scope.playlistsGenre.push();
utils.setValue('SavedGenres', globals.SavedGenres.join(), false);
}
});
$scope.getPlaylists = function (refresh) {
if (globals.settings.Debug) { console.log("LOAD PLAYLISTS"); }
$.ajax({
url: globals.BaseURL() + '/getPlaylists.view?' + globals.BaseParams(),
method: 'GET',
dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout,
success: function (data) {
if (data["subsonic-response"].playlists.playlist !== undefined) {
var items = [];
if (data["subsonic-response"].playlists.playlist.length > 0) {
items = data["subsonic-response"].playlists.playlist;
} else {
items[0] = data["subsonic-response"].playlists.playlist;
}
angular.forEach(items, function (item, key) {
if (item.owner == globals.settings.Username) {
$scope.playlists.push(item);
} else if (item.public) {
$scope.playlistsPublic.push(item);
}
});
$scope.$apply();
}
$rootScope.song = [];
$scope.itemType = 'pl';
$scope.playlists = [];
$scope.playlistsPublic = [];
$scope.playlistsGenre = globals.SavedGenres;
$scope.selectedGenre = null;
$scope.$watch("selectedGenre", function(newValue, oldValue) {
if (newValue !== oldValue) {
globals.SavedGenres.push(newValue);
//$scope.playlistsGenre.push();
utils.setValue('SavedGenres', globals.SavedGenres.join(), false);
}
});
}
$scope.getPlaylist = function (id, action) {
$rootScope.selectedAutoPlaylist = null;
$rootScope.selectedPlaylist = id;
$.ajax({
url: globals.BaseURL() + '/getPlaylist.view?' + globals.BaseParams() + '&id=' + id,
method: 'GET',
dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout,
success: function (data) {
if (typeof data["subsonic-response"].playlist.entry != 'undefined') {
var items = [];
var playlist = data["subsonic-response"].playlist;
if (playlist.entry.length > 0) {
items = playlist.entry;
} else {
items[0] = playlist.entry;
}
if (action == 'add') {
angular.forEach(items, function (item, key) {
$rootScope.queue.push(utils.mapSong(item));
});
$scope.$apply();
$rootScope.showQueue();
notifications.updateMessage(items.length + ' Song(s) Added to Queue', true);
} else if (action == 'play') {
$rootScope.queue = [];
angular.forEach(items, function (item, key) {
$rootScope.queue.push(utils.mapSong(item));
});
var next = $rootScope.queue[0];
$scope.$apply(function () {
$rootScope.playSong(false, next);
});
$rootScope.showQueue();
notifications.updateMessage(items.length + ' Song(s) Added to Queue', true);
} else {
$scope.album = [];
$rootScope.song = [];
angular.forEach(items, function (item, key) {
$rootScope.song.push(utils.mapSong(item));
});
$scope.$apply();
}
} else {
$rootScope.song = [];
}
$scope.getPlaylists = function(refresh) {
if (globals.settings.Debug) {
console.log("LOAD PLAYLISTS");
}
});
}
$scope.getStarred = function (action, type) {
var size = globals.settings.AutoPlaylistSize;
$rootScope.selectedPlaylist = null;
$rootScope.selectedAutoPlaylist = 'starred';
$.ajax({
url: globals.BaseURL() + '/getStarred.view?' + globals.BaseParams() + '&size=' + size,
method: 'GET',
dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout,
success: function (data) {
if (typeof data["subsonic-response"].starred !== 'undefined') {
var items = [];
switch (type) {
case 'artist':
if (typeof data["subsonic-response"].starred.artist !== 'undefined') {
if (data["subsonic-response"].starred.artist.length > 0) {
items = data["subsonic-response"].starred.artist;
} else {
items[0] = data["subsonic-response"].starred.artist;
}
}
break;
case 'album':
if (typeof data["subsonic-response"].starred.album !== 'undefined') {
if (data["subsonic-response"].starred.album.length > 0) {
items = data["subsonic-response"].starred.album;
} else {
items[0] = data["subsonic-response"].starred.album;
}
}
break;
case 'song':
if (typeof data["subsonic-response"].starred.song !== 'undefined') {
if (data["subsonic-response"].starred.song.length > 0) {
items = data["subsonic-response"].starred.song;
} else {
items[0] = data["subsonic-response"].starred.song;
}
if (action == 'add') {
angular.forEach(items, function (item, key) {
$rootScope.queue.push(utils.mapSong(item));
});
$scope.$apply();
$rootScope.showQueue();
notifications.updateMessage(items.length + ' Song(s) Added to Queue', true);
} else if (action == 'play') {
$rootScope.queue = [];
angular.forEach(items, function (item, key) {
$rootScope.queue.push(utils.mapSong(item));
});
var next = $rootScope.queue[0];
$scope.$apply(function () {
$rootScope.playSong(false, next);
});
$rootScope.showQueue();
notifications.updateMessage(items.length + ' Song(s) Added to Queue', true);
} else {
$rootScope.song = [];
angular.forEach(items, function (item, key) {
$rootScope.song.push(utils.mapSong(item));
});
$scope.$apply();
}
}
break;
default:
break;
}
}
}
});
}
$scope.newPlaylist = function (data, event) {
var reply = prompt("Choose a name for your new playlist.", "");
if (reply != 'null' && reply != null && reply != '') {
$.ajax({
url: globals.BaseURL() + '/createPlaylist.view?' + globals.BaseParams() + '&name=' + reply,
url: globals.BaseURL() + '/getPlaylists.view?' + globals.BaseParams(),
method: 'GET',
dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout,
success: function (data) {
loadPlaylists(true);
success: function(data) {
if (data["subsonic-response"].playlists.playlist !== undefined) {
var items = [];
if (data["subsonic-response"].playlists.playlist.length > 0) {
items = data["subsonic-response"].playlists.playlist;
} else {
items[0] = data["subsonic-response"].playlists.playlist;
}
angular.forEach(items, function(item, key) {
if (item.owner == globals.settings.Username) {
$scope.playlists.push(item);
} else if (item.public) {
$scope.playlistsPublic.push(item);
}
});
$scope.$apply();
}
}
});
}
}
$scope.deletePlaylist = function () {
if ($rootScope.selectedPlaylist != null) {
var id = $rootScope.selectedPlaylist;
if (utils.confirmDelete('Are you sure you want to delete the selected playlist?')) {
};
$scope.getPlaylist = function(id, action) {
$rootScope.selectedAutoPlaylist = null;
$rootScope.selectedPlaylist = id;
$.ajax({
url: globals.BaseURL() + '/getPlaylist.view?' + globals.BaseParams() + '&id=' + id,
method: 'GET',
dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout,
success: function(data) {
if (typeof data["subsonic-response"].playlist.entry != 'undefined') {
var items = [];
var playlist = data["subsonic-response"].playlist;
if (playlist.entry.length > 0) {
items = playlist.entry;
} else {
items[0] = playlist.entry;
}
if (action == 'add') {
angular.forEach(items, function(item, key) {
$rootScope.queue.push(utils.mapSong(item));
});
$scope.$apply();
$rootScope.showQueue();
notifications.updateMessage(items.length + ' Song(s) Added to Queue', true);
} else if (action == 'play') {
$rootScope.queue = [];
angular.forEach(items, function(item, key) {
$rootScope.queue.push(utils.mapSong(item));
});
var next = $rootScope.queue[0];
$scope.$apply(function() {
$rootScope.playSong(false, next);
});
$rootScope.showQueue();
notifications.updateMessage(items.length + ' Song(s) Added to Queue', true);
} else {
$scope.album = [];
$rootScope.song = [];
angular.forEach(items, function(item, key) {
$rootScope.song.push(utils.mapSong(item));
});
$scope.$apply();
}
} else {
$rootScope.song = [];
}
}
});
};
$scope.getStarred = function(action, type) {
var size = globals.settings.AutoPlaylistSize;
$rootScope.selectedPlaylist = null;
$rootScope.selectedAutoPlaylist = 'starred';
$.ajax({
url: globals.BaseURL() + '/getStarred.view?' + globals.BaseParams() + '&size=' + size,
method: 'GET',
dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout,
success: function(data) {
if (typeof data["subsonic-response"].starred !== 'undefined') {
var items = [];
switch (type) {
case 'artist':
if (typeof data["subsonic-response"].starred.artist !== 'undefined') {
if (data["subsonic-response"].starred.artist.length > 0) {
items = data["subsonic-response"].starred.artist;
} else {
items[0] = data["subsonic-response"].starred.artist;
}
}
break;
case 'album':
if (typeof data["subsonic-response"].starred.album !== 'undefined') {
if (data["subsonic-response"].starred.album.length > 0) {
items = data["subsonic-response"].starred.album;
} else {
items[0] = data["subsonic-response"].starred.album;
}
}
break;
case 'song':
if (typeof data["subsonic-response"].starred.song !== 'undefined') {
if (data["subsonic-response"].starred.song.length > 0) {
items = data["subsonic-response"].starred.song;
} else {
items[0] = data["subsonic-response"].starred.song;
}
if (action == 'add') {
angular.forEach(items, function(item, key) {
$rootScope.queue.push(utils.mapSong(item));
});
$scope.$apply();
$rootScope.showQueue();
notifications.updateMessage(items.length + ' Song(s) Added to Queue', true);
} else if (action == 'play') {
$rootScope.queue = [];
angular.forEach(items, function(item, key) {
$rootScope.queue.push(utils.mapSong(item));
});
var next = $rootScope.queue[0];
$scope.$apply(function() {
$rootScope.playSong(false, next);
});
$rootScope.showQueue();
notifications.updateMessage(items.length + ' Song(s) Added to Queue', true);
} else {
$rootScope.song = [];
angular.forEach(items, function(item, key) {
$rootScope.song.push(utils.mapSong(item));
});
$scope.$apply();
}
}
break;
default:
break;
}
}
}
});
};
$scope.newPlaylist = function(data, event) {
var reply = prompt("Choose a name for your new playlist.", "");
if (reply !== 'null' && reply !== null && reply !== '') {
$.ajax({
url: globals.BaseURL() + '/deletePlaylist.view?' + globals.BaseParams() + '&id=' + id,
url: globals.BaseURL() + '/createPlaylist.view?' + globals.BaseParams() + '&name=' + reply,
method: 'GET',
dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout,
success: function (data) {
$scope.getPlaylists();
success: function(data) {
loadPlaylists(true);
}
});
}
}
}
$scope.savePlaylist = function () {
if ($rootScope.selectedPlaylist() != null) {
var id = $rootScope.selectedPlaylist().id();
var songs = [];
ko.utils.arrayForEach($rootScope.song(), function (item) {
songs.push(item.id);
});
if (songs.length > 0) {
$.ajax({
type: 'GET',
url: globals.BaseURL() + '/createPlaylist.view?' + globals.BaseParams(),
dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout,
data: { playlistId: id, songId: songs },
success: function () {
$scope.getPlaylist(id);
notifications.updateMessage('Playlist Updated!', true);
},
traditional: true // Fixes POST with an array in JQuery 1.4
});
}
}
}
$scope.removeSelectedSongs = function (data, event) {
ko.utils.arrayForEach($scope.selectedSongs(), function (item) {
$rootScope.song.remove(item);
});
}
/* End Playlists */
};
/* Launch on Startup */
$scope.getPlaylists();
//$scope.getMusicFolders();
$scope.getGenres();
/* End Startup */
});
$scope.deletePlaylist = function() {
if ($rootScope.selectedPlaylist !== null) {
var id = $rootScope.selectedPlaylist;
if (utils.confirmDelete('Are you sure you want to delete the selected playlist?')) {
$.ajax({
url: globals.BaseURL() + '/deletePlaylist.view?' + globals.BaseParams() + '&id=' + id,
method: 'GET',
dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout,
success: function(data) {
$scope.getPlaylists();
}
});
}
}
};
$scope.savePlaylist = function() {
if ($rootScope.selectedPlaylist() !== null) {
var id = $rootScope.selectedPlaylist().id();
var songs = [];
ko.utils.arrayForEach($rootScope.song(), function(item) {
songs.push(item.id);
});
if (songs.length > 0) {
$.ajax({
type: 'GET',
url: globals.BaseURL() + '/createPlaylist.view?' + globals.BaseParams(),
dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout,
data: {
playlistId: id,
songId: songs
},
success: function() {
$scope.getPlaylist(id);
notifications.updateMessage('Playlist Updated!', true);
},
traditional: true // Fixes POST with an array in JQuery 1.4
});
}
}
};
$scope.removeSelectedSongs = function(data, event) {
ko.utils.arrayForEach($scope.selectedSongs(), function(item) {
$rootScope.song.remove(item);
});
};
/* End Playlists */
/* Launch on Startup */
$scope.getPlaylists();
//$scope.getMusicFolders();
$scope.getGenres();
/* End Startup */
});

View file

@ -1,112 +1,142 @@
JamStash.controller('PodcastCtrl',
function PodcastCtrl($scope, $rootScope, $location, utils, globals, model, notifications) {
//$("#left-component").layout($scope.layoutTwoCol);
function PodcastCtrl($scope, $rootScope, $location, utils, globals, model, notifications) {
$rootScope.song = [];
$scope.podcasts = [];
$scope.selectedPodcast;
$scope.getPodcasts = function (refresh) {
if (globals.settings.Debug) { console.log("LOAD PODCASTS"); }
$.ajax({
url: globals.BaseURL() + '/getPodcasts.view?' + globals.BaseParams(),
method: 'GET',
dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout,
success: function (data) {
if (data["subsonic-response"].podcasts.channel !== undefined) {
var items = [];
if (data["subsonic-response"].podcasts.channel.length > 0) {
items = data["subsonic-response"].podcasts.channel;
} else {
items[0] = data["subsonic-response"].podcasts.channel;
}
$scope.podcasts = items;
$scope.$apply();
}
}
});
}
$scope.getPodcast = function (id, action) {
$scope.selectedPodcast = id;
var map = function (data) {
var song = data;
var url, track, rating, starred, contenttype, suffix, description;
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.description == 'undefined') { description = ''; } else { description = song.description; }
if (typeof song.track == 'undefined') { track = '&nbsp;'; } else { track = song.track; }
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, song.title, song.artist, song.artistId, song.album, song.albumId, coverartthumb, coverartfull, song.duration, song.userRating, starred, suffix, specs, url, 0, description);
}
$.ajax({
url: globals.BaseURL() + '/getPodcasts.view?' + globals.BaseParams(),
method: 'GET',
dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout,
success: function (data) {
if (data["subsonic-response"].podcasts.channel !== undefined) {
var podcasts = [];
if (data["subsonic-response"].podcasts.channel.length > 0) {
podcasts = data["subsonic-response"].podcasts.channel;
} else {
podcasts[0] = data["subsonic-response"].podcasts.channel;
}
var items = [];
$.each(podcasts, function (i, item) {
if (item.id == id) {
items = item.episode;
}
});
$rootScope.song = [];
$scope.podcasts = [];
$scope.selectedPodcast = null;
if (typeof items != 'undefined') {
if (action == 'add') {
angular.forEach(items, function (item, key) {
if (item.status != "skipped") {
$rootScope.queue.push(map(item));
}
});
$scope.$apply();
$rootScope.showQueue();
notifications.updateMessage(items.length + ' Song(s) Added to Queue', true);
} else if (action == 'play') {
$rootScope.queue = [];
angular.forEach(items, function (item, key) {
if (item.status != "skipped") {
$rootScope.queue.push(map(item));
}
});
var next = $rootScope.queue[0];
$scope.$apply(function () {
$rootScope.playSong(false, next);
});
$rootScope.showQueue();
notifications.updateMessage(items.length + ' Song(s) Added to Queue', true);
$scope.getPodcasts = function(refresh) {
if (globals.settings.Debug) {
console.log("LOAD PODCASTS");
}
$.ajax({
url: globals.BaseURL() + '/getPodcasts.view?' + globals.BaseParams(),
method: 'GET',
dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout,
success: function(data) {
if (data["subsonic-response"].podcasts.channel !== undefined) {
var items = [];
if (data["subsonic-response"].podcasts.channel.length > 0) {
items = data["subsonic-response"].podcasts.channel;
} else {
$scope.album = [];
$rootScope.song = [];
angular.forEach(items, function (item, key) {
if (item.status != "skipped") {
$rootScope.song.push(map(item));
}
});
$scope.$apply();
items[0] = data["subsonic-response"].podcasts.channel;
}
$scope.podcasts = items;
$scope.$apply();
}
}
});
};
$scope.getPodcast = function(id, action) {
$scope.selectedPodcast = id;
var map = function(data) {
var song = data;
var url, track, rating, starred, contenttype, suffix, description;
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.description == 'undefined') {
description = '';
} else {
description = song.description;
}
if (typeof song.track == 'undefined') {
track = '&nbsp;';
} else {
track = song.track;
}
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, song.title, song.artist, song.artistId, song.album, song.albumId, coverartthumb, coverartfull, song.duration, song.userRating, starred, suffix, specs, url, 0, description);
};
$.ajax({
url: globals.BaseURL() + '/getPodcasts.view?' + globals.BaseParams(),
method: 'GET',
dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout,
success: function(data) {
if (data["subsonic-response"].podcasts.channel !== undefined) {
var podcasts = [];
if (data["subsonic-response"].podcasts.channel.length > 0) {
podcasts = data["subsonic-response"].podcasts.channel;
} else {
podcasts[0] = data["subsonic-response"].podcasts.channel;
}
var items = [];
$.each(podcasts, function(i, item) {
if (item.id == id) {
items = item.episode;
}
});
if (typeof items != 'undefined') {
if (action == 'add') {
angular.forEach(items, function(item, key) {
if (item.status != "skipped") {
$rootScope.queue.push(map(item));
}
});
$scope.$apply();
$rootScope.showQueue();
notifications.updateMessage(items.length + ' Song(s) Added to Queue', true);
} else if (action == 'play') {
$rootScope.queue = [];
angular.forEach(items, function(item, key) {
if (item.status != "skipped") {
$rootScope.queue.push(map(item));
}
});
var next = $rootScope.queue[0];
$scope.$apply(function() {
$rootScope.playSong(false, next);
});
$rootScope.showQueue();
notifications.updateMessage(items.length + ' Song(s) Added to Queue', true);
} else {
$scope.album = [];
$rootScope.song = [];
angular.forEach(items, function(item, key) {
if (item.status != "skipped") {
$rootScope.song.push(map(item));
}
});
$scope.$apply();
}
}
}
}
}
});
}
});
};
/* Launch on Startup */
$scope.getPodcasts();
/* End Startup */
});
/* Launch on Startup */
$scope.getPodcasts();
/* End Startup */
});

View file

@ -1,8 +1,8 @@
JamStash.controller('QueueCtrl',
function QueueCtrl($scope, $rootScope, $routeParams, $location, utils, globals, json, notifications) {
$scope.settings = globals.settings;
//$scope.song = $rootScope.queue;
//angular.copy($rootScope.queue, $scope.song);
function QueueCtrl($scope, $rootScope, $routeParams, $location, utils, globals, json, notifications) {
$scope.settings = globals.settings;
//$scope.song = $rootScope.queue;
//angular.copy($rootScope.queue, $scope.song);
$scope.song = $rootScope.queue;
});
$scope.song = $rootScope.queue;
});

View file

@ -1,83 +1,107 @@
JamStash.controller('SettingsCtrl',
function SettingsCtrl($scope, $routeParams, $location, utils, globals, json, notifications) {
$scope.settings = globals.settings;
$scope.Timeouts = [
{ id: 10000, name: 10 },
{ id: 20000, name: 20 },
{ id: 30000, name: 30 },
{ id: 40000, name: 40 },
{ id: 50000, name: 50 },
{ id: 60000, name: 60 },
{ id: 90000, name: 90 },
{ id: 120000, name: 120 }
];
$scope.Protocols = ["json", "jsonp"];
$scope.Themes = ["Default", "Dark"];
$scope.SearchTypes = globals.SearchTypes;
$scope.Layouts = globals.Layouts;
function SettingsCtrl($scope, $routeParams, $location, utils, globals, json, notifications) {
$scope.settings = globals.settings;
$scope.$watch('settings.HideAZ', function () {
if (globals.settings.HideAZ) {
$('#AZIndex').hide();
} else {
$('#AZIndex').show();
}
});
$scope.reset = function () {
utils.setValue('Settings', null, true);
$scope.loadSettings();
}
$scope.save = function () {
if ($scope.settings.Password != '' && globals.settings.Password.substring(0, 4) != 'enc:') { $scope.settings.Password = 'enc:' + utils.HexEncode($scope.settings.Password); }
if (globals.settings.NotificationSong) {
notifications.requestPermissionIfRequired();
if (!notifications.hasNotificationPermission()) {
alert('HTML5 Notifications are not available for your current browser, Sorry :(');
$scope.Timeouts = [{
id: 10000,
name: 10
}, {
id: 20000,
name: 20
}, {
id: 30000,
name: 30
}, {
id: 40000,
name: 40
}, {
id: 50000,
name: 50
}, {
id: 60000,
name: 60
}, {
id: 90000,
name: 90
}, {
id: 120000,
name: 120
}];
$scope.Protocols = ["json", "jsonp"];
$scope.Themes = ["Default", "Dark"];
$scope.SearchTypes = globals.SearchTypes;
$scope.Layouts = globals.Layouts;
$scope.$watch('settings.HideAZ', function() {
if (globals.settings.HideAZ) {
$('#AZIndex').hide();
} else {
$('#AZIndex').show();
}
}
if (globals.settings.NotificationNowPlaying) {
notifications.requestPermissionIfRequired();
if (!notifications.hasNotificationPermission()) {
alert('HTML5 Notifications are not available for your current browser, Sorry :(');
}
}
if (globals.settings.SaveTrackPosition) {
//saveTrackPosition();
} else {
//deleteCurrentPlaylist();
}
if (globals.settings.Theme) {
utils.switchTheme(globals.settings.Theme);
}
utils.setValue('Settings', $scope.settings, true);
notifications.updateMessage('Settings Updated!', true);
$scope.loadSettings();
if (globals.settings.Server != '' && globals.settings.Username != '' && globals.settings.Password != '') {
$scope.ping();
}
};
json.getChangeLog(function (data) {
$scope.changeLog = data.slice(0, 10);
});
$scope.changeLogShowMore = function () {
json.getChangeLog(function (data) {
$scope.changeLog = data;
});
}
$scope.setupDemo = function () {
var Username = "android-guest";
var Password = "guest";
var Server = "http://subsonic.org/demo";
var Tab = "tabLibrary";
if (utils.confirmDelete("Do you want to connect to the Subsonic Demo server?")) {
globals.settings.Username = Username;
globals.settings.Password = Password;
globals.settings.Server = Server;
//$scope.save();
$location.url('/library');
}
}
/* Load on Startup */
/* End Startup */
});
$scope.reset = function() {
utils.setValue('Settings', null, true);
$scope.loadSettings();
};
$scope.save = function() {
if ($scope.settings.Password !== '' && globals.settings.Password.substring(0, 4) != 'enc:') {
$scope.settings.Password = 'enc:' + utils.HexEncode($scope.settings.Password);
}
if (globals.settings.NotificationSong) {
notifications.requestPermissionIfRequired();
if (!notifications.hasNotificationPermission()) {
alert('HTML5 Notifications are not available for your current browser, Sorry :(');
}
}
if (globals.settings.NotificationNowPlaying) {
notifications.requestPermissionIfRequired();
if (!notifications.hasNotificationPermission()) {
alert('HTML5 Notifications are not available for your current browser, Sorry :(');
}
}
if (globals.settings.SaveTrackPosition) {
//saveTrackPosition();
} else {
//deleteCurrentPlaylist();
}
if (globals.settings.Theme) {
utils.switchTheme(globals.settings.Theme);
}
utils.setValue('Settings', $scope.settings, true);
notifications.updateMessage('Settings Updated!', true);
$scope.loadSettings();
if (globals.settings.Server !== '' && globals.settings.Username !== '' && globals.settings.Password !== '') {
$scope.ping();
}
};
json.getChangeLog(function(data) {
$scope.changeLog = data.slice(0, 10);
});
$scope.changeLogShowMore = function() {
json.getChangeLog(function(data) {
$scope.changeLog = data;
});
};
$scope.setupDemo = function() {
var Username = "android-guest";
var Password = "guest";
var Server = "http://subsonic.org/demo";
var Tab = "tabLibrary";
if (utils.confirmDelete("Do you want to connect to the Subsonic Demo server?")) {
globals.settings.Username = Username;
globals.settings.Password = Password;
globals.settings.Server = Server;
//$scope.save();
$location.url('/library');
}
};
/* Load on Startup */
/* End Startup */
});