mirror of
https://github.com/nasa/openmct.git
synced 2025-01-13 16:29:57 +00:00
UserAPI role updates and UserIndicator improvement
This commit is contained in:
parent
01131c1d90
commit
035cb1e33b
@ -27,6 +27,7 @@ import {
|
||||
} from './constants';
|
||||
import StatusAPI from './StatusAPI';
|
||||
import User from './User';
|
||||
import SessionPersistance from './SessionPersistance';
|
||||
|
||||
class UserAPI extends EventEmitter {
|
||||
/**
|
||||
@ -90,6 +91,45 @@ class UserAPI extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
getPossibleRoles() {
|
||||
if (!this.hasProvider()) {
|
||||
return Promise.resolve(undefined);
|
||||
} else {
|
||||
return this._provider.getPossibleRoles();
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* If a user provider is set, it will return the active role Id
|
||||
* @returns object
|
||||
*/
|
||||
getActiveRole() {
|
||||
if (!this.hasProvider()) {
|
||||
return Promise.resolve(undefined);
|
||||
}
|
||||
|
||||
// get from session storage
|
||||
const sessionStorageValue = SessionPersistance.getActiveRole();
|
||||
if (sessionStorageValue === 'undefined' || sessionStorageValue === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return sessionStorageValue;
|
||||
|
||||
}
|
||||
setActiveRole(role) {
|
||||
SessionPersistance.setActiveRole(role);
|
||||
}
|
||||
|
||||
/**
|
||||
* Will return if a role can provide a operator status response
|
||||
* @memberof module:openmct.UserApi#
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
canProvideStatusForRole(roleId) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* If a user provider is set, it will return the user provider's
|
||||
* 'isLoggedIn' method
|
||||
|
@ -24,3 +24,4 @@ export const MULTIPLE_PROVIDER_ERROR = 'Only one user provider may be set at a t
|
||||
export const NO_PROVIDER_ERROR = 'No user provider has been set.';
|
||||
|
||||
export const SESSION_STORAGE_KEY = 'USER_ROLE';
|
||||
export const BROADCAST_CHANNEL_NAME = 'USER_ROLE';
|
||||
|
@ -73,7 +73,7 @@ export default {
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
allRoles: [{ key: 'FLIGHT', name: 'Flight'}, {key: 'CAPCOM', name: 'CAPCOM'}, { key: 'GUIDO', name: 'GUIDO' }],
|
||||
allRoles: [],
|
||||
role: '--',
|
||||
selectedRole: '',
|
||||
pollQuestionUpdated: '--',
|
||||
@ -117,12 +117,14 @@ export default {
|
||||
// trigger role selection modal
|
||||
this.promptForRoleSelection();
|
||||
}
|
||||
// todo confirm status role
|
||||
|
||||
this.role = await this.openmct.user.status.getStatusRoleForCurrentUser();
|
||||
|
||||
},
|
||||
promptForRoleSelection() {
|
||||
const selectionOptions = this.allRoles;
|
||||
const allRoles = this.openmct.user.getPossibleRoles();
|
||||
const selectionOptions = allRoles.filter(this.openmct.user.canProvideStatusForRole);
|
||||
const dialog = this.openmct.overlays.selection({
|
||||
selectionOptions,
|
||||
iconClass: 'info',
|
||||
@ -138,8 +140,9 @@ export default {
|
||||
label: 'Select',
|
||||
emphasis: true,
|
||||
callback: () => {
|
||||
this.setRole(this.selectedRole);
|
||||
dialog.dismiss();
|
||||
//TODO: introduce a notification of success
|
||||
this.setRole(this.selectedRole);
|
||||
}
|
||||
}
|
||||
]
|
||||
|
@ -23,7 +23,7 @@
|
||||
<template>
|
||||
<div class="c-indicator icon-person c-indicator--clickable">
|
||||
<span class="label c-indicator__label">
|
||||
{{ `${userName}: ${role}` }}
|
||||
{{ role ? `${userName}: ${role}` : userName }}
|
||||
<button>Change Role</button>
|
||||
</span>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user