Skip to content

Commit

Permalink
Merge pull request #178 from warelab/idList
Browse files Browse the repository at this point in the history
Id list
  • Loading branch information
ajo2995 authored Nov 22, 2016
2 parents b53feac + 7d0f9c1 commit 9d0c8af
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
9 changes: 9 additions & 0 deletions scripts/search/getidListFromURLParams.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import _ from "lodash";

export default function getidListFromURLParams() {
const params = _.get(global.gramene, 'searchParams');
if (params && params.idList) {
return _.uniq(params.idList.split(','));
}
return [];
}
20 changes: 20 additions & 0 deletions scripts/search/persist.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@ This module is likely to be replaced if/when we refactor the codebase to use Rea
*/

import _ from 'lodash';
import getidListFromURLParams from './getidListFromURLParams';

let expectedSerializedHashState = '';
let expectedSerializedLocalStorageState = '';
const loc = global.location || {hash: expectedSerializedHashState};
const localStore = global.localStorage || {};

const maxLengthToShow = 3;

export function initUrlHashPersistence(callback) {
var hashChangeHandler = handleHashChangeFactory(callback);
possiblyCopyStateFromLocalStorage();
possiblyHandleIdList();
global.onhashchange = hashChangeHandler;
hashChangeHandler();
}
Expand All @@ -32,6 +36,22 @@ function possiblyCopyStateFromLocalStorage() {
}
}

// if there is an idList query parameter, clear everything and create a filter
function possiblyHandleIdList() {
var idList = getidListFromURLParams();
if (idList.length > 0) {
var state = {filters: {}, taxa: {}};
var fqString = 'id:(' + idList.join(' ') + ')';
state.filters[fqString] = {
category: "Gene",
display_name: idList.length <= maxLengthToShow ? idList.join(', ')
: idList.slice(0,maxLengthToShow).join(', ') + ' and ' + (idList.length - maxLengthToShow) + ' more',
exclude: false,
fq: fqString
};
loc.hash = '#' + encodeURI(JSON.stringify(state));
}
}
function handleHashChangeFactory(callback) {
return function handleHashChange() {
if (hashDidChange()) {
Expand Down

0 comments on commit 9d0c8af

Please sign in to comment.