Skip to content

Commit

Permalink
Queries get saved to and parsed from the URL
Browse files Browse the repository at this point in the history
  • Loading branch information
ihodes committed Nov 21, 2014
1 parent 6dd4b81 commit a69c0ce
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion cycledash/static/js/examine/RecordStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ var RECORD_LIMIT = 250;
var DEFAULT_SORT_BYS = [{columnName: 'contig', order: 'asc'},
{columnName: 'position', order: 'asc'}];

var ENTIRE_GENOME = {start: null, end: null, chromosome: types.ALL_CHROMOSOMES};
var ENTIRE_GENOME = {start: null, end: null, contig: types.ALL_CHROMOSOMES};


function createRecordStore(vcfId, dispatcher) {
// Initial state of the store. This is mutable. There be monsters.
Expand Down Expand Up @@ -123,6 +124,7 @@ function createRecordStore(vcfId, dispatcher) {
}

var query = queryFrom(range, filters, sortBys, page, limit);
setSearchStringToQuery(query);

$.when(deferredGenotypes(vcfId, query))
.done(response => {
Expand Down Expand Up @@ -157,6 +159,23 @@ function createRecordStore(vcfId, dispatcher) {
};
}

function setSearchStringToQuery(query) {
var queryString = encodeURI(JSON.stringify(query));
window.history.pushState(null, null, '?query=' + queryString);
}

// Returns the value with the given name in the URL search string.
function getQueryStringValue(name) {
var search = window.location.search.substring(1),
vars = search.split('&');
var val = _.first(_.filter(vars, v => {
var [key, val] = v.split('=');
return decodeURIComponent(key) == name;
}));
if (val)
return decodeURIComponent(val.split('=')[1]);
}

/**
* Updates the filters by columnName and filterValue. Removes previous any
* previous filter which applies to the columnName, and then appends the new
Expand Down Expand Up @@ -216,6 +235,8 @@ function createRecordStore(vcfId, dispatcher) {
hasLoaded = true;
columns = columnsResponse[0].spec;
contigs = contigsResponse[0].contigs;
var existingQuery = getQueryStringValue('query');
if (existingQuery) setQuery(JSON.parse(existingQuery));
updateGenotypes({append: false});
});

Expand Down

0 comments on commit a69c0ce

Please sign in to comment.