From 3a1fc5b183d7d53b0b4135b5105b2fec941756e0 Mon Sep 17 00:00:00 2001 From: Nils Gehlenborg Date: Tue, 11 Aug 2015 13:17:45 -0400 Subject: [PATCH] Save selection in sessionStorage only on failed API access --- .../js/refinery/core/node_set_manager.js | 17 ++-- refinery/ui/src/js/igv.js | 97 +++++++++++-------- refinery/ui/src/js/node_mapping.js | 15 ++- 3 files changed, 81 insertions(+), 48 deletions(-) diff --git a/refinery/static/source/js/refinery/core/node_set_manager.js b/refinery/static/source/js/refinery/core/node_set_manager.js index 54027998a0..3540c86a8b 100644 --- a/refinery/static/source/js/refinery/core/node_set_manager.js +++ b/refinery/static/source/js/refinery/core/node_set_manager.js @@ -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", @@ -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 ); } }); }; diff --git a/refinery/ui/src/js/igv.js b/refinery/ui/src/js/igv.js index 57e43fc78a..bf51994644 100644 --- a/refinery/ui/src/js/igv.js +++ b/refinery/ui/src/js/igv.js @@ -7,7 +7,7 @@ angular.module('refineryIgv', []) $scope.igvConfig = { query: null, - annotation: null, + annotation: null, node_selection: [], node_selection_blacklist_mode: true }; @@ -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); }; diff --git a/refinery/ui/src/js/node_mapping.js b/refinery/ui/src/js/node_mapping.js index 8e2867afc1..5c479b0c44 100644 --- a/refinery/ui/src/js/node_mapping.js +++ b/refinery/ui/src/js/node_mapping.js @@ -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() { @@ -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); + } + }); };