This repository has been archived by the owner on Aug 25, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #61 - upgrade to recommended angular project structure
- Loading branch information
Showing
52 changed files
with
587 additions
and
1,002 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
File renamed without changes.
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,77 @@ | ||
(function (angular) { | ||
"use strict"; | ||
|
||
var app = angular.module('myApp.account', ['firebase', 'firebase.utils', 'firebase.auth', 'ngRoute']); | ||
|
||
app.controller('AccountCtrl', ['$scope', 'Auth', 'fbutil', 'user', '$location', '$firebaseObject', | ||
function($scope, Auth, fbutil, user, $location, $firebaseObject) { | ||
var unbind; | ||
// create a 3-way binding with the user profile object in Firebase | ||
var profile = $firebaseObject(fbutil.ref('users', user.uid)); | ||
profile.$bindTo($scope, 'profile').then(function(ub) { unbind = ub; }); | ||
|
||
// expose logout function to scope | ||
$scope.logout = function() { | ||
if( unbind ) { unbind(); } | ||
profile.$destroy(); | ||
Auth.$unauth(); | ||
$location.path('/login'); | ||
}; | ||
|
||
$scope.changePassword = function(pass, confirm, newPass) { | ||
resetMessages(); | ||
if( !pass || !confirm || !newPass ) { | ||
$scope.err = 'Please fill in all password fields'; | ||
} | ||
else if( newPass !== confirm ) { | ||
$scope.err = 'New pass and confirm do not match'; | ||
} | ||
else { | ||
Auth.$changePassword({email: profile.email, oldPassword: pass, newPassword: newPass}) | ||
.then(function() { | ||
$scope.msg = 'Password changed'; | ||
}, function(err) { | ||
$scope.err = err; | ||
}) | ||
} | ||
}; | ||
|
||
$scope.clear = resetMessages; | ||
|
||
$scope.changeEmail = function(pass, newEmail) { | ||
resetMessages(); | ||
var oldEmail = profile.email; | ||
Auth.$changeEmail({oldEmail: oldEmail, newEmail: newEmail, password: pass}) | ||
.then(function() { | ||
// store the new email address in the user's profile | ||
return fbutil.handler(function(done) { | ||
fbutil.ref('users', user.uid, 'email').set(newEmail, done); | ||
}); | ||
}) | ||
.then(function() { | ||
$scope.emailmsg = 'Email changed'; | ||
}, function(err) { | ||
$scope.emailerr = err; | ||
}); | ||
}; | ||
|
||
function resetMessages() { | ||
$scope.err = null; | ||
$scope.msg = null; | ||
$scope.emailerr = null; | ||
$scope.emailmsg = null; | ||
} | ||
} | ||
]); | ||
|
||
app.config(['$routeProvider', function($routeProvider) { | ||
// require user to be authenticated before they can access this page | ||
// this is handled by the .whenAuthenticated method declared in | ||
// components/router/router.js | ||
$routeProvider.whenAuthenticated('/account', { | ||
templateUrl: 'account/account.html', | ||
controller: 'AccountCtrl' | ||
}) | ||
}]); | ||
|
||
})(angular); |
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 @@ | ||
|
||
describe('myApp.account', function() { | ||
beforeEach(function() { | ||
module('myApp'); | ||
module('myApp.account'); | ||
}); | ||
|
||
describe('AccountCtrl', function() { | ||
var accountCtrl, $scope; | ||
beforeEach(function() { | ||
module(function($provide) { | ||
// comes from routes.js in the resolve: {} attribute | ||
$provide.value('user', {uid: 'test123'}); | ||
}); | ||
|
||
inject(function($controller) { | ||
$scope = {}; | ||
accountCtrl = $controller('AccountCtrl', {$scope: $scope}); | ||
}); | ||
}); | ||
|
||
it('should define logout method', function() { | ||
expect(typeof $scope.logout).toBe('function'); | ||
}); | ||
|
||
it('should define changePassword method', function() { | ||
expect(typeof $scope.changePassword).toBe('function'); | ||
}); | ||
|
||
it('should define changeEmail method', function() { | ||
expect(typeof $scope.changeEmail).toBe('function'); | ||
}); | ||
|
||
it('should define clear method', function() { | ||
expect(typeof $scope.clear).toBe('function'); | ||
}); | ||
}); | ||
}); |
File renamed without changes.
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,18 @@ | ||
'use strict'; | ||
|
||
// Declare app level module which depends on filters, and services | ||
angular.module('myApp', [ | ||
'myApp.config', | ||
'myApp.security', | ||
'myApp.home', | ||
'myApp.account', | ||
'myApp.chat', | ||
'myApp.login' | ||
]) | ||
|
||
.run(['$rootScope', 'Auth', function($rootScope, Auth) { | ||
// track status of authentication | ||
Auth.$onAuth(function(user) { | ||
$rootScope.loggedIn = !!user; | ||
}); | ||
}]); |
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
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 @@ | ||
(function (angular) { | ||
"use strict"; | ||
|
||
var app = angular.module('myApp.chat', ['ngRoute', 'firebase.utils', 'firebase']); | ||
|
||
app.controller('ChatCtrl', ['$scope', 'messageList', function($scope, messageList) { | ||
$scope.messages = messageList; | ||
$scope.addMessage = function(newMessage) { | ||
if( newMessage ) { | ||
$scope.messages.$add({text: newMessage}); | ||
} | ||
}; | ||
}]); | ||
|
||
app.factory('messageList', ['fbutil', '$firebaseArray', function(fbutil, $firebaseArray) { | ||
var ref = fbutil.ref('messages').limitToLast(10); | ||
return $firebaseArray(ref); | ||
}]); | ||
|
||
app.config(['$routeProvider', function($routeProvider) { | ||
$routeProvider.when('/chat', { | ||
templateUrl: 'chat/chat.html', | ||
controller: 'ChatCtrl' | ||
}); | ||
}]); | ||
|
||
})(angular); |
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,18 @@ | ||
|
||
describe('myApp.chat', function() { | ||
beforeEach(module('myApp.chat')); | ||
|
||
describe('ChatCtrl', function() { | ||
var chatCtrl, $scope; | ||
beforeEach(function() { | ||
inject(function($controller) { | ||
$scope = {}; | ||
chatCtrl = $controller('ChatCtrl', {$scope: $scope}); | ||
}); | ||
}); | ||
|
||
it('creates messages array in scope', function() { | ||
expect(Object.prototype.toString.call($scope.messages)).toBe('[object Array]'); | ||
}); | ||
}); | ||
}); |
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,12 @@ | ||
'use strict'; | ||
|
||
/* Directives */ | ||
|
||
|
||
angular.module('myApp') | ||
|
||
.directive('appVersion', ['version', function(version) { | ||
return function(scope, elm) { | ||
elm.text(version); | ||
}; | ||
}]); |
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,21 @@ | ||
'use strict'; | ||
|
||
/* jasmine specs for directives go here */ | ||
|
||
describe('app-version directive', function() { | ||
beforeEach(function() { | ||
module('mock.firebase'); | ||
module('myApp'); | ||
}); | ||
|
||
it('should print current version', function() { | ||
module(function($provide) { | ||
$provide.constant('version', 'TEST_VER'); | ||
}); | ||
inject(function($compile, $rootScope) { | ||
var element = $compile('<span app-version></span>')($rootScope); | ||
expect(element.text()).toEqual('TEST_VER'); | ||
}); | ||
}); | ||
|
||
}); |
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 @@ | ||
angular.module('firebase.auth', ['firebase', 'firebase.utils']) | ||
.factory('Auth', ['$firebaseAuth', 'fbutil', function($firebaseAuth, fbutil) { | ||
return $firebaseAuth(fbutil.ref()); | ||
}]); |
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 @@ | ||
"use strict"; | ||
describe('Auth', function() { | ||
beforeEach(function() { | ||
module('mock.firebase'); | ||
module('firebase.auth'); | ||
}); | ||
|
||
it('should return $firebaseAuth instance', function() { | ||
inject(function (Auth, $firebaseAuth) { | ||
var ref = new MockFirebase(); | ||
var testInst = $firebaseAuth(ref); | ||
expect(Auth.prototype === testInst.prototype).toBe(true); | ||
}); | ||
}); | ||
}); |
File renamed without changes.
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,19 @@ | ||
"use strict"; | ||
describe('fbutil', function() { | ||
beforeEach(function() { | ||
module('mock.firebase'); | ||
module('firebase.utils'); | ||
}); | ||
|
||
describe('handler', function() { | ||
it('should have tests'); | ||
}); | ||
|
||
describe('defer', function() { | ||
it('should have tests'); | ||
}); | ||
|
||
describe('ref', function() { | ||
it('should have tests'); | ||
}); | ||
}); |
17 changes: 9 additions & 8 deletions
17
app/js/decorators.js → app/components/ngcloak/ngcloak-decorator.js
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
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 @@ | ||
'use strict'; | ||
|
||
/* Filters */ | ||
|
||
angular.module('myApp') | ||
.filter('reverse', function() { | ||
return function(items) { | ||
return items.slice().reverse(); | ||
}; | ||
}); |
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 @@ | ||
describe('reverse', function() { | ||
var reverse; | ||
beforeEach(function() { | ||
module('myApp'); | ||
inject(function (reverseFilter) { | ||
reverse = reverseFilter; | ||
}); | ||
}); | ||
|
||
it('should reverse contents of an array', function() { | ||
expect(reverse([3,2,1])).toEqual([1,2,3]); | ||
}); | ||
}); |
Oops, something went wrong.