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:
Javier Abadia 2014-01-28 12:55:08 +01:00
parent 47136fb7c5
commit 0bbf9ca83a
4 changed files with 80 additions and 4 deletions

View File

@ -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()

View File

@ -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();

View File

@ -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);
}

View File

@ -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()