Enabled eslint:no-use-before-define
Rule enabled, discovered issues resolved. Change-Id: Id8585c5eddd66a14fe0f137fbb7408dc34bee4d1
This commit is contained in:
parent
df89d505b4
commit
7f5a9636c1
@ -50,9 +50,6 @@
|
||||
"camelcase": 0,
|
||||
"no-extra-boolean-cast": 0,
|
||||
|
||||
// Rules to be processed.
|
||||
"no-use-before-define": 0,
|
||||
|
||||
// Stylistic
|
||||
"indent": [2, 4],
|
||||
"max-len": [2, 80],
|
||||
|
@ -30,6 +30,29 @@ angular.module('sb.auth').factory('CurrentUser',
|
||||
var currentUser = null;
|
||||
var currentPromise = null;
|
||||
|
||||
/**
|
||||
* A promise that only resolves if we're currently logged in.
|
||||
*/
|
||||
function resolveLoggedInSession() {
|
||||
var deferred = $q.defer();
|
||||
|
||||
Session.resolveSessionState().then(
|
||||
function (sessionState) {
|
||||
|
||||
if (sessionState === SessionState.LOGGED_IN) {
|
||||
deferred.resolve(sessionState);
|
||||
} else {
|
||||
deferred.reject(sessionState);
|
||||
}
|
||||
},
|
||||
function (error) {
|
||||
deferred.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a current user.
|
||||
*/
|
||||
@ -87,29 +110,6 @@ angular.module('sb.auth').factory('CurrentUser',
|
||||
return currentPromise;
|
||||
}
|
||||
|
||||
/**
|
||||
* A promise that only resolves if we're currently logged in.
|
||||
*/
|
||||
function resolveLoggedInSession() {
|
||||
var deferred = $q.defer();
|
||||
|
||||
Session.resolveSessionState().then(
|
||||
function (sessionState) {
|
||||
|
||||
if (sessionState === SessionState.LOGGED_IN) {
|
||||
deferred.resolve(sessionState);
|
||||
} else {
|
||||
deferred.reject(sessionState);
|
||||
}
|
||||
},
|
||||
function (error) {
|
||||
deferred.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
// Add event listeners.
|
||||
Notification.intercept(function (message) {
|
||||
switch (message.type) {
|
||||
|
@ -5,9 +5,10 @@ angular.module('sb.auth').service('RefreshManager',
|
||||
var currentRefresh = null;
|
||||
var nextRefreshPromise = null;
|
||||
var scheduledForToken = null;
|
||||
var self = this;
|
||||
|
||||
// Try to refresh the expired access_token
|
||||
var tryRefresh = function () {
|
||||
this.tryRefresh = function () {
|
||||
|
||||
if (!currentRefresh) {
|
||||
// Create our promise, since we should always return one.
|
||||
@ -42,7 +43,7 @@ angular.module('sb.auth').service('RefreshManager',
|
||||
function (data) {
|
||||
AccessToken.setToken(data);
|
||||
currentRefresh.resolve(true);
|
||||
scheduleRefresh();
|
||||
self.scheduleRefresh();
|
||||
},
|
||||
function () {
|
||||
AccessToken.clear();
|
||||
@ -55,7 +56,7 @@ angular.module('sb.auth').service('RefreshManager',
|
||||
};
|
||||
|
||||
|
||||
var scheduleRefresh = function () {
|
||||
this.scheduleRefresh = function () {
|
||||
if (!AccessToken.getRefreshToken() || AccessToken.isExpired()) {
|
||||
$log.info('Current token does not require deferred refresh.');
|
||||
return;
|
||||
@ -73,14 +74,10 @@ angular.module('sb.auth').service('RefreshManager',
|
||||
|
||||
var now = Math.round((new Date()).getTime() / 1000);
|
||||
var delay = (expiresAt - preExpireDelta - now) * 1000;
|
||||
nextRefreshPromise = $timeout(tryRefresh, delay, false);
|
||||
nextRefreshPromise = $timeout(self.tryRefresh, delay, false);
|
||||
scheduledForToken = AccessToken.getAccessToken();
|
||||
|
||||
$log.info('Refresh scheduled to happen in ' + delay + ' ms');
|
||||
};
|
||||
|
||||
this.tryRefresh = tryRefresh;
|
||||
this.scheduleRefresh = scheduleRefresh;
|
||||
|
||||
}
|
||||
);
|
||||
|
@ -31,31 +31,13 @@ angular.module('sb.auth').factory('Session',
|
||||
var sessionState = SessionState.PENDING;
|
||||
|
||||
/**
|
||||
* Initialize the session.
|
||||
* Handles state updates and broadcasts.
|
||||
*/
|
||||
function initializeSession() {
|
||||
var deferred = $q.defer();
|
||||
|
||||
if (!AccessToken.getAccessToken()) {
|
||||
$log.debug('No token found');
|
||||
updateSessionState(SessionState.LOGGED_OUT);
|
||||
deferred.resolve();
|
||||
} else {
|
||||
// Validate the token currently in the cache.
|
||||
validateToken()
|
||||
.then(function () {
|
||||
$log.debug('Token validated');
|
||||
updateSessionState(SessionState.LOGGED_IN);
|
||||
deferred.resolve(sessionState);
|
||||
}, function () {
|
||||
$log.debug('Token not validated');
|
||||
AccessToken.clear();
|
||||
updateSessionState(SessionState.LOGGED_OUT);
|
||||
deferred.resolve(sessionState);
|
||||
});
|
||||
function updateSessionState(newState) {
|
||||
if (newState !== sessionState) {
|
||||
sessionState = newState;
|
||||
Notification.send(newState, newState, Severity.SUCCESS);
|
||||
}
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -82,15 +64,32 @@ angular.module('sb.auth').factory('Session',
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handles state updates and broadcasts.
|
||||
* Initialize the session.
|
||||
*/
|
||||
function updateSessionState(newState) {
|
||||
if (newState !== sessionState) {
|
||||
sessionState = newState;
|
||||
Notification.send(newState, newState, Severity.SUCCESS);
|
||||
function initializeSession() {
|
||||
var deferred = $q.defer();
|
||||
|
||||
if (!AccessToken.getAccessToken()) {
|
||||
$log.debug('No token found');
|
||||
updateSessionState(SessionState.LOGGED_OUT);
|
||||
deferred.resolve();
|
||||
} else {
|
||||
// Validate the token currently in the cache.
|
||||
validateToken()
|
||||
.then(function () {
|
||||
$log.debug('Token validated');
|
||||
updateSessionState(SessionState.LOGGED_IN);
|
||||
deferred.resolve(sessionState);
|
||||
}, function () {
|
||||
$log.debug('Token not validated');
|
||||
AccessToken.clear();
|
||||
updateSessionState(SessionState.LOGGED_OUT);
|
||||
deferred.resolve(sessionState);
|
||||
});
|
||||
}
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -74,22 +74,6 @@ angular.module('sb.search').directive('searchResults',
|
||||
$scope.isSearching = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle the filter ID and direction in the UI.
|
||||
*
|
||||
* @param fieldName
|
||||
*/
|
||||
$scope.toggleFilter = function (fieldName) {
|
||||
if ($scope.sortField === fieldName) {
|
||||
$scope.sortDirection =
|
||||
$scope.sortDirection === 'asc' ? 'desc' : 'asc';
|
||||
} else {
|
||||
$scope.sortField = fieldName;
|
||||
$scope.sortDirection = 'desc';
|
||||
}
|
||||
updateResults();
|
||||
};
|
||||
|
||||
/**
|
||||
* Update the results when the criteria change
|
||||
*/
|
||||
@ -145,6 +129,22 @@ angular.module('sb.search').directive('searchResults',
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle the filter ID and direction in the UI.
|
||||
*
|
||||
* @param fieldName
|
||||
*/
|
||||
$scope.toggleFilter = function (fieldName) {
|
||||
if ($scope.sortField === fieldName) {
|
||||
$scope.sortDirection =
|
||||
$scope.sortDirection === 'asc' ? 'desc' : 'asc';
|
||||
} else {
|
||||
$scope.sortField = fieldName;
|
||||
$scope.sortDirection = 'desc';
|
||||
}
|
||||
updateResults();
|
||||
};
|
||||
|
||||
// Watch for changing criteria
|
||||
$scope.$watchCollection(
|
||||
$parse(args.searchCriteria),
|
||||
|
@ -85,24 +85,6 @@ angular.module('sb.util').directive('subscribe',
|
||||
$scope.subscribed = !!$scope.subscription;
|
||||
}
|
||||
|
||||
// Subscribe to login/logout events for enable/disable/resolve.
|
||||
var removeNotifier = Notification.intercept(function (message) {
|
||||
switch (message.type) {
|
||||
case SessionState.LOGGED_IN:
|
||||
$scope.enabled = true;
|
||||
resolveSubscription();
|
||||
break;
|
||||
case SessionState.LOGGED_OUT:
|
||||
$scope.enabled = false;
|
||||
$scope.subscribed = false;
|
||||
break;
|
||||
}
|
||||
|
||||
}, Priority.LAST);
|
||||
|
||||
// Remove the notifier when this scope is destroyed.
|
||||
$scope.$on('$destroy', removeNotifier);
|
||||
|
||||
/**
|
||||
* Resolve whether the current user already has a subscription
|
||||
* to this resource.
|
||||
@ -137,6 +119,24 @@ angular.module('sb.util').directive('subscribe',
|
||||
);
|
||||
}
|
||||
|
||||
// Subscribe to login/logout events for enable/disable/resolve.
|
||||
var removeNotifier = Notification.intercept(function (message) {
|
||||
switch (message.type) {
|
||||
case SessionState.LOGGED_IN:
|
||||
$scope.enabled = true;
|
||||
resolveSubscription();
|
||||
break;
|
||||
case SessionState.LOGGED_OUT:
|
||||
$scope.enabled = false;
|
||||
$scope.subscribed = false;
|
||||
break;
|
||||
}
|
||||
|
||||
}, Priority.LAST);
|
||||
|
||||
// Remove the notifier when this scope is destroyed.
|
||||
$scope.$on('$destroy', removeNotifier);
|
||||
|
||||
/**
|
||||
* When the user clicks on this control, activate/deactivate the
|
||||
* subscription.
|
||||
|
Loading…
x
Reference in New Issue
Block a user