Three choices in timezone switcher (UTC / check's timezone / browser's timezone). Fixes #278

This commit is contained in:
Pēteris Caune 2019-08-22 11:17:27 +03:00
parent dd83ec2214
commit dfd449b101
No known key found for this signature in database
GPG Key ID: E28D7679E9A9EDE2
10 changed files with 35 additions and 29 deletions

View File

@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.
- Show the number of downtimes and total downtime minutes in "Check Details" page - Show the number of downtimes and total downtime minutes in "Check Details" page
- Add the `pruneflips` management command - Add the `pruneflips` management command
- Add Mattermost integration (#276) - Add Mattermost integration (#276)
- Three choices in timezone switcher (UTC / check's timezone / browser's timezone) (#278)
## Bug Fixes ## Bug Fixes
- Fix javascript code to construct correct URLs when running from a subdirectory (#273) - Fix javascript code to construct correct URLs when running from a subdirectory (#273)

View File

@ -22,7 +22,7 @@ class LogTestCase(BaseTestCase):
self.client.login(username="alice@example.org", password="password") self.client.login(username="alice@example.org", password="password")
r = self.client.get(self.url) r = self.client.get(self.url)
self.assertContains(r, "Local Time", status_code=200) self.assertContains(r, "Browser's time zone", status_code=200)
def test_team_access_works(self): def test_team_access_works(self):

View File

@ -109,12 +109,11 @@ $(function () {
var lastFormat = "local"; var lastFormat = "local";
function switchDateFormat(format) { function switchDateFormat(format) {
lastFormat = format; lastFormat = format;
var tz = format == "local" ? spacetime().timezone().name : format;
$("#log tr").each(function(index, row) { $("#log tr").each(function(index, row) {
var dt = moment(row.getAttribute("data-dt")); var s = spacetime(row.getAttribute("data-dt")).goto(tz);
format == "local" ? dt.local() : dt.utc(); $(".date", row).text(s.unixFmt("MMM d"));
$(".time", row).text(s.unixFmt("h:mm"));
$(".date", row).text(dt.format("MMM D"));
$(".time", row).text(dt.format("HH:mm"));
}) })
// The table is initially hidden to avoid flickering as we convert dates. // The table is initially hidden to avoid flickering as we convert dates.

View File

@ -4,19 +4,18 @@ $(function () {
$('#ping-details-modal').modal("show"); $('#ping-details-modal').modal("show");
$.get(this.dataset.url, function(data) { $.get(this.dataset.url, function(data) {
$("#ping-details-body" ).html(data); $("#ping-details-body").html(data);
}); });
return false; return false;
}); });
function switchDateFormat(format) { function switchDateFormat(format) {
var tz = format == "local" ? spacetime().timezone().name : format;
$("#log tr").each(function(index, row) { $("#log tr").each(function(index, row) {
var dt = moment(row.getAttribute("data-dt")); var s = spacetime(row.getAttribute("data-dt")).goto(tz);
format == "local" ? dt.local() : dt.utc(); $(".date", row).text(s.unixFmt("MMM d"));
$(".time", row).text(s.unixFmt("h:mm"));
$(".date", row).text(dt.format("MMM D"));
$(".time", row).text(dt.format("HH:mm"));
}) })
} }

File diff suppressed because one or more lines are too long

1
static/js/spacetime.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -163,5 +163,6 @@ $(function () {
$(".kind-cron").click(showCron); $(".kind-cron").click(showCron);
$("#schedule").on("keyup", updateCronPreview); $("#schedule").on("keyup", updateCronPreview);
$("#tz").on("change", updateCronPreview);
}); });

View File

@ -208,14 +208,21 @@
Log Log
<small>Click on individual items for details</small> <small>Click on individual items for details</small>
<div id="format-switcher" class="btn-group pull-right" data-toggle="buttons"> <div id="format-switcher" class="btn-group pull-right" data-toggle="buttons">
<label class="btn btn-default btn-xs" data-format="utc"> <label class="btn btn-default btn-xs" data-format="UTC">
<input type="radio" name="date-format" checked> <input type="radio" name="date-format">
UTC UTC
</label> </label>
{% if check.kind == "cron" and check.tz != "UTC" %}
<label class="btn btn-default btn-xs" data-format="{{ check.tz }}">
<input type="radio" name="date-format">
{{ check.tz }}
</label>
{% endif %}
<label class="btn btn-default btn-xs active" data-format="local"> <label class="btn btn-default btn-xs active" data-format="local">
<input type="radio" name="date-format"> <input type="radio" name="date-format">
Local Time Browser's time zone
</label> </label>
</div> </div>
</h2> </h2>
@ -255,7 +262,7 @@
<script src="{% static 'js/bootstrap-select.min.js' %}"></script> <script src="{% static 'js/bootstrap-select.min.js' %}"></script>
<script src="{% static 'js/nouislider.min.js' %}"></script> <script src="{% static 'js/nouislider.min.js' %}"></script>
<script src="{% static 'js/snippet-copy.js' %}"></script> <script src="{% static 'js/snippet-copy.js' %}"></script>
<script src="{% static 'js/moment.min.js' %}"></script> <script src="{% static 'js/spacetime.min.js' %}"></script>
<script src="{% static 'js/update-timeout-modal.js' %}"></script> <script src="{% static 'js/update-timeout-modal.js' %}"></script>
<script src="{% static 'js/adaptive-setinterval.js' %}"></script> <script src="{% static 'js/adaptive-setinterval.js' %}"></script>
<script src="{% static 'js/details.js' %}"></script> <script src="{% static 'js/details.js' %}"></script>

View File

@ -87,11 +87,9 @@
{% endfor %} {% endfor %}
</table> </table>
{% if check.n_pings > 20 %}
<p class="text-center"> <p class="text-center">
<a href="{% url 'hc-log' check.code %}">Show More&hellip;</a> <a href="{% url 'hc-log' check.code %}">Show More&hellip;</a>
</p> </p>
{% endif %}
{% else %} {% else %}
<div class="alert alert-info">This check has not received any pings yet.</div> <div class="alert alert-info">This check has not received any pings yet.</div>
{% endif %} {% endif %}

View File

@ -19,14 +19,21 @@
<li id="format-switcher-container" class="pull-right"> <li id="format-switcher-container" class="pull-right">
<div id="format-switcher" class="btn-group" data-toggle="buttons"> <div id="format-switcher" class="btn-group" data-toggle="buttons">
<label class="btn btn-default btn-xs" data-format="utc"> <label class="btn btn-default btn-xs" data-format="UTC">
<input type="radio" name="date-format" checked> <input type="radio" name="date-format" checked>
UTC UTC
</label> </label>
{% if check.kind == "cron" and check.tz != "UTC" %}
<label class="btn btn-default btn-xs" data-format="{{ check.tz }}">
<input type="radio" name="date-format">
{{ check.tz }}
</label>
{% endif %}
<label class="btn btn-default btn-xs active" data-format="local"> <label class="btn btn-default btn-xs active" data-format="local">
<input type="radio" name="date-format"> <input type="radio" name="date-format">
Local Time Browser's time zone
</label> </label>
</div> </div>
</li> </li>
@ -164,7 +171,7 @@
{% compress js %} {% compress js %}
<script src="{% static 'js/jquery-2.1.4.min.js' %}"></script> <script src="{% static 'js/jquery-2.1.4.min.js' %}"></script>
<script src="{% static 'js/bootstrap.min.js' %}"></script> <script src="{% static 'js/bootstrap.min.js' %}"></script>
<script src="{% static 'js/moment.min.js' %}"></script> <script src="{% static 'js/spacetime.min.js' %}"></script>
<script src="{% static 'js/log.js' %}"></script> <script src="{% static 'js/log.js' %}"></script>
{% endcompress %} {% endcompress %}
{% endblock %} {% endblock %}