diff --git a/example/exampleUser/ExampleUserProvider.js b/example/exampleUser/ExampleUserProvider.js index 3afd23760e..89ddcccae8 100644 --- a/example/exampleUser/ExampleUserProvider.js +++ b/example/exampleUser/ExampleUserProvider.js @@ -58,8 +58,7 @@ const STATUSES = [{ * @implements {StatusUserProvider} */ export default class ExampleUserProvider extends EventEmitter { - constructor(openmct, {defaultStatusRole, statusRoles} = { - defaultStatusRole: undefined, + constructor(openmct, {statusRoles} = { statusRoles: [] }) { super(); @@ -73,9 +72,7 @@ export default class ExampleUserProvider extends EventEmitter { status: STATUSES[0] })); this.pollQuestion = undefined; - // this.defaultStatusRole = defaultStatusRole; this.statusRoles = statusRoles; - this.selectedStatusRole = defaultStatusRole; this.ExampleUser = createExampleUser(this.openmct.user.User); this.loginPromise = undefined; @@ -123,9 +120,10 @@ export default class ExampleUserProvider extends EventEmitter { return this.user.getRoles(); } - getStatusRoleForCurrentUser() { + getStatusRoleForCurrentUser(role) { + const matchedRole = this.statusRoleValues.find(x => x.role === role); - return Promise.resolve(this.selectedStatusRole); + return Promise.resolve(matchedRole?.status); } getAllStatusRoles() { diff --git a/src/api/user/StatusAPI.js b/src/api/user/StatusAPI.js index b367246f4e..a86076e520 100644 --- a/src/api/user/StatusAPI.js +++ b/src/api/user/StatusAPI.js @@ -230,7 +230,9 @@ export default class StatusAPI extends EventEmitter { const provider = this.#userAPI.getProvider(); if (provider.getStatusRoleForCurrentUser) { - return provider.getStatusRoleForCurrentUser(); + const activeRole = this.#userAPI.getActiveRole(); + + return provider.getStatusRoleForCurrentUser(activeRole); } else { this.#userAPI.error("User provider cannot provide role status for this user"); } @@ -244,7 +246,7 @@ export default class StatusAPI extends EventEmitter { const provider = this.#userAPI.getProvider(); if (provider.getStatusRoleForCurrentUser) { - const activeStatusRole = await this.#userAPI.getProvider().getStatusRoleForCurrentUser(); + const activeStatusRole = await this.#userAPI.getActiveRole() const canProvideStatus = await this.canProvideStatusForRole(activeStatusRole); return canProvideStatus; diff --git a/src/plugins/operatorStatus/operatorStatus/OperatorStatus.vue b/src/plugins/operatorStatus/operatorStatus/OperatorStatus.vue index dc86d756eb..23635dcbd7 100644 --- a/src/plugins/operatorStatus/operatorStatus/OperatorStatus.vue +++ b/src/plugins/operatorStatus/operatorStatus/OperatorStatus.vue @@ -137,7 +137,7 @@ export default { subscribeToPollQuestion() { this.openmct.user.status.on('pollQuestionChange', this.setPollQuestion); }, - setStatus({role, status}) { + setStatus({status}) { status = this.applyStyling(status); this.selectedStatus = status.key; this.indicator.iconClass(status.iconClassPoll); diff --git a/src/plugins/userIndicator/components/UserIndicator.vue b/src/plugins/userIndicator/components/UserIndicator.vue index a495080557..d6d01eb0e2 100644 --- a/src/plugins/userIndicator/components/UserIndicator.vue +++ b/src/plugins/userIndicator/components/UserIndicator.vue @@ -59,16 +59,14 @@ export default { this.role = this.openmct.user.getActiveRole(); this.loggedIn = this.openmct.user.isLoggedIn(); }, - async fetchOrPromptForRole() { + fetchOrPromptForRole() { const UserAPI = this.openmct.user; const activeRole = UserAPI.getActiveRole(); - this.selectedRole = activeRole; + this.role = activeRole; if (!activeRole) { this.promptForRoleSelection(); } - this.role = await this.openmct.user.status.getStatusRoleForCurrentUser(); - }, promptForRoleSelection() { const allRoles = this.openmct.user.getPossibleRoles(); @@ -82,9 +80,9 @@ export default { iconClass: 'info', title: 'Select Role', message: 'Please select your role for operator status.', - currentSelection: this.selectedRole, + currentSelection: this.role, onChange: (event) => { - this.selectedRole = event.target.value; + this.role = event.target.value; }, buttons: [ { @@ -92,8 +90,8 @@ export default { emphasis: true, callback: () => { dialog.dismiss(); - //TODO: introduce a notification of success - this.updateRole(this.selectedRole); + this.updateRole(this.role); + this.openmct.notifications.info(`Successfully set new role to ${this.role}`); } } ]