Skip to content

Commit

Permalink
Merge pull request #27 from hjeeves/cadc12092
Browse files Browse the repository at this point in the history
CADC-12092: single skaha/image web service call instead of one per session type
  • Loading branch information
at88mph authored Dec 22, 2022
2 parents 3a24e68 + 883ecb2 commit 20d0669
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 46 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 = '1010'
version = '1011'

ext {
intTest_user_name = 'CADCtest'
Expand Down
81 changes: 36 additions & 45 deletions src/main/webapp/js/science_portal_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
_selfPortalForm.getContextData()

// Start loading container image lists
_selfPortalForm.getImageData()
_selfPortalForm.getFullImageList()
}


Expand Down Expand Up @@ -110,70 +110,60 @@
return null
}

function isTypeInList(imageType) {
var isInList = (element) => element === imageType
var typeIndex = _selfPortalForm._sessionTypeList.findIndex(isInList)
if (typeIndex === -1) {
return false
} else {
return true
}
}

// --------------- Image list functions

function getImageData() {

for (var i = 0; i < _selfPortalForm._sessionTypeMap.session_types.length; i++) {
var curTypename = _selfPortalForm._sessionTypeMap.session_types[i].name

// This needs to be done by type, and the type need to be
// pushed through to the 'then' so the right
// values are populated in the image object
var curTypeURL = _selfPortalForm.sessionURLs.images + '?type=' + curTypename

// Do this so each call has it's own curTypeURL
// If the Promise is in this same function, the timing of the ajax
// calls is such that curTypeURL is the same for all lists so
// there's no effective lookup.
_getImageDataForType(curTypeURL, curTypename)
}
}

function _getImageDataForType(callURL, sessionType ){
Promise.resolve(_getAjaxData(callURL))
function getFullImageList(){
var fullListURL = _selfPortalForm.sessionURLs.images
Promise.resolve(_getAjaxData(fullListURL))
.then(function (imageList) {

if (_selfPortalForm._ajaxCallCount !== -9) {
var imageIDList = new Array()
for (var i = 0; i < imageList.length; i++) {
imageIDList.push(imageList[i].id)
// init the image list structure to simplify the loop below
_selfPortalForm._imageData = {}
for (var j=0; j<_selfPortalForm._sessionTypeList.length; j++) {
_selfPortalForm._imageData[_selfPortalForm._sessionTypeList[j]] = {
'imageList': new Array(),
"imageIDList": new Array()
}
}

_selfPortalForm._ajaxCallCount--
_selfPortalForm._imageData.push({
"sessionType": sessionType,
"imageList": imageList,
"imageIDList": imageIDList
})

if (_selfPortalForm._ajaxCallCount === 0) {
trigger(_selfPortalForm, cadc.web.science.portal.form.events.onLoadFormDataDone)
for (var i=0; i<imageList.length; i++) {
var curImage = imageList[i]
if (isTypeInList(curImage.type)) {
// add into the imageList structure
_selfPortalForm._imageData[curImage.type].imageList.push(curImage)
_selfPortalForm._imageData[curImage.type].imageIDList.push(curImage.id)
}
// else skip is it's not a type currently supported in the UI for
// launching sessions.
}

trigger(_selfPortalForm, cadc.web.science.portal.form.events.onLoadFormDataDone)

})
.catch(function (message) {
trigger(_selfPortalForm, cadc.web.science.portal.form.events.onLoadImageDataError, message)
})
}

// Q: is the full session data being passed in or just the type?
//function getImageListForSessionType(sessionData) {
// return getImageListForType(sessionData.name)
//}


function getImageListForType(sessionType) {
// return what it's asking for, in an array of IDs.
var imageList = null
for (var i = 0; i < _selfPortalForm._imageData.length; i++) {
if (_selfPortalForm._imageData[i].sessionType === sessionType) {
imageList = _selfPortalForm._imageData[i].imageIDList
}
if (typeof _selfPortalForm._imageData[sessionType] !== 'undefined') {
return _selfPortalForm._imageData[sessionType].imageIDList
} else {
return imageList
}
return imageList
}


Expand Down Expand Up @@ -296,7 +286,7 @@
getRAMDefault: getRAMDefault,
getCoresArray: getCoresArray,
getCoresDefault: getCoresDefault,
getImageData: getImageData,
getFullImageList: getFullImageList,
getImageListForType: getImageListForType,
getSessionTypeDefault: getSessionTypeDefault,
getSessionTypeList: getSessionTypeList,
Expand All @@ -305,6 +295,7 @@
interruptAjaxProcessing: interruptAjaxProcessing,
loadSessionTypeMap: loadSessionTypeMap,
setServiceURLs: setServiceURLs,
isTypeInList: isTypeInList
})
}

Expand Down

0 comments on commit 20d0669

Please sign in to comment.