diff --git a/hc/api/models.py b/hc/api/models.py index 62cdbde7..31b9ff89 100644 --- a/hc/api/models.py +++ b/hc/api/models.py @@ -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") diff --git a/hc/front/forms.py b/hc/front/forms.py new file mode 100644 index 00000000..077bf035 --- /dev/null +++ b/hc/front/forms.py @@ -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) diff --git a/hc/front/urls.py b/hc/front/urls.py index 80e6fb13..cd3269f5 100644 --- a/hc/front/urls.py +++ b/hc/front/urls.py @@ -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"), ] diff --git a/hc/front/views.py b/hc/front/views.py index 5503cfdf..0d7c8a8e 100644 --- a/hc/front/views.py +++ b/hc/front/views.py @@ -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") diff --git a/static/css/style.css b/static/css/style.css index 32633c83..16a9911e 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -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; +} diff --git a/static/js/checks.js b/static/js/checks.js index 1c8f4d71..a22a7c24 100644 --- a/static/js/checks.js +++ b/static/js/checks.js @@ -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; + }); + }); \ No newline at end of file diff --git a/templates/front/index.html b/templates/front/index.html index 365d203e..cc7a8b91 100644 --- a/templates/front/index.html +++ b/templates/front/index.html @@ -51,7 +51,41 @@ {{ check.code }} - {{ check.timeout }} + +
+
+
+
+ {% csrf_token %} + + + +
+
+
+ + {% for label, value in timeout_choices %} + {% if check.timeout == value %} + {{ label }} + {% endif %} + {% endfor %} + + {% if check.last_ping %} + {% endblock %} \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index 354a0e3f..fbbab476 100644 --- a/templates/index.html +++ b/templates/index.html @@ -13,10 +13,11 @@
@