Colour repo div based on archives/errors
This commit is contained in:
parent
cf099292fe
commit
820e0b391f
|
@ -11,6 +11,16 @@ class Repo(models.Model):
|
|||
last_modified = models.DateTimeField()
|
||||
label = models.OneToOneField(Label, on_delete=models.CASCADE, unique=True)
|
||||
|
||||
def archive_after_latest_error(self):
|
||||
latest_archive = self.latest_archive()
|
||||
latest_error = self.latest_error()
|
||||
if latest_archive is None:
|
||||
return False
|
||||
elif latest_error is None:
|
||||
return True
|
||||
else:
|
||||
return latest_archive.start > latest_error.time
|
||||
|
||||
def last_backup(self):
|
||||
if self.archive_set.all().exists():
|
||||
latest = self.latest_archive().start.replace(tzinfo=None)
|
||||
|
@ -20,7 +30,18 @@ class Repo(models.Model):
|
|||
return "No archives stored"
|
||||
|
||||
def latest_archive(self):
|
||||
return self.archive_set.order_by('-start')[0]
|
||||
archives = self.archive_set.order_by('-start')
|
||||
if len(archives) > 0:
|
||||
return archives[0]
|
||||
else:
|
||||
return None
|
||||
|
||||
def latest_error(self):
|
||||
errors = self.label.errors.all().order_by('-time')
|
||||
if len(errors) > 0:
|
||||
return errors[0]
|
||||
else:
|
||||
return None
|
||||
|
||||
def size(self):
|
||||
if self.archive_set.all().exists():
|
||||
|
@ -35,9 +56,6 @@ class Repo(models.Model):
|
|||
errors = self.label.errors.all().filter(time__gt=days_ago)
|
||||
return errors
|
||||
|
||||
def archive_dates(self):
|
||||
days = self.get_archive_days()
|
||||
|
||||
def get_archive_days(self):
|
||||
current_day = datetime.utcnow().day
|
||||
days = []
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
div {
|
||||
padding: 8px;
|
||||
margin: 8px;
|
||||
background: lightskyblue;
|
||||
}
|
||||
|
||||
dl {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
window.addEventListener("DOMContentLoaded", function () {
|
||||
|
||||
window.addEventListener("DOMContentLoaded", function() {
|
||||
const hour_json = JSON.parse(document.getElementById('hour_list').textContent);
|
||||
hour_json.forEach(function(repo) {
|
||||
hour_json.forEach(function (repo) {
|
||||
console.log(repo.hours);
|
||||
})
|
||||
}, false);
|
||||
}, false);
|
|
@ -4,20 +4,26 @@
|
|||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<title>Borg Summary</title>
|
||||
|
||||
{% load static %}
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-Piv4xVNRyMGpqkS2by6br4gNJ7DXjqk09RmUpJ8jgGtD7zP9yug3goQfGII0yAns" crossorigin="anonymous"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||
|
||||
<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 class="col-md-4 rounded float-xl-left">
|
||||
{% if repo.archive_after_latest_error %}
|
||||
<div class="col-md-4 rounded float-xl-left bg-success">
|
||||
{% else %}
|
||||
<div class="col-md-4 rounded float-xl-left bg-danger">
|
||||
{% endif %}
|
||||
<h3 class="repo_label">{{ repo.label }}<small class="text-muted"> {{ repo.location }}</small></h3>
|
||||
<dl class="row">
|
||||
<dt class="col-sm-3">Latest backup:</dt>
|
||||
|
@ -44,9 +50,11 @@
|
|||
</dl>
|
||||
</div>
|
||||
{% endfor %}
|
||||
<canvas id="daily_backup_graphic" width="200" height="100"></canvas>
|
||||
{% else %}
|
||||
<p>No repos found.</p>
|
||||
{% endif %}
|
||||
<div class="col-md-4 rounded float-xl-left">
|
||||
<canvas id="myChart"></canvas>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user