add initil location api and javascript calls to it
This commit is contained in:
parent
8e90aa7e3c
commit
6805f2fb5f
3 changed files with 46 additions and 2 deletions
|
@ -16,6 +16,7 @@ class RoutingViewSet(ViewSet):
|
||||||
"""
|
"""
|
||||||
/route/ Get routes.
|
/route/ Get routes.
|
||||||
/options/ Get or set route options.
|
/options/ Get or set route options.
|
||||||
|
/locate/ Wifi locate.
|
||||||
"""
|
"""
|
||||||
@list_route(methods=['get', 'post'])
|
@list_route(methods=['get', 'post'])
|
||||||
def route(self, request, *args, **kwargs):
|
def route(self, request, *args, **kwargs):
|
||||||
|
@ -76,3 +77,8 @@ class RoutingViewSet(ViewSet):
|
||||||
options.save()
|
options.save()
|
||||||
|
|
||||||
return Response(options.serialize())
|
return Response(options.serialize())
|
||||||
|
|
||||||
|
@list_route(methods=('POST', ))
|
||||||
|
def locate(self, request, *args, **kwargs):
|
||||||
|
# todo: implement wifi location
|
||||||
|
return Response({'location': None})
|
||||||
|
|
|
@ -127,6 +127,10 @@ c3nav = {
|
||||||
|
|
||||||
window.setInterval(c3nav.load_searchable_locations, 42000);
|
window.setInterval(c3nav.load_searchable_locations, 42000);
|
||||||
|
|
||||||
|
if (window.mobileclient) {
|
||||||
|
window.setInterval(function() { mobileclient.scanNow(); }, 2000);
|
||||||
|
}
|
||||||
|
|
||||||
c3nav.init_completed = true;
|
c3nav.init_completed = true;
|
||||||
},
|
},
|
||||||
get_csrf_token: function() {
|
get_csrf_token: function() {
|
||||||
|
@ -1217,10 +1221,41 @@ c3nav = {
|
||||||
var $user = $('header #user');
|
var $user = $('header #user');
|
||||||
$user.find('span').text(data.title);
|
$user.find('span').text(data.title);
|
||||||
$user.find('small').text(data.subtitle || '');
|
$user.find('small').text(data.subtitle || '');
|
||||||
|
},
|
||||||
|
|
||||||
|
_last_wifi_scant: 0,
|
||||||
|
_wifi_scan_results: function(data) {
|
||||||
|
if (!JSON.parse(data).length) {
|
||||||
|
c3nav._set_user_location(null);
|
||||||
|
}
|
||||||
|
var now = Date.now();
|
||||||
|
if (now-2000 < c3nav._last_wifi_scan) return;
|
||||||
|
|
||||||
|
$.post({
|
||||||
|
url: '/api/routing/locate/',
|
||||||
|
data: data,
|
||||||
|
dataType: 'json',
|
||||||
|
contentType: 'application/json',
|
||||||
|
beforeSend: function(xhrObj){
|
||||||
|
xhrObj.setRequestHeader('X-CSRFToken', c3nav.get_csrf_token());
|
||||||
|
},
|
||||||
|
success: function(data) {
|
||||||
|
c3nav._set_user_location(data.location);
|
||||||
|
}
|
||||||
|
}).fail(function() {
|
||||||
|
c3nav._set_user_location(null);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
_set_user_location: function(location) {
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
$(document).ready(c3nav.init);
|
$(document).ready(c3nav.init);
|
||||||
|
|
||||||
|
function nearby_stations_available() {
|
||||||
|
c3nav._wifi_scan_results(mobileclient.getNearbyStations());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
LevelControl = L.Control.extend({
|
LevelControl = L.Control.extend({
|
||||||
options: {
|
options: {
|
||||||
|
|
|
@ -8,12 +8,15 @@ mobileclient = {
|
||||||
return JSON.stringify(this.nearbyStations);
|
return JSON.stringify(this.nearbyStations);
|
||||||
},
|
},
|
||||||
port: 8042,
|
port: 8042,
|
||||||
|
wait: false,
|
||||||
scanNow: function() {
|
scanNow: function() {
|
||||||
console.log('mobileclient: scanNow');
|
console.log('mobileclient: scanNow');
|
||||||
|
if (mobileclient.wait) return;
|
||||||
|
mobileclient.wait = true;
|
||||||
$.getJSON('http://localhost:'+String(mobileclient.port)+'/scan', function(data) {
|
$.getJSON('http://localhost:'+String(mobileclient.port)+'/scan', function(data) {
|
||||||
mobileclient.setNearbyStations(data.data);
|
mobileclient.setNearbyStations(data.data);
|
||||||
}).fail(function() {
|
}).always(function() {
|
||||||
mobileclient.scanNow();
|
mobileclient.wait = false;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
shareUrl: function(url) {
|
shareUrl: function(url) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue