diff --git a/src/c3nav/settings.py b/src/c3nav/settings.py index 2f8ec8a6..4c07cff3 100644 --- a/src/c3nav/settings.py +++ b/src/c3nav/settings.py @@ -66,6 +66,10 @@ PUBLIC_EDITOR = config.getboolean('c3nav', 'editor', fallback=True) PUBLIC_BASE_MAPDATA = config.getboolean('c3nav', 'public_base_mapdata', fallback=False) AUTO_PROCESS_UPDATES = config.getboolean('c3nav', 'auto_process_updates', fallback=True) +RANDOM_LOCATION_GROUPS = config.get('c3nav', 'random_location_groups', fallback=None) +if RANDOM_LOCATION_GROUPS: + RANDOM_LOCATION_GROUPS = tuple(int(i) for i in RANDOM_LOCATION_GROUPS.split(',')) + if config.has_option('django', 'secret'): SECRET_KEY = config.get('django', 'secret') else: diff --git a/src/c3nav/site/static/site/css/c3nav.scss b/src/c3nav/site/static/site/css/c3nav.scss index 58f451b5..5a0b048e 100644 --- a/src/c3nav/site/static/site/css/c3nav.scss +++ b/src/c3nav/site/static/site/css/c3nav.scss @@ -671,7 +671,18 @@ main.show-options #resultswrapper #route-options { font-size: 35px; top: 5px; } -.locationinput:not(.empty) button.locate, .locationinput.empty button.clear { +main:not([data-random-location-groups]) button.random { + display: none; +} +#search button.random { + right: 45px; + color: lighten($color-icon-light, 18%); + &:hover { + color: lighten($color-icon-light, 8%); + } +} +.locationinput:not(.empty) button.locate, .locationinput.empty button.clear, +main[data-view^=route] button.random, .locationinput:not(.empty) button.random { -webkit-transform: scale(0.7); -ms-transform: scale(0.7); transform: scale(0.7); diff --git a/src/c3nav/site/static/site/js/c3nav.js b/src/c3nav/site/static/site/js/c3nav.js index 497dd561..9728d716 100644 --- a/src/c3nav/site/static/site/js/c3nav.js +++ b/src/c3nav/site/static/site/js/c3nav.js @@ -155,6 +155,8 @@ c3nav = { c3nav.ssids = $main.is('[data-ssids]') ? JSON.parse($main.attr('data-ssids')) : null; + c3nav.random_location_groups = $main.is('[data-random-location-groups]') ? $main.attr('data-random-location-groups').split(',').map(id => parseInt(id)) : null; + history.replaceState(state, window.location.path); c3nav.load_state(state, true); c3nav.update_map_locations(); @@ -864,6 +866,7 @@ c3nav = { .on('keydown', c3nav._locationinput_keydown); $('.locationinput .clear').on('click', c3nav._locationinput_clear); $('.locationinput .locate').on('click', c3nav._locationinput_locate); + $('.locationinput .random').on('click', c3nav._random_location_click); $('.leaflet-control-user-location a').on('click', c3nav._goto_user_location_click).dblclick(function(e) { e.stopPropagation(); }); $('#autocomplete').on('mouseover', '.location', c3nav._locationinput_hover_suggestion) .on('click', '.location', c3nav._locationinput_click_suggestion); @@ -1132,6 +1135,66 @@ c3nav = { } }, + _random_location_click: function() { + var $button = $('button.random'), + parent = $button.parent(), + width = parent.width(), + height = parent.height(); + + $cover = $('
').css({ + 'width': width+'px', + 'height': height+'px', + 'background-color': '#ffffff', + 'position': 'absolute', + 'top': 0, + 'left': $button.position().left+$button.width()/2+'px', + 'z-index': 200, + }).appendTo(parent); + + $cover.animate({ + left: 5+$button.width()/2+'px' + }, 300, 'swing'); + $button.css({ + 'left': $button.position().left, + 'background-color': '#ffffff', + 'right': null, + 'z-index': 201, + 'opacity': 1, + 'transform': 'scale(1)', + 'color': c3nav._primary_color, + 'pointer-events': 'none' + }).animate({ + left: 5, + }, 300, 'swing').queue(function(d) { + d(); + var possible_locations = []; + for (var id of c3nav.random_location_groups) { + var group = c3nav.locations_by_id[id]; + if (!group) continue; + // todo set und so + for (var subid of group.locations) { + if (!(subid in possible_locations) && subid in c3nav.locations_by_id) { + possible_locations.push(subid); + } + } + } + var location = c3nav.locations_by_id[possible_locations[Math.floor(Math.random()*possible_locations.length)]]; + c3nav._locationinput_set($('#destination-input'), location); + c3nav.update_state(false); + c3nav.fly_to_bounds(true); + $cover.animate({ + left: width+$button.width()/2+'px' + }, 300, 'swing'); + $button.animate({ + left: width, + }, 300, 'swing').queue(function(d) { + d(); + $button.attr('style', ''); + $cover.remove(); + }); + }); + }, + modal_noclose: false, open_modal: function (content, no_close) { c3nav.modal_noclose = no_close; diff --git a/src/c3nav/site/templates/site/map.html b/src/c3nav/site/templates/site/map.html index 041d9faa..c6b41c8e 100644 --- a/src/c3nav/site/templates/site/map.html +++ b/src/c3nav/site/templates/site/map.html @@ -4,7 +4,7 @@ {% load i18n %} {% block content %} -
+
{% if not request.mobileclient %}
{% if not embed %} @@ -108,6 +108,7 @@ place +
diff --git a/src/c3nav/site/views.py b/src/c3nav/site/views.py index 5f09b948..a3f9a159 100644 --- a/src/c3nav/site/views.py +++ b/src/c3nav/site/views.py @@ -136,6 +136,9 @@ def map_index(request, mode=None, slug=None, slug2=None, details=None, options=N 'initial_bounds': json.dumps(initial_bounds, separators=(',', ':')) if initial_bounds else None, 'last_site_update': json.dumps(SiteUpdate.last_update()), 'ssids': json.dumps(settings.WIFI_SSIDS, separators=(',', ':')) if settings.WIFI_SSIDS else None, + 'random_location_groups': ( + ','.join(str(i) for i in settings.RANDOM_LOCATION_GROUPS) if settings.RANDOM_LOCATION_GROUPS else None + ), 'editor': can_access_editor(request), 'embed': bool(embed), }