From 97ae44b5aff0446a8500ebcedc292627124483dd Mon Sep 17 00:00:00 2001 From: Michael Rogers Date: Wed, 21 Jun 2023 17:36:11 -0500 Subject: [PATCH] Update OperatorStatusIndicator install to hide if an observer --- src/api/user/UserAPI.js | 1 + .../operatorStatus/OperatorStatus.vue | 20 +++++++++++++++++-- src/plugins/operatorStatus/plugin.js | 10 ++-------- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/api/user/UserAPI.js b/src/api/user/UserAPI.js index deb18ba99f..fbe8468510 100644 --- a/src/api/user/UserAPI.js +++ b/src/api/user/UserAPI.js @@ -126,6 +126,7 @@ class UserAPI extends EventEmitter { */ setActiveRole(role) { SessionPersistance.setActiveRole(role); + this.emit('roleChanged', role); } /** diff --git a/src/plugins/operatorStatus/operatorStatus/OperatorStatus.vue b/src/plugins/operatorStatus/operatorStatus/OperatorStatus.vue index 7557bd5367..c9aeb30f49 100644 --- a/src/plugins/operatorStatus/operatorStatus/OperatorStatus.vue +++ b/src/plugins/operatorStatus/operatorStatus/OperatorStatus.vue @@ -72,7 +72,6 @@ export default { }, data() { return { - allRoles: [], role: '--', pollQuestionUpdated: '--', currentPollQuestion: DEFAULT_POLL_QUESTION, @@ -87,11 +86,15 @@ export default { left: `${this.positionX}px`, top: `${this.positionY}px` }; + }, + canProvideStatusForRole() { + return this.openmct.user.canProvideStatusForRole(this.role); } }, beforeDestroy() { this.openmct.user.status.off('statusChange', this.setStatus); this.openmct.user.status.off('pollQuestionChange', this.setPollQuestion); + this.openmct.user.off('roleChanged', this.fetchMyStatus); }, async mounted() { this.unsubscribe = []; @@ -101,6 +104,7 @@ export default { await this.fetchMyStatus(); this.subscribeToMyStatus(); this.subscribeToPollQuestion(); + this.subscribeToRoleChange(); }, methods: { @@ -124,8 +128,16 @@ export default { }, async fetchMyStatus() { const activeRole = await this.openmct.user.getActiveRole(); - const status = await this.openmct.user.status.getStatusForRole(activeRole); + this.role = activeRole; + // hide indicator for observer + if (!this.openmct.user.canProvideStatusForRole()) { + this.indicator.text(''); + this.indicator.statusClass('hidden'); + return; + } + + const status = await this.openmct.user.status.getStatusForRole(activeRole); if (status !== undefined) { this.setStatus({status}); } @@ -136,7 +148,11 @@ export default { subscribeToPollQuestion() { this.openmct.user.status.on('pollQuestionChange', this.setPollQuestion); }, + subscribeToRoleChange() { + this.openmct.user.on('roleChanged', this.fetchMyStatus); + }, setStatus({status}) { + console.log('set Status firiging?') status = this.applyStyling(status); this.selectedStatus = status.key; this.indicator.iconClass(status.iconClassPoll); diff --git a/src/plugins/operatorStatus/plugin.js b/src/plugins/operatorStatus/plugin.js index 393d755132..8d9b66402e 100644 --- a/src/plugins/operatorStatus/plugin.js +++ b/src/plugins/operatorStatus/plugin.js @@ -30,14 +30,8 @@ export default function operatorStatusPlugin(configuration) { return function install(openmct) { if (openmct.user.hasProvider()) { - const activeRole = openmct.user.getActiveRole(); - openmct.user.status.canProvideStatusForRole(activeRole).then(canProvideStatus => { - if (canProvideStatus) { - const operatorStatusIndicator = new OperatorStatusIndicator(openmct, configuration); - - operatorStatusIndicator.install(); - } - }); + const operatorStatusIndicator = new OperatorStatusIndicator(openmct, configuration); + operatorStatusIndicator.install(); openmct.user.status.canSetPollQuestion().then(canSetPollQuestion => { if (canSetPollQuestion) {