Skip to content

Commit

Permalink
finished module 2
Browse files Browse the repository at this point in the history
  • Loading branch information
OdeToCode committed Jun 2, 2014
1 parent 101ab88 commit 9457133
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 47 deletions.
46 changes: 17 additions & 29 deletions clients/ng/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<link rel="stylesheet" href="/ng/styles.css">
</head>

<body class="container ng-cloak" data-ng-app>
<body class="container ng-cloak" ng-app="atTheMovies">

<nav class="navbar navbar-default navbar-inverse" role="navigation">
<div class="container-fluid">
Expand All @@ -14,52 +14,40 @@
</div>
</div>
</nav>

<div class="row" ng-controller="HelloController">
<button ng-click="showMessage()" class="btn btn-default">Show message</button>
<div class="col-md-12">

<div ng-repeat="i in [0,1,2]">
{{ i }}
</div>


<div class="alert alert-info" ng-show="alert">
{{ alert }}
</div>

{{ message }}
{{ message.length }}
<form ng-submit="saveMessage()">
<input type="text" ng-model="message" />
<input type="submit" value="Save" />
</form>
</div>
</div>


<div class="row" ng-controller="MoviesController">
{{error}}
<div class="col-md-12">
<table class="table table-condensed">
<thead>
<tr>
<th>Title</th>
<th>Released</th>
<th>Length</th>
<th>Year</th>
<th>Rating</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="movie in movies">
<td>{{movie.title}}</td>
<td>{{movie.released}}</td>
<td>{{movie.length}}</td>
<td>{{movie.year}}</td>
<td>{{movie.rating}}</td>
<td>
<button ng-click="increase(movie)">Rating +</button>
<button ng-click="decrease(movie)">Rating -</button>
</td>
</tr>
</tbody>
</table>
</div>
</div>

<script src="/bower_components/angular/angular.js"></script>
<script src="/bower_components/angular/angular.js"></script>
<script src="scripts/atTheMovies.js"></script>

<script src="scripts/HelloController.js"></script>
<script src="scripts/movieService.js"></script>
<script src="scripts/MoviesController.js"></script>
</body>

</html>
30 changes: 12 additions & 18 deletions clients/ng/scripts/HelloController.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
var HelloController = function($scope) {

$scope.showMessage = function() {
$scope.message = "Hello, World!";
};

$scope.saveMessage = function() {
$scope.alert = "Saved...";
};
(function() {

};
var HelloController = function ($scope) {

$scope.showMessage = function () {
$scope.message = "Hello, World!";
};

var MoviesController = function($scope) {
$scope.saveMessage = function () {
$scope.alert = "Saved...";
};

var movies = [
{ title: "Star Wars", length: 120, released: 1981 },
{ title: "Top Gun", length: 90, released: 1984 },
{ title: "Hot Shots", length: 89, released: 1986 }
];
};

$scope.movies = movies;
var module = angular.module("atTheMovies");
module.controller("HelloController", HelloController);
}());

};
31 changes: 31 additions & 0 deletions clients/ng/scripts/MoviesController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
(function() {

var MoviesController = function ($scope, movieService) {

var onMovies = function(response) {
$scope.movies = response.data;
};

var onError = function(reason) {
$scope.error = "There was a problem";
};

movieService.getAll()
.then(onMovies, onError);


$scope.increase = function (movie) {
movie.rating += 1;
};

$scope.decrease = function (movie) {
movie.rating -= 1;
};
};

var module = angular.module("atTheMovies");
module.controller("MoviesController",
["$scope", "movieService", MoviesController]);

}());

13 changes: 13 additions & 0 deletions clients/ng/scripts/atTheMovies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
(function() {

var module = angular.module("atTheMovies", []);

module.config(function($httpProvider) {

});

module.run(function($rootScope) {
$rootScope.version = "v1.0";
});

}());
15 changes: 15 additions & 0 deletions clients/ng/scripts/movieService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
(function() {

var movieService = function($http) {

return {
getAll : function() {
return $http.get("/api/movies");
}
};
};

var module = angular.module("atTheMovies");
module.factory("movieService", movieService);

}());

0 comments on commit 9457133

Please sign in to comment.