mirror of
https://github.com/Esri/offline-editor-js.git
synced 2025-12-15 15:20:05 +00:00
add getAttachmentsByFeatureLayer() method to attachmentsStore
This commit is contained in:
parent
0f76800d34
commit
db7f2b1f45
@ -104,6 +104,28 @@ define([], function()
|
||||
}
|
||||
}
|
||||
|
||||
this.getAttachmentsByFeatureLayer = function(featureLayerUrl,callback)
|
||||
{
|
||||
var attachments = [];
|
||||
|
||||
var objectStore = this._db.transaction([OBJECT_STORE_NAME]).objectStore(OBJECT_STORE_NAME);
|
||||
var index = objectStore.index("featureId");
|
||||
var keyRange = IDBKeyRange.bound(featureLayerUrl + "/0", featureLayerUrl + "/A");
|
||||
index.openCursor(keyRange).onsuccess = function(evt)
|
||||
{
|
||||
var cursor = evt.target.result;
|
||||
if(cursor)
|
||||
{
|
||||
attachments.push( cursor.value );
|
||||
cursor.continue();
|
||||
}
|
||||
else
|
||||
{
|
||||
callback(attachments);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.deleteAttachmentsByFeatureId = function(featureLayerUrl,objectId,callback)
|
||||
{
|
||||
var featureId = featureLayerUrl + "/" + objectId;
|
||||
|
||||
@ -101,6 +101,30 @@ describe("attachments store module", function()
|
||||
});
|
||||
});
|
||||
|
||||
async.it("query attachments of a feature layer", function(done)
|
||||
{
|
||||
g_attachmentsStore.getAttachmentsByFeatureLayer("layer1", function(attachments)
|
||||
{
|
||||
expect(attachments.length).toBe(3);
|
||||
expect(attachments[0].featureId).toContain("layer1/");
|
||||
expect(attachments[1].featureId).toContain("layer1/");
|
||||
expect(attachments[2].featureId).toContain("layer1/");
|
||||
var attachmentIds = attachments.map(function(a){ return a.id; });
|
||||
expect(attachmentIds.sort()).toEqual([1000,1001,1002]);
|
||||
g_attachmentsStore.getAttachmentsByFeatureLayer("layer2", function(attachments)
|
||||
{
|
||||
expect(attachments.length).toBe(1);
|
||||
expect(attachments[0].featureId).toContain("layer2/");
|
||||
expect(attachments[0].id).toBe(1003);
|
||||
g_attachmentsStore.getAttachmentsByFeatureLayer("layer3", function(attachments)
|
||||
{
|
||||
expect(attachments.length).toBe(0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
async.it("replace feature id", function(done)
|
||||
{
|
||||
g_attachmentsStore.replaceFeatureId("layer1",1,100, function(success)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user