Update OperatorStatusIndicator install to hide if an observer

This commit is contained in:
Michael Rogers 2023-06-21 17:36:11 -05:00
parent 6c087a1d1e
commit 97ae44b5af
3 changed files with 21 additions and 10 deletions

View File

@ -126,6 +126,7 @@ class UserAPI extends EventEmitter {
*/
setActiveRole(role) {
SessionPersistance.setActiveRole(role);
this.emit('roleChanged', role);
}
/**

View File

@ -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);

View File

@ -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) {