Skip to content

Commit

Permalink
replace "custom" genome list with "recent", max of 5
Browse files Browse the repository at this point in the history
  • Loading branch information
jrobinso committed Mar 13, 2024
1 parent 6799ee5 commit 93668ff
Showing 1 changed file with 25 additions and 27 deletions.
52 changes: 25 additions & 27 deletions js/widgets/genomeWidgets.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import {ModalTable, GenericDataSource} from '../../node_modules/data-modal/src/index.js'
import {StringUtils} from "../../node_modules/igv-utils/src/index.js"

Expand All @@ -10,7 +9,7 @@ import FileLoadWidget from "./fileLoadWidget.js"
import * as Utils from './utils.js'
import {genarkDatasourceConfigurator} from "./genarkDatasourceConfigurator.js"

const MAX_CUSTOM_GENOMES = 10
const MAX_CUSTOM_GENOMES = 5

let predefinedGenomeIds
let predefinedGenomes
Expand Down Expand Up @@ -104,8 +103,8 @@ async function getAppLaunchGenomes(genomes) {
}
}

function getCustomGenomes() {
const customGenomeString = localStorage.getItem("customGenomes")
function getRecentGenomes() {
const customGenomeString = localStorage.getItem("recentGenomes")
return customGenomeString ? JSON.parse(customGenomeString).reverse() : []
}

Expand Down Expand Up @@ -148,10 +147,10 @@ function updateGenomeList() {
}
}

const customGenomes = getCustomGenomes()
if (customGenomes && customGenomes.length > 0) {
const recentGenomes = getRecentGenomes()
if (recentGenomes && recentGenomes.length > 0) {
$('<div class="dropdown-divider"></div>').insertAfter($divider)
for (let genomeJson of customGenomes) {
for (let genomeJson of recentGenomes) {
addEntryFor(genomeJson)
}

Expand Down Expand Up @@ -181,27 +180,26 @@ async function loadGenome(genomeConfiguration, custom = false) {

// Update the custom list
// hub.txt genomes are indirect, record name and id
if (!predefinedGenomeIds.has(g.id)) {
if (StringUtils.isString(genomeConfiguration)) {
genomeConfiguration = {id: genomeConfiguration}
} else {
if (!genomeConfiguration.id) genomeConfiguration.id = g.id
}
if (!genomeConfiguration.name) {
genomeConfiguration.name = g.name
}


const customGenomesString = localStorage.getItem("customGenomes")
let customGenomes = customGenomesString ? JSON.parse(customGenomesString) : []
customGenomes = customGenomes.filter(r => r.id !== g.id) // If already present, replace
customGenomes.unshift(genomeConfiguration)
if (customGenomes.length > MAX_CUSTOM_GENOMES) {
customGenomes = customGenomes.slice(0, MAX_CUSTOM_GENOMES)
}
localStorage.setItem("customGenomes", JSON.stringify(customGenomes))
updateGenomeList()
if (StringUtils.isString(genomeConfiguration)) {
genomeConfiguration = {id: genomeConfiguration}
} else {
if (!genomeConfiguration.id) genomeConfiguration.id = g.id
}
if (!genomeConfiguration.name) {
genomeConfiguration.name = g.name
}


const recentGenomeList = localStorage.getItem("recentGenomes")
let recentGenomes = recentGenomeList ? JSON.parse(recentGenomeList) : []
recentGenomes = recentGenomes.filter(r => r.id !== g.id) // If already present, replace
recentGenomes.unshift(genomeConfiguration)
if (recentGenomes.length > MAX_CUSTOM_GENOMES) {
recentGenomes = recentGenomes.slice(0, MAX_CUSTOM_GENOMES)
}
localStorage.setItem("recentGenomes", JSON.stringify(recentGenomes))
updateGenomeList()


} catch (e) {
console.error(e)
Expand Down

0 comments on commit 93668ff

Please sign in to comment.