Skip to content

Commit

Permalink
Merge 0c2cec1 into 51977e1
Browse files Browse the repository at this point in the history
  • Loading branch information
mickBoat00 committed Feb 22, 2024
2 parents 51977e1 + 0c2cec1 commit f218c09
Show file tree
Hide file tree
Showing 9 changed files with 215 additions and 83 deletions.
14 changes: 10 additions & 4 deletions hc/front/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,14 +384,20 @@ class SearchForm(forms.Form):

class SeekForm(forms.Form):
# min_value is 2010-01-01, max_value is 2030-01-01
start = forms.IntegerField(min_value=1262296800, max_value=1893448800)
end = forms.IntegerField(min_value=1262296800, max_value=1893448800)
start = forms.IntegerField(
min_value=1262296800, max_value=1893448800, required=False
)
end = forms.IntegerField(min_value=1262296800, max_value=1893448800, required=False)

def clean_start(self) -> datetime:
return datetime.fromtimestamp(self.cleaned_data["start"], tz=timezone.utc)
if self.cleaned_data["start"]:
return datetime.fromtimestamp(self.cleaned_data["start"], tz=timezone.utc)
return None

def clean_end(self) -> datetime:
return datetime.fromtimestamp(self.cleaned_data["end"], tz=timezone.utc)
if self.cleaned_data["end"]:
return datetime.fromtimestamp(self.cleaned_data["end"], tz=timezone.utc)
return None


class TransferForm(forms.Form):
Expand Down
2 changes: 1 addition & 1 deletion hc/front/templatetags/hc_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def now_isoformat() -> str:

@register.filter
def timestamp(dt: datetime) -> int:
return int(dt.timestamp())
return dt.timestamp()


@register.filter
Expand Down
1 change: 1 addition & 0 deletions hc/front/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
path("remove/", views.remove_check, name="hc-remove-check"),
path("clear_events/", views.clear_events, name="hc-clear-events"),
path("log/", views.log, name="hc-log"),
path("log_events/", views.log_events, name="hc-log-events"),
path("status/", views.status_single, name="hc-status-single"),
path("last_ping/", views.ping_details, name="hc-last-ping"),
path("transfer/", views.transfer, name="hc-transfer"),
Expand Down
33 changes: 28 additions & 5 deletions hc/front/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
from collections.abc import Iterable
from datetime import datetime
from datetime import timedelta as td
from datetime import timezone
from email.message import EmailMessage
from secrets import token_urlsafe
from typing import Literal, TypedDict, cast
from typing import Any, Dict, Literal, TypedDict, cast
from urllib.parse import urlencode, urlparse
from uuid import UUID
from zoneinfo import ZoneInfo
Expand Down Expand Up @@ -75,6 +76,7 @@
LAST_PING_TMPL = get_template("front/last_ping_cell.html")
EVENTS_TMPL = get_template("front/details_events.html")
DOWNTIMES_TMPL = get_template("front/details_downtimes.html")
LOGS_TMPL = get_template("front/log_row.html")


def _tags_counts(checks: Iterable[Check]) -> tuple[list[tuple[str, str, str]], int]:
Expand Down Expand Up @@ -207,6 +209,7 @@ def _get_referer_qs(request: HttpRequest) -> str:
return "?" + parsed.query
return ""


@login_required
def checks(request: AuthenticatedHttpRequest, code: UUID) -> HttpResponse:
_refresh_last_active_date(request.profile)
Expand Down Expand Up @@ -918,11 +921,12 @@ def log(request: AuthenticatedHttpRequest, code: UUID) -> HttpResponse:
smin = smin.replace(minute=0, second=0)

form = forms.SeekForm(request.GET)
start, end = smin, smax
if form.is_valid():
start = form.cleaned_data["start"]
end = form.cleaned_data["end"]
else:
start, end = smin, smax
if form.cleaned_data["start"]:
start = form.cleaned_data["start"]
if form.cleaned_data["end"]:
end = form.cleaned_data["end"]

# Clamp the _get_events start argument to the date of the oldest visible ping
get_events_start = start
Expand Down Expand Up @@ -2729,4 +2733,23 @@ def render_result(result: str | None) -> HttpResponse:
return render_result(None)


@login_required
def log_events(request: AuthenticatedHttpRequest, code: UUID) -> HttpResponse:
check, rw = _get_check_for_user(request, code, preload_owner_profile=True)

if "start" in request.GET:
ts = request.GET["start"]
# FIXME must handle non-float values
start = datetime.fromtimestamp(float(ts), tz=timezone.utc)
start += td(microseconds=1)
else:
start = check.created

html = ""
for event in _get_events(check, 1000, start=start, end=now()):
html += LOGS_TMPL.render({"event": event, "describe_body": True})

return JsonResponse({"max": now().timestamp(), "events": html})


# Forks: add custom views after this line
22 changes: 22 additions & 0 deletions static/css/log.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,22 @@
font-size: 13px;
}

#log tbody {
border: 0;
}

#log td {
position: relative;
border: 0;
border-bottom: 1px solid var(--border-muted);
white-space: nowrap;
}

#log tbody.new td {
background: var(--log-new-row-bg);
border-bottom: 1px solid var(--log-new-row-border);
}

#log .duration {
white-space: nowrap;
float: right;
Expand Down Expand Up @@ -97,4 +106,17 @@
#slider-from-formatted,
#slider-to-formatted {
font-weight: bold;
}
#liveUpdates {
display: inline-flex;
align-items: center;
margin-bottom: 5px;
}
#updateIndicator {
display: inline-block;
width: 20px;
height: 20px;
border-radius: 50%;
margin-left: 5px;
background-color: green;
}
4 changes: 4 additions & 0 deletions static/css/variables.css
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
--text-muted: #767676;
--text-success: #3c763d;
--text-danger: #a94442;
--log-new-row-bg: #d9edf7;
--log-new-row-border: #bce8f1;
}


Expand Down Expand Up @@ -155,4 +157,6 @@ body.dark {
--text-muted: hsl(240, 3%, 55%);
--text-success: #22bc66;
--text-danger: #d9534f;
--log-new-row-bg: #123051;
--log-new-row-border: #163c64;
}
6 changes: 6 additions & 0 deletions static/js/details.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
$(function () {
// removing session storage for slider here because
// when a slider is moved it stays at its position event you move to a different page and back.
// It resets only when you move to the detail of the check or another check.
sessionStorage.removeItem('rightSliderHandleMoved');
sessionStorage.removeItem('leftSliderHandleMoved');

$("#edit-name").click(function() {
$('#update-name-modal').modal("show");
$("#update-name-input").focus();
Expand Down

0 comments on commit f218c09

Please sign in to comment.