mirror of
https://github.com/MarekWo/mc-webui.git
synced 2026-05-18 07:15:49 +02:00
fix(phase3): fix database/device access in search, backup, stats, map endpoints
- Search, backup, stats endpoints used current_app.config.get('DEVICE_MANAGER')
which doesn't exist — replaced with _get_dm()/_get_db() helpers
- /api/device/info used old v1 CLI — replaced with DeviceManager.get_device_info()
returning structured dict instead of string (fixes map own device marker)
- Moved search button from navbar to FAB menu (between filter and DM buttons)
- Bump SW cache to v7
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
+15
-23
@@ -1034,31 +1034,25 @@ def cleanup_contacts():
|
||||
@api_bp.route('/device/info', methods=['GET'])
|
||||
def get_device_info():
|
||||
"""
|
||||
Get detailed device information.
|
||||
|
||||
Returns:
|
||||
JSON with device info
|
||||
Get detailed device information from DeviceManager.
|
||||
"""
|
||||
try:
|
||||
success, info = cli.get_device_info()
|
||||
dm = _get_dm()
|
||||
if not dm or not dm.is_connected:
|
||||
return jsonify({'success': False, 'error': 'Device not connected'}), 503
|
||||
|
||||
if success:
|
||||
info = dm.get_device_info()
|
||||
if info:
|
||||
return jsonify({
|
||||
'success': True,
|
||||
'info': info
|
||||
'info': info,
|
||||
}), 200
|
||||
else:
|
||||
return jsonify({
|
||||
'success': False,
|
||||
'error': info
|
||||
}), 500
|
||||
return jsonify({'success': False, 'error': 'No device info available'}), 503
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error getting device info: {e}")
|
||||
return jsonify({
|
||||
'success': False,
|
||||
'error': str(e)
|
||||
}), 500
|
||||
return jsonify({'success': False, 'error': str(e)}), 500
|
||||
|
||||
|
||||
@api_bp.route('/device/stats', methods=['GET'])
|
||||
@@ -1067,13 +1061,14 @@ def get_device_stats():
|
||||
Get device statistics (uptime, radio, packets).
|
||||
"""
|
||||
try:
|
||||
dm = current_app.config.get('DEVICE_MANAGER')
|
||||
dm = _get_dm()
|
||||
if not dm or not dm.is_connected:
|
||||
return jsonify({'success': False, 'error': 'Device not connected'}), 503
|
||||
|
||||
stats = dm.get_device_stats()
|
||||
bat = dm.get_battery()
|
||||
db_stats = dm.db.get_stats() if dm.db else {}
|
||||
db = _get_db()
|
||||
db_stats = db.get_stats() if db else {}
|
||||
|
||||
return jsonify({
|
||||
'success': True,
|
||||
@@ -1789,8 +1784,7 @@ def search_messages():
|
||||
limit = min(limit, 200)
|
||||
|
||||
try:
|
||||
dm = current_app.config.get('DEVICE_MANAGER')
|
||||
db = dm.db if dm else None
|
||||
db = _get_db()
|
||||
if not db:
|
||||
return jsonify({'success': False, 'error': 'Database not available'}), 503
|
||||
|
||||
@@ -3819,8 +3813,7 @@ def clear_console_history():
|
||||
def list_backups():
|
||||
"""List available database backups."""
|
||||
try:
|
||||
dm = current_app.config.get('DEVICE_MANAGER')
|
||||
db = dm.db if dm else None
|
||||
db = _get_db()
|
||||
if not db:
|
||||
return jsonify({'success': False, 'error': 'Database not available'}), 503
|
||||
|
||||
@@ -3854,8 +3847,7 @@ def list_backups():
|
||||
def create_backup():
|
||||
"""Create an immediate database backup."""
|
||||
try:
|
||||
dm = current_app.config.get('DEVICE_MANAGER')
|
||||
db = dm.db if dm else None
|
||||
db = _get_db()
|
||||
if not db:
|
||||
return jsonify({'success': False, 'error': 'Database not available'}), 503
|
||||
|
||||
|
||||
@@ -1240,6 +1240,12 @@ main {
|
||||
color: white;
|
||||
}
|
||||
|
||||
/* Search FAB button (orange gradient) */
|
||||
.fab-search {
|
||||
background: linear-gradient(135deg, #fd7e14 0%, #e8590c 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
/* Filter bar overlay - slides down from top of chat area */
|
||||
.filter-bar {
|
||||
position: absolute;
|
||||
|
||||
@@ -267,12 +267,9 @@ async function showAllContactsOnMap() {
|
||||
const deviceData = await deviceResp.json();
|
||||
const cachedData = await cachedResp.json();
|
||||
|
||||
// Parse self info for own device marker
|
||||
// Use self info for own device marker
|
||||
if (deviceInfoData.success && deviceInfoData.info) {
|
||||
try {
|
||||
const jsonMatch = deviceInfoData.info.match(/\{[\s\S]*\}/);
|
||||
_selfInfo = jsonMatch ? JSON.parse(jsonMatch[0]) : null;
|
||||
} catch (e) { _selfInfo = null; }
|
||||
_selfInfo = deviceInfoData.info;
|
||||
}
|
||||
|
||||
if (deviceData.success && deviceData.contacts) {
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
const CACHE_NAME = 'mc-webui-v6';
|
||||
const CACHE_NAME = 'mc-webui-v7';
|
||||
const ASSETS_TO_CACHE = [
|
||||
'/',
|
||||
'/static/css/style.css',
|
||||
|
||||
@@ -38,9 +38,6 @@
|
||||
{% endif %}
|
||||
</span>
|
||||
<div class="d-flex align-items-center gap-2">
|
||||
<button id="globalSearchBtn" class="btn btn-outline-light btn-sm" data-bs-toggle="modal" data-bs-target="#searchModal" title="Search all messages">
|
||||
<i class="bi bi-search"></i>
|
||||
</button>
|
||||
<div id="notificationBell" class="btn btn-outline-light btn-sm position-relative" style="cursor: pointer;" onclick="markAllChannelsRead()" title="Mark all as read">
|
||||
<i class="bi bi-bell"></i>
|
||||
</div>
|
||||
|
||||
@@ -169,6 +169,9 @@
|
||||
<button class="fab fab-filter" id="filterFab" title="Filter Messages">
|
||||
<i class="bi bi-funnel-fill"></i>
|
||||
</button>
|
||||
<button class="fab fab-search" id="globalSearchBtn" data-bs-toggle="modal" data-bs-target="#searchModal" title="Search Messages">
|
||||
<i class="bi bi-search"></i>
|
||||
</button>
|
||||
<button class="fab fab-dm" data-bs-toggle="modal" data-bs-target="#dmModal" title="Direct Messages">
|
||||
<i class="bi bi-envelope-fill"></i>
|
||||
</button>
|
||||
|
||||
Reference in New Issue
Block a user