Skip to content

Commit

Permalink
Local session file selection U/X build out
Browse files Browse the repository at this point in the history
  • Loading branch information
turner committed Jan 15, 2024
1 parent 48c0bf4 commit 76c0def
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions js/sessionUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async function initializeSessionUtilities(browser, $igvMain, initializeDropbox,
}
}

createLocalTrackFileCard(document.getElementById('igv-main'), 'igv-local-track-file-card')
createLocalTrackFileCard(document.getElementById('igv-main'), 'igv-local-track-file-card', browser)

const sessionLoader = async config => {

Expand Down Expand Up @@ -135,7 +135,10 @@ function presentLocalTrackFileModal(trackFileNamesCard, trackFileNames) {
const rows = trackFileNamesCard.querySelectorAll('.list-group-item')
const fileInput = document.getElementById('igv-local-track-file-input')

rows.forEach(row => row.addEventListener('click', () => fileInput.click()))
rows.forEach(row => row.addEventListener('click', e => {
fileInput.dataset.filename = e.target.innerText
fileInput.click()
}))

trackFileNamesCard.style.left = `128px`
trackFileNamesCard.style.top = `128px`
Expand All @@ -144,7 +147,7 @@ function presentLocalTrackFileModal(trackFileNamesCard, trackFileNames) {
// alert(`Session contains local files that cannot be loaded automatically:\n${ trackFileNames.join('\n')}`)
}

function createLocalTrackFileCard(parentElement, id){
function createLocalTrackFileCard(parentElement, id, browser){

const str =
`The session file used contains these local track files. They cannot be loaded automatically. Click on a name to present the file picker to load the file.`
Expand Down Expand Up @@ -181,12 +184,35 @@ function createLocalTrackFileCard(parentElement, id){
const fileInputElement = fragment.firstChild
parentElement.appendChild(fileInputElement)

fileInputElement.addEventListener('change', e => {
fileInputElement.addEventListener('change', async e => {

const {files} = fileInputElement
const name = files[ 0 ].name

console.log(`Local track file ${ name } will be loaded`)
if (fileInputElement.dataset.filename === name) {

const config = sessionLocalTrackFilesDictionary[ name ]

config.url = files[ 0 ]

if (config) {

try {
await browser.loadTrackList([ config ])
} catch (e) {
console.error(e)
AlertSingleton.present(e)
}

} else {
alert(`Could not find track file named ${ name }`)
}

} else {
alert(`Retrieved file ${ name } does not match selected file ${ fileInputElement.dataset.filename }. `)
}


})

}
Expand Down

0 comments on commit 76c0def

Please sign in to comment.