add some basic framework for the featurereport
This commit is contained in:
parent
f5f23e6fbc
commit
e61c0dcc12
6
htdocs/features.html
Normal file
6
htdocs/features.html
Normal file
@ -0,0 +1,6 @@
|
||||
<HTML><HEAD>
|
||||
<TITLE>OpenWebRX Feature report</TITLE>
|
||||
<script src="static/jquery-3.2.1.min.js"></script>
|
||||
<script src="static/features.js"></script>
|
||||
</HEAD><BODY>
|
||||
</BODY></HTML>
|
5
htdocs/features.js
Normal file
5
htdocs/features.js
Normal file
@ -0,0 +1,5 @@
|
||||
$(function(){
|
||||
$.ajax('/api/features').done(function(data){
|
||||
$('body').html(JSON.stringify(data));
|
||||
});
|
||||
});
|
@ -1,11 +1,13 @@
|
||||
import os
|
||||
import mimetypes
|
||||
import json
|
||||
from datetime import datetime
|
||||
from owrx.websocket import WebSocketConnection
|
||||
from owrx.config import PropertyManager
|
||||
from owrx.source import ClientRegistry
|
||||
from owrx.connection import WebSocketMessageHandler
|
||||
from owrx.version import openwebrx_version
|
||||
from owrx.feature import FeatureDetector
|
||||
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -26,12 +28,7 @@ class Controller(object):
|
||||
if (type(content) == str):
|
||||
content = content.encode()
|
||||
self.handler.wfile.write(content)
|
||||
def render_template(self, template, **variables):
|
||||
f = open('htdocs/' + template)
|
||||
data = f.read()
|
||||
f.close()
|
||||
|
||||
self.send_response(data)
|
||||
|
||||
class StatusController(Controller):
|
||||
def handle_request(self):
|
||||
@ -77,12 +74,21 @@ class AssetsController(Controller):
|
||||
|
||||
class IndexController(AssetsController):
|
||||
def handle_request(self):
|
||||
self.serve_file("index.html", content_type = "text/html")
|
||||
self.serve_file("index.html")
|
||||
|
||||
class MapController(AssetsController):
|
||||
def handle_request(self):
|
||||
#TODO check if we have a google maps api key first?
|
||||
self.serve_file("map.html", content_type = "text/html")
|
||||
self.serve_file("map.html")
|
||||
|
||||
class FeatureController(AssetsController):
|
||||
def handle_request(self):
|
||||
self.serve_file("features.html")
|
||||
|
||||
class ApiController(Controller):
|
||||
def handle_request(self):
|
||||
data = json.dumps(FeatureDetector().feature_report())
|
||||
self.send_response(data, content_type = "application/json")
|
||||
|
||||
class WebSocketController(Controller):
|
||||
def handle_request(self):
|
||||
|
@ -26,6 +26,11 @@ class FeatureDetector(object):
|
||||
def feature_availability(self):
|
||||
return {name: self.is_available(name) for name in FeatureDetector.features}
|
||||
|
||||
def feature_report(self):
|
||||
def feature_details(name):
|
||||
return self.get_requirements(name)
|
||||
return {name: feature_details(name) for name in FeatureDetector.features}
|
||||
|
||||
def is_available(self, feature):
|
||||
return self.has_requirements(self.get_requirements(feature))
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
from owrx.controllers import StatusController, IndexController, AssetsController, WebSocketController, MapController
|
||||
from owrx.controllers import StatusController, IndexController, AssetsController, WebSocketController, MapController, FeatureController, ApiController
|
||||
from http.server import BaseHTTPRequestHandler
|
||||
import re
|
||||
|
||||
@ -21,7 +21,9 @@ class Router(object):
|
||||
{"regex": "(/favicon.ico)", "controller": AssetsController},
|
||||
# backwards compatibility for the sdr.hu portal
|
||||
{"regex": "/(gfx/openwebrx-avatar.png)", "controller": AssetsController},
|
||||
{"route": "/map", "controller": MapController}
|
||||
{"route": "/map", "controller": MapController},
|
||||
{"route": "/features", "controller": FeatureController},
|
||||
{"route": "/api/features", "controller": ApiController}
|
||||
]
|
||||
def find_controller(self, path):
|
||||
for m in Router.mappings:
|
||||
|
Loading…
Reference in New Issue
Block a user