mirror of
https://github.com/nasa/openmct.git
synced 2025-02-08 12:00:38 +00:00
feat: more renaming, get mission role statuses working
This commit is contained in:
parent
efd5466482
commit
1c4b611fbb
@ -9,17 +9,22 @@
|
||||
></button>
|
||||
</div>
|
||||
<div class="c-ucp-mission-status">
|
||||
<template v-for="status in missionStatuses" :key="status">
|
||||
<label class="c-ucp-mission-status__label" :for="status">{{ status }}</label>
|
||||
<div class="c-ucp-mission-status__widget" :class="missionStatusClass(status)">
|
||||
{{ selectedStatus[status] }}
|
||||
<template v-for="role in missionRoles" :key="role">
|
||||
<label class="c-ucp-mission-status__label" :for="role">{{ role }}</label>
|
||||
<div class="c-ucp-mission-status__widget" :class="getMissionRoleStatusClass(role)">
|
||||
{{ missionRoleStatusOptions[missionRoleStatusMap[role]]?.label }}
|
||||
</div>
|
||||
<div class="c-ucp-mission-status__select">
|
||||
<select :id="status" v-model="selectedStatus[status]">
|
||||
<select
|
||||
:id="role"
|
||||
v-model="missionRoleStatusMap[role]"
|
||||
name="setMissionRoleStatus"
|
||||
@change="onChangeStatus(role)"
|
||||
>
|
||||
<option
|
||||
v-for="option in missionStatusOptions"
|
||||
v-for="option in missionRoleStatusOptions"
|
||||
:key="option.key"
|
||||
@change="onChangeStatus"
|
||||
:value="option.key"
|
||||
>
|
||||
{{ option.label }}
|
||||
</option>
|
||||
@ -36,50 +41,73 @@ export default {
|
||||
emits: ['dismiss'],
|
||||
data() {
|
||||
return {
|
||||
missionStatuses: [],
|
||||
missionStatusOptions: [],
|
||||
selectedStatus: {}
|
||||
missionRoles: [],
|
||||
missionRoleStatusOptions: [],
|
||||
missionRoleStatusMap: {}
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
missionStatusClass() {
|
||||
return (status) => {
|
||||
return {
|
||||
'--is-no-go': this.selectedStatus[status] === 'NO GO'
|
||||
};
|
||||
};
|
||||
}
|
||||
},
|
||||
async created() {
|
||||
this.missionStatuses = await this.openmct.user.status.getPossibleMissionStatuses();
|
||||
this.missionStatusOptions = await this.openmct.user.status.getPossibleMissionStatusOptions();
|
||||
this.selectedStatus = await Promise.all(
|
||||
this.missionStatuses.map(
|
||||
this.openmct.user.status.getMissionStatusForRole.bind(this.openmct.user.status)
|
||||
)
|
||||
);
|
||||
try {
|
||||
// Fetch missionStatuses and missionStatusOptions simultaneously
|
||||
const [missionRoles, missionRoleStatusOptions] = await Promise.all([
|
||||
this.openmct.user.status.getPossibleMissionRoles(),
|
||||
this.openmct.user.status.getPossibleMissionStatusOptions()
|
||||
]);
|
||||
|
||||
this.missionRoles = missionRoles;
|
||||
this.missionRoleStatusOptions = missionRoleStatusOptions;
|
||||
|
||||
const statusPromises = missionRoles.map((status) =>
|
||||
this.openmct.user.status.getMissionStatusForRole(status)
|
||||
);
|
||||
|
||||
// Fetch all mission role statuses simultaneously
|
||||
const statuses = await Promise.all(statusPromises);
|
||||
|
||||
// Reduce to a map of mission role to status
|
||||
/** @type {Record<string, T>} */
|
||||
this.missionRoleStatusMap = missionRoles.reduce((acc, status, index) => {
|
||||
acc[status] = statuses[index].key;
|
||||
return acc;
|
||||
}, {});
|
||||
} catch (error) {
|
||||
console.error('Error fetching mission statuses:', error);
|
||||
this.openmct.notifications.error(`Error fetching mission statuses: ${error.message}`);
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
onDismiss() {
|
||||
this.$emit('dismiss');
|
||||
},
|
||||
async onChangeStatus(event) {
|
||||
async onChangeStatus(status) {
|
||||
if (!this.openmct.user.status.canSetMissionStatus()) {
|
||||
this.openmct.notifications.error('Selected role is ineligible to set mission status');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.selectedStatus !== undefined) {
|
||||
const statusObject = this.findStatusByKey(this.selectedStatus);
|
||||
if (this.missionRoleStatusMap !== undefined) {
|
||||
const statusObject = this.findOptionByKey(this.missionRoleStatusMap[status]);
|
||||
|
||||
const result = await this.openmct.user.status.setMissionStatusForRole(statusObject);
|
||||
const result = await this.openmct.user.status.setMissionStatusForRole(status, statusObject);
|
||||
if (result === true) {
|
||||
this.openmct.notifications.info('Successfully set operator status');
|
||||
this.openmct.notifications.info('Successfully set mission status');
|
||||
} else {
|
||||
this.openmct.notifications.error('Unable to set operator status');
|
||||
this.openmct.notifications.error('Unable to set mission status');
|
||||
}
|
||||
}
|
||||
},
|
||||
/**
|
||||
* @param {number} optionKey
|
||||
*/
|
||||
findOptionByKey(optionKey) {
|
||||
return this.missionRoleStatusOptions.find((possibleMatch) => possibleMatch.key === optionKey);
|
||||
},
|
||||
getMissionRoleStatusClass(status) {
|
||||
const statusValue = this.missionRoleStatusOptions[this.missionRoleStatusMap[status]]?.label;
|
||||
return {
|
||||
'--is-no-go': statusValue === 'NO GO'
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user