diff --git a/borgweb/borg/models/repo.py b/borgweb/borg/models/repo.py index 493a0d4..265c4a2 100644 --- a/borgweb/borg/models/repo.py +++ b/borgweb/borg/models/repo.py @@ -22,9 +22,7 @@ class Repo(models.Model): def size(self): cache = self.latest_archive().cache - size = bytes_to_string(cache.unique_size) - csize = bytes_to_string(cache.unique_csize) - return f"{size}/{csize}" + return f"{bytes_to_string(cache.unique_csize)}" def recent_errors(self): days = 7 @@ -34,3 +32,35 @@ class Repo(models.Model): return f"1 error since {days} days ago" else: return f"{len(errors)} errors since {days} days ago" + + def archive_dates(self): + days = self.get_archive_days() + + def get_archive_days(self): + current_day = datetime.utcnow().day + days = [] + for day in reversed(range(1, 31)): + try: + cday = datetime.utcnow().replace(day=day) + except ValueError: + continue + if day > current_day: + days.append(False) + else: + cday_archives = self.archives.all().filter(start__date=cday) + days.append(len(cday_archives) > 0) + return days + + def get_archive_hours_dict(self): + return {"id": self.id, + "label": self.label.label, + "hours": self.get_archive_hours()} + + def get_archive_hours(self): + hours = [] + for hour in range(24): + chour = datetime.utcnow() - timedelta(hours=hour) + cday_archives = self.archives.all().filter(start__date=chour.date()).filter(start__hour=chour.hour) + hours.append(len(cday_archives) > 0) + hours = ''.join(['H' if hour is True else '-' for hour in hours]) + return hours diff --git a/borgweb/borg/static/css/index.css b/borgweb/borg/static/css/index.css new file mode 100644 index 0000000..ad74ac5 --- /dev/null +++ b/borgweb/borg/static/css/index.css @@ -0,0 +1,19 @@ +.repo_info { + outline: 2px solid black; + padding: 8px; + float: left; + width: auto; + margin: 16px; +} + +.repo_label { + font-size: x-large; +} + +.repo_point { + list-style-type: none; +} + +.point_label { + font-weight: bold; +} \ No newline at end of file diff --git a/borgweb/borg/static/js/index.js b/borgweb/borg/static/js/index.js new file mode 100644 index 0000000..455756b --- /dev/null +++ b/borgweb/borg/static/js/index.js @@ -0,0 +1,7 @@ + +window.addEventListener("DOMContentLoaded", function() { + const hour_json = JSON.parse(document.getElementById('hour_list').textContent); + hour_json.forEach(function(repo) { + console.log(repo.hours); + }) + }, false); \ No newline at end of file diff --git a/borgweb/borg/templates/borg/index.html b/borgweb/borg/templates/borg/index.html index 5af0145..f2cb589 100644 --- a/borgweb/borg/templates/borg/index.html +++ b/borgweb/borg/templates/borg/index.html @@ -2,24 +2,29 @@ - Title - {% if repo_list %} + Borg Summary + {% load static %} + + {{ hour_list|json_script:"hour_list" }} + + + +

+{% if repo_list %} {% for repo in repo_list %} -
-
{{ repo.label }} ({{ repo.location }})
-