From 0515ff91fc59ed5444166385b272a3e28630e0b9 Mon Sep 17 00:00:00 2001 From: George Lacey Date: Wed, 6 Apr 2022 13:20:40 +0100 Subject: [PATCH] Retrieve repo information via json requests --- borgweb/borg/static/borg/js/index.js | 41 ++++++++++++++++-- borgweb/borg/templates/borg/index.html | 42 +++---------------- .../borg/templates/borg/repo-template.html | 2 +- borgweb/borg/urls.py | 3 +- borgweb/borg/views/__init__.py | 2 +- borgweb/borg/views/json.py | 14 ++++++- borgweb/borg/views/views.py | 7 +--- 7 files changed, 60 insertions(+), 51 deletions(-) diff --git a/borgweb/borg/static/borg/js/index.js b/borgweb/borg/static/borg/js/index.js index b797a69..c2a0c5d 100644 --- a/borgweb/borg/static/borg/js/index.js +++ b/borgweb/borg/static/borg/js/index.js @@ -1,8 +1,41 @@ +function inflateRepo(repo_json, label, template_id, container_id) { + const template_copy = $(template_id).clone(); + $(template_copy).find(".repo-label").html(label); + $(template_copy).find(".repo-location").html(repo_json.location); + $(template_copy).find(".repo-latest-backup").html(repo_json.latest_backup); + $(template_copy).find(".repo-size").html(repo_json.size); + $(template_copy).find(".repo-recent-errors").html(repo_json.recent_errors); + + let bg_class = "bg-primary"; + if (repo_json.error) { + bg_class = "bg-danger"; + } else if (repo_json.warning) { + bg_class = "bg-warning"; + } + $(template_copy).addClass(bg_class); + + $(container_id).append(template_copy); +} + + window.addEventListener("DOMContentLoaded", function () { - $.getJSON( "repo_daily.json", function( json ) { + // todo: inflate each repo and colour background accordingly + const template = $('#repo-template').html(); + const container = $('#repo-container'); + + $.getJSON(`/repo_list.json`, function (repo_list) { + repo_list.labels.forEach(function (repo_label) { + $.getJSON(`/repo/${repo_label}.json`, function (repo_json) { + inflateRepo(repo_json, repo_label, template, container); + }) + }); + }) + + + $.getJSON("repo_daily.json", function (json) { draw_time_graph("daily_backup_size", json.repos, json.dates, json.units); - }); - $.getJSON( "repo_monthly.json", function( json ) { + }); + $.getJSON("repo_monthly.json", function (json) { draw_time_graph("monthly_backup_size", json.repos, json.dates, json.units); - }); + }); }, false); diff --git a/borgweb/borg/templates/borg/index.html b/borgweb/borg/templates/borg/index.html index a91b2b0..634784a 100644 --- a/borgweb/borg/templates/borg/index.html +++ b/borgweb/borg/templates/borg/index.html @@ -26,50 +26,18 @@ {% endblock %} {% block body %} -{% if repo_list %} -
- {% for repo in repo_list %} -
-
-

{{ repo.label }} - {{ repo.location }} -

-
-
-
Latest backup:
-
{{ repo.last_backup }}
-
-
-
Size:
-
{{ repo.size_string }}
-
- {% if repo.recent_errors|length > 0 %} -
-
Recent errors:
-
-
- {% for error in repo.recent_errors %} -
{{ error.time_ago }}
-
{{ error.error }}
- {% endfor %} - {% endif %} -
-
- {% endfor %} +
- {% else %} -
-
-

No repositories found

+{#
#} +{#
#} +{#

No repositories found

#} +{#
#}
-
- {% endif %}
{% endblock %} diff --git a/borgweb/borg/templates/borg/repo-template.html b/borgweb/borg/templates/borg/repo-template.html index cc9217f..b8fb989 100644 --- a/borgweb/borg/templates/borg/repo-template.html +++ b/borgweb/borg/templates/borg/repo-template.html @@ -1,7 +1,7 @@