Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

base app complete #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
48 changes: 48 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
var app = angular.module('movieApp', []);

app.controller('MainCtrl', ['$scope', function($scope) {
$scope.moviesToWatch = [
{
title: "The Revenant",
watched: false
},
{
title: "Star Wars: The Force Awakens",
watched: false
},
{
title: "Norm of the North",
watched: false
},
{
title: "The Forest",
watched: false
},
{
title: "Sisters",
watched: false
},
{
title: "The Hateful Eight",
watched: false
}
];

$scope.limit = 5;

$scope.addMovie = function() {
$scope.moviesToWatch.push($scope.newMovie);
$scope.addMovieForm = false;
$scope.newMovie = {};
};

$scope.deleteMovie = function(movie) {
var movieIndex = $scope.moviesToWatch.indexOf(movie);
$scope.moviesToWatch.splice(movieIndex, 1);
};

$scope.showMore = function() {
$scope.limit = null;
};

}]);
49 changes: 49 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<!DOCTYPE html>
<html lang="en" ng-app="movieApp">
<head>
<meta charset="UTF-8">

<!-- angular -->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>

<!-- bootstrap -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" integrity="sha256-MfvZlkHCEqatNoGiOXveE8FIwMzZg4W85qfrfIFBfYc= sha512-dTfge/zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz/ixG7ArTxmDjLXDmezHubeNikyKGVyQ==" crossorigin="anonymous">

<!-- custom script -->
<script src="app.js"></script>

<title>Movies to Watch</title>
</head>
<body ng-controller="MainCtrl">
<div class="container">
<div class="row">
<div class="col-md-3 col-md-offset-2">
<h1>Movies to Watch</h1>
<button class="btn btn-info btn-block" ng-click="addMovieForm=true" ng-hide="addMovieForm">Add a Movie</button>
<div ng-show="addMovieForm">
<hr>
<h2>Add a Movie</h2>
<form ng-submit="addMovie()">
<div class="form-group">
<input type="text" class="form-control" ng-model="newMovie.title" placeholder="Title">
</div>
<input type="hidden" ng-model="newMovie.watched" value="false">
<input type="submit" class="btn btn-info btn-block">
</form>
</div>
</div>
<div class="col-md-4 col-md-offset-1">
<h2>Movies List</h2>
<hr>
<h3 ng-repeat="movie in moviesToWatch | orderBy:'title':reverse=true | limitTo:limit">{{ movie.title }} <button class="btn btn-warning btn-xs" ng-click="deleteMovie(movie)"><span class="glyphicon glyphicon-remove"></span></button></h3>
<a href="javascript:void(0)" ng-click="showMore()">View More...</a>
<hr>
<h4>Total: <ng-pluralize count="moviesToWatch.length"
when="{'0': 'No movies to watch.',
'1': '{} movie to watch',
'other': '{} movies to watch'}"></h4>
</div>
</div>
</div>
</body>
</html>