updated view and database
This commit is contained in:
+22
-18
@@ -2,7 +2,7 @@
|
||||
Main web routes for dashboard and device management
|
||||
"""
|
||||
from flask import Blueprint, render_template, request, redirect, url_for, flash, jsonify
|
||||
from app.models import Device, LogEntry, MessageTemplate, AnsibleExecution, WMTUpdateRequest, InventoryGroup, device_inventory_association
|
||||
from app.models import Device, LogEntry, MessageTemplate, AnsibleExecution, PlaybookExecution, WMTUpdateRequest, InventoryGroup, device_inventory_association
|
||||
from config.database_config import get_db
|
||||
from app.services.log_service import LogCompressionService
|
||||
from datetime import datetime, timedelta
|
||||
@@ -242,10 +242,12 @@ def stats():
|
||||
|
||||
# Get execution statistics
|
||||
exec_stats = {
|
||||
'total': session.query(AnsibleExecution).count(),
|
||||
'successful': session.query(AnsibleExecution).filter_by(status='completed').count(),
|
||||
'failed': session.query(AnsibleExecution).filter_by(status='failed').count(),
|
||||
'running': session.query(AnsibleExecution).filter_by(status='running').count()
|
||||
'total': session.query(PlaybookExecution).count(),
|
||||
'successful': session.query(PlaybookExecution).filter_by(status='completed').count(),
|
||||
'failed': session.query(PlaybookExecution).filter_by(status='failed').count(),
|
||||
'running': session.query(PlaybookExecution).filter(
|
||||
PlaybookExecution.status.in_(['queued', 'running'])
|
||||
).count()
|
||||
}
|
||||
|
||||
return render_template('stats.html',
|
||||
@@ -541,6 +543,21 @@ def admin():
|
||||
@main_bp.route('/admin/clear/logs', methods=['POST'])
|
||||
def admin_clear_logs():
|
||||
"""Delete all log entries from the database."""
|
||||
return _clear_all_log_entries()
|
||||
|
||||
|
||||
@main_bp.route('/admin/clear/device-logs', methods=['POST'])
|
||||
def admin_clear_device_logs():
|
||||
"""Delete all log entries from the database (devices stay intact).
|
||||
|
||||
Functionally identical to admin_clear_logs – both endpoints are kept because
|
||||
the admin UI exposes two separate buttons, but they share one implementation.
|
||||
"""
|
||||
return _clear_all_log_entries()
|
||||
|
||||
|
||||
def _clear_all_log_entries():
|
||||
"""Shared implementation: delete every LogEntry row."""
|
||||
try:
|
||||
with get_db().get_session() as session:
|
||||
count = session.query(LogEntry).delete()
|
||||
@@ -551,19 +568,6 @@ def admin_clear_logs():
|
||||
return jsonify({'success': False, 'error': str(e)}), 500
|
||||
|
||||
|
||||
@main_bp.route('/admin/clear/device-logs', methods=['POST'])
|
||||
def admin_clear_device_logs():
|
||||
"""Delete all log entries from the database (devices stay intact)."""
|
||||
try:
|
||||
with get_db().get_session() as session:
|
||||
count = session.query(LogEntry).delete()
|
||||
session.commit()
|
||||
return jsonify({'success': True, 'deleted': count})
|
||||
except Exception as e:
|
||||
logging.error(f'Admin clear device logs error: {e}')
|
||||
return jsonify({'success': False, 'error': str(e)}), 500
|
||||
|
||||
|
||||
@main_bp.route('/admin/delete/device/<int:device_id>', methods=['POST'])
|
||||
def admin_delete_device(device_id):
|
||||
"""Delete a single registered device and its log entries."""
|
||||
|
||||
+2
-21
@@ -216,27 +216,8 @@ def reject_request(req_id):
|
||||
|
||||
@wmt_web_bp.route('/devices')
|
||||
def devices():
|
||||
"""List all WMT-registered devices."""
|
||||
try:
|
||||
with get_db().get_session() as session:
|
||||
device_list = (
|
||||
session.query(Device)
|
||||
.filter(Device.mac_address.isnot(None))
|
||||
.order_by(Device.nume_masa)
|
||||
.all()
|
||||
)
|
||||
return render_template(
|
||||
'wmt/devices.html',
|
||||
devices=device_list,
|
||||
breadcrumbs=[
|
||||
{'url': url_for('wmt_web.index'), 'title': 'WMT Management'},
|
||||
{'url': url_for('wmt_web.devices'), 'title': 'Devices'},
|
||||
],
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(f'WMT devices list error: {e}')
|
||||
flash(f'Error: {e}', 'error')
|
||||
return redirect(url_for('wmt_web.index'))
|
||||
"""Retired: WMT devices are now shown on the unified Devices page."""
|
||||
return redirect(url_for('main.devices'))
|
||||
|
||||
|
||||
@wmt_web_bp.route('/devices/new', methods=['GET', 'POST'])
|
||||
|
||||
Reference in New Issue
Block a user