fakemobileclient.js

This commit is contained in:
Laura Klünder 2017-12-21 00:34:09 +01:00
parent 8aa94e5c2f
commit 9066318b10
5 changed files with 39 additions and 2 deletions

View file

@ -44,6 +44,7 @@
{% endblock %} {% endblock %}
</div> </div>
{% include 'site/fragment_fakemobileclient.html' %}
{% compress js %} {% compress js %}
<script type="text/javascript" src="{% static 'jquery/jquery.js' %}"></script> <script type="text/javascript" src="{% static 'jquery/jquery.js' %}"></script>
<script type="text/javascript" src="{% static 'bootstrap/js/bootstrap.js' %}"></script> <script type="text/javascript" src="{% static 'bootstrap/js/bootstrap.js' %}"></script>

View file

@ -0,0 +1,25 @@
mobileclient = {
nearbyStations: [],
setNearbyStations: function(data) {
this.nearbyStations = data;
nearby_stations_available();
},
getNearbyStations: function() {
return JSON.stringify(this.nearbyStations);
},
port: 8042,
scanNow: function() {
console.log('mobileclient: scanNow');
$.getJSON('http://localhost:'+String(mobileclient.port)+'/scan', function(data) {
mobileclient.setNearbyStations(data.data);
}).fail(function() {
mobileclient.scanNow();
});
},
shareUrl: function(url) {
console.log('mobileclient: sharing url: '+url);
},
createShortcut: function(url, title) {
console.log('mobileclient: shortcut url: '+url+' title: '+title);
}
};

View file

@ -0,0 +1,10 @@
{% load static %}
{% if request.GET.fakemobileclient != None %}
<script type="text/javascript" src="{% static 'site/js/fakemobileclient.js' %}"></script>
{% if request.GET.fakemobileclient and request.GET.fakemobileclient.isdigit %}
<script type="text/javascript">
mobileclient.port = {{ request.GET.fakemobileclient }};
</script>
{% endif %}
{% endif %}

View file

@ -142,6 +142,7 @@
<div id="modal-content"></div> <div id="modal-content"></div>
</div> </div>
{% endif %} {% endif %}
{% include 'site/fragment_fakemobileclient.html' %}
{% compress js %} {% compress js %}
<script type="text/javascript" src="{% static 'jquery/jquery.js' %}"></script> <script type="text/javascript" src="{% static 'jquery/jquery.js' %}"></script>
<script type="text/javascript" src="{% static 'leaflet/leaflet.js' %}"></script> <script type="text/javascript" src="{% static 'leaflet/leaflet.js' %}"></script>

View file

@ -15,8 +15,8 @@ def get_from_lines(lines, keyword):
class FakeMobileClientHandler(http.server.BaseHTTPRequestHandler): class FakeMobileClientHandler(http.server.BaseHTTPRequestHandler):
def do_GET(self): def do_GET(self):
"""Serve a GET request.""" """Serve a GET request."""
if self.path != '/scan/': if self.path != '/scan':
self.send_error(404, explain='Look at /scan/') self.send_error(404, explain='Look at /scan')
return return
while True: while True: