diff --git a/app/modules/auth/auth.factory.js b/app/modules/auth/auth.factory.js index 7db4afc..e63f37a 100644 --- a/app/modules/auth/auth.factory.js +++ b/app/modules/auth/auth.factory.js @@ -6,18 +6,36 @@ require('./auth.module.js') var OAuth = require('panoptes-client/lib/oauth'); // @ngInject -function authFactory($interval, $timeout, $location, $window, localStorageService, ModalsFactory, zooAPI, zooAPIConfig, CribsheetFactory, $rootScope) { +function authFactory($location, $rootScope, $state, $transitions, $window, AnnotationsFactory, zooAPI, CribsheetFactory) { var factory; var _user = {}; OAuth.checkCurrent() - .then(function (user) { - if (user) { - _setUserData(); - } - }); + .then(function (user) { + if (user) { + _setUserData(); + } + }) + .then(function() { + zooAPI.beforeEveryRequest = function() { + return OAuth.checkBearerToken() + .then(function (token) { + // The Panoptes client doesn't return an error but just null when it can't refresh the token. + // So we check for null, instead of using a catch block. + if (_user.id && token === null) { + // We're logged in but don't have a token any more. + alert('Your session is expired. Press OK to save your work and start a new one.') + // Save any unsaved work and redirect to Panoptes for a new token. + AnnotationsFactory.updateCache(); + OAuth.signIn($location.absUrl()); + // Abort ui-router state transition + return Promise.reject(new Error('ui-router transition aborted')); + } + }) + } + }); factory = { signIn: signIn, diff --git a/app/modules/transcribe/subjects.factory.js b/app/modules/transcribe/subjects.factory.js index e4cb9c9..49803ef 100644 --- a/app/modules/transcribe/subjects.factory.js +++ b/app/modules/transcribe/subjects.factory.js @@ -114,10 +114,7 @@ function SubjectsFactory($q, AnnotationsFactory, localStorageService, zooAPI, zo return zooAPI.type('workflows').get(zooAPIConfig.workflow_id) .then(function(wf) { var randomSet = _.sample(wf.links.subject_sets) - return randomSet - }) - .catch(function(error) { - console.log('Error fetching active subject sets', error) + return randomSet; }) } diff --git a/app/modules/transcribe/transcribe.controller.js b/app/modules/transcribe/transcribe.controller.js index a5397f3..6e57965 100644 --- a/app/modules/transcribe/transcribe.controller.js +++ b/app/modules/transcribe/transcribe.controller.js @@ -77,8 +77,9 @@ function TranscribeController($stateParams, $modal, $scope, $window, Annotations function loadSubject() { return SubjectsFactory.$getData($stateParams.subjectSet) - .then(subjectLoaded, subjectLoadError) - .then(loadAggregations); + .then(subjectLoaded) + .then(loadAggregations) + .catch(handleErrors); } function openTutorial() { @@ -93,12 +94,10 @@ function TranscribeController($stateParams, $modal, $scope, $window, Annotations vm.subject = SubjectsFactory.current; } - function subjectLoadError(result) { - if (result === 'outOfData') { + function handleErrors(error) { + if (error === 'outOfData') { $scope.$broadcast('subject:outOfData'); - } else { - console.error('Error loading subject', result); } + console.log(error); } - } diff --git a/app/modules/zoo-api/zooapi.factory.js b/app/modules/zoo-api/zooapi.factory.js index 7d872a9..0029f70 100644 --- a/app/modules/zoo-api/zooapi.factory.js +++ b/app/modules/zoo-api/zooapi.factory.js @@ -6,7 +6,7 @@ require('./zooapi.module.js') var ApiClient = require('panoptes-client/lib/api-client'); // @ngInject -function zooAPI(zooAPIConfig) { +function zooAPI() { // There's only a version of this project on production, so rather than // defer to the client we manually override the API root. diff --git a/app/modules/zoo-api/zooapi.module.js b/app/modules/zoo-api/zooapi.module.js index d21f7eb..b5589ac 100644 --- a/app/modules/zoo-api/zooapi.module.js +++ b/app/modules/zoo-api/zooapi.module.js @@ -1,4 +1,6 @@ 'use strict'; module.exports = require('angular') - .module('app.zooapi', []); + .module('app.zooapi', [ + 'app.transcribe.annotations' + ]); diff --git a/gulp/tasks/browserify.js b/gulp/tasks/browserify.js index 1821b5d..7f6c5f5 100644 --- a/gulp/tasks/browserify.js +++ b/gulp/tasks/browserify.js @@ -66,7 +66,7 @@ function buildScript(file) { .pipe(gulpif(createSourcemap, sourcemaps.init())) .pipe(gulpif(global.isProd, streamify( uglify({ - compress: { drop_console: true } + compress: { } // leave console.log in prod, for testing }) .on('error', handleErrors) ))) diff --git a/package-lock.json b/package-lock.json index 17a7e60..5afa64f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14837,9 +14837,9 @@ "dev": true }, "panoptes-client": { - "version": "2.9.4", - "resolved": "https://registry.npmjs.org/panoptes-client/-/panoptes-client-2.9.4.tgz", - "integrity": "sha1-J7TipkzdAH3qX9eJdbPOtzG3LJ0=", + "version": "2.9.6", + "resolved": "https://registry.npmjs.org/panoptes-client/-/panoptes-client-2.9.6.tgz", + "integrity": "sha1-abQQNSWXLGoaPac9B9ZqoXJF95I=", "dev": true, "requires": { "json-api-client": "3.3.0", diff --git a/package.json b/package.json index 05ff2fc..f8305be 100644 --- a/package.json +++ b/package.json @@ -90,7 +90,7 @@ "nib": "^1.1.0", "node-dir": "0.1.16", "npm": "^5.3.0", - "panoptes-client": "^2.9.4", + "panoptes-client": "^2.9.6", "pretty-hrtime": "^1.0.3", "q": "^1.2.0", "run-sequence": "^2.1.0",