Skip to content

Commit 866b6f9

Browse files
modificando la estructura de los datos
1 parent d016ac1 commit 866b6f9

3 files changed

Lines changed: 59 additions & 32 deletions

File tree

www/index.html

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,28 @@ <h1 class="title">🎂 Birthdays 🎉</h1>
3636
<ion-content>
3737
<ion-toggle ng-model="vm.online" ng-click="vm.setOnline(vm.online)" toggle-class="toggle-calm">online</ion-toggle>
3838
<ion-list>
39-
<div class="item item-divider">
39+
<div class="item item-divider">
4040
local
4141
</div>
4242
<ion-item ng-repeat="b in vm.birthdays" ng-click="vm.showEditBirthdayModal(b)">
4343
<div style="float: left">{{ b.fbVal.Name }}</div>
44-
<div style="float: right">{{ b.fbKey }}</div>
44+
<div style="float: right">{{ b.fbKey }}</div>
4545
<!-- | date:"dd MMMM yyyy" -->
4646
</ion-item>
4747
<div class="item item-divider">
4848
temp
4949
</div>
50-
<ion-item ng-class="{ns:vm.isSync(b.fbKey)}" ng-repeat="b in vm.temp track by b.fbKey" ng-click="vm.showEditBirthdayModal(b)">
51-
<div style="float: left">{{ b.fbVal.Name }}</div>
52-
<div style="float: right">{{ b.fbKey }}</div>
50+
<ion-item ng-class="{ns:vm.isSync(b.$id)}" ng-repeat="b in vm.temp track by b.$id" ng-click="vm.showEditBirthdayModal(b)">
51+
<div style="float: left">{{ b.Name }}</div>
52+
<div style="float: right">{{ b.$id }}</div>
53+
</ion-item>
54+
<div class="item item-divider">
55+
emulate
56+
</div>
57+
<ion-item ng-repeat="b in vm.birthdays track by b.$id" >
58+
<div style="float: left">{{ b.Name }}</div>
59+
<div style="float: right">{{ b.$id }}</div>
5360
</ion-item>
54-
5561
<div class="item item-divider">
5662
firebase
5763
</div>

www/js/birthday.service.js

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,10 @@ var db, birthdays, fbA, tm, temp;
122122
_birthdays = _db.getCollection('birthdays');
123123
if (!_birthdays) {
124124
_birthdays = _db.addCollection('birthdays', {
125-
indices: ['fbKey'],
125+
indices: ['$id'],
126126
clone: true
127127
});
128-
_birthdays.ensureUniqueIndex('fbKey');
128+
_birthdays.ensureUniqueIndex('$id');
129129
}
130130

131131
var isEnabled = true;
@@ -140,13 +140,13 @@ var db, birthdays, fbA, tm, temp;
140140

141141
if (!_temp) {
142142
_temp = _db.addCollection('temp', {
143-
indices: ['fbKey'],
143+
indices: ['$id'],
144144
clone: true
145145
});
146-
_temp.ensureUniqueIndex('fbKey');
146+
_temp.ensureUniqueIndex('$id');
147147

148148
//ejemplo de como obtener el registro
149-
// temp.by('fbKey',"-K5fLRn_P7GM1VceDQTa")
149+
// temp.by('$id',"-K5fLRn_P7GM1VceDQTa")
150150
}
151151

152152
temp = _temp;
@@ -156,13 +156,24 @@ var db, birthdays, fbA, tm, temp;
156156
function trySync() {
157157
_temp.data.forEach(function(obj, i) {
158158
console.log(obj, i);
159-
_bdRef.child(obj.fbKey).set(obj.fbVal, syncCb(obj.fbKey));
159+
var fbKey = obj.$id;
160+
var objClone = angular.copy(obj);
161+
162+
163+
164+
if (delete objClone.$id && delete objClone.$loki) {
165+
console.log('format obj', fbKey, objClone)
166+
_bdRef.child(fbKey).set(objClone, syncCb(fbKey));
167+
168+
}
169+
160170
});
161171
}
162172

163173
function syncCb(fbKey) {
164174

165175
function cbFb(error) {
176+
166177
if (error) {
167178
console.error('error');
168179
} else {
@@ -232,12 +243,12 @@ var db, birthdays, fbA, tm, temp;
232243

233244
if (!_temp) {
234245
_temp = _db.addCollection('temp', {
235-
indices: ['fbKey']
246+
indices: ['$id']
236247
});
237-
_temp.ensureUniqueIndex('fbKey');
248+
_temp.ensureUniqueIndex('$id');
238249

239250
//ejemplo de como obtener el registro
240-
// temp.by('fbKey',"-K5fLRn_P7GM1VceDQTa")
251+
// temp.by('$id',"-K5fLRn_P7GM1VceDQTa")
241252
}
242253
var isEnabled = true;
243254
_birthdays.setChangesApi(isEnabled);
@@ -286,14 +297,17 @@ var db, birthdays, fbA, tm, temp;
286297
var key = _bd.$keyAt(lastIndex);
287298

288299
birthday.$id = key;
289-
// var birthday = _bd.$getRecord(key);
290-
var newObj = {
291-
fbKey: key,
292-
fbVal: birthday
293-
};
294-
console.log(lastIndex, _bd[lastIndex], key, newObj);
295-
_birthdays.insert(newObj);
296-
_temp.insert(newObj);
300+
/* // var birthday = _bd.$getRecord(key);
301+
var newObj = {
302+
fbKey: key,
303+
fbVal: birthday
304+
};
305+
console.log(lastIndex, _bd[lastIndex], key, newObj);
306+
_birthdays.insert(newObj);
307+
_temp.insert(newObj);*/
308+
309+
_birthdays.insert(birthday);
310+
_temp.insert(birthday);
297311
}
298312

299313
function oK(ref) {
@@ -320,7 +334,7 @@ var db, birthdays, fbA, tm, temp;
320334

321335
function removeTempbyId(fbKey) {
322336
_temp.removeWhere({
323-
'fbKey': fbKey
337+
'$id': fbKey
324338
});
325339
}
326340

@@ -332,7 +346,7 @@ var db, birthdays, fbA, tm, temp;
332346
function getTempById(key) {
333347

334348
// $timeout(function() {
335-
var obj = temp.by('fbKey', key);
349+
var obj = temp.by('$id', key);
336350
// console.log('obj', obj);
337351
return obj;
338352
// }, 200);

www/js/overview.controller.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
vm.online = true;
88
vm.fb = birthdayService.getBdArray();
99
vm.isSync = isSync;
10+
vm.emulateFb = emulateFb;
1011
// $ionicPlatform.ready(function() {
1112

1213
// // Initialize the database.
@@ -20,13 +21,19 @@
2021
// });
2122

2223
function isSync(key) {
23-
if( birthdayService.getTempById(key)){
24-
return true;
25-
}
26-
else{
27-
return false;
28-
}
29-
24+
if (birthdayService.getTempById(key)) {
25+
return true;
26+
} else {
27+
return false;
28+
}
29+
30+
}
31+
32+
function emulateFb(lokiObj) {
33+
if (lokiObj.fbVal) {
34+
console.log('lokiObj', lokiObj);
35+
lokiObj.fbVal.$id = lokiObj.fbKey;
36+
}
3037
}
3138

3239

0 commit comments

Comments
 (0)