Show basic repo information
This commit is contained in:
parent
bd31338b9e
commit
feb1953064
|
@ -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
|
||||
|
|
19
borgweb/borg/static/css/index.css
Normal file
19
borgweb/borg/static/css/index.css
Normal file
|
@ -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;
|
||||
}
|
7
borgweb/borg/static/js/index.js
Normal file
7
borgweb/borg/static/js/index.js
Normal file
|
@ -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);
|
|
@ -2,24 +2,29 @@
|
|||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
{% if repo_list %}
|
||||
<title>Borg Summary</title>
|
||||
{% load static %}
|
||||
<link rel="stylesheet" type="text/css" href="{% static 'css/index.css' %}">
|
||||
{{ hour_list|json_script:"hour_list" }}
|
||||
<script src="{% static 'js/index.js' %}"></script>
|
||||
</head>
|
||||
<body>
|
||||
<p id="hours"></p>
|
||||
{% if repo_list %}
|
||||
{% for repo in repo_list %}
|
||||
<div>
|
||||
<header>{{ repo.label }} ({{ repo.location }}) </header>
|
||||
<ul>
|
||||
<li>Latest backup: {{ repo.last_backup }}</li>
|
||||
<li>Un/Compressed size: {{ repo.size }}</li>
|
||||
<li>{{ repo.recent_errors }}</li>
|
||||
<div class="repo_info">
|
||||
<header class="repo_label">{{ repo.label }} ({{ repo.location }}) </header>
|
||||
<ul class="repo_details">
|
||||
<li class="repo_point"><span class="point_label">Latest backup:</span> {{ repo.last_backup }}</li>
|
||||
<li class="repo_point"><span class="point_label">Hourly backups:</span> {{ repo.get_archive_hours }}</li>
|
||||
<li class="repo_point"><span class="point_label">Size:</span> {{ repo.size }}</li>
|
||||
<li class="repo_point"><span class="point_label">{{ repo.recent_errors }}</span></li>
|
||||
</ul>
|
||||
</div>
|
||||
{% endfor %}
|
||||
<canvas id="daily_backup_graphic" width="200" height="100"></canvas>
|
||||
{% else %}
|
||||
<p>No repos found.</p>
|
||||
{% endif %}
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -1,18 +1,14 @@
|
|||
from django.shortcuts import render
|
||||
from django.http import HttpResponse
|
||||
from django.template import loader
|
||||
from django.shortcuts import render
|
||||
|
||||
from .models import Repo, Label
|
||||
from .models import Repo
|
||||
|
||||
|
||||
def index(request):
|
||||
repo_list = Repo.objects.all()
|
||||
label_list = Label.objects.all()
|
||||
# template = loader.get_template('borg/index.html')
|
||||
|
||||
hour_list = [repo.get_archive_hours_dict() for repo in repo_list]
|
||||
context = {
|
||||
'repo_list': repo_list,
|
||||
'label_list': label_list,
|
||||
'hour_list': hour_list
|
||||
}
|
||||
# return HttpResponse(template.render(context, request))
|
||||
return render(request, 'borg/index.html', context)
|
||||
|
|
Loading…
Reference in New Issue
Block a user