mirror of
https://github.com/Esri/offline-editor-js.git
synced 2025-12-15 15:20:05 +00:00
basic push functionality
This commit is contained in:
parent
52adc5c595
commit
150dd1b72d
@ -1,7 +1,7 @@
|
||||
/*global IDBKeyRange,indexedDB */
|
||||
|
||||
"use strict";
|
||||
O.esri.Edit.EditsStore = function()
|
||||
O.esri.Edit.EditStore = function()
|
||||
{
|
||||
this._db = null;
|
||||
|
||||
@ -9,6 +9,7 @@ O.esri.Edit.EditsStore = function()
|
||||
|
||||
var dbName = "features_store";
|
||||
var objectStoreName = "features";
|
||||
var dbIndex = "featureId";
|
||||
|
||||
// ENUMs
|
||||
|
||||
@ -36,6 +37,7 @@ O.esri.Edit.EditsStore = function()
|
||||
try
|
||||
{
|
||||
var edit = {
|
||||
id: graphic.attributes.objectid,
|
||||
operation: operation,
|
||||
layer: layer,
|
||||
graphic: graphic.toJson()
|
||||
@ -44,7 +46,7 @@ O.esri.Edit.EditsStore = function()
|
||||
var transaction = this._db.transaction([objectStoreName],"readwrite");
|
||||
|
||||
transaction.oncomplete = function(event){
|
||||
callback(true, edit);
|
||||
callback(true);
|
||||
};
|
||||
|
||||
transaction.onerror = function(event){
|
||||
@ -66,6 +68,48 @@ O.esri.Edit.EditsStore = function()
|
||||
}
|
||||
};
|
||||
|
||||
this.resetEditsQueue = function(callback)
|
||||
{
|
||||
console.assert(this._db !== null, "indexeddb not initialized");
|
||||
|
||||
var request = this._db.transaction([objectStoreName],"readwrite")
|
||||
.objectStore(objectStoreName)
|
||||
.clear();
|
||||
request.onsuccess = function(event){
|
||||
setTimeout(function(){callback(true);},0);
|
||||
};
|
||||
request.onerror = function(err){
|
||||
callback(false,err);
|
||||
};
|
||||
};
|
||||
|
||||
this.pendingEditsCount = function(callback)
|
||||
{
|
||||
console.assert(this._db !== null, "indexeddb not initialized");
|
||||
|
||||
var count = 0;
|
||||
|
||||
var objectStore = this._db.transaction([objectStoreName]).objectStore(objectStoreName);
|
||||
objectStore.openCursor().onsuccess = function(evt)
|
||||
{
|
||||
var cursor = evt.target.result;
|
||||
if(cursor)
|
||||
{
|
||||
count++;
|
||||
cursor.continue();
|
||||
}
|
||||
else
|
||||
{
|
||||
callback(count);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
this.hasPendingEdits = function()
|
||||
{
|
||||
// DEPRECATED!
|
||||
};
|
||||
|
||||
this.getUsage = function(callback)
|
||||
{
|
||||
console.assert(this._db !== null, "indexeddb not initialized");
|
||||
@ -154,7 +198,7 @@ O.esri.Edit.EditsStore = function()
|
||||
}
|
||||
|
||||
var objectStore = db.createObjectStore(objectStoreName, { keyPath: "id" });
|
||||
objectStore.createIndex("featureId","featureId", {unique: false});
|
||||
objectStore.createIndex(dbIndex,dbIndex, {unique: false});
|
||||
}.bind(this);
|
||||
|
||||
request.onsuccess = function(event)
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "offline-editor-js",
|
||||
"version": "2.4",
|
||||
"version": "2.5",
|
||||
"description": "Lightweight set of libraries for working offline with map tiles and ArcGIS feature services",
|
||||
"author": "Andy Gup <agup@esri.com> (http://blog.andygup.net)",
|
||||
"license": "Apache 2",
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
|
||||
<link rel="stylesheet" href="http://js.arcgis.com/3.10/js/dojo/dijit/themes/claro/claro.css">
|
||||
<link rel="stylesheet" href="http://js.arcgis.com/3.10/js/esri/css/esri.css">
|
||||
<script src="http://js.arcgis.com/3.10/"></script>
|
||||
<script src="http://js.arcgis.com/3.12/"></script>
|
||||
|
||||
<!-- include spec files here... -->
|
||||
<script type="text/javascript" src="spec/editsStoreSpec2.js"></script>
|
||||
@ -35,7 +35,7 @@
|
||||
"esri/SpatialReference","esri/geometry",
|
||||
"dojo/dom", "dojo/on", "dojo/query",
|
||||
"dojo/dom-construct",
|
||||
"../dist/offline-edit-min.js",
|
||||
"../dist/offline-edit-src.js",
|
||||
"dojo/domReady!"],
|
||||
function(Map,
|
||||
GraphicsLayer, Graphic, SimpleFillSymbol, SimpleMarkerSymbol, SimpleLineSymbol,
|
||||
|
||||
@ -194,46 +194,78 @@ describe("Internal Methods", function()
|
||||
});
|
||||
});
|
||||
|
||||
//describe("Public Interface", function()
|
||||
//{
|
||||
// describe("Support detection", function()
|
||||
// {
|
||||
// it("detect local storage support", function()
|
||||
// {
|
||||
// expect(g_editsStore.isSupported()).toBeTruthy();
|
||||
// })
|
||||
// });
|
||||
//
|
||||
// describe("Edit queue management", function()
|
||||
// {
|
||||
// describe("Normal edits", function()
|
||||
// {
|
||||
// it("reset edits queue", function()
|
||||
// {
|
||||
// for( var key in window.localStorage )
|
||||
// {
|
||||
// if( key.indexOf(KEY_PREFIX)==0 )
|
||||
// window.localStorage.removeItem(key);
|
||||
// }
|
||||
//
|
||||
// g_editsStore.resetEditsQueue();
|
||||
// expect(g_editsStore.pendingEditsCount()).toBe(0);
|
||||
// });
|
||||
//
|
||||
// it("add edits to edits queue", function()
|
||||
// {
|
||||
// var result;
|
||||
// result = g_editsStore.pushEdit(g_editsStore.ADD, 6, g_test.pointFeature);
|
||||
// expect(result.success).toBeTruthy();
|
||||
// expect(g_editsStore.pendingEditsCount()).toBe(1);
|
||||
// result = g_editsStore.pushEdit(g_editsStore.UPDATE, 3, g_test.polygonFeature);
|
||||
// expect(result.success).toBeTruthy();
|
||||
// expect(g_editsStore.pendingEditsCount()).toBe(2);
|
||||
// result = g_editsStore.pushEdit(g_editsStore.DELETE, 2, g_test.lineFeature);
|
||||
// expect(result.success).toBeTruthy();
|
||||
// expect(g_editsStore.pendingEditsCount()).toBe(3);
|
||||
// });
|
||||
//
|
||||
var async = new AsyncSpec(this);
|
||||
|
||||
describe("Public Interface", function()
|
||||
{
|
||||
describe("Support detection", function() {
|
||||
it("detect IndexedDB support", function () {
|
||||
expect(g_editsStore.isSupported()).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe("Initialize database", function(){
|
||||
|
||||
async.it("initialize database", function (done) {
|
||||
g_editsStore.init(function (success) {
|
||||
expect(success).toEqual(true);
|
||||
done();
|
||||
})
|
||||
});
|
||||
|
||||
async.it("reset edits queue", function (done) {
|
||||
g_editsStore.resetEditsQueue(function (result) {
|
||||
expect(result).toEqual(true);
|
||||
|
||||
g_editsStore.pendingEditsCount(function (count) {
|
||||
expect(count).toBe(0);
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Edit queue management", function()
|
||||
{
|
||||
describe("Normal edits", function()
|
||||
{
|
||||
async.it("add edits to edits queue", function(done)
|
||||
{
|
||||
g_editsStore.pushEdit(g_editsStore.ADD, 6, g_test.pointFeature, function(result){
|
||||
expect(result).toEqual(true);
|
||||
|
||||
g_editsStore.pendingEditsCount(function(count){
|
||||
expect(count).toBe(1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
async.it("update edits to edits queue", function(done)
|
||||
{
|
||||
g_editsStore.pushEdit(g_editsStore.UPDATE, 3, g_test.polygonFeature, function(result){
|
||||
expect(result).toEqual(true);
|
||||
|
||||
g_editsStore.pendingEditsCount(function(count){
|
||||
expect(count).toBe(2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
async.it("delete edits to edits queue", function(done)
|
||||
{
|
||||
g_editsStore.pushEdit(g_editsStore.DELETE, 2, g_test.lineFeature, function(result){
|
||||
expect(result).toEqual(true);
|
||||
|
||||
g_editsStore.pendingEditsCount(function(count){
|
||||
expect(count).toBe(3);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// it("pending edits", function()
|
||||
// {
|
||||
// expect(g_editsStore.hasPendingEdits()).toBeTruthy();
|
||||
@ -281,7 +313,7 @@ describe("Internal Methods", function()
|
||||
// });
|
||||
// });
|
||||
//
|
||||
// });
|
||||
});
|
||||
//
|
||||
// describe("Local Storage size", function()
|
||||
// {
|
||||
@ -398,8 +430,8 @@ describe("Internal Methods", function()
|
||||
// {
|
||||
// });
|
||||
// }
|
||||
// })
|
||||
//});
|
||||
})
|
||||
});
|
||||
//
|
||||
//describe("Reset store", function()
|
||||
//{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user