diff --git a/app.js b/app.js index 4baa582..ec61c1d 100644 --- a/app.js +++ b/app.js @@ -8,6 +8,16 @@ angularApp.config(['$routeProvider', controller : 'MainCtrl', controllerAs : 'main' }) + .when('/character/:id', { + templateUrl: 'views/character.html', + controller: 'CharacterCtrl', + controllerAs: 'character' + }) + .when('/movie/:id', { + templateUrl: 'views/movie.html', + controller: 'MovieCtrl', + controllerAs: 'movie' + }) .otherwise('/'); } ]); \ No newline at end of file diff --git a/controllers/character.js b/controllers/character.js new file mode 100644 index 0000000..f79f9da --- /dev/null +++ b/controllers/character.js @@ -0,0 +1,22 @@ +angularApp.controller('CharacterCtrl', [ + '$routeParams', + '$scope', + 'SwapiService', + function($routeParams, $scope, SwapiService){ + + $scope.character = {}; + $scope.loading = true; + $scope.id = $routeParams.id; + + SwapiService.people() + .then(function(data) { + angular.forEach(data.data.results, function(person) { + if (person.name.toLowerCase() === $routeParams.id.toLowerCase()) { + angular.copy(person, $scope.character); + console.log(person); + } + }); + $scope.loading = false; + }); + } +]); \ No newline at end of file diff --git a/controllers/main.js b/controllers/main.js index 44cfa5e..0c27a6a 100644 --- a/controllers/main.js +++ b/controllers/main.js @@ -26,7 +26,10 @@ angularApp.controller('MainCtrl', [ // adding film names to list of films angular.forEach($scope.filmInfo, function(film) { var api_call = 'http://swapi.co/api/films/' + film.episode_id + '/'; - $scope.films[api_call] = film.title; + $scope.films[api_call] = { + 'title': film.title, + 'episode_id': film.episode_id + }; }); }); diff --git a/controllers/movie.js b/controllers/movie.js new file mode 100644 index 0000000..8253ede --- /dev/null +++ b/controllers/movie.js @@ -0,0 +1,21 @@ +angularApp.controller('MovieCtrl', [ + '$routeParams', + '$scope', + 'SwapiService', + function($routeParams, $scope, SwapiService){ + + $scope.movie = {}; + $scope.loading = true; + $scope.id = $routeParams.id; + + SwapiService.films() + .then(function(data) { + angular.forEach(data.data.results, function(film) { + if (film.episode_id == $routeParams.id) { + angular.copy(film, $scope.movie); + } + }); + $scope.loading = false; + }); + } +]); \ No newline at end of file diff --git a/index.html b/index.html index b88bf70..d94f60f 100644 --- a/index.html +++ b/index.html @@ -12,6 +12,8 @@ + + diff --git a/views/character.html b/views/character.html new file mode 100644 index 0000000..b7d39f7 --- /dev/null +++ b/views/character.html @@ -0,0 +1,63 @@ +
+ +
+ +
+
+ + + +

Home

+ +

+
+ Name: {{ character.name }} +
+
+
+
+ Height: {{ character.height }} +
+
+
+
+ Mass: {{ character.mass }} +
+
+
+
+ Hair Color: {{ character.hair_color }} +
+
+
+
+ Eye Color: {{ character.eye_color }} +
+
+
+
+ Birth Year: {{ character.birth_year }} +
+
+
+
+ Gender: {{ character.gender }} +
+
+ +
+ +
+ + + + Return Home? + +
+
\ No newline at end of file diff --git a/views/main.html b/views/main.html index cc966e8..f0d26f3 100644 --- a/views/main.html +++ b/views/main.html @@ -5,12 +5,16 @@

Star Wars

-
{{ person.name }}
+
+ {{ person.name }} +
diff --git a/views/movie.html b/views/movie.html new file mode 100644 index 0000000..6e53668 --- /dev/null +++ b/views/movie.html @@ -0,0 +1,56 @@ +
+ +
+ +
+
+ + +

Home

+ +

+
+ Name: {{ movie.title }} +
+
+
+
+ Opening Crawl: +

+ {{ movie.opening_crawl }} +

+
+
+
+
+ Director: {{ movie.director }} +
+
+
+
+ Producer: {{ movie.producer }} +
+
+
+
+ Release Date: {{ movie.release_date }} +
+
+ + +
+ +
+ + + + Return Home? + +
+
\ No newline at end of file