Skip to content

Commit

Permalink
Merge pull request #378 from andygup/v2.11
Browse files Browse the repository at this point in the history
v2.11
  • Loading branch information
andygup committed Jul 30, 2015
2 parents 2ae3071 + 71af75d commit 94f552c
Show file tree
Hide file tree
Showing 17 changed files with 654 additions and 417 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# offline-editor-js - Changelog

## Version 2.11

No breaking changes to the public API. This is a recommended update. This version is focused on improving the sync logic between the library and the feature service. Many internal-only breaking changes.

**Enhancements**
* Closes #361 - Deletes each database record after a successful sync rather than a batch database delete.
* Added additional properties to the `goOnline()` sync process callback object to better capture any errors.
* Improved error handling when submitting edits during sync.

**Breaking Changes Internal - Private**
* INTERNAL: `editStore.editExists()` - if an edit does not exist then the old error message "layer id is not a match" has been replaced with "objectId is not a match".
* INTERNAL: `editStore.deleteFeatureLayerJSON()` - if the deletion was unsuccessful instead of returning `null` the method now returns a message string "object was not deleted".
* INTERNAL: `editsStore.resetLimitedPhantomGraphicsQueue()` - Deprecated.
* INTERNAL: `offlineFeaturesManager._cleanSuccessfulEditsDatabaseRecords()` - Deprecated and replaced by `_cleanDatabase()`.
* INTERNAL: `offlineFeaturesManager._fieldSegment` - Deprecated.
* INTERNAL: `offlineFeaturesManager._fileSegment` - Deprecated.
* INTERNAL: `offlineFeaturesManager._internalApplyEdits()` - Deprecated.
* INTERNAL: `offlineFeaturewsManager._internalApplyEditsFeaturecollection()` - renamed to `_internalApplyEditsAll()`.

## Version 2.10 - July 27, 2015

No breaking changes.
Expand Down
7 changes: 4 additions & 3 deletions dist/offline-edit-min.js

Large diffs are not rendered by default.

449 changes: 281 additions & 168 deletions dist/offline-edit-src.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/offline-tiles-advanced-min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/offline-tiles-advanced-src.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! offline-editor-js - v2.10.0 - 2015-07-27
/*! offline-editor-js - v2.11.0 - 2015-07-30
* Copyright (c) 2015 Environmental Systems Research Institute, Inc.
* Apache License*/
define([
Expand Down Expand Up @@ -31,7 +31,7 @@ define([
callback(false);
}

if( dbConfig === "undefined" || dbConfig === null){
if( dbConfig === undefined || dbConfig === null){
// Database properties
this.DB_NAME = "offline_tile_store"; // Sets the database name.
this.DB_OBJECTSTORE_NAME = "tilepath"; // Represents an object store that allows access to a set of data in the IndexedDB database
Expand Down
4 changes: 2 additions & 2 deletions dist/offline-tiles-basic-min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/offline-tiles-basic-src.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! offline-editor-js - v2.10.0 - 2015-07-27
/*! offline-editor-js - v2.11.0 - 2015-07-30
* Copyright (c) 2015 Environmental Systems Research Institute, Inc.
* Apache License*/
define([
Expand Down Expand Up @@ -42,7 +42,7 @@ define([
layer._minZoom = null;
layer._maxZoom = null;

if( dbConfig === "undefined" || dbConfig === null){
if( dbConfig === undefined || dbConfig === null){
// Database properties
layer.DB_NAME = "offline_tile_store"; // Sets the database name.
layer.DB_OBJECTSTORE_NAME = "tilepath"; // Represents an object store that allows access to a set of data in the IndexedDB database
Expand Down
2 changes: 1 addition & 1 deletion dist/offline-tpk-min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/offline-tpk-src.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! offline-editor-js - v2.10.0 - 2015-07-27
/*! offline-editor-js - v2.11.0 - 2015-07-30
* Copyright (c) 2015 Environmental Systems Research Institute, Inc.
* Apache License*/
/**
Expand Down
20 changes: 20 additions & 0 deletions doc/howtouseeditlibrary.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,3 +361,23 @@ You can check if there are any edits pending. If there are edits then you can it
})
```
### How to empty the edits database during testing?
Some browsers, like Firefox, make it difficult or impossible to delete data that's in an IndexedDB database. And, there may be times during testing were you are stuck with bad or old data in the database and you need to delete it. Fortunately there is a pattern using `editsStore.resetEditsQueue()` for helping you out with this situation.
You can run the reset code seperately or you can run the app with this pattern. If you do use the pattern below be sure to comment out the reset code and then re-run the app. You should be good to go again with a completely empty database.
```js
offlineFeaturesManager.extend(myFeatureLayer,function(result, error) {
if(result) {
console.log("offlineFeaturesManager initialized.");
offlineFeaturesManager._editStore.resetEditsQueue(function(success){
console.log("DATABASE DELETED");
});
. . .
. . .
});
```
155 changes: 76 additions & 79 deletions lib/edit/editsStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,8 @@ O.esri.Edit.EditStore = function () {
// IF the delete was successful, then the record should return an error because it doesn't exist.
// We aren't 100% sure how all platforms will perform so we also trap the promise for return results.
self.editExists(id).then(function (results) {
// If the result is false then in theory the id no longer exists
// and we should return 'true' to indicate a successful delete operation.
results.success === false ? callback(true, {message: "id does not exist"}) : callback(false, {message: null});
// If edit does exist then we have not been successful in deleting the object.
callback(false, {message: "object was not deleted."});
},
function (err) {
// If the result is false then in theory the id no longer exists
Expand All @@ -231,26 +230,22 @@ O.esri.Edit.EditStore = function () {
// Step 1 - lets see if record exits. If it does not then return callback. Otherwise,
// continue on with the deferred.
self.editExists(id).then(function (result) {
if (result && result.success) {

var objectStore = db.transaction([self.objectStoreName], "readwrite").objectStore(self.objectStoreName);
var objectStore = db.transaction([self.objectStoreName], "readwrite").objectStore(self.objectStoreName);

// Step 2 - go ahead and delete graphic
var objectStoreDeleteRequest = objectStore.delete(id);
// Step 2 - go ahead and delete graphic
var objectStoreDeleteRequest = objectStore.delete(id);

// Step 3 - We know that the onsuccess will always fire unless something serious goes wrong.
// So we go ahead and resolve the deferred here.
objectStoreDeleteRequest.onsuccess = function () {
deferred.resolve(true);
};
// Step 3 - We know that the onsuccess will always fire unless something serious goes wrong.
// So we go ahead and resolve the deferred here.
objectStoreDeleteRequest.onsuccess = function () {
deferred.resolve(true);
};

objectStoreDeleteRequest.onerror = function (msg) {
deferred.reject({success: false, error: msg});
};

objectStoreDeleteRequest.onerror = function (msg) {
deferred.reject({success: false, error: msg});
};
}
else {
deferred.reject({success: false, message: "id does not exist"});
}
},
// If there is an error in editExists()
function (err) {
Expand Down Expand Up @@ -396,47 +391,49 @@ O.esri.Edit.EditStore = function () {

// Step 1 - lets see if record exits. If it does then return callback.
self.editExists(id).then(function (result) {
if (result.success) {
// Step 4 - Then we check to see if the record actually exists or not.
deferred.then(function (result) {

// IF the delete was successful, then the record should return 'false' because it doesn't exist.
self.editExists(id).then(function (results) {
results.success === false ? callback(true) : callback(false);
},
function (err) {
callback(true); //because we want this test to throw an error. That means item deleted.
});

// Step 4 - Then we check to see if the record actually exists or not.
deferred.then(function (result) {

// IF the delete was successful, then the record should return 'false' because it doesn't exist.
self.editExists(id).then(function (results) {
callback(false, "item was not deleted"); // item is still in the database!!
},
// There was a problem with the delete operation on the database
function (err) {
callback(false, err);
callback(true, "item successfully deleted"); //because we want this test to throw an error. That means item deleted.
});
},
// There was a problem with the delete operation on the database
function (err) {
callback(false, err);
});

var objectStore = db.transaction([self.objectStoreName], "readwrite").objectStore(self.objectStoreName);
var objectStore = db.transaction([self.objectStoreName], "readwrite").objectStore(self.objectStoreName);

// Step 2 - go ahead and delete graphic
var objectStoreDeleteRequest = objectStore.delete(id);
// Step 2 - go ahead and delete graphic
var objectStoreDeleteRequest = objectStore.delete(id);

// Step 3 - We know that the onsuccess will always fire unless something serious goes wrong.
// So we go ahead and resolve the deferred here.
objectStoreDeleteRequest.onsuccess = function () {
deferred.resolve(true);
};
// Step 3 - We know that the onsuccess will always fire unless something serious goes wrong.
// So we go ahead and resolve the deferred here.
objectStoreDeleteRequest.onsuccess = function () {
deferred.resolve(true);
};

objectStoreDeleteRequest.onerror = function (msg) {
deferred.reject({success: false, error: msg});
};
}
},
// If there is an error in editExists()
function (err) {
callback(false);
});
objectStoreDeleteRequest.onerror = function (msg) {
deferred.reject({success: false, error: msg});
};
},
// If there is an error in editExists()
function (err) {
callback(false, "item doesn't exist in db");
});
});
};

/**
* DEPRECATED at v2.11
* TO-DO remove in the next release
*
* Removes some phantom graphics from database.
* The responseObject contains {id,layer,tempId,addResults,updateResults,deleteResults}.
* IF there are no results.success then nothing will be deleted.
Expand Down Expand Up @@ -728,38 +725,38 @@ O.esri.Edit.EditStore = function () {

// Step 1 - lets see if record exits. If it does then return callback.
self.editExists(id).then(function (result) {
if (result.success) {
// Step 4 - Then we check to see if the record actually exists or not.
deferred.then(function (result) {

// IF the delete was successful, then the record should return 'false' because it doesn't exist.
self.editExists(id).then(function (results) {
results.success === false ? callback(true) : callback(false);
},
function (err) {
callback(true); //because we want this test to throw an error. That means item deleted.
});
},
// There was a problem with the delete operation on the database
function (err) {
callback(false, err);
});

var objectStore = db.transaction([self.objectStoreName], "readwrite").objectStore(self.objectStoreName);
// Step 4 - Then we check to see if the record actually exists or not.
deferred.then(function (result) {

// IF the delete was successful, then the record should return 'false' because it doesn't exist.
self.editExists(id).then(function (results) {
callback(false);
},
function (err) {
callback(true); //because we want this test to throw an error. That means item deleted.
});
},
// There was a problem with the delete operation on the database
function (err) {
callback(false, err);
});

// Step 2 - go ahead and delete graphic
var objectStoreDeleteRequest = objectStore.delete(id);
var objectStore = db.transaction([self.objectStoreName], "readwrite").objectStore(self.objectStoreName);

// Step 3 - We know that the onsuccess will always fire unless something serious goes wrong.
// So we go ahead and resolve the deferred here.
objectStoreDeleteRequest.onsuccess = function () {
deferred.resolve(true);
};
// Step 2 - go ahead and delete graphic
var objectStoreDeleteRequest = objectStore.delete(id);

// Step 3 - We know that the onsuccess will always fire unless something serious goes wrong.
// So we go ahead and resolve the deferred here.
objectStoreDeleteRequest.onsuccess = function () {
deferred.resolve(true);
};

objectStoreDeleteRequest.onerror = function (msg) {
deferred.reject({success: false, error: msg});
};

objectStoreDeleteRequest.onerror = function (msg) {
deferred.reject({success: false, error: msg});
};
}
},
// If there is an error in editExists()
function (err) {
Expand Down Expand Up @@ -819,7 +816,7 @@ O.esri.Edit.EditStore = function () {
};

/**
* Verify is an edit already exists in the database. Checks the objectId and layerId.
* Verify is an edit already exists in the database. Checks the objectId.
* @param id
* @returns {deferred} {success: boolean, error: message}
* @private
Expand All @@ -844,7 +841,7 @@ O.esri.Edit.EditStore = function () {
deferred.resolve({success: true, error: null});
}
else {
deferred.reject({success: false, error: "Layer id is not a match."});
deferred.reject({success: false, error: "objectId is not a match."});
}
};

Expand Down
Loading

0 comments on commit 94f552c

Please sign in to comment.