Files
FabledSteward/steward/templates/dashboard/_widget_drawer.html
T
bvandeusenandClaude Opus 5.5 5ca13f9278
CI / lint (push) Successful in 3s
CI / integration (push) Successful in 1m14s
CI / unit (push) Successful in 1m29s
CI / publish (push) Successful in 1m12s
feat(prometheus): the Prometheus dashboard widget, target + template (#5691)
#5691 "Generic Prometheus dashboard widget: pick a target and a template",
step 3 of milestone 508 "Prometheus widget templates".

- /plugins/prometheus/widget draws one target with one template in widget
  shape: the verdict (led by "isn't answering" when the target is down),
  then each block with problems first, figures beside a share bar or the
  last 24h of bars, and the healthy rest folding to "+N more healthy" past
  six. A missing target or template, or one that no longer checks, says so.
- library.py: bundled templates from plugins/prometheus/widgets/*.yaml,
  the picker's target and template lists, and the default title.
- widgets/fabled_archives.yaml: the first bundled template, against the
  series Archives reports (refined in #5693).
- Dashboard: a widget setting may take `options_from` (read when the picker
  opens) with an `empty` sentence; `default_title`; a Details link may name
  settings ("/plugins/prometheus/targets/{target}"). Prometheus is grouped
  with the integrations.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-14 07:05:15 -04:00

83 lines
4.7 KiB
HTML

{# Bottom drawer — the widget picker, revealed by body.dash-editing. Fixed-position
overlay so it never changes the dashboard's width. Add forms are submitted via
JS (see index.html) which inserts the returned grid item in place. #}
<div class="widget-drawer" id="widget-drawer" aria-label="Add a widget">
<div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:0.75rem;
position:sticky;top:0;background:var(--bg-card);padding-bottom:0.5rem;">
<div class="section-title" style="margin-bottom:0;">Add a widget</div>
<span style="display:flex;gap:0.5rem;align-items:center;">
<form method="post" action="/d/{{ dashboard.id }}/edit/reset" style="margin:0;"
data-confirm="Replace every widget on this dashboard with the recommended layout? Widgets you added or renamed are removed.">{{ csrf_field() }}
<button type="submit" class="btn btn-ghost btn-sm"
title="Overview first, then hosts and monitors, then each integration">Reset to the recommended layout</button>
</form>
<button type="button" class="btn btn-sm" id="dash-edit-done">Done</button>
</span>
</div>
{% if addable %}
{% set _groups = [("core", "Core monitors"), ("capability", "Monitoring capabilities"), ("integration", "Integrations")] %}
{% for _gkey, _glabel in _groups %}
{% set _gw = addable | selectattr("group", "equalto", _gkey) | list %}
{% if _gw %}
<div style="font-size:0.72rem;text-transform:uppercase;letter-spacing:0.04em;color:var(--text-dim);margin:0.6rem 0 0.35rem;">{{ _glabel }}</div>
<div style="display:grid;grid-template-columns:repeat(auto-fill,minmax(250px,1fr));gap:0.5rem;">
{% for w in _gw %}
<div class="card" style="margin-bottom:0;padding:0;overflow:hidden;">
<details>
<summary style="display:flex;align-items:center;justify-content:space-between;gap:0.6rem;
padding:0.7rem 0.85rem;cursor:pointer;list-style:none;user-select:none;">
<div style="flex:1;min-width:0;">
<div style="font-weight:500;font-size:0.85rem;">{{ w.label }}</div>
<div style="font-size:0.74rem;color:var(--text-muted);margin-top:0.1rem;">{{ w.description }}</div>
</div>
<span class="btn btn-sm" style="flex-shrink:0;pointer-events:none;">Add ▾</span>
</summary>
<form action="/d/{{ dashboard.id }}/edit/add/{{ w.key }}" method="post"
class="add-widget-form"
style="padding:0.75rem 0.85rem;padding-top:0;border-top:1px solid var(--border);">{{ csrf_field() }}
<div style="display:grid;gap:0.5rem;padding-top:0.75rem;">
<div>
<label style="font-size:0.74rem;color:var(--text-muted);display:block;margin-bottom:0.2rem;">
Widget title <span style="color:var(--text-dim);">(optional)</span>
</label>
<input type="text" name="title" placeholder="{{ w.label }}" class="input">
</div>
{% for p in w.params %}
<div>
<label style="font-size:0.74rem;color:var(--text-muted);display:block;margin-bottom:0.2rem;">{{ p.label }}</label>
{% if p.type == "select" and p.options_from and not p.options %}
{# A list read when the picker opens (a plugin's targets, its templates) that is empty. #}
<p class="field-hint" style="margin:0;">{{ p.empty or "Nothing to choose from yet." }}</p>
{% elif p.type == "select" %}
<select name="param_{{ p.key }}" class="input"{% if p.options_from %} required{% endif %}>
{% if p.options_from and p.options|length > 1 %}<option value="">— choose —</option>{% endif %}
{% for opt in p.options %}
<option value="{{ opt.value }}" {% if opt.value == p.default %}selected{% endif %}>{{ opt.label }}</option>
{% endfor %}
</select>
{% elif p.type == "host" %}
<select name="param_{{ p.key }}" required class="input">
<option value="">— select a host —</option>
{% for h in hosts %}
<option value="{{ h.id }}">{{ h.name }}</option>
{% endfor %}
</select>
{% endif %}
</div>
{% endfor %}
<button type="submit" class="btn btn-sm" style="width:100%;margin-top:0.1rem;">Add to dashboard</button>
</div>
</form>
</details>
</div>
{% endfor %}
</div>
{% endif %}
{% endfor %}
{% else %}
<div style="color:var(--text-muted);font-size:0.85rem;padding:0.5rem 0;">
No plugin widgets available. Enable plugins in Settings → Plugins.
</div>
{% endif %}
</div>