-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
1,030 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,40 @@ | ||
ndc_oslo_angularjs | ||
==================== | ||
Code for the AngularJS Workshop | ||
|
||
The code here supports two server environments: ASP.NET or Node.js. Pick the environment | ||
you'd like to work in and follow the instructions below. | ||
|
||
Note that some parts of the course will be using Node.js tools regardless of the server environment you choose to work with. | ||
|
||
For an ASP.NET server | ||
==================== | ||
|
||
Go to servers/webapi and open "AtTheMovies.sln" in Visual Studio 2013. Build the solution to restore all | ||
NuGet packages. | ||
|
||
There are two project inside. "AtTheMovies.csproj" is the server for the workshop. We won't make any changes here, but you | ||
do want to make sure the project is set to be the start project. Press CTRL+F5 to run, and the server should listen on port 8080. | ||
Use a browser and navigate to http://localhost:8080 to make sure the server is functioning. | ||
|
||
The "clients" project in this solution is the place where we will be editing files and adding code for AngularJS. You never want | ||
to launch or execute this project, it is for file editing only. | ||
|
||
For a NodeJS server | ||
==================== | ||
Make sure you have bower and grunt-cli installed globally. | ||
npm install bower -g | ||
npm install grunt-cli -g | ||
|
||
Go to the clients folder and run: | ||
bower install | ||
|
||
Go to the servers\node folder and run: | ||
npm install | ||
grunt | ||
|
||
You should now have a server running at http://localhost:3000, try it in a browser to make sure the server is running properly. | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
bower_components/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "AtTheMovies", | ||
"version": "0.0.1", | ||
"homepage": "https://github.com/OdeToCode/AtTheMovies", | ||
"authors": [ | ||
"K. Scott Allen <[email protected]>" | ||
], | ||
"license": "MIT", | ||
"private": true, | ||
"ignore": [ | ||
"**/.*", | ||
"node_modules", | ||
"bower_components", | ||
"test", | ||
"tests" | ||
], | ||
"dependencies": { | ||
"angular": "~1.2.13", | ||
"angular-route": "~1.2.13", | ||
"angular-animate": "~1.2.13", | ||
"bootstrap": "~3.1.1", | ||
"animate.css": "~3.1.0", | ||
"angular-resource": "~1.2.14", | ||
"angular-ui-router": "~0.2.10", | ||
"angular-bootstrap": "~0.10.0", | ||
"jasmine": "2.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<html ng-app> | ||
<head> | ||
<link rel="stylesheet" href="/bower_components/bootstrap/dist/css/bootstrap.css"> | ||
</head> | ||
<body class="container"> | ||
|
||
<nav class="navbar navbar-default navbar-inverse" role="navigation"> | ||
<div class="container-fluid"> | ||
<div class="navbar-header"> | ||
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-collapse"> | ||
<span class="sr-only">Toggle navigation</span> | ||
<span class="icon-bar"></span> | ||
<span class="icon-bar"></span> | ||
<span class="icon-bar"></span> | ||
</button> | ||
<a class="navbar-brand" href="#">Workshop!</a> | ||
</div> | ||
<div class="collapse navbar-collapse" id="navbar-collapse"> | ||
<ul class="nav navbar-nav"> | ||
<li><a href="/ng/default.html">Angular</a></li> | ||
</ul> | ||
</div> | ||
</div> | ||
</nav> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<html> | ||
|
||
<head> | ||
<link rel="stylesheet" href="/bower_components/bootstrap/dist/css/bootstrap.css"> | ||
<link rel="stylesheet" href="/ng/styles.css"> | ||
</head> | ||
|
||
<body class="container"> | ||
|
||
<nav class="navbar navbar-default navbar-inverse" role="navigation"> | ||
<div class="container-fluid"> | ||
<div class="navbar-header"> | ||
<a class="navbar-brand" href="#">At The Movies (NG)</a> | ||
</div> | ||
</div> | ||
</nav> | ||
|
||
<div class="row"> | ||
<div class="col-md-12">This is where we start...</div> | ||
</div> | ||
|
||
<script src="/bower_components/angular/angular.js"></script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
body{ | ||
padding:10px; | ||
background-color: #ccccbb; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
lib-cov | ||
*.seed | ||
*.log | ||
*.csv | ||
*.dat | ||
*.out | ||
*.pid | ||
*.gz | ||
|
||
pids | ||
logs | ||
results | ||
|
||
node_modules | ||
npm-debug.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
var express = require("express"); | ||
var app = express(); | ||
|
||
app.use(express.bodyParser()); | ||
app.use("/", express.static(__dirname + "/../../clients")); | ||
|
||
var routes = require("./routes")(app); | ||
|
||
app.listen(process.env.PORT || 3000); | ||
console.log("Started!!"); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
var dataSource = require("../data/movieDataSource"); | ||
|
||
exports.getAllMovies = function(request, response) { | ||
var movies = dataSource.getAll(); | ||
response.send(movies); | ||
}; | ||
|
||
exports.getMovieById = function(request, response) { | ||
var movie = dataSource.getById(request.params.id); | ||
response.send(movie); | ||
}; | ||
|
||
exports.getMovieByIdSlowly = function(request, response) { | ||
var movie = dataSource.getById(request.params.id); | ||
setTimeout(function(){ | ||
response.send(movie); | ||
}, 3000); | ||
}; | ||
|
||
exports.updateMovie = function(request, response) { | ||
var movie = request.body; | ||
dataSource.update(movie); | ||
response.send(movie); | ||
}; | ||
|
||
exports.createMovie = function(request, response) { | ||
var movie = request.body; | ||
dataSource.create(movie); | ||
response.status(201).send(movie); | ||
}; | ||
|
||
exports.deleteMovie = function(request, response) { | ||
var removed = dataSource.delete(request.params.id); | ||
response.status(200).send(removed); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
var _ = require("lodash"); | ||
var Movie = require("../models/Movie"); | ||
|
||
var id = 4; | ||
var movies = []; | ||
|
||
movies.push(new Movie(1, "Star Wars", 5, 1977)); | ||
movies.push(new Movie(2, "Casablanca", 4, 1942)); | ||
movies.push(new Movie(3, "Jurassic Park", 3, 1993)); | ||
|
||
var getAll = function() { | ||
return movies; | ||
}; | ||
|
||
var getById = function(id) { | ||
var result = _.find(movies, { | ||
id: parseInt(id) | ||
}); | ||
return result; | ||
}; | ||
|
||
var update = function(updatedMovie) { | ||
|
||
var movie = _.find(movies, { | ||
id: parseInt(updatedMovie.id) | ||
}); | ||
|
||
if (movie) { | ||
movie.title = updatedMovie.title; | ||
movie.rating = updatedMovie.rating; | ||
movie.year = updatedMovie.year; | ||
} else { | ||
throw "Movie not found"; | ||
} | ||
}; | ||
|
||
var create = function(movie) { | ||
movie.id = id++; | ||
movies.push(movie); | ||
return movie; | ||
}; | ||
|
||
var remove = function(id) { | ||
var removed = _.remove(movies, { | ||
id: parseInt(id) | ||
}); | ||
return _.first(removed); | ||
}; | ||
|
||
module.exports = { | ||
getAll: getAll, | ||
getById: getById, | ||
update: update, | ||
create: create, | ||
delete: remove | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
var serverJs = [ | ||
"*.js", | ||
"routes/*.js", | ||
"controllers/*.js", | ||
"data/*.js", | ||
"models/*.js" | ||
]; | ||
|
||
var clientJs = [ | ||
"../../clients/ng/**/*.js" | ||
]; | ||
|
||
var html = [ | ||
"../../clients/index.html", | ||
"../../clients/ng/**/*.html" | ||
]; | ||
|
||
module.exports = function(grunt) { | ||
|
||
grunt.initConfig({ | ||
|
||
express: { | ||
dev: { | ||
options: { | ||
script: "app.js" | ||
} | ||
} | ||
}, | ||
|
||
jshint: { | ||
files: serverJs | ||
}, | ||
|
||
watch: { | ||
|
||
options: { | ||
livereload: true | ||
}, | ||
|
||
jshint: { | ||
files: serverJs.concat(clientJs), | ||
tasks: ["jshint"] | ||
}, | ||
|
||
express: { | ||
files: serverJs, | ||
tasks: ["express:dev"], | ||
options: { | ||
spawn: false | ||
} | ||
}, | ||
|
||
html: { | ||
files: html | ||
} | ||
} | ||
}); | ||
|
||
grunt.registerTask("default", ["express:dev", "watch"]); | ||
|
||
grunt.loadNpmTasks("grunt-contrib-jshint"); | ||
grunt.loadNpmTasks("grunt-contrib-watch"); | ||
grunt.loadNpmTasks("grunt-express-server"); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
var Movie = function(id, title, rating, year){ | ||
this.id = id || 0; | ||
this.title = title || ""; | ||
this.rating = rating || 1; | ||
this.year = year || 1900; | ||
}; | ||
|
||
Movie.prototype = { | ||
|
||
validate: function() { | ||
var errors = []; | ||
|
||
if(parseInt(this.id) < 0){ | ||
result.errors.push({id: "ID must be a positive integer"}); | ||
} | ||
|
||
if(!title){ | ||
result.errors.push({title: "Title is required"}); | ||
} | ||
|
||
var rating = parseInt(this.rating); | ||
if(rating < 1 || rating > 5){ | ||
result.errors.push({rating: "Rating must be between 1 and 5"}); | ||
} | ||
|
||
var year = parseInt(this.year); | ||
if(year < 1800 || year > 2100){ | ||
result.errors.push({year: "Year must be between 1800 and 2100"}); | ||
} | ||
|
||
return result; | ||
} | ||
}; | ||
|
||
module.exports = Movie; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "AtTheMovies", | ||
"version": "0.0.1", | ||
"description": "", | ||
"main": "app.js", | ||
"dependencies": { | ||
"express": "~3.4.8", | ||
"lodash": "~2.4.1" | ||
}, | ||
"devDependencies": { | ||
"grunt": "~0.4.2", | ||
"grunt-express-server": "~0.4.13", | ||
"grunt-contrib-watch": "~0.5.3", | ||
"grunt-contrib-jshint": "~0.8.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
var movie = require("../controllers/movies.js"); | ||
|
||
module.exports = function(app) { | ||
|
||
app.get("/api/movies", movie.getAllMovies); | ||
app.get("/api/movies/slow/:id", movie.getMovieByIdSlowly); | ||
app.get("/api/movies/:id", movie.getMovieById); | ||
app.put("/api/movies", movie.updateMovie); | ||
app.post("/api/movies", movie.createMovie); | ||
app.delete("/api/movies/:id", movie.deleteMovie); | ||
}; |
Oops, something went wrong.