From 0ea95c643c0251374de3bae34209947f1fae09b4 Mon Sep 17 00:00:00 2001 From: uw935 Date: Wed, 28 Feb 2024 00:47:39 +0300 Subject: [PATCH] map style changed && viewer change --- README.md | 1 + src/app.py | 5 +- src/static/viewer.css | 5 + src/static/viewer.js | 117 +++++++++-------- src/templates/include/template.html | 17 ++- src/templates/index.html | 2 +- src/templates/viewer.html | 187 ++++++++-------------------- 7 files changed, 132 insertions(+), 202 deletions(-) diff --git a/README.md b/README.md index e8cef61..b6dc046 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ python -m venv venv # downloading requirements && upgrading pip python -m pip install --upgrade pip python -m pip install -r requirements.txt +python -m flask run --host 0.0.0.0 --debug ``` ## Feature diff --git a/src/app.py b/src/app.py index 00d3658..957500c 100644 --- a/src/app.py +++ b/src/app.py @@ -19,7 +19,10 @@ def errorhandler_page(_): @app.route("/api/request") def request_handler(): if request_string := request.args.get("request_string"): - return requests.get(f"{VATSIM_API_URL}{request_string}").json() + try: + return requests.get(f"{VATSIM_API_URL}{request_string}").json() + except requests.exceptions.JSONDecodeError: + return jsonify({"result": "not found"}) return jsonify({"result": "not found"}) diff --git a/src/static/viewer.css b/src/static/viewer.css index c03c1cc..80c7bdb 100644 --- a/src/static/viewer.css +++ b/src/static/viewer.css @@ -6,3 +6,8 @@ .fox_active, .fox_atc_active { background-color: #dee2e6 !important; } + +#fox_map { + width: 100%; + height: 500px; +} diff --git a/src/static/viewer.js b/src/static/viewer.js index 019fda0..eea0357 100644 --- a/src/static/viewer.js +++ b/src/static/viewer.js @@ -1,85 +1,84 @@ -// Fetching user's ATC session informations from API -let userSession = {}; +// // Fetching user's ATC session informations from API +// let userSession = {}; -fetch(ATC_API_URL, {}).then(response => response.json()).then(result => { - if (result && result["result"] == "not found") - return +// fetch(ATC_API_URL, {}).then(response => response.json()).then(result => { +// if (result && result["result"] == "not found") +// return - for (let session of result["items"]) { - // Separate each session by it's connection ID - let session_id = session["connection_id"]["id"]; - userSession[session_id] = session; +// for (let session of result["items"]) { +// // Separate each session by it's connection ID +// let session_id = session["connection_id"]["id"]; +// userSession[session_id] = session; - // Long line. Not in the whole file, but still bad - // Open to any suggestions about fix it - let sessionElement = "
" + session["connection_id"]["callsign"] + "
"; - $("#fox_atc").append(sessionElement); - } +// // Long line. Not in the whole file, but still bad +// // Open to any suggestions about fix it +// let sessionElement = "
" + session["connection_id"]["callsign"] + "
"; +// $("#fox_atc").append(sessionElement); +// } - // Click event handler to left menu button - $(".fox_atc").click(function() { - if ($(this).hasClass("fox_atc_active")) return; +// // Click event handler to left menu button +// $(".fox_atc").click(function() { +// if ($(this).hasClass("fox_atc_active")) return; - $(".fox_atc_active").removeClass("fox_atc_active"); - $(this).addClass("fox_atc_active"); +// $(".fox_atc_active").removeClass("fox_atc_active"); +// $(this).addClass("fox_atc_active"); - showSession(userSession[$(this).attr("id")]); - }); +// showSession(userSession[$(this).attr("id")]); +// }); - showSession(result["items"][0]); -}); +// showSession(result["items"][0]); +// }); -// Fetching user's flightplans from VATSIM API -let userFlightplans = {}; +// // Fetching user's flightplans from VATSIM API +// let userFlightplans = {}; -fetch(FLIGHTPLANS_API_URL, {}).then(response => response.json()).then(result => { - if (result && result["result"] == "not found") - return +// fetch(FLIGHTPLANS_API_URL, {}).then(response => response.json()).then(result => { +// if (result && result["result"] == "not found") +// return - for (let flightplan of result) { - // Separate each flight by it's connection ID - // Like it was with ATC session's - let flightplan_id = flightplan["id"] - userFlightplans[flightplan_id] = flightplan; - userFlightplans[flightplan_id]["not_filed"] = flightplan["connection_id"] === 0 +// for (let flightplan of result) { +// // Separate each flight by it's connection ID +// // Like it was with ATC session's +// let flightplan_id = flightplan["id"] +// userFlightplans[flightplan_id] = flightplan; +// userFlightplans[flightplan_id]["not_filed"] = flightplan["connection_id"] === 0 - // Long line again - let flightplanElement = "
" + flightplan["callsign"] + "
"; - $("#fox_flightplans").append(flightplanElement); - } +// // Long line again +// let flightplanElement = "
" + flightplan["callsign"] + "
"; +// $("#fox_flightplans").append(flightplanElement); +// } - $(".fox_button").click(function() { - if ($(this).hasClass("fox_active")) return; +// $(".fox_button").click(function() { +// if ($(this).hasClass("fox_active")) return; - $(".fox_active").removeClass("fox_active"); - $(this).addClass("fox_active"); +// $(".fox_active").removeClass("fox_active"); +// $(this).addClass("fox_active"); - showFlight(userFlightplans[$(this).attr("id")]); - }); +// showFlight(userFlightplans[$(this).attr("id")]); +// }); - showFlight(result[0]); -}); +// showFlight(result[0]); +// }); -// Fetching airports information -// Get it from localhost -// Becase I think it would be much faster than getting it from VATSIM API -let airports = {}; +// // Fetching airports information +// // Get it from localhost +// // Becase I think it would be much faster than getting it from VATSIM API +// let airports = {}; -$.getJSON("/static/data/airports.json", function(json) { - airports = json; - } -); +// $.getJSON("/static/data/airports.json", function(json) { +// airports = json; +// } +// ); // Map creation const MAP_ELEMENT = L.map("fox_map"); -const MAP_DEFAULT_TARGET = L.latLng("47.50737", "19.04611"); -const MAP_DEFAULT_ZOOM_VIEW = 14; +const MAP_DEFAULT_TARGET = L.latLng("0", "0"); +const MAP_DEFAULT_ZOOM_VIEW = 2; let line = null; - MAP_ELEMENT.setView(MAP_DEFAULT_TARGET, MAP_DEFAULT_ZOOM_VIEW); -L.tileLayer("http://{s}.tile.osm.org/{z}/{x}/{y}.png", { - attribution: '© OpenStreetMap contributors', +L.tileLayer("https://cartodb-basemaps-{s}.global.ssl.fastly.net/light_all/{z}/{x}/{y}.png", { + attribution: '© OpenStreetMap contributors | VATSIM Fox by uw935 (1606255)', subdomains: "abcd", maxZoom: 20, minZoom: 2 diff --git a/src/templates/include/template.html b/src/templates/include/template.html index ed73ee1..711e2db 100644 --- a/src/templates/include/template.html +++ b/src/templates/include/template.html @@ -10,19 +10,30 @@ - {% block title %}{% endblock %} - {% block header_css %}{% endblock %} + {% block above_content %}{% endblock %}
diff --git a/src/templates/index.html b/src/templates/index.html index e01fe89..7bb3f7c 100644 --- a/src/templates/index.html +++ b/src/templates/index.html @@ -7,7 +7,7 @@

See your detailed profile statistic

diff --git a/src/templates/viewer.html b/src/templates/viewer.html index afdbd9e..a8ae227 100644 --- a/src/templates/viewer.html +++ b/src/templates/viewer.html @@ -1,143 +1,54 @@ -{% extends "/include/template.html" %} -{% block title %}User {{user_cid}} statistic — VATSIM Fox{% endblock %} -{% block header_css %} - - -{% endblock %} -{% block content %} -
-

{{data[0]["id"]}}

-

Date of registration:

-
+ + + + + + + + + + + + + + User {{data[0]["id"]}} statistic — VATSIM Fox + + + + + + +
+ +
+
- -
-

Last 100 ATC shifts

-
-
-
-

UUEE_DEL

- - Start time: - - -
- - End time: - - -
- - Aircraft tracked: - - -
- - Aircraft seen: - - -
- - Squawk assigned: - - -
- - Aircraft's transferred: - - -
- - Aircraft's received: - - -
-
-
-{% endblock %} -{% block javascript_code %} - - - -{% endblock %} + + + + +