Skip to content

Commit

Permalink
Merge pull request #485 from flibbertigibbet/feature/trip-reverse-button
Browse files Browse the repository at this point in the history
Add reverse button
  • Loading branch information
flibbertigibbet authored Aug 1, 2016
2 parents 44a91cb + 6d85439 commit f3283b3
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 8 deletions.
2 changes: 1 addition & 1 deletion deployment/ansible/group_vars/test
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ test: true
develop: false
production: false

otp_process_mem: 2G
otp_process_mem: 4G
2 changes: 1 addition & 1 deletion python/cac_tripplanner/cac_tripplanner/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.conf.urls import patterns, include, url
from django.conf.urls import include, url
from django.contrib.gis import admin

from django.contrib.staticfiles import views as staticviews
Expand Down
1 change: 0 additions & 1 deletion python/cac_tripplanner/shortlinks/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ def test_bad_key(self):

class ShortenedLinkViewsTestCase(TestCase):
def setUp(self):
urls = 'shortlinks.test.urls'
self.client = Client()

def test_methods_and_url_resolution(self):
Expand Down
2 changes: 1 addition & 1 deletion python/cac_tripplanner/templates/map.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ <h6>Maximum walking distance</h6>
<div class="sidebar-block sidebar-search hidden-xs">
<input class="typeahead origin" data-typeahead-key="origin" type="search" placeholder="Select an origin " />
<input class="typeahead destination" data-typeahead-key="destination" type="search" placeholder="Select a destination" />
<button type="submit"><span class="glyphicon glyphicon-search"></span></button>
<button id="reverse" type="submit"><span class="glyphicon glyphicon-sort"></span></button>
</div>
<div class="sidebar-block sidebar-options hidden-xs">
<div class="options search">
Expand Down
37 changes: 33 additions & 4 deletions src/app/scripts/cac/control/cac-control-sidebar-directions.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ CAC.Control.SidebarDirections = (function (_, $, Control, BikeModeOptions, Geoco
var defaults = {
selectors: {
bikeTriangleDiv: '#directionsBikeTriangle',
buttonPlanTrip: 'section.directions button[type=submit]',
datepicker: '#datetimeDirections',
departAtSelect: '#directionsDepartAt',
destination: 'section.directions input.destination',
Expand All @@ -31,6 +30,7 @@ CAC.Control.SidebarDirections = (function (_, $, Control, BikeModeOptions, Geoco
modeSelectors: '#directionsModes input',
origin: 'section.directions input.origin',
resultsClass: 'show-results',
reverseButton: '#reverse',
spinner: 'section.directions div.sidebar-details > .sk-spinner',
wheelchairDiv: '#directionsWheelchair',

Expand Down Expand Up @@ -66,11 +66,10 @@ CAC.Control.SidebarDirections = (function (_, $, Control, BikeModeOptions, Geoco
urlRouter = options.urlRouter;
bikeModeOptions = new BikeModeOptions();

// Plan a trip using information provided
$(options.selectors.buttonPlanTrip).click($.proxy(planTrip, this));

$(options.selectors.modeSelectors).change($.proxy(changeMode, this));

$(options.selectors.reverseButton).click($.proxy(reverseOriginDestination, this));

// initiallize date/time picker
datepicker = $(options.selectors.datepicker).datetimepicker({useCurrent: true});
datepicker.on('dp.change', planTrip);
Expand Down Expand Up @@ -300,11 +299,38 @@ CAC.Control.SidebarDirections = (function (_, $, Control, BikeModeOptions, Geoco
}
}

function reverseOriginDestination() {
// read what they are now
var origin = UserPreferences.getPreference('origin');
var originText = UserPreferences.getPreference('originText');
var destination = UserPreferences.getPreference('destination');
var destinationText = UserPreferences.getPreference('destinationText');

// update local storage
UserPreferences.setPreference('origin', destination);
UserPreferences.setPreference('originText', destinationText);
UserPreferences.setPreference('destination', origin);
UserPreferences.setPreference('destinationText', originText);

// update the text control
typeaheadOrigin.setValue(destinationText);
typeaheadDest.setValue(originText);

// set on this object and validate
setDirections('origin', [destination.feature.geometry.y, destination.feature.geometry.x]);
setDirections('destination', [origin.feature.geometry.y, origin.feature.geometry.x]);

// update the directions for the reverse trip
planTrip();
}

function onTypeaheadCleared(event, key) {
clearItineraries();
directions[key] = null;
UserPreferences.clearLocation(key);
mapControl.clearDirectionsMarker(key);
// hide reverse origin/destination button
$(options.selectors.reverseButton).css('visibility', 'hidden');
}

function onTypeaheadSelected(event, key, location) {
Expand All @@ -314,6 +340,9 @@ CAC.Control.SidebarDirections = (function (_, $, Control, BikeModeOptions, Geoco
return;
}

// show reverse origin/destination button
$(options.selectors.reverseButton).css('visibility', 'visible');

// save text for address to preferences
UserPreferences.setLocation(key, location);
setDirections(key, [location.feature.geometry.y, location.feature.geometry.x]);
Expand Down

0 comments on commit f3283b3

Please sign in to comment.