Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix local storage filtering overriding historical session filtering set by url #235

Merged
merged 4 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/historical/HistoricalProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,11 +517,11 @@ define([
}

const sessions = this.getSessionService();
const session = sessions.getHistoricalSession();
const sessionFilter = sessions.getHistoricalSessionFilter();

if (session) {
params.filter.session_id = '(' + session.numbers.join(',') + ')';
params.filter.session_host = session.host;
if (sessionFilter) {
params.filter.session_id = `(${sessionFilter.numbers.join(',')})`;
params.filter.session_host = sessionFilter.host;
} else if (window.openmctMCWSConfig?.sessions?.historicalSessionFilter?.disable !== true && window.openmctMCWSConfig?.sessions?.historicalSessionFilter?.denyUnfilteredQueries === true) {
const notificationMessage = 'Filtering by historical sessions is required for historical queries.';

Expand All @@ -531,7 +531,7 @@ define([
}

if (this.isUnsupportedDomain(provider, options)) {
const message = !session
const message = !sessionFilter
? `This view requires a session or supported time system for historical requests.`
: `This view does not support ${options.domain}. Historical data might not match the time system.`;

Expand Down
2 changes: 1 addition & 1 deletion src/historical/HistoricalProviderSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('Historical Provider', function () {
});

mockSessionService = jasmine.createSpyObj('SessionService', [
'getHistoricalSession'
'getHistoricalSessionFilter'
]);
spyOn(HistoricalProvider.prototype, 'getSessionService').and.returnValue(mockSessionService);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

<div class="c-indicator icon-session"
:class="{
's-status-on': activeSessions.numbers,
's-status-on': sessionFilter.numbers,
's-status-available': availableSessions.length
}">

<span
v-if="historicalSessionDisabled"
v-if="historicalSessionFilterDisabled"
class="c-indicator__label"
>
<span class="angular-w">
Expand All @@ -24,7 +24,7 @@

<template v-if="availableSessions.length">

<span v-if="activeSessions.numbers"
<span v-if="sessionFilter.numbers"
class="angular-w">
{{filteredByMessageString}}
<button @click="openSessionSelector">
Expand Down Expand Up @@ -57,7 +57,7 @@

<historical-session-selector
v-if="showSessionSelector"
:activeSessions="activeSessions"
:sessionFilter="sessionFilter"
@update-available-sessions="setAvailableSessions"
@close-session-selector="closeSessionSelector"
/>
Expand All @@ -83,30 +83,30 @@ export default {
filteredByMessageString() {
let sessionOrSessions;

if (this.activeSessions.numbers.length === 1) {
if (this.sessionFilter.numbers.length === 1) {
sessionOrSessions = 'session'
} else {
sessionOrSessions = 'sessions'
}
return `Historical queries filtered by ${this.activeSessions.numbers.length} ${sessionOrSessions}`;
return `Historical queries filtered by ${this.sessionFilter.numbers.length} ${sessionOrSessions}`;
}
},
data() {
return {
activeSessions: {},
sessionFilter: {},
numFilteredSessions: 8,
availableSessions: [],
showSessionSelector: false,
isRequestingSessions: false,
historicalSessionDisabled: false
historicalSessionFilterDisabled: false
}
},
methods: {
onActiveSessionChange(sessions) {
setHistoricalSessionFilter(sessions) {
if (sessions) {
this.activeSessions = sessions;
this.sessionFilter = sessions;
} else {
this.activeSessions = {};
this.sessionFilter = {};
}
},
setAvailableSessions(sessions) {
Expand All @@ -120,7 +120,7 @@ export default {
this.showSessionSelector = false;
},
clearAllSessions() {
this.sessionService.setHistoricalSession();
this.sessionService.setHistoricalSessionFilter();
},
checkForHistoricalSessions() {
this.isRequestingSessions = true;
Expand All @@ -129,17 +129,17 @@ export default {
},
mounted() {
this.sessionService = SessionService();
this.historicalSessionDisabled = this.sessionService.historicalSessionFilterConfig.disable;
this.historicalSessionFilterDisabled = this.sessionService.historicalSessionFilterConfig.disable;

window.setTimeout(this.checkForHistoricalSessions, 2000);

this.unsubscribeSessionListener = this.sessionService.listenForHistoricalChange(this.onActiveSessionChange);
this.unsubscribeSessionListener = this.sessionService.listenForHistoricalChange(this.setHistoricalSessionFilter);

let activeSessions = this.sessionService.getHistoricalSession();
this.onActiveSessionChange(activeSessions);
const sessionFilter = this.sessionService.getHistoricalSessionFilter();
this.setHistoricalSessionFilter(sessionFilter);
},
beforeUnmount() {
this.table.extendsDestroy();
this.table.extendsDestroy();
this.unsubscribeSessionListener();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@
<div class="c-overlay__button-bar">
<a class="c-button c-button--major"
:class="{disabled: !selectedSessions.length}"
@click="applyHistoricalSessions">
@click="applyHistoricalSessionFilter">
Filter By Selected Sessions
</a>
<a class="c-button"
:class="{disabled: !activeSessions}"
@click="clearHistoricalSessions">
:class="{disabled: !sessionFilter}"
@click="clearHistoricalSessionFilter">
Clear Filtering
</a>
<a class="c-button"
Expand Down Expand Up @@ -149,7 +149,7 @@ import { nextTick } from 'vue';

export default {
inject: ['openmct', 'table'],
props: ['activeSessions'],
props: ['sessionFilter'],
components: {
TelemetryTable
},
Expand Down Expand Up @@ -188,10 +188,10 @@ export default {
});
},
setMarkedSessions() {
if(this.activeSessions.numbers && this.activeSessions.host) {
if(this.sessionFilter.numbers && this.sessionFilter.host) {
this.availableSessions.forEach(session => {
if (this.activeSessions.numbers.some((sessionNumber => sessionNumber == session.number))
&& this.activeSessions.host === session.host) {
if (this.sessionFilter.numbers.some((sessionNumber => sessionNumber === session.number))
&& this.sessionFilter.host === session.host) {

session.marked = true;
}
Expand All @@ -207,8 +207,8 @@ export default {
this.setMarkedSessions();
this.hosts = this.getUniq('host', this.availableSessions)

if (this.activeSessions.host) {
primaryHost = this.activeSessions.host
if (this.sessionFilter.host) {
primaryHost = this.sessionFilter.host
} else {
primaryHost = this.hosts[0];
}
Expand All @@ -221,11 +221,11 @@ export default {
updateSelectedSessions(sessions) {
this.selectedSessions = sessions;
},
clearHistoricalSessions() {
this.sessionService.setHistoricalSession();
clearHistoricalSessionFilter() {
this.sessionService.setHistoricalSessionFilter();
this.closeOverlay();
},
applyHistoricalSessions() {
applyHistoricalSessionFilter() {
let selectedSessions = this.selectedSessions.map(row => row.datum),
host = this.selectedHost,
startTime,
Expand Down Expand Up @@ -253,7 +253,7 @@ export default {
numbers: selectedSessions.map(s => s.number)
}

this.sessionService.setHistoricalSession(sessionObject);
this.sessionService.setHistoricalSessionFilter(sessionObject);
this.closeOverlay();
},
closeOverlay() {
Expand Down
35 changes: 18 additions & 17 deletions src/services/session/SessionLocalStorageHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ define([

sessionService.listen(this.storeRealtimeSession.bind(this));
sessionService.listenForHistoricalChange(
this.storeHistoricalSession.bind(this)
this.storeHistoricalSessionFilter.bind(this)
);
this.initializeFromStorage();
}
Expand All @@ -58,25 +58,26 @@ define([
* from localStorage (if it exists)
*/
SessionLocalStorageHandler.prototype.initializeFromStorage = function () {
if (this.sessionService.hasActiveTopicOrSession()) {
return;
}
if (!this.sessionService.hasActiveTopicOrSession()) {
const realtimeSession = localStorage.getItem(REALTIME_SESSION_KEY);

var realtimeSession = localStorage.getItem(REALTIME_SESSION_KEY);
if (realtimeSession) {
this.sessionService.setActiveTopicOrSession(JSON.parse(realtimeSession));
if (realtimeSession) {
this.sessionService.setActiveTopicOrSession(JSON.parse(realtimeSession));
}
}

var historicalSessionJSON = localStorage.getItem(HISTORICAL_SESSION_KEY);
if (!this.sessionService.hasHistoricalSessionFilter()) {
const sessionFilterJSON = localStorage.getItem(HISTORICAL_SESSION_KEY);

if (historicalSessionJSON) {
var historicalSession = JSON.parse(historicalSessionJSON);
if (sessionFilterJSON) {
const sessionFilter = JSON.parse(sessionFilterJSON);

if (!historicalSession.numbers) {
historicalSession.numbers = [historicalSession.number];
if (!sessionFilter.numbers) {
sessionFilter.numbers = [sessionFilter.number];
}

this.sessionService.setHistoricalSession(historicalSession);
this.sessionService.setHistoricalSessionFilter(sessionFilter);
}
}
};

Expand All @@ -92,11 +93,11 @@ define([
};

/**
* store the historical session in localStorage.
* store the historical session filter in localStorage.
*/
SessionLocalStorageHandler.prototype.storeHistoricalSession = function (historicalSession) {
if (historicalSession) {
localStorage.setItem(HISTORICAL_SESSION_KEY, JSON.stringify(historicalSession));
SessionLocalStorageHandler.prototype.storeHistoricalSessionFilter = function (sessionFilter) {
if (sessionFilter) {
localStorage.setItem(HISTORICAL_SESSION_KEY, JSON.stringify(sessionFilter));
} else {
localStorage.removeItem(HISTORICAL_SESSION_KEY);
}
Expand Down
39 changes: 16 additions & 23 deletions src/services/session/SessionService.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class SessionService {
historical: []
};
this.activeModel = undefined;
this.historicalSession = undefined;
this.historicalSessionFilter = undefined;
this.sessionConfig = openmctMCWSConfig.sessions;
this.realtimeSessionConfig = this.sessionConfig.realtimeSession;
this.historicalSessionFilterConfig = this.sessionConfig.historicalSessionFilter;
Expand All @@ -61,9 +61,9 @@ class SessionService {
openmct.on('start', () => {
new SessionURLHandler(this, openmct);
new SessionLocalStorageHander(this);
});

this.pollForActiveSession();
this.pollForActiveSession();
});
}

/**
Expand Down Expand Up @@ -332,18 +332,25 @@ class SessionService {
return historicalSessions;
};

getHistoricalSession() {
return this.historicalSession;
getHistoricalSessionFilter() {
return this.historicalSessionFilter;
};

setHistoricalSession(model) {
/**
* @returns boolean true if a historical session filtering is active, otherwise false.
*/
hasHistoricalSessionFilter() {
return Boolean(this.historicalSessionFilter);
};

setHistoricalSessionFilter(model) {
if (this.historicalSessionFilterConfig.disable) {
this.notificationService.alert('Historical Session Filtering has been disabled in config');

return;
}

this.historicalSession = model;
this.historicalSessionFilter = model;
this.subscriptions.historical.forEach((listener) => {
try {
listener(model);
Expand All @@ -353,7 +360,7 @@ class SessionService {
}
});

this.notifyUserOfHistoricalSessionChange(model);
this.notifyUserOfHistoricalSessionFilterChange(model);

//clear plots and tables before requery
this.openmct.objectViews.emit('clearData');
Expand Down Expand Up @@ -388,7 +395,7 @@ class SessionService {
}
};

notifyUserOfHistoricalSessionChange(model) {
notifyUserOfHistoricalSessionFilterChange(model) {
let notificationString = 'Historical queries not restricted by session.';

if (model) {
Expand All @@ -398,20 +405,6 @@ class SessionService {
this.notificationService.info(notificationString);
};

isActiveHistoricalSession(model) {
if ((!this.historicalSession || !model) && this.activeModel !== model) {

return false;
}

if (this.historicalSession.topic === model.topic && this.historicalSession.number === model.number) {

return true;
}

return false;
};

sessionOrTopic(model) {
return model.number ? 'session' : 'topic';
};
Expand Down
Loading