mirror of
https://github.com/Esri/offline-editor-js.git
synced 2025-12-15 15:20:05 +00:00
take care of updates for features added offline (replace negative tmp id by final id)
still has the problem with the Editor that removes the graphic from the layer after the update
This commit is contained in:
parent
47136fb7c5
commit
0bbf9ca83a
@ -88,9 +88,22 @@ define(["esri/graphic"], function(Graphic)
|
||||
return null;
|
||||
},
|
||||
|
||||
replaceTempId: function(tempId, objectid)
|
||||
replaceTempId: function(tempId, newObjectId, objectIdField)
|
||||
{
|
||||
console.log("temp:",tempId,"objectid:",objectid);
|
||||
var edits = this._retrieveEditsQueue();
|
||||
var replaceCount = 0;
|
||||
edits.forEach(function(edit)
|
||||
{
|
||||
var graphic = this._deserialize(edit.graphic);
|
||||
if( graphic.attributes[ objectIdField] == tempId )
|
||||
{
|
||||
graphic.attributes[objectIdField] = newObjectId;
|
||||
edit.graphic = this._serialize(graphic);
|
||||
replaceCount += 1;
|
||||
}
|
||||
},this);
|
||||
var success = this._storeEditsQueue(edits);
|
||||
return success? replaceCount : false;
|
||||
},
|
||||
|
||||
hasPendingEdits: function()
|
||||
|
||||
@ -159,7 +159,7 @@ define([
|
||||
editsStore.popFirstEdit();
|
||||
if( addResults )
|
||||
{
|
||||
editsStore.replaceTempId(tempId, addResults[0].objectId);
|
||||
editsStore.replaceTempId(tempId, addResults[0].objectId, layer.objectIdField);
|
||||
}
|
||||
self.emit('edits-sent',arguments);
|
||||
self.replayStoredEdits();
|
||||
|
||||
@ -90,7 +90,10 @@
|
||||
|
||||
g_test.pointFeature = new Graphic( g_test.point, g_test.pointSymbol, {"name": "the name of the feature", "objectid":2});
|
||||
g_test.lineFeature = new Graphic( g_test.line, g_test.lineSymbol, {"nombre": "España","objectid":5});
|
||||
g_test.polygonFeature = new Graphic( g_test.polygon, g_test.polygonSymbol, {"nombre": "España","timestamp": new Date().getTime(), "objectid":5});
|
||||
g_test.polygonFeature = new Graphic( g_test.polygon, g_test.polygonSymbol, {"nombre": "España","timestamp": new Date().getTime(), "objectid":8});
|
||||
|
||||
g_test.newPointFeature = new Graphic( g_test.point, g_test.pointSymbol, {"name": "the name of the feature", "objectid":-1});
|
||||
g_test.newPointFeatureUpdated = new Graphic( g_test.point, g_test.pointSymbol, {"name": "the name of the feature modified", "objectid":-1});
|
||||
|
||||
console.log(g_test);
|
||||
}
|
||||
|
||||
@ -305,6 +305,66 @@ describe("Public Interface", function()
|
||||
});
|
||||
});
|
||||
|
||||
describe("Replacement of Temporary Ids", function()
|
||||
{
|
||||
function getObjectIds()
|
||||
{
|
||||
var edits = g_editsStore._retrieveEditsQueue();
|
||||
var objectids = edits.map(function(edit)
|
||||
{
|
||||
return g_editsStore._deserialize(edit.graphic).attributes.objectid
|
||||
});
|
||||
return objectids;
|
||||
}
|
||||
|
||||
it("reset edits queue", function()
|
||||
{
|
||||
g_editsStore.resetEditsQueue();
|
||||
expect(g_editsStore.pendingEditsCount()).toBe(0);
|
||||
});
|
||||
|
||||
it("add edits to edits queue", function()
|
||||
{
|
||||
var success, objectids;
|
||||
expect(g_test.newPointFeature.attributes.objectid).toBe(-1);
|
||||
success = g_editsStore.pushEdit(g_editsStore.ADD, 6, g_test.newPointFeature);
|
||||
expect(g_editsStore.pendingEditsCount()).toBe(1);
|
||||
expect(success).toBeTruthy();
|
||||
expect(g_editsStore.peekFirstEdit().graphic.attributes.objectid).toBe(-1);
|
||||
|
||||
expect(g_test.polygonFeature.attributes.objectid).toBe(8);
|
||||
success = g_editsStore.pushEdit(g_editsStore.UPDATE, 3, g_test.polygonFeature);
|
||||
expect(success).toBeTruthy();
|
||||
expect(g_editsStore.pendingEditsCount()).toBe(2);
|
||||
objectids = getObjectIds();
|
||||
expect(objectids).toEqual([-1,8]);
|
||||
|
||||
expect(g_test.lineFeature.attributes.objectid).toBe(5);
|
||||
success = g_editsStore.pushEdit(g_editsStore.UPDATE, 3, g_test.lineFeature);
|
||||
expect(success).toBeTruthy();
|
||||
expect(g_editsStore.pendingEditsCount()).toBe(3);
|
||||
objectids = getObjectIds();
|
||||
expect(objectids).toEqual([-1,8,5]);
|
||||
});
|
||||
|
||||
it("replace ids", function()
|
||||
{
|
||||
var replaceCount, objectids;
|
||||
|
||||
objectids = getObjectIds();
|
||||
expect(objectids).toEqual([-1,8,5]);
|
||||
|
||||
replaceCount = g_editsStore.replaceTempId(-1,10,"objectid");
|
||||
|
||||
expect(replaceCount).toBe(1);
|
||||
objectids = getObjectIds();
|
||||
expect(objectids).toEqual([10,8,5]);
|
||||
|
||||
replaceCount = g_editsStore.replaceTempId(-1,10,"objectid");
|
||||
expect(replaceCount).toBe(0);
|
||||
});
|
||||
})
|
||||
|
||||
describe("Undo/Redo management", function()
|
||||
{
|
||||
it("reset edits queue", function()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user