Skip to content

Commit

Permalink
reset for oslo
Browse files Browse the repository at this point in the history
  • Loading branch information
OdeToCode committed May 31, 2014
1 parent 64ef2f2 commit bda9a7a
Show file tree
Hide file tree
Showing 29 changed files with 1,030 additions and 0 deletions.
37 changes: 37 additions & 0 deletions README.md
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.




1 change: 1 addition & 0 deletions clients/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bower_components/*
28 changes: 28 additions & 0 deletions clients/bower.json
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"
}
}
27 changes: 27 additions & 0 deletions clients/index.html
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>
25 changes: 25 additions & 0 deletions clients/ng/default.html
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>
4 changes: 4 additions & 0 deletions clients/ng/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
body{
padding:10px;
background-color: #ccccbb;
}
15 changes: 15 additions & 0 deletions servers/node/.gitignore
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
11 changes: 11 additions & 0 deletions servers/node/app.js
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!!");

36 changes: 36 additions & 0 deletions servers/node/controllers/movies.js
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);
};

56 changes: 56 additions & 0 deletions servers/node/data/movieDataSource.js
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
};
64 changes: 64 additions & 0 deletions servers/node/gruntfile.js
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");
};
35 changes: 35 additions & 0 deletions servers/node/models/movie.js
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;
16 changes: 16 additions & 0 deletions servers/node/package.json
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"
}
}
11 changes: 11 additions & 0 deletions servers/node/routes/index.js
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);
};
Loading

0 comments on commit bda9a7a

Please sign in to comment.