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

Angular #7

Open
wants to merge 3 commits into
base: basicAuth
from
Open

Angular #7

Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -2,3 +2,4 @@ node_modules/
**/bower_components/
db/

dist/
@@ -24,9 +24,9 @@ module.exports = function(grunt) {
all: {
expand: true,
cwd: 'app/',
src: ['*.css', '*.html', '/images/**/*', '!Gruntfile.js'],
src: ['*.css', '*.html', 'views/*.html', '/images/**/*', '!Gruntfile.js'],
dest: 'dist/',
flatten: true,
flatten: false,
filter: 'isFile'
},
},
@@ -75,11 +75,12 @@ module.exports = function(grunt) {
},
watch: {
scripts: {
files: ['app/js/**/*.js','test/**/*.js']
files: ['app/js/**/*.js', 'app/bower_components/**/*.js', 'test/**/*.js', 'app/**/*.html'],
tasks: ['build']
},
express: {
files: ['server.js'],
tasks: ['browserify'],
files: ['server.js', 'routes/*.js', 'models/*.js'],
tasks: ['server'],
options: {
spawn: false
}
@@ -102,7 +103,7 @@ module.exports = function(grunt) {

});

grunt.registerTask('serve', [ 'shell', 'build', 'express:dev','watch' ]);
grunt.registerTask('serve', [ 'build', 'express:dev','watch' ]);
grunt.registerTask('server', 'serve');
grunt.registerTask('test:acceptance',['express:dev','casper']);
grunt.registerTask('test:api','simplemocha');
@@ -2,10 +2,12 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jQuery Browserify Ajax Demo</title>
<title>Angular Note Demo</title>
</head>
<body>
<ul id="notes"></ul>
<div ng-app="notesApp">
<div ng-view></div>
</div>
<script src="client.js" charset="utf-8"></script>
</body>
</html>
</html>

This file was deleted.

@@ -0,0 +1,31 @@
require('angular/angular');
require('angular-route');
require('angular-resource');
require('angular-base64');
require('angular-cookies');

var notesApp = angular.module('notesApp', ['ngRoute', 'base64', 'ngCookies']);

require('./controllers/notesController')(notesApp);
require('./controllers/newNotesController')(notesApp);
require('./controllers/signInController')(notesApp);

notesApp.config(['$routeProvider', function($routeProvider) {
$routeProvider
.when('/notes', {
templateUrl: 'views/notes.html',
controller: 'NotesController'
})
.when('/notes/new', {
templateUrl: 'views/newNote.html',
controller: 'NewNotesController'
})
.when('/signin', {
templateUrl: 'views/signIn.html',
controller: 'SignInController'
})
.otherwise({
redirectTo: '/signin'
});
}]);

@@ -0,0 +1,16 @@
'use strict';

module.exports = function(app) {
app.controller('NewNotesController', function($scope, $http, $location, $log) {
$scope.note = {'noteBody' : ''};
$scope.saveNote = function() {
$http.post('/api/v1/notes', $scope.note)
.success(function(data, status, headers, config) {
$location.path('/notes')
})
.error(function(data) {
$log.warn(data);
});
};
});
};
@@ -0,0 +1,15 @@
'use strict';

module.exports = function(app) {
app.controller('NotesController', function($scope, $http, $cookies) {
$http.defaults.headers.common['jwt'] = $cookies.jwt;
$http({
method: 'GET',
url: '/api/v1/notes'
}).success(function(data, status, headers, config) {
$scope.notes = data;
}).error(function(data, status, headers, config) {
console.log(data);
});
});
};
@@ -0,0 +1,17 @@
module.exports = function(app) {
app.controller('SignInController', function($scope, $http, $base64, $cookies, $location, $log) {
$scope.signIn = function() {
$http.defaults.headers.common['Authorization'] = 'Basic ' + $base64.encode($scope.user.email + ':' + $scope.user.password);
$http({
method: "GET",
url: '/api/v1/users',
data: {}
}).success(function(data) {
$cookies.jwt = data.jwt;
$location.path('/notes');
}).error(function(data) {
console.log(data);
});
}
});
}
@@ -0,0 +1,5 @@
<div ng-controller="NewNotesController">
<label>New Note</label></br>
<input type="text" ng-model="note.noteBody">
<button ng-click="saveNote()">Save Note</button>
</div>
@@ -0,0 +1,8 @@
<div ng-controller="NotesController">
<h3>Notes</h3>
<a ng-href="#/notes/new">New Note</a>
<div ng-repeat="note in notes">
<p>{{note.noteBody}}</p>
</div>
</div>

@@ -0,0 +1,9 @@
<div ng-controller="SignInController">
<h3>Sign In</h3>
<label>Email</label>
<input type="text" ng-model="user.email">
<label>Password</label>
<input type="password" ng-model="user.password">
<button ng-click="signIn()">Sign In</button>
</div>

@@ -17,6 +17,10 @@
"tests"
],
"dependencies": {
"jquery": "~2.1.1"
"angular": "*",
"angular-route": "~1.2.17",
"angular-resource": "~1.2.17",
"angular-base64": "~2.0.2",
"angular-cookies": "~1.2.18"
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.