Filtre domaine + zones (DMZ, EMV, LAN) dans dropdown
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
c7831f5b86
commit
0a309ea4f7
@ -54,9 +54,12 @@ async def audit_full_list(request: Request, db=Depends(get_db)):
|
|||||||
AND id IN (SELECT DISTINCT ON (hostname) id FROM server_audit_full WHERE status = 'ok' ORDER BY hostname, audit_date DESC)
|
AND id IN (SELECT DISTINCT ON (hostname) id FROM server_audit_full WHERE status = 'ok' ORDER BY hostname, audit_date DESC)
|
||||||
""")).fetchone()
|
""")).fetchone()
|
||||||
|
|
||||||
# Domaines pour le filtre
|
# Domaines + zones pour le filtre
|
||||||
all_domains = db.execute(text(
|
all_domains = db.execute(text(
|
||||||
"SELECT code, name FROM domains ORDER BY name"
|
"SELECT code, name, 'domain' as type FROM domains ORDER BY name"
|
||||||
|
)).fetchall()
|
||||||
|
all_zones = db.execute(text(
|
||||||
|
"SELECT name as code, name, 'zone' as type FROM zones ORDER BY name"
|
||||||
)).fetchall()
|
)).fetchall()
|
||||||
|
|
||||||
# Requete avec filtres
|
# Requete avec filtres
|
||||||
@ -84,15 +87,25 @@ async def audit_full_list(request: Request, db=Depends(get_db)):
|
|||||||
elif filtre == "uptime":
|
elif filtre == "uptime":
|
||||||
audits = [a for a in audits if a.uptime and ("month" in a.uptime or "year" in a.uptime)]
|
audits = [a for a in audits if a.uptime and ("month" in a.uptime or "year" in a.uptime)]
|
||||||
|
|
||||||
# Filtre domaine
|
# Filtre domaine ou zone
|
||||||
if domain:
|
if domain:
|
||||||
domain_servers = {r.hostname for r in db.execute(text("""
|
# D'abord chercher comme zone
|
||||||
|
zone_servers = {r.hostname for r in db.execute(text("""
|
||||||
SELECT s.hostname FROM servers s
|
SELECT s.hostname FROM servers s
|
||||||
JOIN domain_environments de ON s.domain_env_id = de.id
|
JOIN zones z ON s.zone_id = z.id
|
||||||
JOIN domains d ON de.domain_id = d.id
|
WHERE z.name = :name
|
||||||
WHERE d.code = :dc
|
"""), {"name": domain}).fetchall()}
|
||||||
"""), {"dc": domain}).fetchall()}
|
if zone_servers:
|
||||||
audits = [a for a in audits if a.hostname in domain_servers]
|
audits = [a for a in audits if a.hostname in zone_servers]
|
||||||
|
else:
|
||||||
|
# Sinon chercher comme domaine
|
||||||
|
domain_servers = {r.hostname for r in db.execute(text("""
|
||||||
|
SELECT s.hostname FROM servers s
|
||||||
|
JOIN domain_environments de ON s.domain_env_id = de.id
|
||||||
|
JOIN domains d ON de.domain_id = d.id
|
||||||
|
WHERE d.code = :dc
|
||||||
|
"""), {"dc": domain}).fetchall()}
|
||||||
|
audits = [a for a in audits if a.hostname in domain_servers]
|
||||||
|
|
||||||
# Recherche hostname
|
# Recherche hostname
|
||||||
if search:
|
if search:
|
||||||
@ -109,7 +122,7 @@ async def audit_full_list(request: Request, db=Depends(get_db)):
|
|||||||
ctx.update({
|
ctx.update({
|
||||||
"app_name": APP_NAME, "audits": audits_page, "kpis": kpis,
|
"app_name": APP_NAME, "audits": audits_page, "kpis": kpis,
|
||||||
"filter": filtre, "search": search, "domain": domain,
|
"filter": filtre, "search": search, "domain": domain,
|
||||||
"all_domains": all_domains,
|
"all_domains": all_domains, "all_zones": all_zones,
|
||||||
"page": page, "total_pages": total_pages, "total_filtered": total_filtered,
|
"page": page, "total_pages": total_pages, "total_filtered": total_filtered,
|
||||||
"msg": request.query_params.get("msg"),
|
"msg": request.query_params.get("msg"),
|
||||||
})
|
})
|
||||||
|
|||||||
@ -58,8 +58,13 @@
|
|||||||
{% if filter %}<input type="hidden" name="filter" value="{{ filter }}">{% endif %}
|
{% if filter %}<input type="hidden" name="filter" value="{{ filter }}">{% endif %}
|
||||||
<input type="text" name="q" value="{{ search }}" placeholder="Rechercher un serveur..." class="text-xs py-1 px-3 flex-1 min-w-[200px] font-mono">
|
<input type="text" name="q" value="{{ search }}" placeholder="Rechercher un serveur..." class="text-xs py-1 px-3 flex-1 min-w-[200px] font-mono">
|
||||||
<select name="domain" class="text-xs py-1 px-2" onchange="this.form.submit()">
|
<select name="domain" class="text-xs py-1 px-2" onchange="this.form.submit()">
|
||||||
<option value="">Tous les domaines</option>
|
<option value="">Tous</option>
|
||||||
|
<optgroup label="Zones">
|
||||||
|
{% for z in all_zones %}<option value="{{ z.code }}" {% if domain == z.code %}selected{% endif %}>{{ z.name }}</option>{% endfor %}
|
||||||
|
</optgroup>
|
||||||
|
<optgroup label="Domaines">
|
||||||
{% for d in all_domains %}<option value="{{ d.code }}" {% if domain == d.code %}selected{% endif %}>{{ d.name }}</option>{% endfor %}
|
{% for d in all_domains %}<option value="{{ d.code }}" {% if domain == d.code %}selected{% endif %}>{{ d.name }}</option>{% endfor %}
|
||||||
|
</optgroup>
|
||||||
</select>
|
</select>
|
||||||
<button type="submit" class="btn-primary px-3 py-1 text-xs">Filtrer</button>
|
<button type="submit" class="btn-primary px-3 py-1 text-xs">Filtrer</button>
|
||||||
{% if search or domain %}<a href="/audit-full{% if filter %}?filter={{ filter }}{% endif %}" class="text-xs text-gray-400 hover:text-cyber-accent">Reset</a>{% endif %}
|
{% if search or domain %}<a href="/audit-full{% if filter %}?filter={{ filter }}{% endif %}" class="text-xs text-gray-400 hover:text-cyber-accent">Reset</a>{% endif %}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user