web4bio / webgen

WebGen Vertically Integrated Project
https://web4bio.github.io/webgen/main/html/
11 stars 26 forks source link

set url parameters with selected queries #361

Open kaczmarj opened 2 years ago

kaczmarj commented 2 years ago

When a user selects an option, the option will be set as a parameter in the url. The next step is to set the initial values for the select2 boxes using the url parameters, if they are given. Once this is implemented, a user can copy-paste a url to select the same things. Imagine that a user wants to send the results to a friend. That friend can enter the url and will have the same selection as the original user.

kaczmarj commented 2 years ago

form values can be auto-populated using the code below. one thing i haven't figured out yet is how to integrate this with local storage... because i realized we save cohorts in local storage. but would it make more sense to persist it in the url instead of localstorage?

const autoSelectFromURLParam = function(select2Object, key) {
    const url = new URL(window.location.href);
    const value = url.searchParams.get(key);
    if (value === undefined || value === null || value === "") {
        return
    }
    select2Object.select2("val", value.split(",")).trigger("change");
}
autoSelectFromURLParam($("#cancerTypeMultipleSelection"), "cohorts");
autoSelectFromURLParam($("#geneOneMultipleSelection"), "genesMutation");
autoSelectFromURLParam($("#clinicalMultipleSelection"), "clinical")
autoSelectFromURLParam($("#geneTwoMultipleSelection"), "genesExpression")
autoSelectFromURLParam($("#pathwayMultipleSelection"), "pathways")