Skip to content

Commit

Permalink
feat(attrib-loader): handle data load fail elegantly
Browse files Browse the repository at this point in the history
  • Loading branch information
james-rae committed May 1, 2015
1 parent 9fd4b28 commit 8de270e
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions src/js/RAMP/Modules/attributeLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,23 +105,28 @@ define([
});

defData.then(function (dataResult) {
var len = dataResult.features.length;
if (len > 0) {
if (maxBatch === -1) {
//this is our first batch and our server is 10.0. set the max batch size to this batch size
maxBatch = len;
}
if (len < maxBatch) {
//this batch is less than the max. this is last batch. no need to query again.
callerDef.resolve(dataArray.concat(dataResult.features));
if (dataResult.features) {
var len = dataResult.features.length;
if (len > 0) {
if (maxBatch === -1) {
//this is our first batch and our server is 10.0. set the max batch size to this batch size
maxBatch = len;
}
if (len < maxBatch) {
//this batch is less than the max. this is last batch. no need to query again.
callerDef.resolve(dataArray.concat(dataResult.features));
} else {
//stash the result and call the service again for the next batch of data.
//max id becomes last object id in the current batch
loadDataBatch(dataResult.features[len - 1].attributes[idField], maxBatch, dataArray.concat(dataResult.features), layerUrl, idField, callerDef);
}
} else {
//stash the result and call the service again for the next batch of data.
//max id becomes last object id in the current batch
loadDataBatch(dataResult.features[len - 1].attributes[idField], maxBatch, dataArray.concat(dataResult.features), layerUrl, idField, callerDef);
//no more data. we are done
callerDef.resolve(dataArray);
}
} else {
//no more data. we are done
callerDef.resolve(dataArray);
//it is possible to have an error, but it comes back on the "success" channel.
callerDef.reject(dataResult.error);
}
},
function (error) {
Expand All @@ -143,7 +148,6 @@ define([
case GlobalStorage.layerType.feature:

console.log('BEGIN ATTRIB LOAD: ' + layerId);
RampMap.updateDatagridUpdatingState(RAMP.layerRegistry[layerId], true);

//extract info for this service
var defService = script.get(layerUrl, {
Expand All @@ -152,6 +156,8 @@ define([
});

defService.then(function (serviceResult) {
RampMap.updateDatagridUpdatingState(RAMP.layerRegistry[layerId], true);

//set up layer data object based on layer data
var maxBatchSize = serviceResult.maxRecordCount || -1, //10.0 server will not supply a max record value
defFinished = new Deferred(),
Expand Down Expand Up @@ -183,8 +189,10 @@ define([
console.log('END ATTRIB LOAD: ' + layerId);
},
function (error) {
console.log('error getting attribute data');
console.log(error);
console.log('error getting attribute data for id ' + layerId);
//set layer to error state
RampMap.updateDatagridUpdatingState(RAMP.layerRegistry[layerId], false);
topic.publish(EventManager.LayerLoader.LAYER_ERROR, { layer: RAMP.layerRegistry[layerId], error: error });
});
},
function (error) {
Expand Down

0 comments on commit 8de270e

Please sign in to comment.