Cleaned up examples folder

This commit is contained in:
Max Lynch
2013-11-07 10:01:01 -06:00
parent 53bae2af16
commit eb7bc3edba
35 changed files with 0 additions and 218 deletions

View File

@ -0,0 +1,16 @@
angular.module('ionic.todo', [
'ionic.todo.filters',
'ionic.todo.services',
'ionic.todo.controllers',
'ionic.service.modal',
'ionic.service.actionSheet',
'ionic.ui',
'firebase',
'ngRoute',
'ngAnimate'])
// Our Firebase URL
.constant('FIREBASE_URL', 'https://ionic-todo-demo.firebaseio.com/todo');

View File

@ -0,0 +1,224 @@
angular.module('ionic.todo.controllers', ['ionic.todo'])
// The main controller for the application
.controller('TodoCtrl', function($scope, $rootScope, AuthService) {
$scope.candy = 'yes';
$scope.navController.pushFromTemplate('splash.html');
$rootScope.$on('angularFireAuth:login', function(evt, user) {
$scope.navController.pushFromTemplate('tasks.html');
});
$rootScope.$on('angularFireAuth:logout', function(evt, user) {
$scope.navController.pushFromTemplate('signup.html');
});
$rootScope.$on('angularFireAuth:error', function(evt, err) {
$scope.navController.pushFromTemplate('signup.html');
});
})
.controller('SplashCtrl', function($scope) {
})
// The login form controller
.controller('LoginCtrl', function($scope, $rootScope, AuthService) {
console.log('Created login Ctrl');
$scope.loginForm = {
email: 'ihasmax@gmail.com',
password: 'traintown'
};
$scope.close = function() {
$scope.modal.hide();
};
$scope.tryLogin = function(data) {
$scope.loginError = false;
AuthService.login(data.email, data.password)
.then(function(e) {
$scope.loginError = false;
}, function(e) {
$scope.loginError = true;
});
};
$rootScope.$on('angularFireAuth:login', function(evt, user) {
$scope.modal.hide();
});
})
// The signup form controller
.controller('SignupCtrl', function($scope, AuthService, Modal, ActionSheet) {
$scope.signupForm = {};
Modal.fromTemplateUrl('login.html', function(modal) {
$scope.loginModal = modal;
});
$scope.trySignup = function(data) {
AuthService.signup(data.email, data.password);
};
$scope.showLogin = function() {
$scope.loginModal && $scope.loginModal.show();
};
})
// The tasks controller (main app controller)
.controller('TasksCtrl', function($scope, angularFire, angularFireCollection, Modal, ActionSheet, FIREBASE_URL) {
/*
var lastProjectRef = new Firebase(FIREBASE_URL + '/lastproject');
var lastProjectPromise = angularFire(lastProjectRef, $scope, 'lastProject');
$scope.lastProject = null;
*/
$scope.isEditingProjects = false;
// Load our settings modal
Modal.fromTemplateUrl('settings.html', function(modal) {
$scope.settingsModal = modal;
});
$scope.newProject = {};
$scope.newTask = {};
$scope.showSettings = function() {
$scope.settingsModal && $scope.settingsModal.show();
};
/**
* Add a new tasks to the current project.
*/
$scope.addTask = function(task) {
if(!$scope.activeProject) {
return;
}
if(!$scope.activeProject.tasks) {
$scope.activeProject.tasks = [];
}
var task = $scope.activeProject.tasks.add({
title: task.title,
user_id: $scope.user.id,
isCompleted: false
});
task.setPriority(-(+new Date));
// Set the priorty for this project to the new date, so it will
// sort higher
//$scope.activeProject.project.setPriority(-(+new Date));
$scope.newTask = {};
};
/**
* Set the current project
*/
$scope.setActiveProject = function(project) {
// Grab the ref. It's the object on new project, and the $ref
// object on exist (for example, from the ng-repeat)
var ref = project;
if(project.$ref) {
ref = project.$ref;
}
$scope.activeProject = {
project: ref,
title: project.title,
tasks: angularFireCollection(ref.child('tasks').limit(100))
};
};
$scope.selectProject = function(project) {
$scope.setActiveProject(project);
$scope.sideMenuCtrl.close();
};
/**
* Add a project to the projects list.
*/
$scope.addProject = function(newProject) {
var p = {
title: newProject.title,
user_id: $scope.user.id,
tasks: [],
};
console.log("Adding project:", p);
// Reset the form
$scope.newProject = {};
var np = $scope.projects.add(p);
//np.setPriority(-(+new Date));
$scope.setActiveProject(np);
// Set these explicitly, some firebase delay or something happening
// here.
$scope.activeProject.title = newProject.title;
$scope.activeProject.user_id = newProject.user_id;
$scope.sideMenuCtrl.close();
};
$scope.deleteProject = function(project) {
var ref = project;
ActionSheet.show({
buttons: [],
destructiveText: 'Delete Project',
cancelText: 'Cancel',
cancel: function() {
return true;
},
destructiveButtonClicked: function() {
if(project.$ref) {
ref = project.$ref;
}
ref.remove();
return true;
}
});
};
$scope.toggleProjectEditing = function() {
$scope.isEditingProjects = !$scope.isEditingProjects;
};
var projectsRef = new Firebase(FIREBASE_URL + '/project_list');
$scope.projects = angularFireCollection(projectsRef.limit(100), function(snapshot) {
if(!snapshot.val()) {
var title = prompt('Create your first list:');
if(title) {
$scope.addProject({
title: title
});
}
}
});
// Listen for the first child added so we can set it as the active project
projectsRef.once('child_added', function(snapshot, prevChildName) {
$scope.setActiveProject(
angular.extend({
'$ref': snapshot.ref(),
}, snapshot.val())
)
});
projectsRef.on('child_added', function(snapshot, prevChildName) {
console.log('CHILD ADDED', snapshot.val());
});
})
.controller('SettingsCtrl', function($scope, AuthService) {
$scope.close = function() {
$scope.modal.hide();
}
$scope.logout = function() {
AuthService.logout();
};
})

View File

@ -0,0 +1,11 @@
angular.module('ionic.todo.filters', [])
.filter('reverse', function() {
return function(items) {
if(items) {
return items.slice().reverse();
}
return [];
};
});

View File

@ -0,0 +1,49 @@
angular.module('ionic.todo.services', ['ionic.todo', 'firebase'])
// The AuthService handles user authentication with Firebase.
.factory('AuthService', function(angularFireAuth, $rootScope, FIREBASE_URL) {
// Initialize the angularFireAuth service.
var ref = new Firebase(FIREBASE_URL);
angularFireAuth.initialize(ref, {
scope: $rootScope,
callback: function(user, err) {
console.log('AUTH CHANGED', err, user);
},
name: 'user'
});
return {
// Try to log in with the given email and pass
login: function(email, password) {
if(!email || !password) {
return;
}
console.log('Logging in', email, password);
return angularFireAuth.login('password', {
email: email,
password: password
});
},
logout: function() {
angularFireAuth.logout();
},
// Try to sign up with the given email and pass
signup: function(email, password) {
if(!email || !password) {
return;
}
console.log('Signing up', name, email, password);
angularFireAuth.createUser(email, password, function(err, user) {
if(err && err.code == "EMAIL_TAKEN") {
alert('That email is already taken');
}
});
}
};
})