Jamstash/app/app.js
Carey Metcalfe 8c279093df Refactor media keys and fix play/pause
- Using space to play/pause was broken due to an issue with data
  binding. Running `$scope.$apply()` after updating the `player.pauseSong`
  property using `player.togglePause()` seems to have fixed this.
- All of the key event processing has been moved into the JS. This means
  that all the key event logic is all in one spot (easier to understand
  IMO). Additionally, this removes the need to redefine functions for
  each shortcut.
- Removed the now-unused `angular-ui-utils/keypress.js` package.
- Fixed key events being active when editing dropdown/checkbox controls
  in the settings menu
- Removed the custom `[Home]` shortcut since this is done natively by
  the browser already.
- Removed the 1-6 shortcuts for the tabs. Logic being that it seems
  pretty rare that you would want to rapidly switch between them (you
  would have to use the mouse to do anything on all tabs except the
  subsonic one anyway), and they were already broken without anyone
  complaining.
- Fixed tests
2017-11-10 14:31:01 -05:00

83 lines
3.4 KiB
JavaScript
Executable file

'use strict';
/* Declare app level module */
angular.module('JamStash', [
'ngCookies',
'ngRoute',
'ngSanitize',
'ngLodash',
'jamstash.subsonic.controller',
'jamstash.archive.controller',
'jamstash.player.controller',
'jamstash.queue.controller',
'jamstash.settings.controller',
'jamstash.persistence',
'jamstash.loading'
])
.config(['$routeProvider',function ($routeProvider) {
$routeProvider
.when('/index', { redirectTo: '/library' })
.when('/settings', { templateUrl: 'settings/settings.html', controller: 'SettingsController' })
.when('/library', { templateUrl: 'subsonic/subsonic.html', controller: 'SubsonicController' })
.when('/library/:artistId', { templateUrl: 'subsonic/subsonic.html', controller: 'SubsonicController', reloadOnSearch: false })
.when('/library/:artistId/:albumId', { templateUrl: 'subsonic/subsonic.html', controller: 'SubsonicController', reloadOnSearch: false })
.when('/podcasts', { templateUrl: 'podcasts/podcasts.html', controller: 'PodcastController' })
.when('/archive', { templateUrl: 'archive/archive.html', controller: 'ArchiveController' })
.when('/archive/:artist', { templateUrl: 'archive/archive.html', controller: 'ArchiveController' })
.when('/archive/:artist/:album', { templateUrl: 'archive/archive.html', controller: 'ArchiveController' })
.otherwise({ redirectTo: '/index' });
}])
.config(['$httpProvider', function httpConfig ($httpProvider) {
$httpProvider.interceptors.push(authenticationInterceptor);
$httpProvider.interceptors.push(loadingInterceptor);
}]);
authenticationInterceptor.$inject = ['$rootScope', '$location', '$q', 'globals'];
function authenticationInterceptor($rootScope, $location, $q, globals) {
return {
'request': function (request) {
// if we're not logged-in to the AngularJS app, redirect to login page
//$rootScope.loggedIn = $rootScope.loggedIn || globals.settings.Username;
$rootScope.loggedIn = false;
if (globals.settings.Username != "" && globals.settings.Password != "" && globals.settings.Server != "") {
$rootScope.loggedIn = true;
}
var path = '';
path = $location.path();
if (globals.settings.Debug) { console.log('Logged In: ' + $rootScope.loggedIn); }
if (globals.settings.Debug) { console.log('Current Path: ' + path); }
if (!$rootScope.loggedIn && path != '/settings' && path.search('archive') < 0) {
$location.path('/settings');
}
return request;
},
'responseError': function (rejection) {
// if we're not logged-in to the web service, redirect to login page
if (rejection.status === 401 && $location.path() != '/settings') {
$rootScope.loggedIn = false;
$location.path('/settings');
}
return $q.reject(rejection);
}
};
}
loadingInterceptor.$inject = ['Loading'];
function loadingInterceptor(Loading) {
return {
request: function (request) {
Loading.isLoading = true;
return request;
},
response: function (response) {
Loading.isLoading = false;
return response;
},
responseError: function (error) {
Loading.isLoading = false;
return error;
}
};
}