Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
HAWKULAR-178 - Last used persona is the default upon login
Browse files Browse the repository at this point in the history
  • Loading branch information
jpkrohling committed Dec 4, 2015
1 parent 5eb4adb commit 30135ca
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions console/src/main/scripts/plugins/accounts/ts/persona.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,42 @@ module HawkularAccounts {

public loadData():void {
this.loading = true;
this.currentPersona = this.HawkularAccount.Persona.get({id: 'current'},
let personaToGet = 'current';

let lastPersonaId = localStorage.getItem('lastPersona');
if (null != lastPersonaId) {
personaToGet = lastPersonaId;
}

this.loadAsCurrentPersona(personaToGet);
}

public loadAsCurrentPersona(personaId:string):void {
this.$log.debug(`Persona ID to load: ${personaId}`);
this.currentPersona = this.HawkularAccount.Persona.get({id: personaId},
(response:IPersona) => {
this.$rootScope.$broadcast('CurrentPersonaLoaded', response);
if (response.id == null) {
if (personaId === 'current') {
// at this point, we were requested to get the personaId , but we got an empty response from the server...
// there's not much we can do here, and it should never happen
this.NotificationsService.error(`Failed to retrieve the current persona. Empty response.`);
this.$log.warn(`Failed to retrieve the current persona. Empty response.`);
} else {
// fall back, load the 'current' user, which is the actual user, not a persona
this.loadAsCurrentPersona('current');
}
} else {
// we got the persona we wanted!
this.$rootScope.$broadcast('CurrentPersonaLoaded', response);
}
}, (error:IErrorPayload) => {
this.NotificationsService.error(`Failed to retrieve the current persona: ${error.data.message}`);
this.$log.warn(`Failed to retrieve the current persona: ${error.data.message}`);
if (personaId === 'current') {
this.NotificationsService.error(`Failed to retrieve the current persona: ${error.data.message}`);
this.$log.warn(`Failed to retrieve the current persona: ${error.data.message}`);
} else {
// fall back, load the 'current' user, which is the actual user, not a persona
this.loadAsCurrentPersona('current');
}
}
);
}
Expand All @@ -74,6 +104,7 @@ module HawkularAccounts {
public switchPersona(persona:IPersona):void {
this.currentPersona = persona;
this.$rootScope.$broadcast('SwitchedPersona', persona);
localStorage.setItem('lastPersona', persona.id);
}
}

Expand Down

0 comments on commit 30135ca

Please sign in to comment.