Development
This commit is contained in:
parent
20befb920c
commit
fa8a5c1b45
2 changed files with 48 additions and 15 deletions
|
|
@ -166,6 +166,40 @@ def get_dashboard_done():
|
||||||
return items
|
return items
|
||||||
|
|
||||||
|
|
||||||
|
def get_done_timestamps():
|
||||||
|
"""Return dict of {uuid: applied_ts} from .dashboard-done."""
|
||||||
|
result = {}
|
||||||
|
try:
|
||||||
|
for line in open(DASHBOARD_DONE).read().splitlines():
|
||||||
|
if not line.strip():
|
||||||
|
continue
|
||||||
|
parts = line.split(None, 1)
|
||||||
|
if len(parts) >= 2:
|
||||||
|
result[parts[0]] = int(parts[1])
|
||||||
|
elif len(parts) == 1:
|
||||||
|
result[parts[0]] = None
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def load_all_snapshots():
|
||||||
|
"""Return all snapshot dicts from .snapshots/, sorted newest first."""
|
||||||
|
snaps = []
|
||||||
|
try:
|
||||||
|
for fname in sorted(os.listdir(SNAPSHOTS_DIR), reverse=True):
|
||||||
|
if not fname.endswith('.json'):
|
||||||
|
continue
|
||||||
|
try:
|
||||||
|
with open(os.path.join(SNAPSHOTS_DIR, fname)) as f:
|
||||||
|
snaps.append(json.load(f))
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
return snaps
|
||||||
|
|
||||||
|
|
||||||
def flush_pending_to_queue():
|
def flush_pending_to_queue():
|
||||||
"""Move all entries from .dashboard-pending to .dashboard-queue and clear pending."""
|
"""Move all entries from .dashboard-pending to .dashboard-queue and clear pending."""
|
||||||
items = _read_dashboard_pending()
|
items = _read_dashboard_pending()
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import json, re, subprocess, os, sys, html as html_mod
|
||||||
import sanitize
|
import sanitize
|
||||||
import validation as validate
|
import validation as validate
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
from config_utils import config_hash, get_pending_entries, get_dashboard_pending, get_dashboard_done, load_snapshot_for_uuid, queue_command, _apply_changes_immediately, _seconds_until_next_run, _format_timing, _is_locked, _lock_mtime, WEB_APP_DISPLAY_NAME, CONFIGS_DIR, DATA_DIR
|
from config_utils import config_hash, get_pending_entries, get_dashboard_pending, get_dashboard_done, load_snapshot_for_uuid, load_all_snapshots, get_done_timestamps, queue_command, _apply_changes_immediately, _seconds_until_next_run, _format_timing, _is_locked, _lock_mtime, WEB_APP_DISPLAY_NAME, CONFIGS_DIR, DATA_DIR
|
||||||
|
|
||||||
bp = Blueprint('view_page', __name__)
|
bp = Blueprint('view_page', __name__)
|
||||||
|
|
||||||
|
|
@ -622,24 +622,23 @@ def collect_tokens():
|
||||||
tokens['PENDING_ACTIONS_HTML'] = pending_html
|
tokens['PENDING_ACTIONS_HTML'] = pending_html
|
||||||
tokens['NO_PENDING'] = 'true' if not pending_items else ''
|
tokens['NO_PENDING'] = 'true' if not pending_items else ''
|
||||||
|
|
||||||
done_items = get_dashboard_done()
|
all_snaps = load_all_snapshots()
|
||||||
if done_items:
|
done_ts_map = get_done_timestamps()
|
||||||
|
if all_snaps:
|
||||||
hist_rows = ''
|
hist_rows = ''
|
||||||
_hist_onclick = (
|
_hist_onclick = (
|
||||||
'onclick="if(event.target.type!==\'checkbox\')'
|
'onclick="if(event.target.type!==\'checkbox\')'
|
||||||
'this.nextElementSibling.hidden=!this.nextElementSibling.hidden"'
|
'this.nextElementSibling.hidden=!this.nextElementSibling.hidden"'
|
||||||
)
|
)
|
||||||
for _uuid, applied_ts in done_items:
|
for snap in all_snaps:
|
||||||
snap = load_snapshot_for_uuid(_uuid)
|
_uuid = snap.get('uuid', '')
|
||||||
if applied_ts:
|
applied_ts = done_ts_map.get(_uuid)
|
||||||
dt_str = datetime.fromtimestamp(applied_ts).strftime('%Y-%m-%d %H:%M')
|
dt_str = datetime.fromtimestamp(applied_ts).strftime('%Y-%m-%d %H:%M') if applied_ts else '-'
|
||||||
else:
|
snap_desc = e(snap.get('description', ''))
|
||||||
dt_str = '-'
|
before_val = snap.get('before')
|
||||||
snap_desc = e(snap['description']) if snap else ''
|
after_val = snap.get('after')
|
||||||
before_val = snap.get('before') if snap else None
|
snap_id = e(_uuid[:8])
|
||||||
after_val = snap.get('after') if snap else None
|
snap_user = e(snap.get('user', ''))
|
||||||
snap_id = e(_uuid[:8]) if snap else ''
|
|
||||||
snap_user = e(snap['user']) if snap else ''
|
|
||||||
hist_rows += (f'<tr class="row-expandable" {_hist_onclick}>'
|
hist_rows += (f'<tr class="row-expandable" {_hist_onclick}>'
|
||||||
f'<td class="table-cell"><input type="checkbox" name="selected_uuids" value="{e(_uuid)}"/></td>'
|
f'<td class="table-cell"><input type="checkbox" name="selected_uuids" value="{e(_uuid)}"/></td>'
|
||||||
f'<td class="table-cell">{e(dt_str)}</td>'
|
f'<td class="table-cell">{e(dt_str)}</td>'
|
||||||
|
|
@ -671,7 +670,7 @@ def collect_tokens():
|
||||||
else:
|
else:
|
||||||
history_html = '<p class="text-muted">No change history.</p>'
|
history_html = '<p class="text-muted">No change history.</p>'
|
||||||
tokens['CHANGE_HISTORY_HTML'] = history_html
|
tokens['CHANGE_HISTORY_HTML'] = history_html
|
||||||
tokens['NO_HISTORY'] = 'true' if not done_items else ''
|
tokens['NO_HISTORY'] = 'true' if not all_snaps else ''
|
||||||
|
|
||||||
servers = dns.get('upstream_servers', [])
|
servers = dns.get('upstream_servers', [])
|
||||||
tokens['DNS_STRICT_ORDER'] = 'true' if dns.get('strict_order') else 'false'
|
tokens['DNS_STRICT_ORDER'] = 'true' if dns.get('strict_order') else 'false'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue