|
@@ -7,6 +7,7 @@ from concurrent.futures import ThreadPoolExecutor
|
|
|
from flask import Blueprint, current_app, flash, redirect, render_template, request, url_for
|
|
from flask import Blueprint, current_app, flash, redirect, render_template, request, url_for
|
|
|
|
|
|
|
|
from db import db, Job, Destination, RemoteInstance, _size_human
|
|
from db import db, Job, Destination, RemoteInstance, _size_human
|
|
|
|
|
+from helpers import get_ynh_apps
|
|
|
|
|
|
|
|
bp = Blueprint("overview", __name__)
|
|
bp = Blueprint("overview", __name__)
|
|
|
|
|
|
|
@@ -29,20 +30,22 @@ def _retention_label(job):
|
|
|
return "—"
|
|
return "—"
|
|
|
|
|
|
|
|
|
|
|
|
|
-def _job_detail(job):
|
|
|
|
|
|
|
+def _job_detail(job, ynh_app_labels=None):
|
|
|
"""Détail affiché à côté du nom du job pour distinguer des jobs homonymes
|
|
"""Détail affiché à côté du nom du job pour distinguer des jobs homonymes
|
|
|
(ex: instances multiples d'une même app YunoHost, toutes nommées pareil)."""
|
|
(ex: instances multiples d'une même app YunoHost, toutes nommées pareil)."""
|
|
|
if job.type not in ("ynh_app", "custom_dir", "mysql", "postgresql"):
|
|
if job.type not in ("ynh_app", "custom_dir", "mysql", "postgresql"):
|
|
|
return ""
|
|
return ""
|
|
|
cfg = json.loads(job.config_json or "{}")
|
|
cfg = json.loads(job.config_json or "{}")
|
|
|
if job.type == "ynh_app":
|
|
if job.type == "ynh_app":
|
|
|
- return cfg.get("app_id", "")
|
|
|
|
|
|
|
+ app_id = cfg.get("app_id", "")
|
|
|
|
|
+ label = (ynh_app_labels or {}).get(app_id)
|
|
|
|
|
+ return f"{label} ({app_id})" if label and label != app_id else app_id
|
|
|
if job.type == "custom_dir":
|
|
if job.type == "custom_dir":
|
|
|
return cfg.get("source_path", "")
|
|
return cfg.get("source_path", "")
|
|
|
return cfg.get("database", "")
|
|
return cfg.get("database", "")
|
|
|
|
|
|
|
|
|
|
|
|
|
-def _group_archives(archive_list, jobs, instance):
|
|
|
|
|
|
|
+def _group_archives(archive_list, jobs, instance, ynh_app_labels=None):
|
|
|
"""
|
|
"""
|
|
|
archive_list : [{"name": "jerry_nextcloud_20260716", "size_bytes": N}]
|
|
archive_list : [{"name": "jerry_nextcloud_20260716", "size_bytes": N}]
|
|
|
Retourne (groups, orphaned) où chaque group est associé à un job.
|
|
Retourne (groups, orphaned) où chaque group est associé à un job.
|
|
@@ -63,7 +66,7 @@ def _group_archives(archive_list, jobs, instance):
|
|
|
groups.append({
|
|
groups.append({
|
|
|
"job": job,
|
|
"job": job,
|
|
|
"retention_label": _retention_label(job),
|
|
"retention_label": _retention_label(job),
|
|
|
- "detail": _job_detail(job),
|
|
|
|
|
|
|
+ "detail": _job_detail(job, ynh_app_labels),
|
|
|
"archives": matching,
|
|
"archives": matching,
|
|
|
})
|
|
})
|
|
|
|
|
|
|
@@ -142,6 +145,7 @@ def overview():
|
|
|
data_dir = current_app.config["DATA_DIR"]
|
|
data_dir = current_app.config["DATA_DIR"]
|
|
|
instance = current_app.config["INSTANCE_NAME"]
|
|
instance = current_app.config["INSTANCE_NAME"]
|
|
|
jobs = Job.query.order_by(Job.name).all()
|
|
jobs = Job.query.order_by(Job.name).all()
|
|
|
|
|
+ ynh_app_labels = {a["id"]: a.get("label") or a.get("name", "") for a in get_ynh_apps()}
|
|
|
|
|
|
|
|
# Construire la liste des tâches de collecte dans l'ordre d'affichage souhaité
|
|
# Construire la liste des tâches de collecte dans l'ordre d'affichage souhaité
|
|
|
dests = Destination.query.filter_by(enabled=True).order_by(Destination.name).all()
|
|
dests = Destination.query.filter_by(enabled=True).order_by(Destination.name).all()
|
|
@@ -180,7 +184,7 @@ def overview():
|
|
|
if error:
|
|
if error:
|
|
|
locations.append({**meta, "error": error, "groups": [], "orphaned": []})
|
|
locations.append({**meta, "error": error, "groups": [], "orphaned": []})
|
|
|
else:
|
|
else:
|
|
|
- groups, orphaned = _group_archives(archives, jobs, instance)
|
|
|
|
|
|
|
+ groups, orphaned = _group_archives(archives, jobs, instance, ynh_app_labels)
|
|
|
locations.append({**meta, "error": None, "groups": groups, "orphaned": orphaned})
|
|
locations.append({**meta, "error": None, "groups": groups, "orphaned": orphaned})
|
|
|
|
|
|
|
|
# --- Vue par job : pivot de locations → jobs ---
|
|
# --- Vue par job : pivot de locations → jobs ---
|
|
@@ -205,7 +209,7 @@ def overview():
|
|
|
jobs_view.append({
|
|
jobs_view.append({
|
|
|
"job": job,
|
|
"job": job,
|
|
|
"retention_label": _retention_label(job),
|
|
"retention_label": _retention_label(job),
|
|
|
- "detail": _job_detail(job),
|
|
|
|
|
|
|
+ "detail": _job_detail(job, ynh_app_labels),
|
|
|
"locations": jlocs,
|
|
"locations": jlocs,
|
|
|
})
|
|
})
|
|
|
|
|
|