mirror of
https://github.com/Esri/offline-editor-js.git
synced 2025-12-15 15:20:05 +00:00
adds getPhantomGraphicsArray(), getAllEditsArray()
This commit is contained in:
parent
4c7ca1f225
commit
c53f43a557
@ -35,7 +35,7 @@ Methods | Returns | Description
|
|||||||
`goOffline()` | nothing | Forces library into an offline state. Any edits applied to extended FeatureLayers during this condition will be stored locally.
|
`goOffline()` | nothing | Forces library into an offline state. Any edits applied to extended FeatureLayers during this condition will be stored locally.
|
||||||
`goOnline(callback)` | `callback( boolean, errors )` | Forces library to return to an online state. If there are pending edits, an attempt will be made to sync them with the remote feature server. Callback function will be called when resync process is done.
|
`goOnline(callback)` | `callback( boolean, errors )` | Forces library to return to an online state. If there are pending edits, an attempt will be made to sync them with the remote feature server. Callback function will be called when resync process is done.
|
||||||
`getOnlineStatus()` | `ONLINE`, `OFFLINE` or `RECONNECTING`| Determines the current state of the manager. Please, note that this library doesn't detect actual browser offline/online condition. You need to use the `offline.min.js` library included in `vendor\offline` directory to detect connection status and connect events to goOffline() and goOnline() methods. See `military-offline.html` sample.
|
`getOnlineStatus()` | `ONLINE`, `OFFLINE` or `RECONNECTING`| Determines the current state of the manager. Please, note that this library doesn't detect actual browser offline/online condition. You need to use the `offline.min.js` library included in `vendor\offline` directory to detect connection status and connect events to goOffline() and goOnline() methods. See `military-offline.html` sample.
|
||||||
`getReadableEdit()` | String | **DEPRECATED** at v2.5. A string value representing human readable information on pending edits.
|
`getReadableEdit()` | String | **DEPRECATED** at v2.5. A string value representing human readable information on pending edits. Use featureLayer.getAllEditsArray().
|
||||||
|
|
||||||
|
|
||||||
###Events
|
###Events
|
||||||
@ -54,9 +54,9 @@ Application code can subscribe to offlineFeaturesManager events to be notified o
|
|||||||
Event | Value | Returns | Description
|
Event | Value | Returns | Description
|
||||||
--- | --- | --- | ---
|
--- | --- | --- | ---
|
||||||
`events.EDITS_SENT` | "edits-sent" | nothing | When any edit is actually sent to the server.
|
`events.EDITS_SENT` | "edits-sent" | nothing | When any edit is actually sent to the server.
|
||||||
`events.EDITS_SENT_ERROR` | "edits-sent-error" | {msg:error} | (Added at v2.5) There was a problem while sending errors to the server.
|
`events.EDITS_SENT_ERROR` | "edits-sent-error" | {msg:error} | **New at v2.5** There was a problem while sending errors to the server.
|
||||||
`events.EDITS_ENQUEUED` | "edits-enqueued" | nothing | When an edit is enqueued and not sent to the server.
|
`events.EDITS_ENQUEUED` | "edits-enqueued" | nothing | When an edit is enqueued and not sent to the server.
|
||||||
`events.EDITS_ENQUEUED_ERROR` | "edits-enqueued-error" | {msg:error} | (Added at v2.5) An error occurred while trying to store the edit. In your app it is recommended to verify if the edit is in the database or not.
|
`events.EDITS_ENQUEUED_ERROR` | "edits-enqueued-error" | {msg:error} | **New at v2.5** An error occurred while trying to store the edit. In your app it is recommended to verify if the edit is in the database or not.
|
||||||
`events.ALL_EDITS_SENT` | "all-edits-sent" | nothing| After going online and there are no pending edits remaining in the queue.
|
`events.ALL_EDITS_SENT` | "all-edits-sent" | nothing| After going online and there are no pending edits remaining in the queue.
|
||||||
`events.ATTACHMENT_ENQUEUED` | "attachment-enqueued" | nothing | An attachment is in the queue to be sent to the server.
|
`events.ATTACHMENT_ENQUEUED` | "attachment-enqueued" | nothing | An attachment is in the queue to be sent to the server.
|
||||||
`events.ATTACHMENTS_SENT` | "attachments-sent" | nothing | When any attachment is actually sent to the server.
|
`events.ATTACHMENTS_SENT` | "attachments-sent" | nothing | When any attachment is actually sent to the server.
|
||||||
@ -85,8 +85,10 @@ Methods | Returns | Description
|
|||||||
`getFeatureDefinition(` `featureLayer, featuresArr` `geometryType, callback)` | Object | Used with offline browser restarts. Pass it a FeatureLayer instance, an array of features and specify the Esri geometry type. It will return a FeatureLayer Definition object that can be used to reconstitute a Feature Layer from scratch. The appcache-features.html sample demonstrates this pattern. Go here for more info on the ArcGIS REST API [layerDefinition](http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#//02r30000004v000000), and [Layer](http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#/Layer/02r30000004q000000/).
|
`getFeatureDefinition(` `featureLayer, featuresArr` `geometryType, callback)` | Object | Used with offline browser restarts. Pass it a FeatureLayer instance, an array of features and specify the Esri geometry type. It will return a FeatureLayer Definition object that can be used to reconstitute a Feature Layer from scratch. The appcache-features.html sample demonstrates this pattern. Go here for more info on the ArcGIS REST API [layerDefinition](http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#//02r30000004v000000), and [Layer](http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#/Layer/02r30000004q000000/).
|
||||||
`setPhantomLayerGraphics( graphicsArray) ` | nothing | Used with offline browser restarts. Adds the graphics in the `graphicsArray` to the internal phantom graphics layer. This layer is designed to indicate to the user any graphic that has been modified while offline. The appcache-features.html sample demonstrates this pattern.
|
`setPhantomLayerGraphics( graphicsArray) ` | nothing | Used with offline browser restarts. Adds the graphics in the `graphicsArray` to the internal phantom graphics layer. This layer is designed to indicate to the user any graphic that has been modified while offline. The appcache-features.html sample demonstrates this pattern.
|
||||||
`getPhantomLayerGraphics( callback) ` | `callback( graphicsLayerJSON)` | Used with offline browser restarts. Returns a JSON representation of the internal phantom graphics layer. This layer is designed to indicate to the user any graphic that has been modified while offline. The appcache-features.html sample demonstrates this pattern.
|
`getPhantomLayerGraphics( callback) ` | `callback( graphicsLayerJSON)` | Used with offline browser restarts. Returns a JSON representation of the internal phantom graphics layer. This layer is designed to indicate to the user any graphic that has been modified while offline. The appcache-features.html sample demonstrates this pattern.
|
||||||
`addAttachments()` | TBD | **New @ v2.5.** TBD
|
`addAttachments()` | Internal | Adds an attachment.
|
||||||
`deleteAttachments()` | TBD | **New @ v2.5.** TBD
|
`deleteAttachments()` | Internal | Deletes an attachment.
|
||||||
|
`getPhantomGraphicsArray( callback)` | `callback(boolean, array)` | **New @ v2.5** Used with offline browser restarts. Returns an array of phantom graphics from the database.
|
||||||
|
`getAllEditsArray(callback)` | `callback(boolean, array)` | **New @ v2.5** Returns an array of all edits stored in the database.
|
||||||
`getFeatureLayerJSON(url,callback)` | `callback( boolean, JSON )` | **New @ v2.5.** Retrieves the feature layer's JSON using `f=json` parameter.
|
`getFeatureLayerJSON(url,callback)` | `callback( boolean, JSON )` | **New @ v2.5.** Retrieves the feature layer's JSON using `f=json` parameter.
|
||||||
`convertFeatureGraphicsToJSON(` `[features],callback)` | `callback( jsonString )` | **New @ v2.5.** Converts an array of feature layer graphics to a JSON string.
|
`convertFeatureGraphicsToJSON(` `[features],callback)` | `callback( jsonString )` | **New @ v2.5.** Converts an array of feature layer graphics to a JSON string.
|
||||||
|
|
||||||
|
|||||||
@ -528,6 +528,21 @@ define([
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an array of phantom graphics from the database.
|
||||||
|
* @param callback callback (true, array) or (false, errorString)
|
||||||
|
*/
|
||||||
|
layer.getPhantomGraphicsArray = function(callback){
|
||||||
|
self._editStore.getPhantomGraphicsArray(function(array,message){
|
||||||
|
if(message == "end"){
|
||||||
|
callback(true,array);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
callback(false,message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a featureDefinition
|
* Create a featureDefinition
|
||||||
* @param featureLayer
|
* @param featureLayer
|
||||||
@ -549,6 +564,21 @@ define([
|
|||||||
callback(featureDefinition);
|
callback(featureDefinition);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an interable array of all edits stored in the database
|
||||||
|
* @param callback (true, array) or (false, errorString)
|
||||||
|
*/
|
||||||
|
layer.getAllEditsArray = function(callback){
|
||||||
|
self._editStore.getAllEditsArray(function(array,message){
|
||||||
|
if(message == "end"){
|
||||||
|
callback(true,array);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
callback(false,message);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
/* internal methods */
|
/* internal methods */
|
||||||
|
|
||||||
layer._getFilesFromForm = function (formNode) {
|
layer._getFilesFromForm = function (formNode) {
|
||||||
|
|||||||
@ -425,7 +425,7 @@ describe("Offline Editing", function()
|
|||||||
|
|
||||||
describe("Test PhantomGraphicsLayer", function()
|
describe("Test PhantomGraphicsLayer", function()
|
||||||
{
|
{
|
||||||
async.it("Get PhantomLayerGraphics array", function(done){
|
async.it("Get PhantomLayerGraphics array via editsStore", function(done){
|
||||||
g_editsStore.getPhantomGraphicsArray(function(results,errors){
|
g_editsStore.getPhantomGraphicsArray(function(results,errors){
|
||||||
|
|
||||||
// Should be the same size as the number of edits!!
|
// Should be the same size as the number of edits!!
|
||||||
@ -444,6 +444,25 @@ describe("Offline Editing", function()
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// offlineFeaturesManager results should be the same as getting results directly from database
|
||||||
|
async.it("Get PhantomLayerGraphics via the layer", function(done){
|
||||||
|
g_featureLayers[0].getPhantomGraphicsArray(function(result,array){
|
||||||
|
expect(result).toBe(true);
|
||||||
|
expect(typeof array).toBe("object");
|
||||||
|
expect(array.length).toBe(9);
|
||||||
|
expect(array[0].id).toBe("phantom-layer|@|-1");
|
||||||
|
expect(array[1].id).toBe("phantom-layer|@|-2");
|
||||||
|
expect(array[2].id).toBe("phantom-layer|@|-3");
|
||||||
|
expect((array[3].id).indexOf(g_editsStore.PHANTOM_GRAPHIC_PREFIX)).toBe(0);
|
||||||
|
expect((array[4].id).indexOf(g_editsStore.PHANTOM_GRAPHIC_PREFIX)).toBe(0);
|
||||||
|
expect((array[5].id).indexOf(g_editsStore.PHANTOM_GRAPHIC_PREFIX)).toBe(0);
|
||||||
|
expect((array[6].id).indexOf(g_editsStore.PHANTOM_GRAPHIC_PREFIX)).toBe(0);
|
||||||
|
expect((array[7].id).indexOf(g_editsStore.PHANTOM_GRAPHIC_PREFIX)).toBe(0);
|
||||||
|
expect((array[8].id).indexOf(g_editsStore.PHANTOM_GRAPHIC_PREFIX)).toBe(0);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
async.it("Set PhantomLayerGraphic", function(done){
|
async.it("Set PhantomLayerGraphic", function(done){
|
||||||
var graphic = new g_modules.Graphic({"geometry":{"x":-109900,"y":5137000,"spatialReference":{"wkid":102100}},"attributes":{"objectId":"test001","symbolname":"Reference Point DLRP","z":null,"additionalinformation":null,"eny":null,"datetimevalid":null,"datetimeexpired":null,"distance":null,"azimuth":null,"uniquedesignation":null,"x":null,"y":null}} );
|
var graphic = new g_modules.Graphic({"geometry":{"x":-109900,"y":5137000,"spatialReference":{"wkid":102100}},"attributes":{"objectId":"test001","symbolname":"Reference Point DLRP","z":null,"additionalinformation":null,"eny":null,"datetimevalid":null,"datetimeexpired":null,"distance":null,"azimuth":null,"uniquedesignation":null,"x":null,"y":null}} );
|
||||||
g_editsStore.pushPhantomGraphic(graphic,function(result,error){
|
g_editsStore.pushPhantomGraphic(graphic,function(result,error){
|
||||||
@ -619,17 +638,28 @@ describe("Offline Editing", function()
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("go Online", function()
|
describe("Before going online", function(){
|
||||||
{
|
|
||||||
async.it("Before going online validate graphic layer properties", function(done){
|
async.it("Before going online validate graphic layer properties", function(done){
|
||||||
// Remember we deleted g3! So our total count is 8 not 9. HOWEVER, there should be 9 records in the database!
|
// Remember we deleted g3! So our total count is 8 not 9. HOWEVER, there should be 9 records in the database!
|
||||||
expect(getObjectIds(g_featureLayers[0].graphics)).toEqual(getObjectIds([g1,g2,g4,g5,g6]));
|
expect(getObjectIds(g_featureLayers[0].graphics)).toEqual(getObjectIds([g1,g2,g4,g5,g6]));
|
||||||
expect(getObjectIds(g_featureLayers[1].graphics)).toEqual(getObjectIds([l1,l2,l3]));
|
expect(getObjectIds(g_featureLayers[1].graphics)).toEqual(getObjectIds([l1,l2,l3]));
|
||||||
expect(g_featureLayers[0].graphics.length).toBe(5);
|
expect(g_featureLayers[0].graphics.length).toBe(5);
|
||||||
expect(g_featureLayers[1].graphics.length).toBe(3);
|
expect(g_featureLayers[1].graphics.length).toBe(3);
|
||||||
|
expect(g_featureLayers[2].graphics.length).toBe(0);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
async.it("Retrieve edits array from the layer", function(done){
|
||||||
|
g_featureLayers[0].getAllEditsArray(function(success,array){
|
||||||
|
expect(success).toBe(true); console.log("ARRAY " + JSON.stringify(array))
|
||||||
|
expect(array.length).toBe(9);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("go Online", function()
|
||||||
|
{
|
||||||
async.it("go Online", function(done)
|
async.it("go Online", function(done)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -680,7 +710,9 @@ describe("Offline Editing", function()
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("After online", function(){
|
||||||
async.it("After online - verify feature layer graphic counts",function(done){
|
async.it("After online - verify feature layer graphic counts",function(done){
|
||||||
// all of them are positive
|
// all of them are positive
|
||||||
expect(getObjectIds(g_featureLayers[0].graphics).filter(function(id){ return id<0; })).toEqual([]);
|
expect(getObjectIds(g_featureLayers[0].graphics).filter(function(id){ return id<0; })).toEqual([]);
|
||||||
@ -711,6 +743,5 @@ describe("Offline Editing", function()
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
Loading…
x
Reference in New Issue
Block a user