Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 39 additions & 33 deletions src/app.config.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,43 @@
'use strict';
angular
.module('app.config', [])
.config(configs)
.run(runs);

function configs($httpProvider) {
var interceptor = function($location, $log, $q) {
function error(response) {
if (response.status === 401) {
$log.error('You are unauthorised to access the requested resource (401)');
} else if (response.status === 404) {
$log.error('The requested resource could not be found (404)');
} else if (response.status === 500) {
$log.error('Internal server error (500)');
(function() {
angular
.module('app.config', [])
.config(configs)
.run(runs);

configs.$inject = ['$httpProvider'];
runs.$inject = ['$rootScope', 'PageValues'];

function configs($httpProvider) {
var interceptor = function($location, $log, $q) {
function error(response) {
if (response.status === 401) {
$log.error('You are unauthorised to access the requested resource (401)');
} else if (response.status === 404) {
$log.error('The requested resource could not be found (404)');
} else if (response.status === 500) {
$log.error('Internal server error (500)');
}
return $q.reject(response);
}
function success(response) {
//Request completed successfully
return response;
}
return function(promise) {
return promise.then(success, error);
}
return $q.reject(response);
}
function success(response) {
//Request completed successfully
return response;
}
return function(promise) {
return promise.then(success, error);
}
};
$httpProvider.interceptors.push(interceptor);
}
};
$httpProvider.interceptors.push(interceptor);
}

function runs($rootScope, PageValues) {
$rootScope.$on('$routeChangeStart', function() {
PageValues.loading = true;
});
$rootScope.$on('$routeChangeSuccess', function() {
PageValues.loading = false;
});
}
function runs($rootScope, PageValues) {
$rootScope.$on('$routeChangeStart', function() {
PageValues.loading = true;
});
$rootScope.$on('$routeChangeSuccess', function() {
PageValues.loading = false;
});
}
})();
94 changes: 49 additions & 45 deletions src/app.routes.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,55 @@
'use strict';

angular
.module('app.routes', ['ngRoute'])
.config(config);
(function() {
angular
.module('app.routes', ['ngRoute'])
.config(config);

function config ($routeProvider) {
$routeProvider.
when('/', {
templateUrl: 'sections/home/home.tpl.html',
controller: 'HomeController as home'
})
.when('/premieres', {
templateUrl: 'sections/premieres/premieres.tpl.html',
controller: 'PremieresController as premieres',
resolve: {
shows: function(ShowService) {
return ShowService.getPremieres();
config.$inject = ['$routeProvider'];

function config ($routeProvider) {
$routeProvider.
when('/', {
templateUrl: 'sections/home/home.tpl.html',
controller: 'HomeController as home'
})
.when('/premieres', {
templateUrl: 'sections/premieres/premieres.tpl.html',
controller: 'PremieresController as premieres',
resolve: {
shows: function(ShowService) {
return ShowService.getPremieres();
}
}
}
})
.when('/search', {
templateUrl: 'sections/search/search.tpl.html',
controller: 'SearchController as search'
})
.when('/search/:query', {
templateUrl: 'sections/search/search.tpl.html',
controller: 'SearchController as search'
})
.when('/popular', {
templateUrl: 'sections/popular/popular.tpl.html',
controller: 'PopularController as popular',
resolve: {
shows: function(ShowService) {
return ShowService.getPopular();
})
.when('/search', {
templateUrl: 'sections/search/search.tpl.html',
controller: 'SearchController as search'
})
.when('/search/:query', {
templateUrl: 'sections/search/search.tpl.html',
controller: 'SearchController as search'
})
.when('/popular', {
templateUrl: 'sections/popular/popular.tpl.html',
controller: 'PopularController as popular',
resolve: {
shows: function(ShowService) {
return ShowService.getPopular();
}
}
}
})
.when('/view/:id', {
templateUrl: 'sections/view/view.tpl.html',
controller: 'ViewController as view',
resolve: {
show: function(ShowService, $route) {
return ShowService.get($route.current.params.id);
})
.when('/view/:id', {
templateUrl: 'sections/view/view.tpl.html',
controller: 'ViewController as view',
resolve: {
show: function(ShowService, $route) {
return ShowService.get($route.current.params.id);
}
}
}
})
.otherwise({
redirectTo: '/'
});
}
})
.otherwise({
redirectTo: '/'
});
}
})();
4 changes: 2 additions & 2 deletions src/components/bar/bar.ctrl.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';
angular
.module('app.core')
.controller('BarController', function($scope, PageValues) {
.controller('BarController', ['$scope', 'PageValues', function($scope, PageValues) {
//Setup the view model object
var vm = this;
vm.data = PageValues;
});
}]);
43 changes: 25 additions & 18 deletions src/components/show/show.drct.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
angular
.module('app.core')
.directive('show', show);
function show(ShowService) {
var directive = {
controller: controller,
templateUrl: 'components/show/show.tpl.html',
restrict: 'E',
scope: {
show: '='
'use strict';

(function() {
angular
.module('app.core')
.directive('show', show);

show.$inject = ['ShowService'];

function show(ShowService) {
var directive = {
controller: controller,
templateUrl: 'components/show/show.tpl.html',
restrict: 'E',
scope: {
show: '='
}
};
return directive;
function controller($scope) {
$scope.genres = [];
ShowService.get($scope.show.id).then(function(response){
$scope.genres = response.genres;
});
}
};
return directive;
function controller($scope) {
$scope.genres = [];
ShowService.get($scope.show.id).then(function(response){
$scope.genres = response.genres;
});
}
}
})();
34 changes: 19 additions & 15 deletions src/directives/ngEnter.drct.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
angular
.module('app.core')
.directive('ngEnter', ngEnter);
'use strict';

function ngEnter() {
return function(scope, element, attrs) {
element.bind("keydown keypress", function(event) {
if(event.which === 13) {
scope.$apply(function(){
scope.$eval(attrs.ngEnter);
});
event.preventDefault();
}
});
};
}
(function() {
angular
.module('app.core')
.directive('ngEnter', ngEnter);

function ngEnter() {
return function(scope, element, attrs) {
element.bind("keydown keypress", function(event) {
if(event.which === 13) {
scope.$apply(function(){
scope.$eval(attrs.ngEnter);
});
event.preventDefault();
}
});
};
}
})();
4 changes: 2 additions & 2 deletions src/sections/home/home.ctrl.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
angular
.module('app.core')
.controller('HomeController', function($scope, PageValues) {
.controller('HomeController', ['$scope', 'PageValues', function($scope, PageValues) {
//Set page title and description
PageValues.title = "HOME";
PageValues.description = "Learn AngularJS using best practice real world examples.";
Expand Down Expand Up @@ -39,4 +39,4 @@ angular
link: "#"
}
];
});
}]);
4 changes: 2 additions & 2 deletions src/sections/popular/popular.ctrl.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use strict';
angular
.module('app.core')
.controller('PopularController', function($scope, PageValues, shows) {
.controller('PopularController', ['$scope', 'PageValues', 'shows', function($scope, PageValues, shows) {
//Set page title and description
PageValues.title = "POPULAR";
PageValues.description = "The most popular TV shows.";
//Setup view model object
var vm = this;
vm.shows = shows;
});
}]);
4 changes: 2 additions & 2 deletions src/sections/premieres/premieres.ctrl.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use strict';
angular
.module('app.core')
.controller('PremieresController', function($scope, shows, PageValues) {
.controller('PremieresController', ['$scope', 'shows', 'PageValues', function($scope, shows, PageValues) {
//Set page title and description
PageValues.title = "PREMIERES";
PageValues.description = "Brand new shows showing this month.";
//Setup view model object
var vm = this;
vm.shows = shows;
});
}]);
6 changes: 3 additions & 3 deletions src/sections/search/search.ctrl.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
angular
.module('app.core')
.controller('SearchController', function($location, $routeParams, ShowService, PageValues) {
.controller('SearchController', ['$location', '$routeParams', 'ShowService', 'PageValues', function($location, $routeParams, ShowService, PageValues) {
//Set page title and description
PageValues.title = "SEARCH";
PageValues.description = "Search for your favorite TV shows.";
Expand All @@ -21,8 +21,8 @@ angular
vm.loading = false;
});
};
if (typeof $routeParams.query != "undefined") {
if (typeof $routeParams.query !== "undefined") {
vm.performSearch($routeParams.query);
vm.query = decodeURI($routeParams.query);
}
});
}]);
4 changes: 2 additions & 2 deletions src/sections/view/view.ctrl.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
angular
.module('app.core')
.controller('ViewController', function($scope, $location, PageValues, show, ShowService, $routeParams) {
.controller('ViewController', ['$scope', '$location', 'PageValues', 'show', 'ShowService', '$routeParams', function($scope, $location, PageValues, show, ShowService, $routeParams) {
//Set page title and description
PageValues.title = "VIEW";
PageValues.description = "Overview, seasons & info for '" + show.original_name + "'.";
Expand All @@ -19,4 +19,4 @@ angular
ShowService.getCast(vm.show.id).then(function(response){
vm.show.cast = response.cast;
});
});
}]);
Loading