Merge branch 'autorefresh' into 'main'

 — Add autorefresh feature on dashboard

See merge request framasoft/framaspace/argos!21
This commit is contained in:
Luc Didry 2023-12-14 15:41:17 +00:00
commit 20062fc683
4 changed files with 75 additions and 12 deletions

View file

@ -18,7 +18,12 @@ templates = Jinja2Templates(directory="argos/server/templates")
@route.get("/")
async def get_severity_counts(request: Request, db: Session = Depends(get_db)):
async def get_severity_counts(
request: Request,
db: Session = Depends(get_db),
refresh: bool = False,
delay: int = 15
):
"""Shows the number of results per severity"""
counts_dict = await queries.get_severity_counts(db)
@ -30,6 +35,8 @@ async def get_severity_counts(request: Request, db: Session = Depends(get_db)):
"request": request,
"counts_dict": counts_dict,
"agents": agents,
"refresh": refresh,
"delay": delay,
},
)

View file

@ -15,3 +15,13 @@ code {
margin-top: 0;
margin-bottom: 1rem;
}
.inline-label {
display: inline-block;
}
.initial-width {
width: initial !important;
}
#refresh-form {
margin-bottom: 0;
}

View file

@ -5,7 +5,12 @@
<title>Argos</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<link href="{{ url_for('static', path='/styles.css') }}" rel="stylesheet">
{% if refresh %}
<meta http-equiv="refresh"
content="{{ delay }}">
{% endif %}
<link href="{{ url_for('static', path='/styles.css') }}"
rel="stylesheet">
</head>
<body>
<main class="container">

View file

@ -1,27 +1,68 @@
{% extends "base.html" %}
{% block title %}<h2>Dashboard</h2>{% endblock %}
{% block content %}
<div id="domains" class="frame">
<p>
<a href="/agents">{{ agents | length }} agent{% if agents| length > 1 %}s{% endif %}</a>
</p>
<nav>
<ul>
<li>
<a href="{{ url_for('get_agents_view') }}">
{{ agents | length }} agent{{ 's' if agents | length > 1 }}
</a>
</li>
</ul>
<ul>
<li>
<input id="auto-refresh"
type="checkbox"
form="refresh-form"
{{ 'checked' if refresh }}>
<label for="auto-refresh" class="inline-label">Auto-refresh</label>
</li>
<li>
<label class="inline-label">
Every <input id="refresh-delay"
class="initial-width"
type="number"
form="refresh-form"
min="1"
value="{{ delay }}"> seconds
</label>
</li>
<li>
<form id="refresh-form"
method="get"
action="{{ url_for('get_severity_counts_view') }}">
<input type="Submit">
</form>
</li>
</ul>
</nav>
<div class="container">
<div class="grid grid-index">
<article>
<header>✅ OK </header>
{{ counts_dict['ok'] }}
<header title="Unknown"></header>
<span id="sev-unknown">{{ counts_dict['unknown'] }}</span>
</article>
<article>
<header>⚠️ Warning</header>
{{ counts_dict['warning'] }}
<header title="OK"></header>
<span id="sev-ok">{{ counts_dict['ok'] }}</span>
</article>
<article>
<header>❌ Critical</header>
{{ counts_dict['critical'] }}
<header title="Warning">⚠️</header>
<span id="sev-warning">{{ counts_dict['warning'] }}</span>
</article>
<article>
<header title="Critical"></header>
<span id="sev-critical">{{ counts_dict['critical'] }}</span>
</article>
</div>
<p class="text-center">
<a href="/details" role="button">Details</a>
<a href="{{ url_for('get_domains_view') }}"
class="outline"
role="button">
Domains
</a>
</p>
</div>
</div>