Skip to content

Commit

Permalink
integracion firebase lokijs funcionando correctamente
Browse files Browse the repository at this point in the history
  • Loading branch information
correasebastian committed Dec 19, 2015
1 parent 8a0ec5b commit 2845e1b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
2 changes: 1 addition & 1 deletion www/css/style.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Empty. Add your own CSS if you like */
.ns{
background-color: red;
background-color: rgba(243, 59, 52, 0.72);
}
41 changes: 35 additions & 6 deletions www/js/birthday.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ var db, birthdays, fbA, tm, temp;
function validateTempCollection() {
_temp = _db.getCollection('temp');



if (!_temp) {
_temp = _db.addCollection('temp', {
indices: ['fbKey'],
Expand All @@ -148,6 +150,29 @@ var db, birthdays, fbA, tm, temp;
}

temp = _temp;
trySync();
}

function trySync() {
_temp.data.forEach(function(obj, i) {
console.log(obj, i);
_bdRef.child(obj.fbKey).set(obj.fbVal, syncCb(obj.fbKey));
});
}

function syncCb(fbKey) {

function cbFb(error) {
if (error) {
console.error('error');
} else {
console.log('inserted to sync');
removeTempbyId(fbKey);
}
}

return cbFb;
// body...
}

function getBirthdays() {
Expand Down Expand Up @@ -264,9 +289,7 @@ var db, birthdays, fbA, tm, temp;
function oK(ref) {
var fbKey = ref.key();
console.log('ok', fbKey, ref);
_temp.removeWhere({
'fbKey': fbKey
});
removeTempbyId(fbKey);
}

function eR(error) {
Expand All @@ -285,6 +308,12 @@ var db, birthdays, fbA, tm, temp;
return _bd;
}

function removeTempbyId(fbKey) {
_temp.removeWhere({
'fbKey': fbKey
});
}


function syncFb() {

Expand All @@ -293,9 +322,9 @@ var db, birthdays, fbA, tm, temp;
function getTempById(key) {

// $timeout(function() {
var obj = temp.by('fbKey', key);
console.log('obj', obj);
return obj;
var obj = temp.by('fbKey', key);
// console.log('obj', obj);
return obj;
// }, 200);

}
Expand Down

0 comments on commit 2845e1b

Please sign in to comment.