changed properties of stored attachments to mimic return values of queryAttachmentInfos REST API

This commit is contained in:
Javier Abadia 2014-04-05 01:40:41 +02:00
parent c650761c7f
commit c50559a575
2 changed files with 26 additions and 22 deletions

View File

@ -17,7 +17,7 @@ define([], function()
return true;
}
this.store = function(attachmentId, featureId, attachmentFile, callback)
this.store = function(attachmentId, objectId, attachmentFile, callback)
{
try
{
@ -36,9 +36,13 @@ define([], function()
var objectStore = transaction.objectStore(OBJECT_STORE_NAME);
var request = objectStore.put(
{
attachmentId: attachmentId,
featureId: featureId,
attachmentFile: attachmentFile
id: attachmentId,
objectId: objectId,
contentType: attachmentFile.type,
name: attachmentFile.name,
size: attachmentFile.size,
url: attachmentFile.url,
content: attachmentFile.content
});
request.onsuccess = function(event)
{
@ -76,13 +80,13 @@ define([], function()
}
}
this.getAttachmentsByFeatureId = function(featureId,callback)
this.getAttachmentsByFeatureId = function(objectId,callback)
{
var attachments = [];
var objectStore = this._db.transaction([OBJECT_STORE_NAME]).objectStore(OBJECT_STORE_NAME);
var index = objectStore.index("featureId");
var keyRange = IDBKeyRange.only(featureId);
var index = objectStore.index("objectId");
var keyRange = IDBKeyRange.only(objectId);
index.openCursor(keyRange).onsuccess = function(evt)
{
var cursor = evt.target.result;
@ -159,7 +163,7 @@ define([], function()
{
console.log("init AttachmentStore");
var request = indexedDB.open(DB_NAME, 9);
var request = indexedDB.open(DB_NAME, 10);
callback = callback? callback : function(success) { console.log("AttachmentsStore::init() success:", success)}.bind(this);
request.onerror = function(event)
@ -177,8 +181,8 @@ define([], function()
db.deleteObjectStore(OBJECT_STORE_NAME);
}
var objectStore = db.createObjectStore(OBJECT_STORE_NAME, { keyPath: "attachmentId" });
objectStore.createIndex("featureId","featureId", {unique: false});
var objectStore = db.createObjectStore(OBJECT_STORE_NAME, { keyPath: "id" });
objectStore.createIndex("objectId","objectId", {unique: false});
}.bind(this);
request.onsuccess = function(event)

View File

@ -1,10 +1,10 @@
"use strict";
var testData = [
[ 1000, 1, "content of the file of attachment 1000 for feature 1"],
[ 1001, 1, "content of the file of attachment 1001 for feature 1"],
[ 1002, 2, "content of the file of attachment 1002 for feature 2"],
[ 1003, 3, "content of the file of attachment 1003 for feature 3"]
[ 1000, 1, { name: "attachment1000.txt", type: "text", size: "43", content: "content of the file of attachment 1000 for feature 1", url:""}],
[ 1001, 1, { name: "attachment1001.txt", type: "text", size: "43", content: "content of the file of attachment 1001 for feature 1", url:""}],
[ 1002, 2, { name: "attachment1002.txt", type: "text", size: "43", content: "content of the file of attachment 1002 for feature 2", url:""}],
[ 1003, 3, { name: "attachment1003.txt", type: "text", size: "43", content: "content of the file of attachment 1003 for feature 3", url:""}]
];
describe("attachments store module", function()
@ -46,7 +46,7 @@ describe("attachments store module", function()
g_attachmentsStore.getUsage(function(usage)
{
expect(usage).not.toBeNull();
expect(usage.sizeBytes).toBe(107);
expect(usage.sizeBytes).toBe(159);
expect(usage.attachmentCount).toBe(1);
done();
})
@ -64,7 +64,7 @@ describe("attachments store module", function()
g_attachmentsStore.getUsage(function(usage)
{
expect(usage).not.toBeNull();
expect(usage.sizeBytes).toBe(107 * i);
expect(usage.sizeBytes).toBe(159 * i);
expect(usage.attachmentCount).toBe(i);
if( i == n)
done();
@ -83,15 +83,15 @@ describe("attachments store module", function()
g_attachmentsStore.getAttachmentsByFeatureId(1, function(attachments)
{
expect(attachments.length).toBe(2);
expect(attachments[0].featureId).toBe(1);
expect(attachments[1].featureId).toBe(1);
expect(attachments[0].attachmentFile).toContain("feature 1");
expect(attachments[1].attachmentFile).toContain("feature 1");
expect(attachments[0].objectId).toBe(1);
expect(attachments[1].objectId).toBe(1);
expect(attachments[0].content).toContain("feature 1");
expect(attachments[1].content).toContain("feature 1");
g_attachmentsStore.getAttachmentsByFeatureId(2, function(attachments)
{
expect(attachments.length).toBe(1);
expect(attachments[0].featureId).toBe(2);
expect(attachments[0].attachmentFile).toContain("feature 2");
expect(attachments[0].objectId).toBe(2);
expect(attachments[0].content).toContain("feature 2");
done();
});
});