forked from spbooks/mean1
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Simon Mackie
committed
Dec 10, 2014
0 parents
commit 126f038
Showing
25 changed files
with
921 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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
var express = require('express'); | ||
var app = express(); | ||
|
||
// Route One | ||
app.get('/teams/:teamName/employees/:employeeId', function (req, res, next) { | ||
console.log('teamName = ' + req.params.teamName); | ||
console.log('employeeId = ' + req.params.employeeId); | ||
res.send('path one'); | ||
}); | ||
|
||
// Route Two | ||
app.get('/teams/:teamName/employees', function (req, res, next) { | ||
console.log('setting content type'); | ||
res.set('Content-Type', 'application/json'); | ||
res.locals.data = 100 ; | ||
next(); | ||
}, function (req, res, next) { | ||
console.log('teamName = ' + req.params.teamName); | ||
console.log(res.locals.data); | ||
res.send('path two'); | ||
}); | ||
|
||
// Route Three | ||
app.get(/^\/groups\/(\w+)\/(\d+)$/, function (req, res, next) { | ||
console.log('groupname = ' + req.params[0]); | ||
console.log('groupId = ' + req.params[1]); | ||
res.send('path three'); | ||
}); | ||
|
||
var server = app.listen(1337, function() { | ||
console.log('Server started on port 1337'); | ||
}); |
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,38 @@ | ||
var express = require('express'); | ||
var router = express.Router(); | ||
|
||
/* GET users listing. */ | ||
router.get('/', function(req, res, next) { | ||
setTimeout(function() { | ||
res.locals.users = [{ | ||
first: 'Abraham', | ||
last: 'Lincoln' | ||
}, { | ||
first: 'Andrew', | ||
last: 'Johnson' | ||
}, { | ||
first: 'Ulysses', | ||
last: 'Grant' | ||
}]; | ||
return next(); | ||
}, 1000) | ||
}, function (req, res, next) { | ||
res.locals.time = Date.now(); | ||
res.set({ | ||
'X-Special-Header': 'MEAN Stack' | ||
}); | ||
|
||
var view = '<!DOCTYPE html><html lang="en">' | ||
+ '<head><link rel="stylesheet" href="/stylesheets/style.css")' | ||
+ '<body><h1>User Output</h1><table>'; | ||
for (var i = 0, length = res.locals.users.length; i < length; i++) { | ||
var user = res.locals.users[i]; | ||
view += '<tr><td>' + user.first + '</td><td>' + user.last + '</td></tr>'; | ||
} | ||
|
||
view += '</table></body></html>'; | ||
|
||
res.send(view); | ||
}); | ||
|
||
module.exports = router; |
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,73 @@ | ||
var Hapi = require('hapi'); | ||
var server = new Hapi.Server('localhost', 3000); | ||
|
||
server.route({ | ||
method: 'GET', | ||
path: '/users', | ||
config: { | ||
handler: function (request, reply) { | ||
var result = {}; | ||
setTimeout(function () { | ||
result.users = [{ | ||
first: 'Abraham', | ||
last: 'Lincoln' | ||
}, { | ||
first: 'Andrew', | ||
last: 'Johnson' | ||
}, { | ||
first: 'Ulysses', | ||
last: 'Grant' | ||
}]; | ||
result.time = Date.now(); | ||
|
||
return reply(result).header('X-Special-Header', 'MEAN Stack'); | ||
}, 3000); | ||
} | ||
} | ||
}); | ||
|
||
var plug = { | ||
register: function (plugin, options, next) { | ||
plugin.route({ | ||
method: 'GET', | ||
path: options.prefix + '/view', | ||
config: { | ||
handler: function (request, reply) { | ||
request.server.inject({ | ||
url: '/users' | ||
}, function (res) { | ||
var users = res.result.users; | ||
var view = '<!DOCTYPE html><html lang="en"><body><h1>User Output</h1><table>'; | ||
|
||
for (var i = 0; i < users.length; i++) { | ||
var user = users[i]; | ||
view += '<tr><td>' + user.first + '</td><td>' + user.last + '</td></tr>'; | ||
} | ||
|
||
view += '</table></body></html>'; | ||
reply(view); | ||
}); | ||
} | ||
} | ||
}); | ||
|
||
next(); | ||
} | ||
}; | ||
plug.register.attributes = { | ||
name: 'viewer', | ||
version: '1.0.0' | ||
}; | ||
|
||
server.pack.register({ | ||
plugin: plug, | ||
options: { | ||
prefix: '/users' | ||
} | ||
}, function (err) { | ||
if (err) { | ||
console.log(err); | ||
} else { | ||
server.start(); | ||
} | ||
}); |
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,13 @@ | ||
<html lang="en" ng-app> | ||
<body> | ||
<input type="text" ng-model="firstName" placeholder="first name"> | ||
<input type="text" ng-model="lastName" placeholder="last name"> | ||
<h2>Gender {{gender}}</h2> | ||
<input type="radio" ng-model="gender" value="male" ng-click="style={color:'yellow'}">Male | ||
<input type="radio" ng-model="gender" value="female" ng-click="style={color:'orange'}">Female | ||
<br /> | ||
<h2 ng-style=style>Welcome {{firstName + ' ' + lastName}}</h2> | ||
<button ng-disabled="!(firstName.length && lastName.length)" ng-click="signup()">Sign Up</button> | ||
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.16/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,15 @@ | ||
var app = angular.module('app', []); | ||
app.controller('main', ['$scope', function($scope) { | ||
$scope.firstName = $scope.lastName = undefined; | ||
$scope.gender = 'female'; | ||
$scope.style = {color:'orange'}; | ||
|
||
$scope.signup = function () { | ||
var person = { | ||
first: $scope.firstName, | ||
last: $scope.lastName, | ||
gender: $scope.gender | ||
} | ||
console.log(person); | ||
}; | ||
}]); |
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,43 @@ | ||
<html lang="en" ng-app="app"> | ||
<body ng-controller="main"> | ||
<input type="text" ng-model="firstName" placeholder="first name"> | ||
<input type="text" ng-model="lastName" placeholder="first name"> | ||
<button ng-disabled="!(firstName.length && lastName.length)" ng-click="add()">Add</button> | ||
<table> | ||
<tr ng-repeat="p in presidents"> | ||
<td>{{p.first}}</td> | ||
<td>{{p.last}}</td> | ||
<td><button ng-click="$parent.remove(p)">Remove</button></td> | ||
</tr> | ||
</table> | ||
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.js"></script> | ||
<script> | ||
var app = angular.module('app', []); | ||
app.controller('main', ['$scope', function($scope) { | ||
$scope.presidents = [{ | ||
first: 'Abraham', | ||
last: 'Lincoln' | ||
}, { | ||
first: 'Andrew', | ||
last: 'Johnson' | ||
}, { | ||
first: 'Ulysses', | ||
last: 'Grant' | ||
}]; | ||
|
||
$scope.add = function () { | ||
$scope.presidents.push({ | ||
first: $scope.firstName, | ||
last: $scope.lastName | ||
}); | ||
|
||
$scope.firstName = $scope.lastName = ''; | ||
}; | ||
|
||
$scope.remove = function(president) { | ||
$scope.presidents.splice($scope.presidents.indexOf(president), 1 ); | ||
} | ||
}]); | ||
</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,60 @@ | ||
<html lang="en" ng-app="app"> | ||
<body> | ||
<div ng-controller="main"> | ||
<input type="text" ng-model="firstName" placeholder="first name"> | ||
<input type="text" ng-model="lastName" placeholder="first name"> | ||
<button ng-disabled="!(firstName.length && lastName.length)" ng-click="add()">Add</button> | ||
<table> | ||
<tr ng-repeat="p in employees"> | ||
<td>{{p.id}}</td> | ||
<td><span>{{p.first}} {{p.last}}</span></td> | ||
<td><button ng-click="$parent.remove(p)">Remove</button></td> | ||
</tr> | ||
</table> | ||
</div> | ||
<div ng-controller="logger"> | ||
<pre> | ||
<p ng-repeat="e in events track by $index">{{$index}} - {{e}}</p> | ||
</pre> | ||
</div> | ||
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.js"></script> | ||
<script> | ||
var app = angular.module('app', []); | ||
|
||
app.controller('main', ['$scope', '$http', '$rootScope', function($scope, $http, $rootScope) { | ||
$scope.employees = []; | ||
$scope.firstName = $scope.lastName = ''; | ||
|
||
$http.get('/employees').success(function(data) { | ||
$scope.employees = data; | ||
$rootScope.$emit('log', 'GET /employees success'); | ||
}); | ||
|
||
$scope.add = function () { | ||
$http.post('/employees', { | ||
first: $scope.firstName, | ||
last: $scope.lastName | ||
}).success(function(data) { | ||
$scope.employees.push(data); | ||
$scope.firstName = $scope.lastName = ''; | ||
$rootScope.$emit('log', 'POST /employees success'); | ||
}); | ||
}; | ||
|
||
$scope.remove = function(employee) { | ||
$http.delete('/employees/' + employee.id).success(function(data) { | ||
$scope.employees = data; | ||
$rootScope.$emit('log', 'DELETE /employees success'); | ||
}); | ||
} | ||
}]); | ||
app.controller('logger', ['$scope', '$rootScope', function ($scope, $rootScope) { | ||
$scope.events = []; | ||
|
||
$rootScope.$on('log', function (event, data) { | ||
$scope.events.push(data.trim()); | ||
}); | ||
}]); | ||
</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,73 @@ | ||
<html lang="en" ng-app="app"> | ||
<body> | ||
<div ng-controller="main"> | ||
<input type="text" ng-model="firstName" placeholder="first name"> | ||
<input type="text" ng-model="lastName" placeholder="first name"> | ||
<button ng-disabled="!(firstName.length && lastName.length)" ng-click="add()">Add</button> | ||
<table> | ||
<tr ng-repeat="p in employees"> | ||
<td>{{p.id}}</td> | ||
<td><span>{{p.first}} {{p.last}}</span></td> | ||
<td><button ng-click="$parent.remove(p)">Remove</button></td> | ||
</tr> | ||
</table> | ||
</div> | ||
<div ng-controller="logger"> | ||
<pre> | ||
<p ng-repeat="e in events track by $index">{{$index}} - {{e}}</p> | ||
</pre> | ||
</div> | ||
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.js"></script> | ||
<script> | ||
var app = angular.module('app', ['ngResource']); | ||
app.factory('EmployeeService', ['$resource', function($resource) { | ||
return $resource('/employees/:employeeId', {}, { | ||
get: { | ||
isArray: true | ||
}, | ||
post: { | ||
method: 'POST', | ||
isArray: false | ||
} | ||
}); | ||
}]); | ||
|
||
app.controller('main', ['$scope', 'EmployeeService', function($scope, EmployeeService) { | ||
$scope.employees = []; | ||
$scope.firstName = $scope.lastName = ''; | ||
|
||
EmployeeService.get(function (data) { | ||
$scope.employees = data; | ||
}); | ||
|
||
$scope.addDisabled = function () { | ||
return !($scope.firstName.trim().length && $scope.lastName.trim().length); | ||
} | ||
|
||
$scope.add = function () { | ||
EmployeeService.post({ | ||
first: $scope.firstName, | ||
last: $scope.lastName | ||
}, function (data) { | ||
$scope.employees.push(data); | ||
$scope.firstName = $scope.lastName = ''; | ||
}); | ||
}; | ||
$scope.remove = function(employee) { | ||
$http.delete('/employees/' + employee.id).success(function(data) { | ||
$scope.employees = data; | ||
$rootScope.$emit('log', 'DELETE /employees success'); | ||
}); | ||
} | ||
}]); | ||
|
||
app.controller('logger', ['$scope', '$rootScope', function ($scope, $rootScope) { | ||
$scope.events = []; | ||
|
||
$rootScope.$on('log', function (event, data) { | ||
$scope.events.push(data.trim()); | ||
}); | ||
}]); | ||
</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,6 @@ | ||
<fieldset> | ||
<legend>{{employee.first}} {{employee.last}}</legend> | ||
<input type="text" name="first" ng-model="employee.first"><label for="first">First Name</label> | ||
<input type="text" name="last" ng-model="employee.last"><label for="last">Last Name</label> | ||
</fieldset> | ||
<a href='#/view'>Back <<< </a> |
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,10 @@ | ||
<html lang="en" ng-app="app"> | ||
<body> | ||
<h1>Your Human Resource Application</h1> | ||
<ng-view></ng-view> | ||
</body> | ||
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.js"></script> | ||
<script src="//code.angularjs.org/1.2.16/angular-route.js"></script> | ||
<script src="//code.angularjs.org/1.2.16/angular-resource.js"></script> | ||
<script src="scripts/webapp.js"></script> | ||
</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,8 @@ | ||
<table> | ||
<tr ng-repeat="p in employees"> | ||
<td>{{p.id}}</td> | ||
<td>{{p.first}}</td> | ||
<td>{{p.last}}</td> | ||
<td><a href="#/edit/{{p.id}}">Edit >>> </a></td> | ||
</tr> | ||
</table> |
Oops, something went wrong.