Skip to content

Commit

Permalink
Merge pull request #26 from hjeeves/cadc12075
Browse files Browse the repository at this point in the history
CADC-12075: filter session list - interactive sessions, pending and running only.
  • Loading branch information
at88mph authored Dec 9, 2022
2 parents 0f94dfa + a547549 commit 3a24e68
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 21 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies {

sourceCompatibility = '1.8'
group = 'ca.nrc.cadc'
version = '1009'
version = '1010'

ext {
intTest_user_name = 'CADCtest'
Expand Down
20 changes: 16 additions & 4 deletions src/main/webapp/js/science_portal.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,29 @@
function init() {
attachListeners()
// loads from session_type_map_en.json. No known timing issues
// Issues onLoadTypeMapDone, which will call continueInit
// Needed because the session types declared in the config file
// are needed for filtering session lists
portalForm.loadSessionTypeMap()

// add tooltips
$('[data-toggle="tooltip"]').tooltip()


}

function continueInit() {
// Nothing happens if user is not authenticated, so no other page
// load information is done until this call comes back (see onAuthenticated event below)
// onAuthenticated event triggered if everything is OK.
// Put this up because the authentication step can be a bit tardy, otherwise
// it looks like the portal isn't doing anything.
portalSessions.setSessionTypeList(portalForm.getSessionTypeList())
portalCore.setInfoModal('Initialising', 'Validating credentials',
false, true, true)
portalCore.checkAuthentication()
}


function attachListeners() {
// Button/page click listeners
$('.sp-add-session').click(handleAddSession)
Expand Down Expand Up @@ -121,7 +129,9 @@

portalCore.subscribe(portalSessions, cadc.web.science.portal.session.events.onLoadSessionListDone, function (e) {
// Build session list on top of page
populateSessionList(portalSessions.getSessionList())
var filteredList = portalSessions.getFilteredSessionList()
populateSessionList(filteredList)

portalCore.setProgressBar("okay")
portalCore.hideInfoModal(true)

Expand All @@ -137,7 +147,8 @@
.then(function (finalState) {
if (finalState == 'done') {
// Grab new session list
populateSessionList(portalSessions.getSessionList())
var filteredList = portalSessions.getFilteredSessionList()
populateSessionList(filteredList)
}
})
.catch(function (message) {
Expand All @@ -154,7 +165,7 @@

portalCore.subscribe(portalSessions, cadc.web.science.portal.session.events.onPollingContinue, function (e) {
// Rebuild session list on top of page
populateSessionList(portalSessions.getSessionList())
populateSessionList(portalSessions.getFilteredSessionList())
})

portalCore.subscribe(_selfPortalApp, cadc.web.science.portal.events.onSessionRequestOK, function (e, sessionData) {
Expand All @@ -169,6 +180,7 @@
})

// Portal Form listeners
portalCore.subscribe(portalForm, cadc.web.science.portal.form.events.onLoadTypeMapDone, continueInit)
portalCore.subscribe(portalForm, cadc.web.science.portal.form.events.onLoadFormDataDone, initForm)
portalCore.subscribe(portalForm, cadc.web.science.portal.form.events.onLoadContextDataError, handleServiceError)
portalCore.subscribe(portalForm, cadc.web.science.portal.form.events.onLoadImageDataError, handleServiceError)
Expand Down
20 changes: 11 additions & 9 deletions src/main/webapp/js/science_portal_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
PortalForm: PortalForm,
// Events
events: {
onLoadTypeMapDone: new jQuery.Event('sciPort:onLoadTypeMapDone'),
onLoadFormDataDone: new jQuery.Event('sciPort:onLoadFormDataDone'),
onLoadFormDataError: new jQuery.Event('sciPort:onLoadFormDataError'),
onLoadImageDataDone: new jQuery.Event('sciPort:onLoadImageDataDone'),
Expand Down Expand Up @@ -57,15 +58,6 @@

// -- init form data gather functions
function getFormData() {

// Build session type list
var tempTypeList = new Array()
for (var i = 0; i < _selfPortalForm._sessionTypeMap.session_types.length; i++) {
// each entry has id, type, digest, only 'id' is needed
tempTypeList.push( _selfPortalForm._sessionTypeMap.session_types[i].name)
}
_selfPortalForm._sessionTypeList = tempTypeList

// Set up counter for ajax calls used to load page data
// 1 = call for contexts
_selfPortalForm._ajaxCallCount = 1 + _selfPortalForm._sessionTypeMap.session_types.length;
Expand All @@ -90,6 +82,16 @@
// number of sessions will increase fairly soon.
$.getJSON(contentFileURL, function (jsonData) {
_selfPortalForm._sessionTypeMap = jsonData

// Build session type list
var tempTypeList = new Array()
for (var i = 0; i < _selfPortalForm._sessionTypeMap.session_types.length; i++) {
// each entry has id, type, digest, only 'id' is needed
tempTypeList.push( _selfPortalForm._sessionTypeMap.session_types[i].name)
}
_selfPortalForm._sessionTypeList = tempTypeList

trigger(_selfPortalForm, cadc.web.science.portal.form.events.onLoadTypeMapDone)
})
// Used to reset launch form
_selfPortalForm._sessionTypeMap.default = 'notebook'
Expand Down
38 changes: 31 additions & 7 deletions src/main/webapp/js/science_portal_session.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,18 @@
this._filteredSessionList = {}
this.sessionURLs = {}

// This is here because it can be used in case of timing issues
// with loading the session type map.
this._sessionTypeList = new Array()

function setServiceURLs(URLObject) {
_selfPortalSess.sessionServiceURL = URLObject.session
}

function setSessionTypeList(thelist) {
_selfPortalSess._sessionTypeList = thelist
}

function initSessionLists() {
_isEmpty = true
_selfPortalSess._sessionList = {}
Expand All @@ -52,10 +60,25 @@
}

function getFilteredSessionList() {
if (_selfPortalSess._filteredSessionList === {}) {
initSessionLists()
_selfPortalSess._filteredSessionList = new Array()

var tmpList = new Array()

for (var i=0; i<_selfPortalSess._sessionList.length; i++) {
var curSes = _selfPortalSess._sessionList[i]

const isInList = (element) => element === curSes.type
var typeIndex = _selfPortalSess._sessionTypeList.findIndex(isInList)

if (typeIndex !== -1) {
if ( curSes.status === 'Running' || curSes.status === 'Pending') {
tmpList.push(curSes)
}
}
}
return _selfPortalSess._filteredSessionList
_selfPortalSess._filteredSessionList = tmpList

return tmpList
}


Expand Down Expand Up @@ -112,8 +135,8 @@
var allStable = true

for (var i = 0; i < _selfPortalSess._sessionList.length; i++) {
if ( (_selfPortalSess._sessionList[i].status !== 'Running') &&
(_selfPortalSess._sessionList[i].status !== 'Succeeded') ) {
// Only Pending state will trigger a poll
if (_selfPortalSess._sessionList[i].status === 'Pending') {
allStable = false
break
}
Expand Down Expand Up @@ -152,9 +175,9 @@
}
}

// TODO: have a 'setFilteredSessionList(filterOutList, filterInList) {}

function setFilteredSessionList(filterOutList) {
function setFilteredSessionList() {
// Filter for 'Running' and 'Pending' of the valid list
if (sessionList.length > 0) {
// TODO: consider what session types are filtered out by default
_selfPortalSess._sessionList = sessionList
Expand Down Expand Up @@ -310,6 +333,7 @@
isSessionListEmpty : isSessionListEmpty,
pollSessionList: pollSessionList,
deleteSession: deleteSession,
setSessionTypeList: setSessionTypeList
})
}

Expand Down

0 comments on commit 3a24e68

Please sign in to comment.