mirror of
https://github.com/IrosTheBeggar/mStream.git
synced 2025-10-27 07:31:02 +00:00
Code re-organization
This commit is contained in:
parent
0c8aabde17
commit
6a11fe0e5a
@ -4,8 +4,6 @@
|
||||
var MSTREAMAPI = (function () {
|
||||
let mstreamModule = {};
|
||||
|
||||
|
||||
|
||||
mstreamModule.listOfServers = [];
|
||||
mstreamModule.currentServer = {
|
||||
host:"",
|
||||
@ -14,8 +12,14 @@ var MSTREAMAPI = (function () {
|
||||
vPath: ""
|
||||
}
|
||||
|
||||
$.ajaxPrefilter(function( options ) {
|
||||
options.beforeSend = function (xhr) {
|
||||
xhr.setRequestHeader('x-access-token', MSTREAMAPI.currentServer.token);
|
||||
}
|
||||
});
|
||||
|
||||
// TODO: Special functions for handling multipel servers
|
||||
|
||||
// TODO: Special functions for handling multiple servers
|
||||
// Add Server
|
||||
// Delete Server
|
||||
// Select Server
|
||||
@ -25,7 +29,6 @@ var MSTREAMAPI = (function () {
|
||||
|
||||
|
||||
|
||||
|
||||
function makeRequest(url, type, dataObject, callback){
|
||||
var request = $.ajax({
|
||||
url: url,
|
||||
@ -36,12 +39,12 @@ var MSTREAMAPI = (function () {
|
||||
});
|
||||
|
||||
request.done(function( response ) {
|
||||
callback(response);
|
||||
callback(response, false);
|
||||
});
|
||||
|
||||
// TODO: AHandle errors
|
||||
request.fail(function( jqXHR, textStatus ) {
|
||||
callback(false);
|
||||
callback(textStatus, jqXHR);
|
||||
});
|
||||
}
|
||||
|
||||
@ -111,7 +114,16 @@ var MSTREAMAPI = (function () {
|
||||
|
||||
// LOGIN
|
||||
mstreamModule.login = function(username, password, callback){
|
||||
makePOSTRequest("/login", { time: shareTimeInDays, playlist: playlist}, callback);
|
||||
makePOSTRequest("/login", { username: username, password: password}, callback);
|
||||
}
|
||||
mstreamModule.updateCurrentServer = function(username, token, vPath){
|
||||
currentServer.user = username;
|
||||
currentServer.token = token;
|
||||
currentServer.vPath = vPath;
|
||||
}
|
||||
|
||||
mstreamModule.ping = function(callback){
|
||||
makeGETRequest("/ping", false, callback);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -1,302 +1,125 @@
|
||||
$(document).ready(function(){
|
||||
|
||||
function setupJukeboxPanel(){
|
||||
// Hide the directory bar
|
||||
$('.directoryTitle').hide();
|
||||
// Change the panel name
|
||||
$('.panel_one_name').html('Jukebox Mode');
|
||||
// clear the list
|
||||
$('#filelist').empty();
|
||||
$('#filelist').removeClass('scrollBoxHeight1');
|
||||
$('#filelist').removeClass('scrollBoxHeight2');
|
||||
$('#filelist').addClass('scrollBoxHeight2');
|
||||
|
||||
// TODO: Check if connection has been established
|
||||
// setup correct html
|
||||
var newHtml = '';
|
||||
if(JUKEBOX.stats.live !== false && JUKEBOX.connection !== false){
|
||||
newHtml = createJukeboxPanel();
|
||||
|
||||
}else{
|
||||
newHtml = '\
|
||||
<p class="jukebox-panel">\
|
||||
<br><br>\
|
||||
<h3>Jukebox Mode allows you to control this page remotely<h3> <br><br>\
|
||||
<div class="jukebox_connect button"> CONNECT IT!</div>\
|
||||
</p>\
|
||||
<img src="public/img/loading.gif" class="hide jukebox-loading">';
|
||||
}
|
||||
|
||||
// Add the content
|
||||
$('#filelist').html(newHtml);
|
||||
}
|
||||
|
||||
// The jukebox panel
|
||||
$('#jukebox_mode').on('click', function(){
|
||||
setupJukeboxPanel();
|
||||
});
|
||||
|
||||
|
||||
// Setup Jukebox
|
||||
$('body').on('click', '.jukebox_connect', function(){
|
||||
$(this).prop("disabled", true);
|
||||
$(this).hide();
|
||||
$('.jukebox-loading').toggleClass('hide');
|
||||
|
||||
JUKEBOX.createWebsocket( MSTREAMAPI.currentServer.token, function(){
|
||||
// Wait a while and display the status
|
||||
setTimeout(function(){
|
||||
// TODO: Check that status has changed
|
||||
|
||||
setupJukeboxPanel();
|
||||
},1800);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
function createJukeboxPanel(){
|
||||
var returnHtml = '<p class="jukebox-panel">';
|
||||
|
||||
if(JUKEBOX.stats.error !== false){
|
||||
// TODO: WARN THE USER
|
||||
returnHtml = '';
|
||||
return returnHtml;
|
||||
}
|
||||
|
||||
if(JUKEBOX.stats.adminCode){
|
||||
returnHtml += '<h1>Code: ' + JUKEBOX.stats.adminCode + '</h1>';
|
||||
}
|
||||
|
||||
if(JUKEBOX.stats.guestCode){
|
||||
returnHtml += '<h2>Guest Code: ' + JUKEBOX.stats.guestCode + '</h2>';
|
||||
}
|
||||
|
||||
var adrs = window.location.protocol + '//' + window.location.host + '/remote';
|
||||
returnHtml += '<br><h4>Remote Jukebox Controls: <a target="_blank" href="' + adrs + '"> ' + adrs + '</a><h4>';
|
||||
|
||||
returnHtml += '</p>';
|
||||
return returnHtml;
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////// Global Variables
|
||||
// These vars track your position within the file explorer
|
||||
var fileExplorerArray = [];
|
||||
var fileExplorerScrollPosition = [];
|
||||
// Stores an array of searchable ojects
|
||||
var currentBrowsingList = [];
|
||||
|
||||
////////////////////////////// Login Form
|
||||
// Handle login form
|
||||
$('#login-form').on('submit', function(e){
|
||||
e.preventDefault();
|
||||
$("#login-submit").attr("disabled","disabled");
|
||||
|
||||
// MSTREAMAPI.login( $('#login-username').val(), $('#login-password').val(), function(response){
|
||||
// });
|
||||
MSTREAMAPI.login($('#login-username').val(), $('#login-password').val(), function(response, error){
|
||||
if(error !== false){
|
||||
// Alert the user
|
||||
$("#login-submit").attr("disabled",false);
|
||||
$('#login-alert').removeClass('super-hide');
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
var request = $.ajax({
|
||||
url: "login",
|
||||
type: "POST",
|
||||
contentType: "application/json",
|
||||
dataType: "json",
|
||||
data: JSON.stringify(
|
||||
{
|
||||
username: $('#login-username').val(),
|
||||
password: $('#login-password').val()
|
||||
}
|
||||
)
|
||||
});
|
||||
|
||||
request.done(function( msg ) {
|
||||
$('#login-alert').toggleClass('alert');
|
||||
$('#login-alert').toggleClass('alert');
|
||||
$('#login-alert').toggleClass('success');
|
||||
$('#login-alert').text('Welcome To mStream!');
|
||||
|
||||
// Get the key
|
||||
var parsedResponse = msg;
|
||||
var token = parsedResponse.token;
|
||||
|
||||
// Add the token to the cookies
|
||||
Cookies.set('token', token);
|
||||
Cookies.set('token', response.token);
|
||||
|
||||
// Add the token the URL calls
|
||||
updateCurrentServer($('#login-username').val(), response.token, response.vPath)
|
||||
|
||||
// Add the token the URL calls
|
||||
MSTREAMAPI.currentServer.token = token;
|
||||
MSTREAMAPI.currentServer.vPath = parsedResponse.vPath;
|
||||
loadFileExplorer();
|
||||
|
||||
// Remove the overlay
|
||||
$('.login-overlay').fadeOut( "slow" );
|
||||
$("#login-submit").attr("disabled",false);
|
||||
});
|
||||
|
||||
request.fail(function( jqXHR, textStatus ) {
|
||||
// Alert the user
|
||||
$("#login-submit").attr("disabled",false);
|
||||
$('#login-alert').removeClass('super-hide');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
$.ajaxPrefilter(function( options ) {
|
||||
options.beforeSend = function (xhr) {
|
||||
xhr.setRequestHeader('x-access-token', MSTREAMAPI.currentServer.token);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
// Determine if the user needs to log in
|
||||
function testIt(){
|
||||
var token = Cookies.get('token');
|
||||
|
||||
if(token){
|
||||
MSTREAMAPI.currentServer.token = token;
|
||||
}
|
||||
|
||||
|
||||
var request = $.ajax({
|
||||
url: "ping",
|
||||
type: "GET"
|
||||
});
|
||||
|
||||
request.done(function( msg ) {
|
||||
// Remove login screen
|
||||
// set vPath
|
||||
var decoded = msg;
|
||||
MSTREAMAPI.currentServer.vPath = decoded.vPath;
|
||||
});
|
||||
|
||||
request.fail(function( jqXHR, textStatus ) {
|
||||
// alert( "Request failed: " + textStatus );
|
||||
$('.login-overlay').fadeIn( "slow" );
|
||||
|
||||
});
|
||||
|
||||
MSTREAMAPI.ping( function(response, error){
|
||||
if(error !== false){
|
||||
$('.login-overlay').fadeIn( "slow" );
|
||||
return;
|
||||
}
|
||||
// set vPath
|
||||
MSTREAMAPI.currentServer.vPath = response.vPath;
|
||||
// Setup the filebrowser
|
||||
loadFileExplorer();
|
||||
});
|
||||
}
|
||||
|
||||
testIt();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////// Initialization code
|
||||
|
||||
// Supported file types
|
||||
var filetypes = '["mp3","ogg","wav","m4a","flac"]';
|
||||
|
||||
// These vars track your position within the file explorer
|
||||
var fileExplorerArray = [];
|
||||
var fileExplorerScrollPosition = [];
|
||||
|
||||
// Setup the filebrowser
|
||||
loadFileExplorer();
|
||||
|
||||
// TODO: This will store an array of searchable ojects
|
||||
var currentBrowsingList = [];
|
||||
|
||||
///////////////////////////// The Now Playing Column
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// clear the playlist
|
||||
$("#clear").click(function() {
|
||||
MSTREAM.clearPlaylist();
|
||||
});
|
||||
|
||||
|
||||
// when you click an mp3, add it to the now playling playlist
|
||||
//////////////////////////////// Administrative stuff
|
||||
// when you click an mp3, add it to the now playling playlist
|
||||
$("#filelist").on('click', 'div.filez', function() {
|
||||
MSTREAM.addSongWizard($(this).data("file_location"));
|
||||
});
|
||||
|
||||
// Handle panel stuff
|
||||
function resetPanel(panelName, className){
|
||||
$('#filelist').empty();
|
||||
$('.directoryTitle').hide();
|
||||
$('#filelist').removeClass('scrollBoxHeight1');
|
||||
$('#filelist').removeClass('scrollBoxHeight2');
|
||||
|
||||
$('#filelist').addClass(className);
|
||||
$('.panel_one_name').html(panelName);
|
||||
}
|
||||
|
||||
function boilerplateFailure(response, error){
|
||||
$('#filelist').empty();
|
||||
$('#filelist').html('<p>Call Failed</p>');
|
||||
}
|
||||
|
||||
// Adds file to the now playing playlist
|
||||
// There is no longer addfile1
|
||||
// function addFile2(file_location){
|
||||
// var raw_location = file_location;
|
||||
//
|
||||
// if(MSTREAMAPI.currentServer.vPath){
|
||||
// file_location = MSTREAMAPI.currentServer.vPath + '/' + file_location;
|
||||
// }
|
||||
//
|
||||
// if( MSTREAMAPI.currentServer.token){
|
||||
// file_location = file_location + '?token=' + MSTREAMAPI.currentServer.token;
|
||||
// }
|
||||
//
|
||||
// MSTREAM.addSong({
|
||||
// url: file_location,
|
||||
// filepath: raw_location
|
||||
// });
|
||||
// }
|
||||
|
||||
|
||||
// when you click 'add directory', add entire directory to the playlist
|
||||
$("#addall").on('click', function() {
|
||||
//make an array of all the mp3 files in the curent directory
|
||||
var elems = document.getElementsByClassName('filez');
|
||||
var arr = jQuery.makeArray(elems);
|
||||
|
||||
//loop through array and add each file to the playlist
|
||||
$.each( arr, function() {
|
||||
MSTREAM.addSongWizard($(this).data("file_location"));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
// Remove item from Now Playling playlist
|
||||
$('body').on('click', 'a.closeit', function(e){
|
||||
$(this).parent().remove();
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////// File Explorer
|
||||
// clear the playlist
|
||||
$("#clear").on('click', function() {
|
||||
MSTREAM.clearPlaylist();
|
||||
});
|
||||
|
||||
/////////////////////////////////////// File Explorer
|
||||
function loadFileExplorer(){
|
||||
|
||||
$('.directoryTitle').hide();
|
||||
$('#directory_bar').show();
|
||||
|
||||
$('.panel_one_name').html('File Explorer');
|
||||
resetPanel('File Explorer', 'scrollBoxHeight1');
|
||||
$('#directory_bar').show();
|
||||
|
||||
// Reset file explorer vars
|
||||
fileExplorerArray = [];
|
||||
fileExplorerScrollPosition = [];
|
||||
|
||||
$('#filelist').removeClass('scrollBoxHeight1');
|
||||
$('#filelist').removeClass('scrollBoxHeight2');
|
||||
$('#filelist').addClass('scrollBoxHeight1');
|
||||
|
||||
//send this directory to be parsed and displayed
|
||||
senddir(0);
|
||||
|
||||
}
|
||||
|
||||
// Load up the file explorer
|
||||
// Load up the file explorer
|
||||
$('.get_file_explorer').on('click', loadFileExplorer);
|
||||
|
||||
// when you click on a directory, go to that directory
|
||||
// when you click on a directory, go to that directory
|
||||
$("#filelist").on('click', 'div.dirz', function() {
|
||||
//get the id of that class
|
||||
var nextDir = $(this).attr("id");
|
||||
fileExplorerArray.push(nextDir);
|
||||
|
||||
// Save the scroll position
|
||||
var scrollPosition = $('.testScroll').scrollTop();
|
||||
var scrollPosition = $('#filelist').scrollTop();
|
||||
fileExplorerScrollPosition.push(scrollPosition);
|
||||
|
||||
//pass this value along
|
||||
// pass this value along
|
||||
senddir(0);
|
||||
});
|
||||
|
||||
// when you click the back directory
|
||||
// when you click the back directory
|
||||
$(".backButton").on('click', function() {
|
||||
if(fileExplorerArray.length != 0){
|
||||
// remove the last item in the array
|
||||
@ -308,10 +131,7 @@ $(document).ready(function(){
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
// send a new directory to be parsed.
|
||||
// send a new directory to be parsed.
|
||||
function senddir(scrollPosition){
|
||||
// Construct the directory string
|
||||
var directoryString = "";
|
||||
@ -319,28 +139,25 @@ $(document).ready(function(){
|
||||
directoryString += fileExplorerArray[i] + "/";
|
||||
}
|
||||
|
||||
MSTREAMAPI.dirparser(directoryString, false, function(response){
|
||||
// TODO: Check for failure
|
||||
|
||||
MSTREAMAPI.dirparser(directoryString, false, function(response, error){
|
||||
if(error !== false){
|
||||
boilerplateFailure(response, error);
|
||||
}
|
||||
// Set any directory views
|
||||
$('.directoryName').html('/' + directoryString);
|
||||
// hand this data off to be printed on the page
|
||||
printdir(response);
|
||||
// Set scroll postion
|
||||
$('.testScroll').scrollTop(scrollPosition);
|
||||
$('#filelist').scrollTop(scrollPosition);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
// function that will recieve JSON array of a directory listing. It will then make a list of the directory and tack on classes for functionality
|
||||
// function that will recieve JSON array of a directory listing. It will then make a list of the directory and tack on classes for functionality
|
||||
function printdir(response){
|
||||
currentBrowsingList = [];
|
||||
|
||||
var path = response.path;
|
||||
currentBrowsingList = response.contents;
|
||||
|
||||
//clear the list
|
||||
// clear the list
|
||||
$('#filelist').empty();
|
||||
$('#search_folders').val('');
|
||||
|
||||
@ -354,9 +171,9 @@ $(document).ready(function(){
|
||||
filelist.push('<div id="'+this.name+'" class="dirz">'+this.name+'</div>');
|
||||
}else{
|
||||
if(this.artist!=null || this.title!=null){
|
||||
filelist.push('<div data-filetype="'+this.type+'" data-file_location="'+path+this.name+'" class="filez"><span class="pre-char">♬</span> <span class="title">'+this.artist+' - '+this.title+'</span></div>');
|
||||
filelist.push('<div data-filetype="'+this.type+'" data-file_location="'+response.path+this.name+'" class="filez"><span class="pre-char">♬</span> <span class="title">'+this.artist+' - '+this.title+'</span></div>');
|
||||
}else{
|
||||
filelist.push('<div data-filetype="'+this.type+'" data-file_location="'+path+this.name+'" class="filez"><span class="pre-char">♫</span> <span class="title">'+this.name+'</span></div>');
|
||||
filelist.push('<div data-filetype="'+this.type+'" data-file_location="'+response.path+this.name+'" class="filez"><span class="pre-char">♫</span> <span class="title">'+this.name+'</span></div>');
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -365,73 +182,64 @@ $(document).ready(function(){
|
||||
$('#filelist').html(filelist);
|
||||
}
|
||||
|
||||
// when you click 'add directory', add entire directory to the playlist
|
||||
$("#addall").on('click', function() {
|
||||
//make an array of all the mp3 files in the curent directory
|
||||
var elems = document.getElementsByClassName('filez');
|
||||
var arr = jQuery.makeArray(elems);
|
||||
|
||||
// Search Files
|
||||
$('#search_folders').on('keyup', function(){
|
||||
var searchVal = $(this).val();
|
||||
|
||||
var path = ""; // Construct the directory string
|
||||
for (var i = 0; i < fileExplorerArray.length; i++) {
|
||||
path += fileExplorerArray[i] + "/";
|
||||
}
|
||||
|
||||
var filelist = [];
|
||||
//loop through array and add each file to the playlist
|
||||
$.each( arr, function() {
|
||||
MSTREAM.addSongWizard($(this).data("file_location"));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
if($(this).val().length>1){
|
||||
// Search Files
|
||||
$('#search_folders').on('keyup', function(){
|
||||
if($(this).val().length>1){
|
||||
var searchVal = $(this).val();
|
||||
|
||||
$.each(currentBrowsingList, function() {
|
||||
var lowerCase = this.name.toLowerCase();
|
||||
var path = ""; // Construct the directory string
|
||||
for (var i = 0; i < fileExplorerArray.length; i++) {
|
||||
path += fileExplorerArray[i] + "/";
|
||||
}
|
||||
|
||||
if (lowerCase.indexOf( searchVal.toLowerCase() ) !== -1) {
|
||||
if(this.type=='directory'){
|
||||
filelist.push('<div id="'+this.name+'" class="dirz">'+this.name+'</div>');
|
||||
}else{
|
||||
if(this.artist!=null || this.title!=null){
|
||||
filelist.push('<div data-filetype="'+this.type+'" data-file_location="'+path+this.name+'" class="filez"><span class="pre-char">♬</span> <span class="title">'+this.artist+' - '+this.title+'</span></div>');
|
||||
}else{
|
||||
filelist.push('<div data-filetype="'+this.type+'" data-file_location="'+path+this.name+'" class="filez"><span class="pre-char">♫</span> <span class="title">'+this.name+'</span></div>');
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
var filelist = [];
|
||||
$.each(currentBrowsingList, function() {
|
||||
var lowerCase = this.name.toLowerCase();
|
||||
|
||||
}else{
|
||||
if (lowerCase.indexOf( searchVal.toLowerCase() ) !== -1) {
|
||||
if(this.type=='directory'){
|
||||
filelist.push('<div id="'+this.name+'" class="dirz">'+this.name+'</div>');
|
||||
}else{
|
||||
if(this.artist!=null || this.title!=null){
|
||||
filelist.push('<div data-filetype="'+this.type+'" data-file_location="'+path+this.name+'" class="filez"><span class="pre-char">♬</span> <span class="title">'+this.artist+' - '+this.title+'</span></div>');
|
||||
}else{
|
||||
filelist.push('<div data-filetype="'+this.type+'" data-file_location="'+path+this.name+'" class="filez"><span class="pre-char">♫</span> <span class="title">'+this.name+'</span></div>');
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$.each(currentBrowsingList, function() {
|
||||
if(this.type=='directory'){
|
||||
filelist.push('<div id="'+this.name+'" class="dirz">'+this.name+'</div>');
|
||||
}else{
|
||||
if(this.artist!=null || this.title!=null){
|
||||
filelist.push('<div data-filetype="'+this.type+'" data-file_location="'+path+this.name+'" class="filez"><span class="pre-char">♬</span> <span class="title">'+this.artist+' - '+this.title+'</span></div>');
|
||||
}else{
|
||||
filelist.push('<div data-filetype="'+this.type+'" data-file_location="'+path+this.name+'" class="filez"><span class="pre-char">♫</span> <span class="title">'+this.name+'</span></div>');
|
||||
}
|
||||
}
|
||||
});
|
||||
// Post the html to the filelist div
|
||||
$('#filelist').html(filelist);
|
||||
});
|
||||
|
||||
}
|
||||
$('#search-explorer').on('click', function(){
|
||||
// Hide Filepath
|
||||
$('#search_folders').toggleClass( 'hide' );
|
||||
// Show Search Input
|
||||
$('.directoryName').toggleClass( 'hide' );
|
||||
|
||||
// Post the html to the filelist div
|
||||
$('#filelist').html(filelist);
|
||||
});
|
||||
if(!$('#search_folders').hasClass('hide')){
|
||||
$( "#search_folders" ).focus();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
$('#search-explorer').on('click', function(){
|
||||
// Hide Filepath
|
||||
$('#search_folders').toggleClass( 'hide' );
|
||||
// Show Search Input
|
||||
$('.directoryName').toggleClass( 'hide' );
|
||||
|
||||
if(!$('#search_folders').hasClass('hide')){
|
||||
$( "#search_folders" ).focus();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
////////////////////////////////////// Share playlists
|
||||
|
||||
// Save a new playlist
|
||||
////////////////////////////////////// Share playlists
|
||||
$('#share_playlist_form').on('submit', function(e){
|
||||
e.preventDefault();
|
||||
|
||||
@ -457,18 +265,19 @@ $('#search-explorer').on('click', function(){
|
||||
return;
|
||||
}
|
||||
|
||||
MSTREAMAPI.makeShared(stuff, shareTimeInDays, function(response){
|
||||
MSTREAMAPI.makeShared(stuff, shareTimeInDays, function(response, error){
|
||||
if(error !== false){
|
||||
return boilerplateFailure(response, error);
|
||||
}
|
||||
$('#share_it').prop("disabled",false);
|
||||
var l = window.location;
|
||||
var adrs = l.protocol + '//' + l.host + '/shared/playlist/' + response.id;
|
||||
var adrs = window.location.protocol + '//' + window.location.host + '/shared/playlist/' + response.id;
|
||||
$('.share-textarea').val(adrs);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
////////////////////////////////////// Save/Load playlists
|
||||
|
||||
// Save a new playlist
|
||||
////////////////////////////////////// Save/Load playlists
|
||||
// Save a new playlist
|
||||
$('#save_playlist_form').on('submit', function(e){
|
||||
e.preventDefault();
|
||||
|
||||
@ -479,6 +288,7 @@ $('#search-explorer').on('click', function(){
|
||||
}
|
||||
|
||||
if(MSTREAM.playlist.length == 0){
|
||||
// TODO: Alert user nothing was saved
|
||||
return;
|
||||
}
|
||||
|
||||
@ -488,39 +298,29 @@ $('#search-explorer').on('click', function(){
|
||||
//loop through array and add each file to the playlist
|
||||
var songs = [];
|
||||
for (let i = 0; i < MSTREAM.playlist.length; i++) {
|
||||
//Do something
|
||||
songs.push(MSTREAM.playlist[i].filepath);
|
||||
}
|
||||
|
||||
MSTREAMAPI.savePlaylist(title, songs, function(response){
|
||||
// TODO: Check for failure
|
||||
MSTREAMAPI.savePlaylist(title, songs, function(response, error){
|
||||
if(error !== false){
|
||||
return boilerplateFailure(response, error);
|
||||
}
|
||||
$('#save_playlist').prop("disabled",false);
|
||||
$('#close_save_playlist').trigger("click");
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
// Get all playlists
|
||||
// Get all playlists
|
||||
$('.get_all_playlists').on('click', function(){
|
||||
// Hide the directory bar
|
||||
$('.directoryTitle').hide();
|
||||
// Change the panel name
|
||||
$('.panel_one_name').html('Playlists');
|
||||
//clear the list
|
||||
$('#filelist').empty();
|
||||
resetPanel('Playlists', 'scrollBoxHeight2');
|
||||
|
||||
$('#filelist').removeClass('scrollBoxHeight1');
|
||||
$('#filelist').removeClass('scrollBoxHeight2');
|
||||
$('#filelist').addClass('scrollBoxHeight2');
|
||||
|
||||
fileExplorerScrollPosition = [];
|
||||
|
||||
MSTREAMAPI.getAllPlaylists( function(response){
|
||||
//parse through the json array and make an array of corresponding divs
|
||||
MSTREAMAPI.getAllPlaylists( function(response, error){
|
||||
if(error !== false){
|
||||
return boilerplateFailure(response, error);
|
||||
}
|
||||
// loop through the json array and make an array of corresponding divs
|
||||
var playlists = [];
|
||||
$.each(response, function() {
|
||||
// TODO: Append delete button
|
||||
playlists.push('<div data-playlistname="'+this.name+'" class="playlist_row_container"><span data-playlistname="'+this.name+'" class="playlistz force-width">'+this.name+'</span><span data-playlistname="'+this.name+'" class="deletePlaylist">x</span></div>');
|
||||
});
|
||||
|
||||
@ -529,64 +329,59 @@ $('#search-explorer').on('click', function(){
|
||||
});
|
||||
});
|
||||
|
||||
// delete playlist
|
||||
$("#filelist").on('click', '.deletePlaylist', function(){
|
||||
// Get Playlist ID
|
||||
var playlistname = $(this).data('playlistname');
|
||||
var that = this;
|
||||
|
||||
$("#filelist").on('click', '.deletePlaylist', function(){
|
||||
// Get Playlist ID
|
||||
var playlistname = $(this).data('playlistname');
|
||||
var that = this;
|
||||
|
||||
MSTREAMAPI.deletePlaylist(playlistname, function(response){
|
||||
$(that).parent().remove();
|
||||
MSTREAMAPI.deletePlaylist(playlistname, function(response, error){
|
||||
if(error !== false){
|
||||
return boilerplateFailure(response, error);
|
||||
}
|
||||
$(that).parent().remove();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// load up a playlist
|
||||
$("#filelist").on('click', '.playlistz', function() {
|
||||
var playlistname = $(this).data('playlistname');
|
||||
var name = $(this).html();
|
||||
|
||||
// load up a playlist
|
||||
$("#filelist").on('click', '.playlistz', function() {
|
||||
var playlistname = $(this).data('playlistname');
|
||||
var name = $(this).html();
|
||||
MSTREAMAPI.loadPlaylist(playlistname, function(response, error){
|
||||
if(error !== false){
|
||||
return boilerplateFailure(response, error);
|
||||
}
|
||||
// Add the playlist name to the modal
|
||||
$('#playlist_name').val(name);
|
||||
|
||||
MSTREAMAPI.loadPlaylist(playlistname, function(response){
|
||||
console.log(response);
|
||||
// Add the playlist name to the modal
|
||||
$('#playlist_name').val(name);
|
||||
// Clear the playlist
|
||||
MSTREAM.clearPlaylist();
|
||||
|
||||
// Clear the playlist
|
||||
MSTREAM.clearPlaylist();
|
||||
|
||||
// Append the playlist items to the playlist
|
||||
$.each( response, function(i ,item) {
|
||||
MSTREAM.addSongWizard(item.filepath);
|
||||
});
|
||||
// Append the playlist items to the playlist
|
||||
$.each( response, function(i ,item) {
|
||||
MSTREAM.addSongWizard(item.filepath);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
/////////////////////////////////////////
|
||||
/////////////// DOWNLOADS ///////////////
|
||||
/////////////////////////////////////////
|
||||
|
||||
|
||||
// Download a playlist
|
||||
/////////////// Download Playlist
|
||||
$('#downloadPlaylist').click(function(){
|
||||
//loop through array and add each file to the playlist
|
||||
// Loop through array and add each file to the playlist
|
||||
var downloadFiles = [];
|
||||
for (let i = 0; i < MSTREAM.playlist.length; i++) {
|
||||
downloadFiles.push(MSTREAM.playlist[i].filepath);
|
||||
}
|
||||
|
||||
var downloadJOSN = JSON.stringify(downloadFiles);
|
||||
|
||||
// Use key is necessary
|
||||
// Use key if necessary
|
||||
if( MSTREAMAPI.currentServer.token){
|
||||
$("#downform").attr("action", "download?token=" + MSTREAMAPI.currentServer.token);
|
||||
}
|
||||
|
||||
|
||||
$('<input>').attr({
|
||||
type: 'hidden',
|
||||
name: 'fileArray',
|
||||
value: downloadJOSN,
|
||||
value: JSON.stringify(downloadFiles),
|
||||
}).appendTo('#downform');
|
||||
|
||||
//submit form
|
||||
@ -595,61 +390,53 @@ $("#filelist").on('click', '.playlistz', function() {
|
||||
$('#downform').empty();
|
||||
});
|
||||
|
||||
|
||||
|
||||
///////////////////////////// Database Management
|
||||
|
||||
// The Manage DB panel
|
||||
///////////////////////////// Database Management
|
||||
// The Manage DB panel
|
||||
$('#manage_database').on('click', function(){
|
||||
// Hide the directory bar
|
||||
$('.directoryTitle').hide();
|
||||
// Change the panel name
|
||||
$('.panel_one_name').html('Database Management');
|
||||
//clear the list
|
||||
$('#filelist').empty();
|
||||
resetPanel('Database Management', 'scrollBoxHeight2');
|
||||
|
||||
$('#filelist').removeClass('scrollBoxHeight1');
|
||||
$('#filelist').removeClass('scrollBoxHeight2');
|
||||
$('#filelist').addClass('scrollBoxHeight2');
|
||||
|
||||
MSTREAMAPI.dbStatus( function(response){
|
||||
// If there is an error
|
||||
MSTREAMAPI.dbStatus( function(response, error){
|
||||
if(error !== false){
|
||||
return boilerplateFailure(response, error);
|
||||
}
|
||||
// If there is an error
|
||||
if(response.error){
|
||||
$('#filelist').html('<p>The database returned the following error:</p><p>' + response.error + '</p>');
|
||||
return;
|
||||
}
|
||||
|
||||
// Add Beets Msg
|
||||
if(response.dbType == 'beets' || response.dbType == 'beets-default' ){
|
||||
$('#filelist').append('<h3><img style="height:40px;" src="img/database-icon.svg" >Powered by Beets DB</h3>');
|
||||
}
|
||||
|
||||
// if the DB is locked
|
||||
if(response.locked){
|
||||
$('#filelist').append('<p>The database is currently being built. Currently ' + response.totalFileCount + ' files are in the DB</p><input type="button" value="Check Progress" class="button secondary small" id="check_db_progress" >');
|
||||
return;
|
||||
}
|
||||
|
||||
// If you got this far the db is made and working
|
||||
$('#filelist').append('<p>Your DB has ' + response.totalFileCount + ' files</p><input type="button" class="button secondary rounded small" value="Build Database" id="build_database">');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
// Build the database
|
||||
$('body').on('click', '#build_database', function(){
|
||||
$(this).prop("disabled", true);
|
||||
|
||||
MSTREAMAPI.dbScan( function(response){
|
||||
MSTREAMAPI.dbScan( function(response, error){
|
||||
if(error !== false){
|
||||
return boilerplateFailure(response, error);
|
||||
}
|
||||
// Append the check db button so the user can start checking right away
|
||||
$('#filelist').append('<input type="button" value="Check Progress" id="check_db_progress" >');
|
||||
});
|
||||
});
|
||||
|
||||
// Check DB build progress
|
||||
// Check DB build progress
|
||||
$('body').on('click', '#check_db_progress', function(){
|
||||
MSTREAMAPI.dbStatus( function(response){
|
||||
// remove a <p> tage with the id of "db_progress_report"
|
||||
MSTREAMAPI.dbStatus( function(response, error){
|
||||
if(error !== false){
|
||||
return boilerplateFailure(response, error);
|
||||
}
|
||||
$( "#db_progress_report" ).remove();
|
||||
|
||||
// if file_count is 0, report that the the build script is not done counting files
|
||||
@ -664,23 +451,15 @@ $("#filelist").on('click', '.playlistz', function() {
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////// Sort by Albums
|
||||
//Load up album explorer
|
||||
//////////////////////////////////// Sort by Albums
|
||||
//Load up album explorer
|
||||
$('.get_all_albums').on('click', function(){
|
||||
resetPanel('Albums', 'scrollBoxHeight2');
|
||||
|
||||
$('.directoryTitle').hide();
|
||||
fileExplorerScrollPosition = [];
|
||||
|
||||
$('#filelist').removeClass('scrollBoxHeight1');
|
||||
$('#filelist').removeClass('scrollBoxHeight2');
|
||||
$('#filelist').addClass('scrollBoxHeight2');
|
||||
|
||||
MSTREAMAPI.albums( function(response){
|
||||
//clear the list
|
||||
$('#filelist').empty();
|
||||
|
||||
MSTREAMAPI.albums( function(response, error){
|
||||
if(error !== false){
|
||||
return boilerplateFailure(response, error);
|
||||
}
|
||||
//parse through the json array and make an array of corresponding divs
|
||||
var albums = [];
|
||||
$.each(response.albums, function(index, value) {
|
||||
@ -688,16 +467,17 @@ $("#filelist").on('click', '.playlistz', function() {
|
||||
});
|
||||
|
||||
$('#filelist').html(albums);
|
||||
$('.panel_one_name').html('Albums');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
// Load up album-songs
|
||||
$("#filelist").on('click', '.albumz', function() {
|
||||
var album = $(this).data('album');
|
||||
|
||||
MSTREAMAPI.albumSongs(album, function(response){
|
||||
MSTREAMAPI.albumSongs(album, function(response, error){
|
||||
if(error !== false){
|
||||
return boilerplateFailure(response, error);
|
||||
}
|
||||
//clear the list
|
||||
$('#filelist').empty();
|
||||
|
||||
@ -716,43 +496,33 @@ $("#filelist").on('click', '.playlistz', function() {
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////// Artists
|
||||
// Load up album-songs
|
||||
|
||||
/////////////////////////////////////// Artists
|
||||
// Load up album-songs
|
||||
$('.get_all_artists').on('click', function(){
|
||||
resetPanel('Artists', 'scrollBoxHeight2');
|
||||
|
||||
$('.directoryTitle').hide();
|
||||
fileExplorerScrollPosition = [];
|
||||
$('#filelist').removeClass('scrollBoxHeight1');
|
||||
$('#filelist').removeClass('scrollBoxHeight2');
|
||||
$('#filelist').addClass('scrollBoxHeight2');
|
||||
|
||||
MSTREAMAPI.artists( function(response){
|
||||
//clear the list
|
||||
$('#filelist').empty();
|
||||
|
||||
MSTREAMAPI.artists( function(response, error){
|
||||
if(error !== false){
|
||||
return boilerplateFailure(response, error);
|
||||
}
|
||||
//parse through the json array and make an array of corresponding divs
|
||||
var artists = [];
|
||||
$.each(response.artists, function(index,value) {
|
||||
artists.push('<div data-artist="'+value+'" class="artistz">'+value+' </div>');
|
||||
});
|
||||
|
||||
|
||||
$('#filelist').html(artists);
|
||||
$('.panel_one_name').html('Artists');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
$("#filelist").on('click', '.artistz', function() {
|
||||
var artist = $(this).data('artist');
|
||||
fileExplorerScrollPosition = [];
|
||||
|
||||
MSTREAMAPI.artistAlbums(artist, function(response){
|
||||
MSTREAMAPI.artistAlbums(artist, function(response, error){
|
||||
if(error !== false){
|
||||
return boilerplateFailure(response, error);
|
||||
}
|
||||
//clear the list
|
||||
$('#filelist').empty();
|
||||
|
||||
@ -767,28 +537,21 @@ $("#filelist").on('click', '.playlistz', function() {
|
||||
});
|
||||
|
||||
|
||||
|
||||
///////////////////////////// Search Function
|
||||
///////////////////////////// Search Function
|
||||
// Setup the search interface
|
||||
$('#search_database').on('click', function(){
|
||||
$('.directoryTitle').hide();
|
||||
$('#search_container').show();
|
||||
|
||||
$('#filelist').html('');
|
||||
|
||||
|
||||
$('#filelist').removeClass('scrollBoxHeight1');
|
||||
$('#filelist').removeClass('scrollBoxHeight2');
|
||||
$('#filelist').addClass('scrollBoxHeight1');
|
||||
|
||||
$('.panel_one_name').html('Search');
|
||||
resetPanel('Search', 'scrollBoxHeight1');
|
||||
$('#search_container').show();
|
||||
});
|
||||
|
||||
// Auto Search
|
||||
$('#search_it').on('keyup', function(){
|
||||
// TODO: Put this on some kind of time delay. That way rapid keystrokes won't spam the server
|
||||
if($(this).val().length>1){
|
||||
MSTREAMAPI.search($(this).val(), function(response){
|
||||
MSTREAMAPI.search($(this).val(), function(response, error){
|
||||
if(error !== false){
|
||||
return boilerplateFailure(response, error);
|
||||
}
|
||||
var htmlString = '';
|
||||
|
||||
if(response.artists.length > 0){
|
||||
@ -810,4 +573,67 @@ $("#filelist").on('click', '.playlistz', function() {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
//////////////////////// Jukebox Mode
|
||||
function setupJukeboxPanel(){
|
||||
// Hide the directory bar
|
||||
resetPanel('Jukebox Mode', 'scrollBoxHeight2');
|
||||
|
||||
var newHtml;
|
||||
if(JUKEBOX.stats.live !== false && JUKEBOX.connection !== false){
|
||||
newHtml = createJukeboxPanel();
|
||||
}else{
|
||||
newHtml = '\
|
||||
<p class="jukebox-panel">\
|
||||
<br><br>\
|
||||
<h3>Jukebox Mode allows you to control this page remotely<h3> <br><br>\
|
||||
<div class="jukebox_connect button"> CONNECT IT!</div>\
|
||||
</p>\
|
||||
<img src="public/img/loading.gif" class="hide jukebox-loading">';
|
||||
}
|
||||
|
||||
// Add the content
|
||||
$('#filelist').html(newHtml);
|
||||
}
|
||||
|
||||
// The jukebox panel
|
||||
$('#jukebox_mode').on('click', function(){
|
||||
setupJukeboxPanel();
|
||||
});
|
||||
|
||||
// Setup Jukebox
|
||||
$('body').on('click', '.jukebox_connect', function(){
|
||||
$(this).prop("disabled", true);
|
||||
$(this).hide();
|
||||
$('.jukebox-loading').toggleClass('hide');
|
||||
|
||||
JUKEBOX.createWebsocket( MSTREAMAPI.currentServer.token, function(){
|
||||
// Wait a while and display the status
|
||||
setTimeout(function(){
|
||||
// TODO: Check that status has changed
|
||||
setupJukeboxPanel();
|
||||
},1800);
|
||||
});
|
||||
});
|
||||
|
||||
function createJukeboxPanel(){
|
||||
var returnHtml = '<p class="jukebox-panel">';
|
||||
|
||||
if(JUKEBOX.stats.error !== false){
|
||||
return returnHtml + 'An error occurred. Please refresh the page and try again</p>';
|
||||
}
|
||||
|
||||
if(JUKEBOX.stats.adminCode){
|
||||
returnHtml += '<h1>Code: ' + JUKEBOX.stats.adminCode + '</h1>';
|
||||
}
|
||||
if(JUKEBOX.stats.guestCode){
|
||||
returnHtml += '<h2>Guest Code: ' + JUKEBOX.stats.guestCode + '</h2>';
|
||||
}
|
||||
|
||||
var adrs = window.location.protocol + '//' + window.location.host + '/remote';
|
||||
returnHtml += '<br><h4>Remote Jukebox Controls: <a target="_blank" href="' + adrs + '"> ' + adrs + '</a><h4>';
|
||||
|
||||
return returnHtml + '</p>';
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user