Browse Source

In the cron expression dialog, show a human-friendly version of the expression

pull/387/head
Pēteris Caune 4 years ago
parent
commit
eccc193b87
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
6 changed files with 22 additions and 1 deletions
  1. +1
    -0
      CHANGELOG.md
  2. +1
    -0
      hc/front/tests/test_cron_preview.py
  3. +3
    -0
      hc/front/views.py
  4. +1
    -0
      requirements.txt
  5. +15
    -1
      static/css/my_checks.css
  6. +1
    -0
      templates/front/cron_preview.html

+ 1
- 0
CHANGELOG.md View File

@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.
- Add "Get a list of checks's logged pings" API call (#371)
- The /api/v1/checks/ endpoint now accepts either UUID or `unique_key` (#370)
- Added /api/v1/checks/uuid/flips/ endpoint (#349)
- In the cron expression dialog, show a human-friendly version of the expression
### Bug Fixes


+ 1
- 0
hc/front/tests/test_cron_preview.py View File

@ -10,6 +10,7 @@ class CronPreviewTestCase(BaseTestCase):
payload = {"schedule": "* * * * *", "tz": "UTC"}
r = self.client.post("/checks/cron_preview/", payload)
self.assertContains(r, "cron-preview-title", status_code=200)
self.assertContains(r, "“Every minute”")
def test_it_rejects_invalid_cron_expression(self):
samples = ["", "*", "100 100 100 100 100", "* * * * * *", "1,2 3,* * * *"]


+ 3
- 0
hc/front/views.py View File

@ -4,6 +4,7 @@ import os
from secrets import token_urlsafe
from urllib.parse import urlencode
from cron_descriptor import ExpressionDescriptor
from croniter import croniter
from django.conf import settings
from django.contrib import messages
@ -408,6 +409,8 @@ def cron_preview(request):
it = croniter(schedule, now_local)
for i in range(0, 6):
ctx["dates"].append(it.get_next(datetime))
ctx["desc"] = str(ExpressionDescriptor(schedule, use_24hour_time_format=True))
except UnknownTimeZoneError:
ctx["bad_tz"] = True
except:


+ 1
- 0
requirements.txt View File

@ -1,3 +1,4 @@
cron-descriptor==1.2.24
croniter==0.3.31
Django==3.0.7
django-compressor==2.4


+ 15
- 1
static/css/my_checks.css View File

@ -87,9 +87,19 @@
width: 300px;
}
#cron-description {
text-align: center;
font-weight: bold;
font-style: italic;
font-size: 18px;
color: #FFF;
color: #333;
padding: 16px 8px 0px 8px;
}
#cron-preview {
background: #f8f8f8;
height: 256px;
min-height: 298px;
}
#cron-preview p {
@ -103,6 +113,10 @@
font-size: small;
}
#cron-preview-table {
margin: 0;
}
#cron-preview-table tr td:nth-child(1) {
width: 120px;
}


+ 1
- 0
templates/front/cron_preview.html View File

@ -9,6 +9,7 @@
{% elif bad_tz %}
<p id="invalid-arguments">Invalid timezone</p>
{% else %}
{% if desc %}<div id="cron-description">“{{ desc }}”</div>{% endif %}
<table id="cron-preview-table" class="table">
<tr><th id="cron-preview-title" colspan="3">Expected Ping Dates</th></tr>
{% for d in dates %}


Loading…
Cancel
Save