Skip to content

Commit

Permalink
Save selection in sessionStorage only on failed API access
Browse files Browse the repository at this point in the history
  • Loading branch information
ngehlenborg committed Aug 11, 2015
1 parent b4ac6a5 commit 3a1fc5b
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 48 deletions.
17 changes: 9 additions & 8 deletions refinery/static/source/js/refinery/core/node_set_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,6 @@ NodeSetManager.prototype.updateState = function (state, callbackSuccess) {

var data = state;

// save to sessionStorage
self.saveCurrentSelectionToSession(
data.name,
data.summary,
data.solr_query,
data.solr_query_components,
data.node_count );

$.ajax({
url: self.createUpdateUrl(state),
type: "PUT",
Expand All @@ -210,6 +202,15 @@ NodeSetManager.prototype.updateState = function (state, callbackSuccess) {
if ($.isEmptyObject(result)) {
return;
}
},
error: function(result) {
// save to sessionStorage
self.saveCurrentSelectionToSession(
data.name,
data.summary,
data.solr_query,
data.solr_query_components,
data.node_count );
}
});
};
Expand Down
97 changes: 59 additions & 38 deletions refinery/ui/src/js/igv.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ angular.module('refineryIgv', [])

$scope.igvConfig = {
query: null,
annotation: null,
annotation: null,
node_selection: [],
node_selection_blacklist_mode: true
};
Expand Down Expand Up @@ -42,51 +42,72 @@ angular.module('refineryIgv', [])
$scope.igvConfig.node_selection_blacklist_mode = JSON.parse( response.objects[0].solr_query_components ).documentSelectionBlacklistMode;
$scope.igvConfig.annotation = null; //response.objects[0].solr_query;

$http({
method: 'POST',
url: '/solr/igv/',
headers: {'X-Requested-With': 'XMLHttpRequest'},
dataType: 'json',
data: $scope.igvConfig,
}).success(function(response) {

// update message
if ( response.species_count === 0 ) {
$scope.message = "Unable to detect species and genome build. Please select the correct genome and launch IGV.";
}
else if ( response.species_count === 1 ) {
$scope.message = null;
$scope.speciesIndex = 0;
}
else {
$scope.message = "Multiple species detected. Please select a genome and launch IGV. You may repeat this step multiple times.";
}
$scope.retrieveSpecies();

// update species list
$scope.speciesList.length = 0;
for (var key in response.species) {
if (response.species.hasOwnProperty(key)) {
$scope.speciesList.push( { name: key, url: response.species[key] });
}
}, function(response){
$scope.isLoadingSpecies = true;
$scope.messageType = "error";
$scope.message = "Sorry! Unable to get the contents of the selected file set.";
$log.info( "Error accessing Node Set API. Attempting to read from sessionStorage" );

if ($window.sessionStorage) {
var currentSelectionSessionKey = externalStudyUuid + "_" + externalAssayUuid + "_" + "currentSelection";
console.log( "Reading " + currentSelectionSessionKey + " from session storage" );
response.objects = [angular.fromJson( $window.sessionStorage.getItem(currentSelectionSessionKey))];
$scope.igvConfig.query = response.objects[0].solr_query;
$scope.igvConfig.node_selection = JSON.parse( response.objects[0].solr_query_components ).documentSelection;
$scope.igvConfig.node_selection_blacklist_mode = JSON.parse( response.objects[0].solr_query_components ).documentSelectionBlacklistMode;
$scope.igvConfig.annotation = null; //response.objects[0].solr_query;

$scope.retrieveSpecies();
}

else {
$scope.isLoadingSpecies = false;
}

}).error(function(response, status) {
$scope.isLoadingSpecies = false;
$scope.messageType = "error";
$scope.message = "Sorry! Unable to configure IGV for the selected file set.";
$log.error("Error creating IGV session URLs. (error status " + status + ")");
});

}, function(response){
$scope.isLoadingSpecies = false;
$scope.messageType = "error";
$scope.message = "Sorry! Unable to get the contents of the selected file set.";
$log.error( "Error accessing Node Set API." );
});
};

$scope.retrieveSpecies = function() {
$http({
method: 'POST',
url: '/solr/igv/',
headers: {'X-Requested-With': 'XMLHttpRequest'},
dataType: 'json',
data: $scope.igvConfig,
}).success(function(response) {

// update message
if ( response.species_count === 0 ) {
$scope.message = "Unable to detect species and genome build. Please select the correct genome and launch IGV.";
}
else if ( response.species_count === 1 ) {
$scope.message = null;
$scope.speciesIndex = 0;
}
else {
$scope.message = "Multiple species detected. Please select a genome and launch IGV. You may repeat this step multiple times.";
}

// update species list
$scope.speciesList.length = 0;
for (var key in response.species) {
if (response.species.hasOwnProperty(key)) {
$scope.speciesList.push( { name: key, url: response.species[key] });
}
}

$scope.isLoadingSpecies = false;

}).error(function(response, status) {
$scope.isLoadingSpecies = false;
$scope.messageType = "error";
$scope.message = "Sorry! Unable to configure IGV for the selected file set.";
$log.error("Error creating IGV session URLs. (error status " + status + ")");
});
};

$scope.launchIgv = function() {
$window.open($scope.speciesList[$scope.speciesIndex].url);
};
Expand Down
15 changes: 13 additions & 2 deletions refinery/ui/src/js/node_mapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ angular.module('refineryNodeMapping', [
};
})

.controller('NodeSetListApiCtrl', function($scope, $rootScope, NodeSetList) {
.controller('NodeSetListApiCtrl', function($scope, $rootScope, $window, NodeSetList) {
'use strict';

$scope.updateCurrentNodeSet = function() {
Expand All @@ -546,8 +546,19 @@ angular.module('refineryNodeMapping', [
}).$promise.then(function(data){
$scope.nodesetList = data.objects;
$scope.updateCurrentNodeSet();

},function(error){
console.log(error);
console.log("Couldn't read node set list.");
if ($window.sessionStorage) {
var currentSelectionSessionKey = externalStudyUuid + "_" + externalAssayUuid + "_" + "currentSelection";
console.log( "Reading " + currentSelectionSessionKey + " from session storage" );
$scope.nodesetList = [angular.fromJson( $window.sessionStorage.getItem(currentSelectionSessionKey))];
$scope.updateCurrentNodeSet();
}
else {
console.log(error);
}

});
};

Expand Down

0 comments on commit 3a1fc5b

Please sign in to comment.