Browse Source

fix: afficher le libellé YunoHost + app_id au lieu de l'ID en double

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Cedric Hansen 2 tuần trước cách đây
mục cha
commit
f940e79697

+ 10 - 2
sources/blueprints/jobs.py

@@ -30,8 +30,9 @@ def index():
         for j in jobs
     }
     instances = RemoteInstance.query.order_by(RemoteInstance.name).all()
+    ynh_app_labels = {a["id"]: a.get("label", "") for a in get_ynh_apps()}
     return render_template("dashboard_local.html", jobs=jobs, last_runs=last_runs,
-                           instances=instances)
+                           instances=instances, ynh_app_labels=ynh_app_labels)
 
 
 # --- CRUD Jobs ----------------------------------------------------------------
@@ -153,7 +154,8 @@ def job_toggle(job_id):
 def job_history(job_id):
     job = db.get_or_404(Job, job_id)
     runs = Run.query.filter_by(job_id=job_id).order_by(Run.started_at.desc()).limit(100).all()
-    return render_template("job_history.html", job=job, runs=runs)
+    ynh_app_labels = {a["id"]: a.get("label", "") for a in get_ynh_apps()} if job.type == "ynh_app" else {}
+    return render_template("job_history.html", job=job, runs=runs, ynh_app_labels=ynh_app_labels)
 
 
 # --- Navigateur d'archives ----------------------------------------------------
@@ -176,15 +178,20 @@ def archives():
             runs_by_archive[run.archive_name] = run
     jobs_by_id = {j.id: j for j in Job.query.all()}
 
+    ynh_app_labels = {a["id"]: a.get("label", "") for a in get_ynh_apps()}
+
     items = []
     for name in sorted_names:
         size_bytes = file_stats[name]["size_bytes"] or None
         run = runs_by_archive.get(name)
         job = jobs_by_id.get(run.job_id) if run else None
         app_id = None
+        app_label = None
         if job and job.type == "ynh_app" and job.config_json:
             try:
                 app_id = json.loads(job.config_json).get("app_id")
+                if app_id:
+                    app_label = ynh_app_labels.get(app_id, "")
             except Exception:
                 pass
         items.append({
@@ -193,6 +200,7 @@ def archives():
             "job_name": job.name if job else "—",
             "job_id": job.id if job else None,
             "app_id": app_id,
+            "app_label": app_label,
             "last_status": run.status if run else None,
             "run_at": run.started_at if run else None,
             "size_bytes": size_bytes,

+ 7 - 1
sources/templates/archives.html

@@ -76,7 +76,13 @@
               {{ item.job_name }}
             {% endif %}
             {% if item.app_id %}
-              <br><span class="font-mono text-xs text-gray-400">{{ item.app_id }}</span>
+              <br>
+              {% if item.app_label and item.app_label != item.app_id %}
+                <span class="text-xs text-gray-500">{{ item.app_label }}</span>
+                <span class="font-mono text-xs text-gray-400"> — {{ item.app_id }}</span>
+              {% else %}
+                <span class="font-mono text-xs text-gray-400">{{ item.app_id }}</span>
+              {% endif %}
             {% endif %}
           </td>
           <td class="px-6 py-3 text-xs text-gray-500 whitespace-nowrap">

+ 10 - 2
sources/templates/dashboard_local.html

@@ -89,8 +89,16 @@
                 <span class="font-medium text-gray-900">{{ job.name }}</span>
                 {% if job.type == 'ynh_app' and job.config_json %}
                   {% set _cfg = job.config_json | fromjson %}
-                  {% if _cfg.get('app_id') %}
-                    <br><span class="font-mono text-xs text-gray-400">{{ _cfg.get('app_id') }}</span>
+                  {% set _app_id = _cfg.get('app_id') %}
+                  {% if _app_id %}
+                    {% set _label = ynh_app_labels.get(_app_id, '') %}
+                    <br>
+                    {% if _label and _label != _app_id %}
+                      <span class="text-xs text-gray-500">{{ _label }}</span>
+                      <span class="font-mono text-xs text-gray-400"> — {{ _app_id }}</span>
+                    {% else %}
+                      <span class="font-mono text-xs text-gray-400">{{ _app_id }}</span>
+                    {% endif %}
                   {% endif %}
                 {% endif %}
               </td>

+ 9 - 2
sources/templates/job_history.html

@@ -8,8 +8,15 @@
     <h1 class="text-xl font-bold text-gray-900">{{ job.name }}</h1>
     {% if job.type == 'ynh_app' and job.config_json %}
       {% set _cfg = job.config_json | fromjson %}
-      {% if _cfg.get('app_id') %}
-        <span class="font-mono text-xs text-gray-400">{{ _cfg.get('app_id') }}</span>
+      {% set _app_id = _cfg.get('app_id') %}
+      {% if _app_id %}
+        {% set _label = ynh_app_labels.get(_app_id, '') %}
+        {% if _label and _label != _app_id %}
+          <span class="text-xs text-gray-500">{{ _label }}</span>
+          <span class="font-mono text-xs text-gray-400"> — {{ _app_id }}</span>
+        {% else %}
+          <span class="font-mono text-xs text-gray-400">{{ _app_id }}</span>
+        {% endif %}
       {% endif %}
     {% endif %}
   </div>