From a5581aade5874198fefad2ddfbb4bc23d6bb801c Mon Sep 17 00:00:00 2001 From: Andy Gup Date: Wed, 18 Mar 2015 11:00:17 -0600 Subject: [PATCH] adds layer.getUsage() --- doc/offlinefeaturesmanager.md | 1 + lib/edit/editsStore.js | 2 +- lib/edit/offlineFeaturesManager.js | 10 ++++++++++ test/spec/offlineFeaturesManagerSpec.js | 2 +- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/doc/offlinefeaturesmanager.md b/doc/offlinefeaturesmanager.md index 4527c85..a14e216 100644 --- a/doc/offlinefeaturesmanager.md +++ b/doc/offlinefeaturesmanager.md @@ -87,6 +87,7 @@ Methods | Returns | Description `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()` | Internal | Adds an attachment. `deleteAttachments()` | Internal | Deletes an attachment. +`getUsage(callback)`| `callback({usage}, error)` | **New @ v2.5** Returns the approximate size of the database in bytes. the usage Object is {sizeBytes: number, editCount: number}. `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. diff --git a/lib/edit/editsStore.js b/lib/edit/editsStore.js index 2e03802..b789bce 100644 --- a/lib/edit/editsStore.js +++ b/lib/edit/editsStore.js @@ -798,7 +798,7 @@ O.esri.Edit.EditStore = function () { /** * Returns the approximate size of the database in bytes * IMPORTANT: Currently requires all data be serialized! - * @param callback {usage, error} Whereas, the usage Object is {sizeBytes: number, editCount: number} + * @param callback callback({usage}, error) Whereas, the usage Object is {sizeBytes: number, editCount: number} */ this.getUsage = function (callback) { console.assert(this._db !== null, "indexeddb not initialized"); diff --git a/lib/edit/offlineFeaturesManager.js b/lib/edit/offlineFeaturesManager.js index e6ac961..16a3e61 100644 --- a/lib/edit/offlineFeaturesManager.js +++ b/lib/edit/offlineFeaturesManager.js @@ -543,6 +543,16 @@ define([ }); }; + /** + * Returns the approximate size of the database in bytes + * @param callback callback({usage}, error) Whereas, the usage Object is {sizeBytes: number, editCount: number} + */ + layer.getUsage = function(callback){ + self._editStore.getUsage(function(usage,error){ + callback(usage,error); + }); + }; + /** * Create a featureDefinition * @param featureLayer diff --git a/test/spec/offlineFeaturesManagerSpec.js b/test/spec/offlineFeaturesManagerSpec.js index 69d7596..98407bb 100644 --- a/test/spec/offlineFeaturesManagerSpec.js +++ b/test/spec/offlineFeaturesManagerSpec.js @@ -410,7 +410,7 @@ describe("Offline Editing", function() }); async.it("check db size", function(done){ - g_editsStore.getUsage(function(usage,error){ + g_featureLayers[0].getUsage(function(usage,error){ expect(usage.sizeBytes).toBe(7834); expect(usage.editCount).toBe(9); expect(error).toBe(null);