
The idea is that the service should ideally be used directly, so we know who depends on what and don't end up with cycles. To achieve this, we should not add functions to $rootScope but instead provide them from our service. Services can use them directly, and controllers have to create other functions in their own scope. This means that we have a player-controller that does not do much by itself but it enables us to avoid filling up the $rootScope. I have left the $rootScope additions at the end of player-service because it's going to take some time to refactor it, so in the meantime I want things to keep working.
54 lines
2.8 KiB
JavaScript
Executable file
54 lines
2.8 KiB
JavaScript
Executable file
|
|
/* Declare app level module */
|
|
angular.module('JamStash', ['ngCookies', 'ngRoute', 'ngSanitize',
|
|
'jamstash.subsonic.ctrl', 'jamstash.archive.ctrl', 'jamstash.player.ctrl'])
|
|
|
|
.config(['$routeProvider',function($routeProvider) {
|
|
'use strict';
|
|
|
|
$routeProvider
|
|
.when('/index', { redirectTo: '/library' })
|
|
.when('/settings', { templateUrl: 'settings/settings.html', controller: 'SettingsCtrl' })
|
|
.when('/queue', { templateUrl: 'queue/queue.html', controller: 'QueueCtrl' })
|
|
.when('/library', { templateUrl: 'subsonic/subsonic.html', controller: 'SubsonicCtrl' })
|
|
.when('/library/:artistId', { templateUrl: 'subsonic/subsonic.html', controller: 'SubsonicCtrl', reloadOnSearch: false })
|
|
.when('/library/:artistId/:albumId', { templateUrl: 'subsonic/subsonic.html', controller: 'SubsonicCtrl', reloadOnSearch: false })
|
|
.when('/podcasts', { templateUrl: 'podcasts/podcasts.html', controller: 'PodcastCtrl' })
|
|
.when('/archive', { templateUrl: 'archive/archive.html', controller: 'ArchiveCtrl' })
|
|
.when('/archive/:artist', { templateUrl: 'archive/archive.html', controller: 'ArchiveCtrl' })
|
|
.when('/archive/:artist/:album', { templateUrl: 'archive/archive.html', controller: 'ArchiveCtrl' })
|
|
.otherwise({ redirectTo: '/index' });
|
|
}])
|
|
|
|
.config(['$httpProvider',function($httpProvider) {
|
|
'use strict';
|
|
|
|
$httpProvider.interceptors.push(['$rootScope', '$location', '$q', 'globals', function ($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);
|
|
}
|
|
};
|
|
}]);
|
|
}]);
|