Browse Source

Can edit timeouts

pull/7/head
Pēteris Caune 10 years ago
parent
commit
31119fd11f
8 changed files with 108 additions and 18 deletions
  1. +2
    -15
      hc/api/models.py
  2. +20
    -0
      hc/front/forms.py
  3. +1
    -0
      hc/front/urls.py
  4. +16
    -1
      hc/front/views.py
  5. +18
    -0
      static/css/style.css
  6. +13
    -0
      static/js/checks.js
  7. +36
    -1
      templates/front/index.html
  8. +2
    -1
      templates/index.html

+ 2
- 15
hc/api/models.py View File

@ -5,20 +5,7 @@ from django.contrib.auth.models import User
from django.db import models
STATUSES = (("up", "Up"), ("down", "Down"), ("new", "New"))
ONEDAY = td(days=1)
DURATIONS = (
(td(minutes=5), "5 minutes"),
(td(minutes=10), "10 minutes"),
(td(minutes=30), "30 minutes"),
(td(hours=1), "1 hour"),
(td(hours=2), "2 hours"),
(td(hours=6), "6 hours"),
(td(hours=12), "12 hours"),
(ONEDAY, "1 day"),
(td(days=2), "2 days"),
(td(weeks=1), "1 week"),
(td(weeks=2), "2 weeks")
)
DEFAULT_TIMEOUT = td(days=1)
class Check(models.Model):
@ -26,7 +13,7 @@ class Check(models.Model):
code = models.UUIDField(default=uuid.uuid4, editable=False)
user = models.ForeignKey(User)
created = models.DateTimeField(auto_now_add=True)
timeout = models.DurationField(default=ONEDAY)
timeout = models.DurationField(default=DEFAULT_TIMEOUT)
last_ping = models.DateTimeField(null=True, blank=True)
alert_after = models.DateTimeField(null=True, blank=True, editable=False)
status = models.CharField(max_length=6, choices=STATUSES, default="new")

+ 20
- 0
hc/front/forms.py View File

@ -0,0 +1,20 @@
from datetime import timedelta as td
from django import forms
TIMEOUT_CHOICES = (
("15 minutes", td(minutes=15)),
("30 minutes", td(minutes=30)),
("1 hour", td(hours=1)),
("3 hours", td(hours=3)),
("6 hours", td(hours=6)),
("12 hours", td(hours=12)),
("1 day", td(days=1)),
("2 days", td(days=2)),
("3 days", td(days=3)),
("1 week", td(weeks=1))
)
class TimeoutForm(forms.Form):
timeout = forms.ChoiceField(choices=TIMEOUT_CHOICES)

+ 1
- 0
hc/front/urls.py View File

@ -7,4 +7,5 @@ urlpatterns = [
url(r'^checks/$', views.checks, name="hc-checks"),
url(r'^checks/add/$', views.add_check, name="hc-add-check"),
url(r'^checks/([\w-]+)/name/$', views.update_name, name="hc-update-name"),
url(r'^checks/([\w-]+)/timeout/$', views.update_timeout, name="hc-update-timeout"),
]

+ 16
- 1
hc/front/views.py View File

@ -3,6 +3,7 @@ from django.shortcuts import redirect, render
from django.utils import timezone
from hc.api.models import Check
from hc.front.forms import TimeoutForm, TIMEOUT_CHOICES
def index(request):
@ -16,7 +17,8 @@ def checks(request):
ctx = {
"checks": checks,
"now": timezone.now
"now": timezone.now,
"timeout_choices": TIMEOUT_CHOICES
}
return render(request, "front/index.html", ctx)
@ -40,3 +42,16 @@ def update_name(request, code):
check.save()
return redirect("hc-checks")
@login_required
def update_timeout(request, code):
assert request.method == "POST"
form = TimeoutForm(request.POST)
if form.is_valid():
check = Check.objects.get(code=code)
check.timeout = form.cleaned_data["timeout"]
check.save()
return redirect("hc-checks")

+ 18
- 0
static/css/style.css View File

@ -63,3 +63,21 @@ table.table tr.checks-row > td {
opacity: 1;
}
td.inactive .popover {
visibility: hidden;
}
.popover.timeout-dialog.bottom {
display: block;
position: absolute;
top: auto;
left: auto;
margin-top: 32px;
margin-left: -77px;
}
.timeout:hover {
color: #337ab7;
text-decoration: underline;
cursor: pointer;
}

+ 13
- 0
static/js/checks.js View File

@ -26,5 +26,18 @@ $(function () {
return false;
});
$(".timeout").click(function() {
$(".timeout-cell").addClass("inactive");
$cell = $(this.parentNode);
$cell.removeClass("inactive");
});
$(".timeout-edit-cancel").click(function() {
console.log("aaa");
$(this).parents("td").addClass("inactive");
return false;
});
});

+ 36
- 1
templates/front/index.html View File

@ -51,7 +51,41 @@
<code>{{ check.code }}</code>
</small>
</td>
<td>{{ check.timeout }}</td>
<td class="timeout-cell inactive">
<div class="timeout-dialog popover bottom">
<div class="arrow"></div>
<div class="popover-content">
<form
method="post"
action="{% url 'hc-update-timeout' check.code %}"
class="form-inline">
{% csrf_token %}
<select class="form-control" name="timeout">
{% for label, value in timeout_choices %}
{% if check.timeout == value %}
<option selected>{{ label }}</option>
{% else %}
<option>{{ label }}</option>
{% endif %}
{% endfor %}
</select>
<button class="btn btn-primary" type="submit">
<span class="glyphicon glyphicon-ok"></span>
</button>
<button class="btn btn-default timeout-edit-cancel">
<span class="glyphicon glyphicon-remove"></span>
</button>
</form>
</div>
</div>
<span class="timeout">
{% for label, value in timeout_choices %}
{% if check.timeout == value %}
{{ label }}
{% endif %}
{% endfor %}
</span>
</td>
<td>
{% if check.last_ping %}
<span
@ -83,4 +117,5 @@
</div>
{% endblock %}

+ 2
- 1
templates/index.html View File

@ -13,10 +13,11 @@
<div class="input-group input-group-lg">
<div class="input-group-addon">@</div>
<input
type="text"
type="email"
class="form-control"
id="id_email"
name="email"
autocomplete="email"
placeholder="Email">
</div>
</div>


Loading…
Cancel
Save