Skip to content

Instantly share code, notes, and snippets.

@morenoh149
Created February 23, 2014 09:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save morenoh149/9169224 to your computer and use it in GitHub Desktop.
Save morenoh149/9169224 to your computer and use it in GitHub Desktop.
'use strict';
/**
* The Project factory handles saving and loading projects
* from firebase, and also lets us save and load the
* last active project index.
*/
app.factory('Projects', function($firebase, FIREBASE_URL, $scope) {
var ref = new Firebase(FIREBASE_URL + 'projects');
var firebase_projects = $firebase(ref);
var keys = firebase_projects.$getIndex();
console.log(keys);
var Projects = {
all: function () {
return firebase_projects;
},
save: function(client_projects) {
firebase_projects.$save(client_projects);
},
newProject: function(projectTitle) {
// Add a new project
return {
title: projectTitle,
tasks: []
};
},
getLastActiveIndex: function () {
var keys = firebase_projects.$getIndex();
//console.log(firebase_projects);
return parseInt(window.localStorage['lastActiveProject']) || keys[0];
},
setLastActiveIndex: function (index) {
window.localStorage['lastActiveProject'] = index;
}
}
return Projects;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment