add getAttachmentsByFeatureLayer() method to attachmentsStore

This commit is contained in:
Javier Abadia 2014-04-14 18:00:04 +02:00
parent 0f76800d34
commit db7f2b1f45
2 changed files with 46 additions and 0 deletions

View File

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

View File

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