Skip to content

Commit

Permalink
Merge pull request #450 from robkspeer/robkspeerBranch
Browse files Browse the repository at this point in the history
v3.0.6
  • Loading branch information
andygup committed Mar 30, 2016
2 parents 82bb4a7 + 574b8b9 commit c19b4ce
Show file tree
Hide file tree
Showing 21 changed files with 299 additions and 112 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# offline-editor-js - Changelog

## Version 3.0.6 - March 30, 2016

No breaking changes

**Bug Fixes**
* Closes #448 - OfflineEditAdvanced - after multiple offline restarts, UID begins at -1 again for Adds.

**Enhancements**
* Closes #451 - OfflineTiles - Option for offline_id_manager localStorage key name
* Updates to howtousetiles.md documentation for the offlineIdManager parameter.

## Version 3.0.5 - Feb 2, 2016

No breaking changes. Documentation updates only.
Expand Down
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ module.exports = function(grunt) {
beautify: {
semicolons: false //Required: prevents dojo parser errors w/ minified files in this project
},
preserveComments: 'some',
preserveComments: /^!/,
wrap: false
// mangle: {
// except: ['O']
Expand Down
18 changes: 12 additions & 6 deletions dist/offline-edit-advanced-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 67 additions & 3 deletions dist/offline-edit-advanced-src.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*! esri-offline-maps - v3.0.3 - 2015-11-30
* Copyright (c) 2015 Environmental Systems Research Institute, Inc.
/*! esri-offline-maps - v3.0.6 - 2016-03-30
* Copyright (c) 2016 Environmental Systems Research Institute, Inc.
* Apache License*/
// Configure offline/online detection
// Requires: http://github.hubspot.com/offline/docs/welcome/
Expand Down Expand Up @@ -1166,7 +1166,19 @@ define([

// we need to identify ADDs before sending them to the server
// we assign temporary ids (using negative numbers to distinguish them from real ids)
layer._nextTempId = -1;
// query the database first to find any existing offline adds, and find the next lowest integer to start with.
this._editStore.getNextLowestTempId(layer, function(value, status){
if(status === "success"){
console.log("_nextTempId:", value);
layer._nextTempId = value;
}
else{
console.log("_nextTempId, not success:", value);
layer._nextTempId = -1;
console.debug(layer._nextTempId);
}
});

layer._getNextTempId = function () {
return this._nextTempId--;
};
Expand Down Expand Up @@ -2673,6 +2685,58 @@ O.esri.Edit.EditStore = function () {
}
};

/*
* Query the database, looking for any existing Add temporary OIDs, and return the nextTempId to be used.
* @param feature - extended layer from offline edit advanced
* @param callback {int, messageString} or {null, messageString}
*/
this.getNextLowestTempId = function (feature, callback) {
var addOIDsArray = [],
self = this;

if (this._db !== null) {

var fLayerJSONId = this.FEATURE_LAYER_JSON_ID;
var fCollectionId = this.FEATURE_COLLECTION_ID;
var phantomGraphicPrefix = this.PHANTOM_GRAPHIC_PREFIX;

var transaction = this._db.transaction([this.objectStoreName])
.objectStore(this.objectStoreName)
.openCursor();

transaction.onsuccess = function (event) {
var cursor = event.target.result;
if (cursor && cursor.value && cursor.value.id) {
// Make sure we are not return FeatureLayer JSON data or a Phantom Graphic
if (cursor.value.id !== fLayerJSONId && cursor.value.id !== fCollectionId && cursor.value.id.indexOf(phantomGraphicPrefix) == -1) {
if(cursor.value.layer === feature.url && cursor.value.operation === "add"){ // check to make sure the edit is for the feature we are looking for, and that the operation is an add.
addOIDsArray.push(cursor.value.graphic.attributes[self.objectId]); // add the temporary OID to the array
}
}
cursor.continue();
}
else {
if(addOIDsArray.length === 0){ // if we didn't find anything,
callback(-1, "success"); // we'll start with -1
}
else{
var filteredOIDsArray = addOIDsArray.filter(function(val){ // filter out any non numbers from the array...
return !isNaN(val); // .. should anything have snuck in or returned a NaN
});
var lowestTempId = Math.min.apply(Math, filteredOIDsArray); // then find the lowest number from the array
callback(lowestTempId-1, "success"); // and we'll start with one less than tat.
}
}
}.bind(this);
transaction.onerror = function (err) {
callback(null, err);
};
}
else {
callback(null, "no db");
}
},

/**
* Returns all the edits as a single Array via the callback
* @param callback {array, messageString} or {null, messageString}
Expand Down
Loading

0 comments on commit c19b4ce

Please sign in to comment.