add station info api

This commit is contained in:
DJ2LS 2024-05-01 12:16:52 +02:00
parent 41c8430c93
commit 140d47c80c
7 changed files with 115 additions and 3 deletions

View file

@ -2,7 +2,7 @@
"name": "FreeDATA",
"description": "FreeDATA Client application for connecting to FreeDATA server",
"private": true,
"version": "0.15.5-alpha",
"version": "0.15.6-alpha",
"main": "dist-electron/main/index.js",
"scripts": {
"start": "vite",

View file

@ -6,6 +6,8 @@ import chat_conversations from "./chat_conversations.vue";
import chat_messages from "./chat_messages.vue";
import chat_new_message from "./chat_new_message.vue";
import {getStationInfo} from "./../js/api";
import { setActivePinia } from "pinia";
import pinia from "../store/index";
setActivePinia(pinia);
@ -115,9 +117,62 @@ watch(
});
},
);
const stationInfo = ref({});
async function getStationInfoByCallsign(){
stationInfo.value = await getStationInfo(chat.selectedCallsign);
}
</script>
<template>
<!-- Station Info Modal -->
<div
class="modal fade"
ref="modalEle"
id="stationInfoModal"
tabindex="-1"
aria-hidden="true"
>
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="p-0 m-0">{{ stationInfo.callsign }}</h4>
<button
type="button"
class="btn-close"
data-bs-dismiss="modal"
aria-label="Close"
></button>
</div>
<div class="modal-body">
<p><strong>Location:</strong> {{ stationInfo.location.gridsquare }}</p>
<p><strong>Details:</strong> {{ stationInfo.details }}</p>
</div>
<div class="modal-footer">
<button
type="button"
class="btn btn-secondary"
data-bs-dismiss="modal"
>
Close
</button>
</div>
</div>
</div>
</div>
<div class="container-fluid d-flex p-0">
<!-- Chat Conversations -->
<div class="bg-light p-0" style="width: 250px">
@ -133,7 +188,17 @@ watch(
<div class="d-flex flex-column">
<!-- Top Navbar -->
<nav class="navbar sticky-top z-0 bg-body-tertiary border-bottom p-1">
<h4 class="p-0 m-0">{{ chat.selectedCallsign }}</h4>
<button
class="btn btn-sm btn-outline-secondary ms-2 border-0"
data-bs-target="#stationInfoModal"
data-bs-toggle="modal"
@click="getStationInfoByCallsign()"
>
<h4 class="p-0 m-0">{{ chat.selectedCallsign }}</h4>
</button>
<div class="input-group mb-0 p-0 w-25">
<button type="button" class="btn btn-outline-secondary" disabled>

View file

@ -211,6 +211,7 @@ const transmissionSpeedChartDataMessageInfo = computed(() => ({
</div>
</div>
<!-- Message Info Modal -->
<div
class="modal fade"

View file

@ -200,3 +200,7 @@ export async function deleteFreedataMessage(id) {
export async function getBeaconDataByCallsign(callsign) {
return await apiGet(`/freedata/beacons/${callsign}`);
}
export async function getStationInfo(callsign) {
return await apiGet(`/freedata/station/${callsign}`);
}

View file

@ -34,6 +34,7 @@ export async function processFreedataMessages(data) {
chatStore.callsign_list = createCallsignListFromAPI(data);
chatStore.sorted_chat_list = createSortedMessagesList(data);
console.log(chatStore.sorted_chat_list)
// also update the selectedCallsign - if its undefined, then we select the first available callsign
if (typeof chatStore.selectedCallsign == "undefined"){
chatStore.selectedCallsign = Object.keys(chatStore.sorted_chat_list)[0]

View file

@ -0,0 +1,34 @@
from sqlalchemy.orm import Session
from sqlalchemy.exc import SQLAlchemyError
from message_system_db_model import Station
from message_system_db_manager import DatabaseManager
import os
class DatabaseManagerStations(DatabaseManager):
def __init__(self, db_file=None):
if not db_file:
script_dir = os.path.dirname(os.path.abspath(__file__))
db_path = os.path.join(script_dir, 'freedata-messages.db')
db_file = 'sqlite:///' + db_path
super().__init__(db_file)
def get_station(self, callsign):
"""
Retrieves a station by its callsign.
"""
session = self.get_thread_scoped_session()
try:
station = session.query(Station).filter_by(callsign=callsign).first()
return station.to_dict() if station else None
except Exception as e:
self.log(f"error fetching database station with error: {e}", isWarning=True)
self.log(f"---> please delete or update existing database", isWarning=True)
return []
finally:
session.remove()

View file

@ -31,12 +31,13 @@ from message_system_db_manager import DatabaseManager
from message_system_db_messages import DatabaseManagerMessages
from message_system_db_attachments import DatabaseManagerAttachments
from message_system_db_beacon import DatabaseManagerBeacon
from message_system_db_station import DatabaseManagerStations
from schedule_manager import ScheduleManager
app = Flask(__name__)
CORS(app, resources={r"/*": {"origins": "*"}})
sock = Sock(app)
MODEM_VERSION = "0.15.5-alpha"
MODEM_VERSION = "0.15.6-alpha"
# set config file to use
def set_config():
@ -316,6 +317,12 @@ def get_beacons_by_callsign(callsign):
beacons = DatabaseManagerBeacon(app.event_manager).get_beacons_by_callsign(callsign)
return api_response(beacons)
@app.route('/freedata/station/<string:callsign>', methods=['GET'])
def get_station_info_by_callsign(callsign):
station = DatabaseManagerStations(app.event_manager).get_station(callsign)
print(station)
return api_response(station)
# Event websocket
@sock.route('/events')
def sock_events(sock):