Skip to content

Commit

Permalink
v3.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
andygup committed May 12, 2016
1 parent 538ab19 commit d5d2252
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 44 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# offline-editor-js - Changelog

## Version 3.2.0 - May 11, 2016

No breaking changes.

**Enhancements**
* Added CleanFeatureService.js util for deleting all features in a demo feature service

**Bug Fixes**
* Closes #461 - proxyPath not respected in OfflineEditAdvanced. Also fixed proxyPath in OfflineEditBasic
* Closes #462 - getNextLowestTempId does not exist in editStorePOLS.
* Closes #463 - sample feature service no longer allows editing. Complete rewrite.

## Version 3.1.0 - April 21, 2016

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

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

11 changes: 7 additions & 4 deletions dist/offline-edit-advanced-src.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! esri-offline-maps - v3.1.0 - 2016-04-21
/*! esri-offline-maps - v3.2.0 - 2016-05-12
* Copyright (c) 2016 Environmental Systems Research Institute, Inc.
* Apache License*/
// Configure offline/online detection
Expand Down Expand Up @@ -2056,8 +2056,11 @@ define([
}
}

// Respect the proxyPath if one has been set (Added at v3.2.0)
var url = this.proxyPath ? this.proxyPath + "?" + layer.url : layer.url;

var req = new XMLHttpRequest();
req.open("POST", layer.url + "/applyEdits", true);
req.open("POST", url + "/applyEdits", true);
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
req.onload = function()
{
Expand All @@ -2068,7 +2071,7 @@ define([
callback(obj.addResults, obj.updateResults, obj.deleteResults);
}
catch(err) {
console.error("EDIT REQUEST REPONSE WAS NOT SUCCESSFUL:", req);
console.error("EDIT REQUEST RESPONSE WAS NOT SUCCESSFUL:", req);
errback("Unable to parse xhr response", req);
}
}
Expand Down Expand Up @@ -2735,7 +2738,7 @@ O.esri.Edit.EditStore = function () {
else {
callback(null, "no db");
}
},
};

/**
* Returns all the edits as a single Array via the callback
Expand Down
16 changes: 11 additions & 5 deletions dist/offline-edit-basic-min.js

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

112 changes: 85 additions & 27 deletions dist/offline-edit-basic-src.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! esri-offline-maps - v3.1.0 - 2016-04-21
/*! esri-offline-maps - v3.2.0 - 2016-05-12
* Copyright (c) 2016 Environmental Systems Research Institute, Inc.
* Apache License*/
// Configure offline/online detection
Expand Down Expand Up @@ -501,21 +501,6 @@ define([
}, this);
return files;
};

// we need to identify ADDs before sending them to the server
// we assign temporary ids (using negative numbers to distinguish them from real ids)
// 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 All @@ -524,20 +509,39 @@ define([
// We are currently only passing in a single deferred.
all(extendPromises).then(function (r) {

if(self._autoOfflineDetect){
Offline.on('up', function(){ // jshint ignore:line
if(r[0].success){

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

Offline.on('down', function(){ // jshint ignore:line
self.goOffline(); // jshint ignore:line
});
}
if(self._autoOfflineDetect){
Offline.on('up', function(){ // jshint ignore:line

callback(true, null);
self.goOnline(function(success,error){ // jshint ignore:line
console.log("GOING ONLINE");
});
});

Offline.on('down', function(){ // jshint ignore:line
self.goOffline(); // jshint ignore:line
});
}

callback(true, null);
}
else {
callback(false, r[0].error);
}
});

}, // extend
Expand Down Expand Up @@ -963,8 +967,11 @@ define([
}
}

// Respect the proxyPath if one has been set (Added at v3.2.0)
var url = this.proxyPath ? this.proxyPath + "?" + layer.url : layer.url;

var req = new XMLHttpRequest();
req.open("POST", layer.url + "/applyEdits", true);
req.open("POST", url + "/applyEdits", true);
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
req.onload = function()
{
Expand Down Expand Up @@ -1196,6 +1203,57 @@ O.esri.Edit.EditStorePOLS = 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 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) {
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");
}
};

/**
* Update an edit already exists in the database
* @param operation add, update or delete
Expand Down
2 changes: 1 addition & 1 deletion dist/offline-tiles-advanced-src.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! esri-offline-maps - v3.1.0 - 2016-04-21
/*! esri-offline-maps - v3.2.0 - 2016-05-12
* Copyright (c) 2016 Environmental Systems Research Institute, Inc.
* Apache License*/
define([
Expand Down
2 changes: 1 addition & 1 deletion dist/offline-tiles-basic-src.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! esri-offline-maps - v3.1.0 - 2016-04-21
/*! esri-offline-maps - v3.2.0 - 2016-05-12
* Copyright (c) 2016 Environmental Systems Research Institute, Inc.
* Apache License*/
define([
Expand Down
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 @@
/*! esri-offline-maps - v3.1.0 - 2016-04-21
/*! esri-offline-maps - v3.2.0 - 2016-05-12
* Copyright (c) 2016 Environmental Systems Research Institute, Inc.
* Apache License*/
/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "esri-offline-maps",
"version": "3.1.0",
"version": "3.2.0",
"description": "Lightweight set of libraries for working offline with map tiles and editing with ArcGIS feature services",
"author": "Andy Gup <[email protected]> (http://blog.andygup.net)",
"license": "Apache 2.0",
Expand Down
2 changes: 1 addition & 1 deletion samples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"appHomePage": "appcache-tiles.html",
"optimizedApiURL": "../samples/jsolib",
"arcGISBaseURL": "http://js.arcgis.com/3.14",
"version": "3.1.0",
"version": "3.2.0",
"private": true,
"description": "manifest generator project",
"repository": {
Expand Down

0 comments on commit d5d2252

Please sign in to comment.