Fixed up the updating and stuff
This commit is contained in:
parent
0732d1c4a6
commit
6062364f4c
@ -42,10 +42,8 @@ export class SyncService {
|
|||||||
private addMapSymbol(s: MapSymbol, key: string) {
|
private addMapSymbol(s: MapSymbol, key: string) {
|
||||||
let map = this.mapData.value;
|
let map = this.mapData.value;
|
||||||
if(!map[key]) map[key] = {};
|
if(!map[key]) map[key] = {};
|
||||||
do {
|
s.updated = new Date().getTime();
|
||||||
s.updated = new Date().getTime();
|
if(!s.id) s.id = Md5.hashStr(s.updated.toString()).toString();
|
||||||
s.id = Md5.hashStr(s.updated.toString()).toString();
|
|
||||||
} while (!!map[key][s.id]);
|
|
||||||
map[key][s.id] = s;
|
map[key][s.id] = s;
|
||||||
this.mapData.next(map);
|
this.mapData.next(map);
|
||||||
this.mapChanged = true;
|
this.mapChanged = true;
|
||||||
@ -90,7 +88,10 @@ export class SyncService {
|
|||||||
|
|
||||||
delete(...symbols) {
|
delete(...symbols) {
|
||||||
let map = this.mapData.value;
|
let map = this.mapData.value;
|
||||||
Object.keys(map).forEach(key => symbols.filter(s => !!map[key][s.id]).forEach(s => map[key][s.id].deleted = true));
|
Object.keys(map).forEach(key => symbols.filter(s => !!map[key][s.id]).forEach(s => {
|
||||||
|
map[key][s.id].updated = new Date().getTime();
|
||||||
|
map[key][s.id].deleted = true
|
||||||
|
}));
|
||||||
this.mapData.next(map);
|
this.mapData.next(map);
|
||||||
this.mapChanged = true;
|
this.mapChanged = true;
|
||||||
this.status.next('modified');
|
this.status.next('modified');
|
||||||
@ -132,15 +133,14 @@ export class SyncService {
|
|||||||
let map: MapData = {locations: {}};
|
let map: MapData = {locations: {}};
|
||||||
Object.keys(newMap).forEach(key => {
|
Object.keys(newMap).forEach(key => {
|
||||||
if(!map[key]) map[key] = {};
|
if(!map[key]) map[key] = {};
|
||||||
Object.keys(newMap[key]).filter(id => !newMap[key][id].deleted)
|
Object.keys(newMap[key]).forEach(id => map[key][id] = newMap[key][id]);
|
||||||
.forEach(id => map[key][id] = newMap[key][id]);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Object.keys(oldMap).filter(key => key != 'locations').forEach(key => {
|
Object.keys(oldMap).filter(key => key != 'locations').forEach(key => {
|
||||||
if(!map[key]) map[key] = {};
|
if(!map[key]) map[key] = {};
|
||||||
Object.keys(oldMap[key]).filter(id => {
|
Object.keys(oldMap[key]).filter(id => {
|
||||||
let newS = map[key][id] || false;
|
let newS = map[key][id] || false;
|
||||||
return newS && newS.updated > map[key][id].updated;
|
return !newS && !oldMap[key][id].deleted || newS && oldMap[key][id].updated > newS.updated;
|
||||||
}).forEach(id => map[key][id] = oldMap[key][id]);
|
}).forEach(id => map[key][id] = oldMap[key][id]);
|
||||||
});
|
});
|
||||||
return map;
|
return map;
|
||||||
|
@ -112,11 +112,8 @@ export class MapComponent implements OnDestroy, OnInit {
|
|||||||
if(e.symbol.noClick) return;
|
if(e.symbol.noClick) return;
|
||||||
this.syncService.freeze.next(true);
|
this.syncService.freeze.next(true);
|
||||||
this.sub = this.bottomSheet.open(EditSymbolComponent, {data: e, disableClose: true, hasBackdrop: false}).afterDismissed().pipe(finalize(() => this.sub = null)).subscribe(symbol => {
|
this.sub = this.bottomSheet.open(EditSymbolComponent, {data: e, disableClose: true, hasBackdrop: false}).afterDismissed().pipe(finalize(() => this.sub = null)).subscribe(symbol => {
|
||||||
|
this.syncService.addCircle(symbol);
|
||||||
this.syncService.freeze.next(false);
|
this.syncService.freeze.next(false);
|
||||||
this.syncService.delete(e.symbol);
|
|
||||||
if(e.item instanceof L.Circle) {
|
|
||||||
this.syncService.addCircle(symbol);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user