mirror of
https://github.com/nasa/openmct.git
synced 2025-05-06 10:38:23 +00:00
[Time conductor] Better persistence handling for history (#3246)
This commit is contained in:
parent
b76d4b76cb
commit
abc458cef4
@ -143,7 +143,7 @@
|
|||||||
<ConductorHistory
|
<ConductorHistory
|
||||||
v-if="isFixed"
|
v-if="isFixed"
|
||||||
class="c-conductor__history-select"
|
class="c-conductor__history-select"
|
||||||
:bounds="openmct.time.bounds()"
|
:bounds="bounds"
|
||||||
:time-system="timeSystem"
|
:time-system="timeSystem"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@ -190,6 +190,10 @@ export default {
|
|||||||
start: offsets && durationFormatter.format(Math.abs(offsets.start)),
|
start: offsets && durationFormatter.format(Math.abs(offsets.start)),
|
||||||
end: offsets && durationFormatter.format(Math.abs(offsets.end))
|
end: offsets && durationFormatter.format(Math.abs(offsets.end))
|
||||||
},
|
},
|
||||||
|
bounds: {
|
||||||
|
start: bounds.start,
|
||||||
|
end: bounds.end
|
||||||
|
},
|
||||||
formattedBounds: {
|
formattedBounds: {
|
||||||
start: timeFormatter.format(bounds.start),
|
start: timeFormatter.format(bounds.start),
|
||||||
end: timeFormatter.format(bounds.end)
|
end: timeFormatter.format(bounds.end)
|
||||||
@ -210,7 +214,7 @@ export default {
|
|||||||
document.addEventListener('keydown', this.handleKeyDown);
|
document.addEventListener('keydown', this.handleKeyDown);
|
||||||
document.addEventListener('keyup', this.handleKeyUp);
|
document.addEventListener('keyup', this.handleKeyUp);
|
||||||
this.setTimeSystem(JSON.parse(JSON.stringify(this.openmct.time.timeSystem())));
|
this.setTimeSystem(JSON.parse(JSON.stringify(this.openmct.time.timeSystem())));
|
||||||
this.openmct.time.on('bounds', this.setViewFromBounds);
|
this.openmct.time.on('bounds', this.handleNewBounds);
|
||||||
this.openmct.time.on('timeSystem', this.setTimeSystem);
|
this.openmct.time.on('timeSystem', this.setTimeSystem);
|
||||||
this.openmct.time.on('clock', this.setViewFromClock);
|
this.openmct.time.on('clock', this.setViewFromClock);
|
||||||
this.openmct.time.on('clockOffsets', this.setViewFromOffsets);
|
this.openmct.time.on('clockOffsets', this.setViewFromOffsets);
|
||||||
@ -220,6 +224,13 @@ export default {
|
|||||||
document.removeEventListener('keyup', this.handleKeyUp);
|
document.removeEventListener('keyup', this.handleKeyUp);
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
handleNewBounds(bounds) {
|
||||||
|
this.setBounds(bounds);
|
||||||
|
this.setViewFromBounds(bounds);
|
||||||
|
},
|
||||||
|
setBounds(bounds) {
|
||||||
|
this.bounds = bounds;
|
||||||
|
},
|
||||||
handleKeyDown(event) {
|
handleKeyDown(event) {
|
||||||
if (event.key === 'Alt') {
|
if (event.key === 'Alt') {
|
||||||
this.altPressed = true;
|
this.altPressed = true;
|
||||||
@ -246,10 +257,13 @@ export default {
|
|||||||
this.formattedBounds.end = this.timeFormatter.format(bounds.end);
|
this.formattedBounds.end = this.timeFormatter.format(bounds.end);
|
||||||
},
|
},
|
||||||
endZoom(bounds) {
|
endZoom(bounds) {
|
||||||
const _bounds = bounds ? bounds : this.openmct.time.bounds();
|
|
||||||
this.isZooming = false;
|
this.isZooming = false;
|
||||||
|
|
||||||
this.openmct.time.bounds(_bounds);
|
if (bounds) {
|
||||||
|
this.handleNewBounds(bounds);
|
||||||
|
} else {
|
||||||
|
this.setViewFromBounds(this.bounds);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
setTimeSystem(timeSystem) {
|
setTimeSystem(timeSystem) {
|
||||||
this.timeSystem = timeSystem;
|
this.timeSystem = timeSystem;
|
||||||
|
@ -207,7 +207,7 @@ export default {
|
|||||||
this.$emit('panAxis', panBounds);
|
this.$emit('panAxis', panBounds);
|
||||||
},
|
},
|
||||||
endPan() {
|
endPan() {
|
||||||
const panBounds = this.dragStartX && this.dragX && this.dragStartX !== this.dragX
|
const panBounds = this.isChangingViewBounds()
|
||||||
? this.getPanBounds()
|
? this.getPanBounds()
|
||||||
: undefined;
|
: undefined;
|
||||||
this.$emit('endPan', panBounds);
|
this.$emit('endPan', panBounds);
|
||||||
@ -251,16 +251,14 @@ export default {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
endZoom() {
|
endZoom() {
|
||||||
const zoomRange = this.dragStartX && this.dragX && this.dragStartX !== this.dragX
|
let zoomBounds;
|
||||||
? this.getZoomRange()
|
if (this.isChangingViewBounds()) {
|
||||||
: undefined;
|
const zoomRange = this.getZoomRange();
|
||||||
|
zoomBounds = {
|
||||||
const zoomBounds = zoomRange
|
|
||||||
? {
|
|
||||||
start: this.scaleToBounds(zoomRange.start),
|
start: this.scaleToBounds(zoomRange.start),
|
||||||
end: this.scaleToBounds(zoomRange.end)
|
end: this.scaleToBounds(zoomRange.end)
|
||||||
|
};
|
||||||
}
|
}
|
||||||
: this.openmct.time.bounds();
|
|
||||||
|
|
||||||
this.zoomStyle = {};
|
this.zoomStyle = {};
|
||||||
this.$emit('endZoom', zoomBounds);
|
this.$emit('endZoom', zoomBounds);
|
||||||
@ -290,6 +288,9 @@ export default {
|
|||||||
|
|
||||||
return bounds.start + offset;
|
return bounds.start + offset;
|
||||||
},
|
},
|
||||||
|
isChangingViewBounds() {
|
||||||
|
return this.dragStartX && this.dragX && this.dragStartX !== this.dragX;
|
||||||
|
},
|
||||||
resize() {
|
resize() {
|
||||||
if (this.$refs.axisHolder.clientWidth !== this.width) {
|
if (this.$refs.axisHolder.clientWidth !== this.width) {
|
||||||
this.setAxisDimensions();
|
this.setAxisDimensions();
|
||||||
|
@ -84,7 +84,12 @@ export default {
|
|||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
history: {}, // contains arrays of timespans {start, end}, array key is time system key
|
/**
|
||||||
|
* previous bounds entries available for easy re-use
|
||||||
|
* @history array of timespans
|
||||||
|
* @timespans {start, end} number representing timestamp
|
||||||
|
*/
|
||||||
|
history: this.getHistoryFromLocalStorage(),
|
||||||
presets: []
|
presets: []
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@ -111,22 +116,20 @@ export default {
|
|||||||
this.addTimespan();
|
this.addTimespan();
|
||||||
},
|
},
|
||||||
deep: true
|
deep: true
|
||||||
},
|
|
||||||
history: {
|
|
||||||
handler() {
|
|
||||||
this.persistHistoryToLocalStorage();
|
|
||||||
},
|
|
||||||
deep: true
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.getHistoryFromLocalStorage();
|
this.initializeHistoryIfNoHistory();
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
getHistoryFromLocalStorage() {
|
getHistoryFromLocalStorage() {
|
||||||
if (localStorage.getItem(LOCAL_STORAGE_HISTORY_KEY)) {
|
const localStorageHistory = localStorage.getItem(LOCAL_STORAGE_HISTORY_KEY);
|
||||||
this.history = JSON.parse(localStorage.getItem(LOCAL_STORAGE_HISTORY_KEY));
|
const history = localStorageHistory ? JSON.parse(localStorageHistory) : undefined;
|
||||||
} else {
|
|
||||||
|
return history;
|
||||||
|
},
|
||||||
|
initializeHistoryIfNoHistory() {
|
||||||
|
if (!this.history) {
|
||||||
this.history = {};
|
this.history = {};
|
||||||
this.persistHistoryToLocalStorage();
|
this.persistHistoryToLocalStorage();
|
||||||
}
|
}
|
||||||
@ -157,6 +160,8 @@ export default {
|
|||||||
|
|
||||||
currentHistory.unshift(timespan);
|
currentHistory.unshift(timespan);
|
||||||
this.history[key] = currentHistory;
|
this.history[key] = currentHistory;
|
||||||
|
|
||||||
|
this.persistHistoryToLocalStorage();
|
||||||
},
|
},
|
||||||
selectTimespan(timespan) {
|
selectTimespan(timespan) {
|
||||||
this.openmct.time.bounds(timespan);
|
this.openmct.time.bounds(timespan);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user