only change time options if independent conductor enabled

re-use timeContext across composables
This commit is contained in:
David Tsay 2024-07-10 18:25:31 -07:00
parent eb314a6fab
commit 9924f53128
7 changed files with 36 additions and 37 deletions

View File

@ -100,14 +100,14 @@ export default {
inject: ['openmct', 'configuration'],
setup(props) {
const openmct = inject('openmct');
const { timeContext } = useTimeContext(openmct, () => props.objectPath);
const { timeContext } = useTimeContext(openmct);
const { timeSystemFormatter, timeSystemDurationFormatter, isTimeSystemUTCBased } =
useTimeSystem(openmct);
useTimeSystem(openmct, timeContext);
const { timeMode, isFixedTimeMode, isRealTimeMode, getAllModeMetadata, getModeMetadata } =
useTimeMode(openmct);
const { bounds, isTick } = useTimeBounds(openmct);
const { clock, getAllClockMetadata, getClockMetadata } = useClock(openmct);
const { offsets } = useClockOffsets(openmct);
useTimeMode(openmct, timeContext);
const { bounds, isTick } = useTimeBounds(openmct, timeContext);
const { clock, getAllClockMetadata, getClockMetadata } = useClock(openmct, timeContext);
const { offsets } = useClockOffsets(openmct, timeContext);
provide('timeSystemFormatter', timeSystemFormatter);
provide('timeSystemDurationFormatter', timeSystemDurationFormatter);

View File

@ -111,15 +111,15 @@ export default {
},
setup(props) {
const openmct = inject('openmct');
const { timeContext } = useTimeContext(openmct, getReactiveObjectPath);
const { timeContext } = useTimeContext(openmct, () => props.objectPath);
const { timeSystemFormatter, timeSystemDurationFormatter, isTimeSystemUTCBased } =
useTimeSystem(openmct, getReactiveObjectPath);
useTimeSystem(openmct, timeContext);
const { timeMode, isFixedTimeMode, isRealTimeMode, getAllModeMetadata, getModeMetadata } =
useTimeMode(openmct, getReactiveObjectPath);
const { bounds, isTick } = useTimeBounds(openmct, getReactiveObjectPath);
const { clock, getAllClockMetadata, getClockMetadata } = useClock(openmct, getReactiveObjectPath);
const { offsets } = useClockOffsets(openmct, getReactiveObjectPath);
useTimeMode(openmct, timeContext);
const { bounds, isTick } = useTimeBounds(openmct, timeContext);
const { clock, getAllClockMetadata, getClockMetadata } = useClock(openmct, timeContext);
const { offsets } = useClockOffsets(openmct, timeContext);
watch(timeContext, () => {
console.log('context changed setup');
@ -225,16 +225,22 @@ export default {
this.handleIndependentTimeConductorChange();
},
clock() {
this.saveClock();
if (this.independentTCEnabled) {
this.saveClock();
}
},
timeMode() {
this.saveMode();
if (this.independentTCEnabled) {
this.saveMode();
}
},
clockOffsets() {
this.saveClockOffsets();
if (this.independentTCEnabled) {
this.saveClockOffsets();
}
},
bounds() {
if (this.isTick === false) {
if (this.independentTCEnabled && this.isTick === false) {
this.saveFixedBounds();
}
}
@ -321,12 +327,20 @@ export default {
const independentTimeContextBoundsOrOffsets = this.isFixedTimeMode ? bounds : offsets;
const independentTimeContextClockKey = this.isFixedTimeMode ? undefined : clockKey;
if (!this.timeContext.hasOwnContext()) {
const independentTimeContext = this.openmct.time.getIndependentContext(this.keyString);
if (!independentTimeContext.hasOwnContext()) {
this.unregisterIndependentTimeContext = this.openmct.time.addIndependentContext(
this.keyString,
independentTimeContextBoundsOrOffsets,
independentTimeContextClockKey
);
} else {
if (this.isRealTimeMode) {
independentTimeContext.setClock(this.timeOptions.clock);
}
independentTimeContext.setMode(this.timeOptions.mode, independentTimeContextBoundsOrOffsets);
}
},
registerIndependentTimeOffsets() {

View File

@ -23,7 +23,6 @@
import { onBeforeUnmount, shallowRef, watch } from 'vue';
import { TIME_CONTEXT_EVENTS } from '../../api/time/constants.js';
import { useTimeContext } from './useTimeContext.js';
/**
* Provides reactive `clock` which is reactive to a time context,
@ -38,11 +37,9 @@ import { useTimeContext } from './useTimeContext.js';
* getClockMetadata: () => Object
* }}
*/
export function useClock(openmct, objectPath) {
export function useClock(openmct, timeContext) {
let stopObservingClock;
const { timeContext } = useTimeContext(openmct, objectPath);
const clock = shallowRef(timeContext.value.getClock());
onBeforeUnmount(() => stopObservingClock?.());

View File

@ -23,7 +23,6 @@
import { onBeforeUnmount, shallowRef, watch } from 'vue';
import { TIME_CONTEXT_EVENTS } from '../../api/time/constants.js';
import { useTimeContext } from './useTimeContext.js';
/**
* Provides reactive `offsets`,
@ -37,11 +36,9 @@ import { useTimeContext } from './useTimeContext.js';
* offsets: import('vue').Ref<object>,
* }}
*/
export function useClockOffsets(openmct, objectPath) {
export function useClockOffsets(openmct, timeContext) {
let stopObservingClockOffsets;
const { timeContext } = useTimeContext(openmct, objectPath);
const offsets = shallowRef(timeContext.value.getClockOffsets());
onBeforeUnmount(() => stopObservingClockOffsets?.());

View File

@ -23,7 +23,6 @@
import { onBeforeUnmount, ref, shallowRef, watch } from 'vue';
import { TIME_CONTEXT_EVENTS } from '../../api/time/constants.js';
import { useTimeContext } from './useTimeContext.js';
import throttle from '../../utils/throttle.js';
const THROTTLE_RATE = 300;
@ -40,11 +39,9 @@ const THROTTLE_RATE = 300;
* isTick: import('vue').Ref<boolean>
* }}
*/
export function useTimeBounds(openmct, objectPath) {
export function useTimeBounds(openmct, timeContext) {
let stopObservingTimeBounds;
const { timeContext } = useTimeContext(openmct, objectPath);
const bounds = shallowRef(timeContext.value.getBounds());
const isTick = ref(false);

View File

@ -27,7 +27,6 @@ import {
REALTIME_MODE_KEY,
TIME_CONTEXT_EVENTS
} from '../../api/time/constants.js';
import { useTimeContext } from './useTimeContext.js';
/**
* Provides reactive `timeMode` which is reactive to a time context,
@ -42,11 +41,9 @@ import { useTimeContext } from './useTimeContext.js';
* isRealTimeMode: import('vue').Ref<boolean>
* }}
*/
export function useTimeMode(openmct, objectPath) {
export function useTimeMode(openmct, timeContext) {
let stopObservingTimeMode;
const { timeContext } = useTimeContext(openmct, objectPath);
const timeMode = ref(timeContext.value.getMode());
const isFixedTimeMode = computed(() => timeMode.value === FIXED_MODE_KEY);
const isRealTimeMode = computed(() => timeMode.value === REALTIME_MODE_KEY);

View File

@ -23,7 +23,6 @@
import { onBeforeUnmount, ref, watch } from 'vue';
import { TIME_CONTEXT_EVENTS } from '../../api/time/constants.js';
import { useTimeContext } from './useTimeContext.js';
const DEFAULT_DURATION_FORMATTER = 'duration';
@ -43,11 +42,9 @@ const DEFAULT_DURATION_FORMATTER = 'duration';
* isTimeSystemUTCBased: import('vue').Ref<boolean>
* }}
*/
export function useTimeSystem(openmct, objectPath) {
export function useTimeSystem(openmct, timeContext) {
let stopObservingTimeSystem;
const { timeContext } = useTimeContext(openmct, objectPath);
const initialTimeSystem = timeContext.value.getTimeSystem();
const timeSystemKey = ref(initialTimeSystem.key);