Skip to content

Commit

Permalink
fix(visualize): Deep linking now includes selected category
Browse files Browse the repository at this point in the history
Fixes #250
  • Loading branch information
atruskie committed Feb 15, 2016
1 parent a382feb commit c64411f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ angular

// object reference!
let defaults = Object.assign({
initialExtent: null,
initialSelection: null,
visualizationYMax: 1000,
visualizationTileHeight: 100
}, $scope.options);
Expand Down Expand Up @@ -79,7 +79,7 @@ angular
visualizationMiddles.map(x => moment.duration(x, "seconds").humanize()) || "";
}

$scope.options.functions.extentUpdated(newExtent);
$scope.options.functions.extentUpdated(newExtent, selectedLane);

function update() {
// object reference!
Expand Down Expand Up @@ -135,16 +135,21 @@ angular

// new behaviour, set default extent to full width of data
if (self.data.items.length > 0) {
let extent = [self.data.minimum, self.data.maximum];
let extent = [self.data.minimum, self.data.maximum],
category = null;

// additionally, support setting initial extent for deep linking scenarios
if ($scope.options.initialExtent) {
extent = $scope.options.initialExtent;
if ($scope.options.initialSelection) {

({extent, category} = $scope.options.initialSelection); // jshint ignore:line

// only set initial extent once
$scope.options.initialExtent = null;
$scope.options.initialSelection = null;
}

if (category) {
self.detail.selectedCategory = category;
}
$scope.options.functions.extentUpdate(extent);
}
}
Expand Down
37 changes: 22 additions & 15 deletions src/app/visualize/visualize.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,21 @@ angular
paths, constants, modelAssociations,
Project, Site, AudioRecording, AnalysisResultFile, UserProfile) {
const extent0Key = "extent0",
extent1Key = "extent1";
extent1Key = "extent1",
selectedLaneKey = "lane";

var projectToSiteLinker = modelAssociations.generateLinker("Project", "Site");
var siteToProjectLinker = modelAssociations.generateLinker("Site", "Project");

var updateLocationSearch = _.throttle(function (newExtent) {
var updateLocationSearch = _.throttle(function (newExtent, category) {
//console.debug(...newExtent);

$location.replace();
$location.search({
[$scope.filterType]: $routeParams[$scope.filterType],
[extent0Key]: +newExtent[0],
[extent1Key]: +newExtent[1]
[$scope.filterType]: $routeParams[$scope.filterType],
[extent0Key]: +newExtent[0],
[extent1Key]: +newExtent[1],
[selectedLaneKey]: category
});
}, 250);

Expand Down Expand Up @@ -194,19 +196,19 @@ angular
startOffsetSeconds
);
},
extentUpdated(newExtent) {
extentUpdated(newExtent, category) {
//console.debug(...newExtent);
// if value has changed, update the search for deep linkingness
if (newExtent) {
updateLocationSearch(newExtent);
updateLocationSearch(newExtent, category);
}
}
},
// TODO: do not hard code
availableResolutions: [0.02, 0.04, 0.08, 0.16, 0.2, 0.4, 0.6, 1, 2, 4, 6, 12, 24, 60],
visualizationTileHeight: 256,
visualizationYMax: 11025,
initialExtent: parameters.initialExtent
initialSelection: parameters.initialSelection
};

$scope.getLegendClass = function (site) {
Expand Down Expand Up @@ -272,19 +274,24 @@ angular

$scope.ids = ids;

var initialExtent = null;
var initialSelection = null;
if ($routeParams.hasOwnProperty(extent0Key) &&
$routeParams.hasOwnProperty(extent1Key)) {
initialExtent = [
new Date(Number($routeParams[extent0Key])),
new Date(Number($routeParams[extent1Key]))
];
$routeParams.hasOwnProperty(extent1Key) &&
$routeParams.hasOwnProperty(selectedLaneKey)
) {
initialSelection = {
category: Number($routeParams[selectedLaneKey]),
extent: [
new Date(Number($routeParams[extent0Key])),
new Date(Number($routeParams[extent1Key]))
]
};
}

return {
error: $scope.errorState,
ids,
initialExtent,
initialSelection,
projectFirst: hasProjectId
};
}
Expand Down

0 comments on commit c64411f

Please sign in to comment.