Renamed all controlles from 'Ctrl' to 'Controller' to better follow angular best practices.

This commit is contained in:
Hyzual 2014-12-10 22:06:17 +01:00
parent 91b112cb0a
commit 226a768987
12 changed files with 49 additions and 71 deletions

View file

@ -1,22 +1,22 @@
/* Declare app level module */
angular.module('JamStash', ['ngCookies', 'ngRoute', 'ngSanitize',
'jamstash.subsonic.ctrl', 'jamstash.archive.ctrl', 'jamstash.player.ctrl', 'jamstash.queue.ctrl'])
'jamstash.subsonic.controller', 'jamstash.archive.controller', 'jamstash.player.controller', 'jamstash.queue.controller'])
.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' })
.when('/settings', { templateUrl: 'settings/settings.html', controller: 'SettingsController' })
.when('/queue', { templateUrl: 'queue/queue.html', controller: 'QueueController' })
.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' });
}])

View file

@ -1,11 +1,11 @@
/**
* jamstash.archive.ctrl Module
/**
* jamstash.archive.controller Module
*
* Access Archive.org
*/
angular.module('jamstash.archive.ctrl', ['jamstash.archive.service'])
angular.module('jamstash.archive.controller', ['jamstash.archive.service'])
.controller('ArchiveCtrl', ['$scope', '$rootScope', '$location', '$routeParams', '$http', '$timeout', 'utils', 'globals', 'model', 'notifications', 'player', 'archive', 'json',
.controller('ArchiveController', ['$scope', '$rootScope', '$location', '$routeParams', '$http', '$timeout', 'utils', 'globals', 'model', 'notifications', 'player', 'archive', 'json',
function($scope, $rootScope, $location, $routeParams, $http, $timeout, utils, globals, model, notifications, player, archive, json){
'use strict';

View file

@ -1,5 +1,5 @@
angular.module('JamStash')
.controller('AppCtrl', ['$scope', '$rootScope', '$document', '$window', '$location', '$cookieStore', '$http', 'utils', 'globals', 'model', 'notifications', 'player',
.controller('AppController', ['$scope', '$rootScope', '$document', '$window', '$location', '$cookieStore', '$http', 'utils', 'globals', 'model', 'notifications', 'player',
function($scope, $rootScope, $document, $window, $location, $cookieStore, $http, utils, globals, model, notifications, player) {
'use strict';

View file

@ -21,7 +21,7 @@
<link href="styles/Mobile.css" rel="stylesheet" type="text/css" data-name="main" />
<link href="" rel="stylesheet" type="text/css" data-name="theme" />
</head>
<body ng-controller="AppCtrl">
<body ng-controller="AppController">
<div id="container">
<div id="header">
<div id="messages">
@ -49,7 +49,7 @@
<div class="clear"></div>
</div><!-- end #content -->
<div id="SideBar" ng-controller="QueueCtrl">
<div id="SideBar" ng-controller="QueueController">
<div class="headeractions">
<a class="buttonimg" title="Shuffle Queue" ng-click="queueShuffle()"><img src="images/fork_gd_11x12.png"></a>
<a class="buttonimg" id="action_Empty" title="Delete Queue" ng-click="queueEmpty()"><img src="images/trash_fill_gd_12x12.png"></a>
@ -75,7 +75,7 @@
-->
</div>
<!-- Player -->
<jamstash-player ng-controller="PlayerCtrl"></jamstash-player>
<jamstash-player ng-controller="PlayerController"></jamstash-player>
</div> <!-- End container -->
<script>
(function (i, s, o, g, r, a, m) {

View file

@ -3,9 +3,9 @@
*
* Control the HTML5 player through jplayer.js
*/
angular.module('jamstash.player.ctrl', ['jamstash.player.service', 'jamstash.player.directive'])
angular.module('jamstash.player.controller', ['jamstash.player.service', 'jamstash.player.directive'])
.controller('PlayerCtrl', ['$scope', 'player', function($scope, player){
.controller('PlayerController', ['$scope', 'player', function($scope, player){
'use strict';
$scope.previousTrack = function () {

View file

@ -4,7 +4,7 @@ describe("Player controller", function() {
var player, scope;
beforeEach(function() {
module('jamstash.player.ctrl');
module('jamstash.player.controller');
inject(function ($controller, $rootScope, _player_) {
scope = $rootScope.$new();
@ -15,7 +15,7 @@ describe("Player controller", function() {
spyOn(player, "previousTrack").and.stub();
spyOn(player, "defaultPlay").and.stub();
$controller('PlayerCtrl', {
$controller('PlayerController', {
$scope: scope,
player: player
});

View file

@ -1,7 +1,7 @@

angular.module('JamStash')
.controller('PodcastCtrl', ['$scope', '$rootScope', function PodcastCtrl($scope, $rootScope) {
.controller('PodcastController', ['$scope', '$rootScope', function ($scope, $rootScope) {
'use strict';
$rootScope.song = [];

View file

@ -1,7 +1,7 @@
angular.module('jamstash.queue.ctrl', ['jamstash.player.service'])
angular.module('jamstash.queue.controller', ['jamstash.player.service'])
.controller('QueueCtrl', ['$scope', '$rootScope', 'globals', 'player',
function QueueCtrl($scope, $rootScope, globals, player) {
.controller('QueueController', ['$scope', '$rootScope', 'globals', 'player',
function ($scope, $rootScope, globals, player) {
'use strict';
$scope.settings = globals.settings;
$scope.song = $rootScope.queue;

View file

@ -4,7 +4,7 @@ describe("Queue controller", function() {
var player, $rootScope, scope, globals;
beforeEach(function() {
module('jamstash.queue.ctrl');
module('jamstash.queue.controller');
inject(function ($controller, _$rootScope_, _globals_, _player_) {
$rootScope = _$rootScope_;
@ -15,7 +15,7 @@ describe("Queue controller", function() {
// Mock the functions of the services
spyOn(player, "playSong").and.stub();
$controller('QueueCtrl', {
$controller('QueueController', {
$rootScope: $rootScope,
$scope: scope,
globals: globals,

View file

@ -1,11 +1,10 @@
angular.module('JamStash')
.controller('SettingsCtrl', ['$rootScope', '$scope', '$routeParams', '$location', '$http', '$q', 'utils', 'globals', 'json', 'notifications', 'player',
function ($rootScope, $scope, $routeParams, $location, $http, $q, utils, globals, json, notifications, player) {
.controller('SettingsController', ['$rootScope', '$scope', '$routeParams', '$location', 'utils', 'globals', 'json', 'notifications', 'player',
function ($rootScope, $scope, $routeParams, $location, utils, globals, json, notifications, player) {
'use strict';
$rootScope.hideQueue();
$scope.settings = globals.settings; /* See service.js */
$scope.ApiVersion = globals.settings.ApiVersion;
$scope.Timeouts = [
{ id: 10000, name: 10 },
{ id: 20000, name: 20 },
@ -28,34 +27,6 @@
$('#AZIndex').show();
}
});
$scope.ping = function () {
var exception = {reason: 'Error when contacting the Subsonic server.'};
var deferred = $q.defer();
var httpPromise;
httpPromise = $http({
method: 'GET',
timeout: globals.settings.Timeout,
// 2015-1-5: This API call only works with json as of SS v5.0?!?
//url: globals.BaseURL() + '/ping.view?' + globals.BaseParams(),
url: globals.BaseURL() + '/ping.view?' + globals.BaseJSONParams()
});
httpPromise.success(function(data, status) {
var subsonicResponse = (data['subsonic-response'] !== undefined) ? data['subsonic-response'] : {status: 'failed'};
if (subsonicResponse.status === 'ok') {
$scope.ApiVersion = subsonicResponse.version;
globals.settings.ApiVersion = $scope.ApiVersion;
deferred.resolve(data);
} else {
if(subsonicResponse.status === 'failed' && subsonicResponse.error !== undefined) {
notifications.updateMessage(subsonicResponse.error.message);
}
}
}).error(function(data, status) {
exception.httpError = status;
deferred.reject(exception);
});
return deferred.promise;
};
$scope.reset = function () {
utils.setValue('Settings', null, true);
$scope.loadSettings();
@ -92,9 +63,16 @@
notifications.updateMessage('Settings Updated!', true);
$scope.loadSettings();
if (globals.settings.Server !== '' && globals.settings.Username !== '' && globals.settings.Password !== '') {
$scope.ping().then(function() {
$scope.ping().then(function(data) {
if (data["subsonic-response"].status == 'ok') {
globals.settings.ApiVersion = data["subsonic-response"].version;
$location.path('/library').replace();
$rootScope.showIndex = true;
} else {
if (typeof data["subsonic-response"].error != 'undefined') {
notifications.updateMessage(data["subsonic-response"].error.message);
}
}
});
}
};

View file

@ -1,13 +1,13 @@
/**
* jamstash.subsonic.ctrl Module
* jamstash.subsonic.controller Module
*
* Access and use the Subsonic Server. The Controller is in charge of relaying the Service's messages to the user through the
* notifications.
*/
angular.module('jamstash.subsonic.ctrl', ['jamstash.subsonic.service', 'jamstash.player.service'])
angular.module('jamstash.subsonic.controller', ['jamstash.subsonic.service', 'jamstash.player.service'])
.controller('SubsonicCtrl', ['$scope', '$rootScope', '$routeParams', 'utils', 'globals', 'map', 'subsonic', 'notifications', 'player',
function SubsonicCtrl($scope, $rootScope, $routeParams, utils, globals, map, subsonic, notifications, player) {
.controller('SubsonicController', ['$scope', '$rootScope', '$routeParams', 'utils', 'globals', 'map', 'subsonic', 'notifications', 'player',
function ($scope, $rootScope, $routeParams, utils, globals, map, subsonic, notifications, player) {
'use strict';
$scope.settings = globals.settings;

View file

@ -7,7 +7,7 @@ describe("Subsonic controller", function() {
beforeEach(function() {
jasmine.addCustomEqualityTester(angular.equals);
module('jamstash.subsonic.ctrl');
module('jamstash.subsonic.controller');
inject(function ($controller, _$rootScope_, utils, globals, map, _subsonic_, _notifications_, $q, _player_) {
$rootScope = _$rootScope_;
@ -26,7 +26,7 @@ describe("Subsonic controller", function() {
spyOn(player, 'playSong').and.stub();
$rootScope.queue = [];
$controller('SubsonicCtrl', {
$controller('SubsonicController', {
$scope: scope,
$rootScope: $rootScope,
$routeParams: {},