mirror of
https://github.com/nasa/openmct.git
synced 2025-01-14 16:59:54 +00:00
UserAPI role updates and UserIndicator improvement
This commit is contained in:
parent
01131c1d90
commit
035cb1e33b
@ -27,6 +27,7 @@ import {
|
|||||||
} from './constants';
|
} from './constants';
|
||||||
import StatusAPI from './StatusAPI';
|
import StatusAPI from './StatusAPI';
|
||||||
import User from './User';
|
import User from './User';
|
||||||
|
import SessionPersistance from './SessionPersistance';
|
||||||
|
|
||||||
class UserAPI extends EventEmitter {
|
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
|
* If a user provider is set, it will return the user provider's
|
||||||
* 'isLoggedIn' method
|
* '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 NO_PROVIDER_ERROR = 'No user provider has been set.';
|
||||||
|
|
||||||
export const SESSION_STORAGE_KEY = 'USER_ROLE';
|
export const SESSION_STORAGE_KEY = 'USER_ROLE';
|
||||||
|
export const BROADCAST_CHANNEL_NAME = 'USER_ROLE';
|
||||||
|
@ -73,7 +73,7 @@ export default {
|
|||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
allRoles: [{ key: 'FLIGHT', name: 'Flight'}, {key: 'CAPCOM', name: 'CAPCOM'}, { key: 'GUIDO', name: 'GUIDO' }],
|
allRoles: [],
|
||||||
role: '--',
|
role: '--',
|
||||||
selectedRole: '',
|
selectedRole: '',
|
||||||
pollQuestionUpdated: '--',
|
pollQuestionUpdated: '--',
|
||||||
@ -117,12 +117,14 @@ export default {
|
|||||||
// trigger role selection modal
|
// trigger role selection modal
|
||||||
this.promptForRoleSelection();
|
this.promptForRoleSelection();
|
||||||
}
|
}
|
||||||
|
// todo confirm status role
|
||||||
|
|
||||||
this.role = await this.openmct.user.status.getStatusRoleForCurrentUser();
|
this.role = await this.openmct.user.status.getStatusRoleForCurrentUser();
|
||||||
|
|
||||||
},
|
},
|
||||||
promptForRoleSelection() {
|
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({
|
const dialog = this.openmct.overlays.selection({
|
||||||
selectionOptions,
|
selectionOptions,
|
||||||
iconClass: 'info',
|
iconClass: 'info',
|
||||||
@ -138,8 +140,9 @@ export default {
|
|||||||
label: 'Select',
|
label: 'Select',
|
||||||
emphasis: true,
|
emphasis: true,
|
||||||
callback: () => {
|
callback: () => {
|
||||||
this.setRole(this.selectedRole);
|
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
|
//TODO: introduce a notification of success
|
||||||
|
this.setRole(this.selectedRole);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="c-indicator icon-person c-indicator--clickable">
|
<div class="c-indicator icon-person c-indicator--clickable">
|
||||||
<span class="label c-indicator__label">
|
<span class="label c-indicator__label">
|
||||||
{{ `${userName}: ${role}` }}
|
{{ role ? `${userName}: ${role}` : userName }}
|
||||||
<button>Change Role</button>
|
<button>Change Role</button>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user