[hamradio-commits] [dump1090] 01/01: backport web-ui auto-configuration from Debian packaging

Matthew Ernisse mernisse-guest at moszumanska.debian.org
Thu Oct 23 17:31:14 UTC 2014


This is an automated email from the git hooks/post-receive script.

mernisse-guest pushed a commit to branch backport
in repository dump1090.

commit 788297cffe9ec55f2500de57a99ae690c1c199de
Author: Matthew Ernisse <mernisse at ub3rgeek.net>
Date:   Thu Oct 23 13:30:26 2014 -0400

    backport web-ui auto-configuration from Debian packaging
---
 net_io.c              | 12 +++++++++++
 public_html/script.js | 60 ++++++++++++++++++++++++++++++---------------------
 2 files changed, 47 insertions(+), 25 deletions(-)

diff --git a/net_io.c b/net_io.c
index 83ce20b..ef6e60f 100644
--- a/net_io.c
+++ b/net_io.c
@@ -745,9 +745,21 @@ int handleHTTPRequest(struct client *c, char *p) {
     // Select the content to send, we have just two so far:
     // "/" -> Our google map application.
     // "/data.json" -> Our ajax request to update planes.
+    // "/config.json" -> Our ajax request to configure the webui.
     if (strstr(url, "/data.json")) {
         content = aircraftsToJson(&clen);
         //snprintf(ctype, sizeof ctype, MODES_CONTENT_TYPE_JSON);
+    } else if (strstr(url, "/config.json")) {
+        if (Modes.fUserLat != 0.0 && Modes.fUserLon != 0.0) {
+            char buf[128];
+            clen = snprinft(buf, sizeof(buf),
+                "{\"SiteLat\": %f, \"SiteLon\": %f}",
+                Modes.fUserLat, Modes.fUserLon);
+            content = strdup(buf);
+        } else {
+            content = strdup("{}");
+            clen = strlen(content);
+        }
     } else {
         struct stat sbuf;
         int fd = -1;
diff --git a/public_html/script.js b/public_html/script.js
index ed2a4dc..728f000 100644
--- a/public_html/script.js
+++ b/public_html/script.js
@@ -53,6 +53,36 @@ function fetchData() {
 	});
 }
 
+function fetchJSONConfig() {
+	// Load config from json if able.
+	$.getJSON('/dump1090/config.json', function(data) {
+		if (!("SiteLat" in data) || !("SiteLon" in data)) {
+			return;
+		}
+		SiteShow = true;
+		SiteLat = data["SiteLat"];
+		SiteLon = data["SiteLon"];
+		var markerImage = new google.maps.MarkerImage(
+			'http://maps.google.com/mapfiles/kml/pal4/icon57.png',
+			new google.maps.Size(32, 32),
+			new google.maps.Point(0, 0),
+			new google.maps.Point(16, 16));
+		var marker = new google.maps.Marker({
+			position: new google.maps.LatLng(SiteLat, SiteLon),
+			map: GoogleMap,
+			icon: markerImage,
+			title: 'My Radar Site',
+			zIndex: -99999
+		});
+
+		if (SiteCircles) {
+			for (var i=0;i<SiteCirclesDistances.length;i++) {
+				drawCircle(marker, SiteCirclesDistances[i]);
+			}
+		}
+	});
+}
+
 // Initalizes the map and starts up our timers to call various functions
 function initialize() {
 	// Make a list of all the available map IDs
@@ -167,34 +197,14 @@ function initialize() {
     google.maps.event.addListener(GoogleMap, 'zoom_changed', function() {
         localStorage['ZoomLvl']  = GoogleMap.getZoom();
     }); 
-	
-	// Add home marker if requested
-	if (SiteShow && (typeof SiteLat !==  'undefined' || typeof SiteLon !==  'undefined')) {
-	    var siteMarker  = new google.maps.LatLng(SiteLat, SiteLon);
-	    var markerImage = new google.maps.MarkerImage(
-	        'http://maps.google.com/mapfiles/kml/pal4/icon57.png',
-            new google.maps.Size(32, 32),   // Image size
-            new google.maps.Point(0, 0),    // Origin point of image
-            new google.maps.Point(16, 16)); // Position where marker should point 
-	    var marker = new google.maps.Marker({
-          position: siteMarker,
-          map: GoogleMap,
-          icon: markerImage,
-          title: 'My Radar Site',
-          zIndex: -99999
-        });
-        
-        if (SiteCircles) {
-            for (var i=0;i<SiteCirclesDistances.length;i++) {
-              drawCircle(marker, SiteCirclesDistances[i]); // in meters
-            }
-        }
-	}
+
 	
 	// These will run after page is complitely loaded
 	$(window).load(function() {
-        $('#dialog-modal').css('display', 'inline'); // Show hidden settings-windows content
-    });
+		$('#dialog-modal').css('display', 'inline'); // Show hidden settings-windows content
+	});
+
+	fetchJSONConfig();
 
 	// Load up our options page
 	optionsInitalize();

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-hamradio/dump1090.git



More information about the pkg-hamradio-commits mailing list