From 72d608902d66b5b6e2361a466baf9c9c538b8419 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Mon, 12 Aug 2019 23:29:32 +0300 Subject: [PATCH] Fix JS to construct correct URLs when running from a subdirectory. Fixes #273 --- CHANGELOG.md | 3 + hc/front/urls.py | 2 +- static/js/add_trello.js | 3 +- static/js/checks.js | 13 +- static/js/collapse-native.js | 204 ------------------------- static/js/details.js | 3 +- static/js/signup.js | 3 +- static/js/tab-native.js | 117 -------------- static/js/update-timeout-modal.js | 34 +---- templates/base.html | 2 +- templates/front/details.html | 1 + templates/front/my_checks_desktop.html | 2 +- 12 files changed, 24 insertions(+), 363 deletions(-) delete mode 100644 static/js/collapse-native.js delete mode 100644 static/js/tab-native.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 2573badc..2daaa5dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ 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 - Add the `pruneflips` management command +## Bug Fixes +- Fix javascript code to construct correct URLs when running from a subdirectory (#273) + ## 1.8.0 - 2019-07-08 diff --git a/hc/front/urls.py b/hc/front/urls.py index e23ba45a..a3c98d5e 100644 --- a/hc/front/urls.py +++ b/hc/front/urls.py @@ -10,7 +10,7 @@ check_urls = [ path("pause/", views.pause, name="hc-pause"), path("remove/", views.remove_check, name="hc-remove-check"), path("log/", views.log, name="hc-log"), - path("status/", views.status_single), + 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"), path( diff --git a/static/js/add_trello.js b/static/js/add_trello.js index 9ebbdf88..258bcadd 100644 --- a/static/js/add_trello.js +++ b/static/js/add_trello.js @@ -15,9 +15,10 @@ $(function() { $("integration-settings").text("Loading..."); token = tokenMatch[1]; + var base = document.getElementById("base-url").getAttribute("href").slice(0, -1); var csrf = $('input[name=csrfmiddlewaretoken]').val(); $.ajax({ - url: "/integrations/add_trello/settings/", + url: base + "/integrations/add_trello/settings/", type: "post", headers: {"X-CSRFToken": csrf}, data: {token: token}, diff --git a/static/js/checks.js b/static/js/checks.js index 4e7b96a0..ad77a96d 100644 --- a/static/js/checks.js +++ b/static/js/checks.js @@ -1,8 +1,9 @@ $(function () { + var base = document.getElementById("base-url").getAttribute("href").slice(0, -1); $(".my-checks-name").click(function() { var code = $(this).closest("tr.checks-row").attr("id"); - var url = "/checks/" + code + "/name/"; + var url = base + "/checks/" + code + "/name/"; $("#update-name-form").attr("action", url); $("#update-name-input").val(this.dataset.name); @@ -31,7 +32,7 @@ $(function () { var checkCode = $(this).closest("tr.checks-row").attr("id"); var channelCode = $("#ch-" + idx).data("code"); - var url = "/checks/" + checkCode + "/channels/" + channelCode + "/enabled"; + var url = base + "/checks/" + checkCode + "/channels/" + channelCode + "/enabled"; $.ajax({ url: url, @@ -52,12 +53,12 @@ $(function () { $('#ping-details-modal').modal("show"); var code = $(this).closest("tr.checks-row").attr("id"); - var lastPingUrl = "/checks/" + code + "/last_ping/"; + var lastPingUrl = base + "/checks/" + code + "/last_ping/"; $.get(lastPingUrl, function(data) { $("#ping-details-body" ).html(data); }); - var logUrl = "/checks/" + code + "/log/"; + var logUrl = base + "/checks/" + code + "/log/"; $("#ping-details-log").attr("href", logUrl); return false; @@ -79,7 +80,7 @@ $(function () { // Update hash if (window.history && window.history.replaceState) { - var url = $("#checks-table").data("list-url");; + var url = $("#checks-table").data("list-url"); if (qs.length) { url += "?" + $.param(qs); } @@ -132,7 +133,7 @@ $(function () { $(".show-log").click(function(e) { var code = $(this).closest("tr.checks-row").attr("id"); - var url = "/checks/" + code + "/details/"; + var url = base + "/checks/" + code + "/details/"; window.location = url; return false; }); diff --git a/static/js/collapse-native.js b/static/js/collapse-native.js deleted file mode 100644 index 2da5eee2..00000000 --- a/static/js/collapse-native.js +++ /dev/null @@ -1,204 +0,0 @@ -// Native Javascript for Bootstrap 3 | Collapse -// by dnp_theme - -(function(factory){ - - // CommonJS/RequireJS and "native" compatibility - if(typeof module !== "undefined" && typeof exports == "object") { - // A commonJS/RequireJS environment - if(typeof window != "undefined") { - // Window and document exist, so return the factory's return value. - module.exports = factory(); - } else { - // Let the user give the factory a Window and Document. - module.exports = factory; - } - } else { - // Assume a traditional browser. - window.Collapse = factory(); - } - -})(function(){ - - // COLLAPSE DEFINITION - // =================== - var Collapse = function( element, options ) { - options = options || {}; - - this.btn = typeof element === 'object' ? element : document.querySelector(element); - this.accordion = null; - this.collapse = null; - this.duration = 300; // default collapse transition duration - this.options = {}; - this.options.duration = /ie/.test(document.documentElement.className) ? 0 : (options.duration || this.duration); - this.init(); - } - - // COLLAPSE METHODS - // ================ - Collapse.prototype = { - - init : function() { - this.actions(); - this.btn.addEventListener('click', this.toggle, false); - - // allows the collapse to expand - // ** when window gets resized - // ** or via internal clicks handers such as dropwowns or any other - document.addEventListener('click', this.update, false); - window.addEventListener('resize', this.update, false) - }, - - actions : function() { - var self = this; - - this.toggle = function(e) { - self.btn = self.getTarget(e).btn; - self.collapse = self.getTarget(e).collapse; - - if (!/in/.test(self.collapse.className)) { - self.open(e) - } else { - self.close(e) - } - }, - this.close = function(e) { - e.preventDefault(); - self.btn = self.getTarget(e).btn; - self.collapse = self.getTarget(e).collapse; - self._close(self.collapse); - self.btn.className = self.btn.className.replace(' collapsed',''); - }, - this.open = function(e) { - e.preventDefault(); - self.btn = self.getTarget(e).btn; - self.collapse = self.getTarget(e).collapse; - self.accordion = self.btn.getAttribute('data-parent') && self.getClosest(self.btn, self.btn.getAttribute('data-parent')); - - self._open(self.collapse); - self.btn.className += ' collapsed'; - - if ( self.accordion !== null ) { - var active = self.accordion.querySelectorAll('.collapse.in'), al = active.length, i = 0; - for (i;i 1 ) { - return activeTabs[activeTabs.length-1] - } - }, - this.getActiveContent = function() { - var a = self.getActiveTab().getElementsByTagName('A')[0].getAttribute('href').replace('#',''); - return a && document.getElementById(a) - } - } - } - - - // TAB DATA API - // ================= - var Tabs = document.querySelectorAll("[data-toggle='tab'], [data-toggle='pill']"), tbl = Tabs.length, i=0; - for ( i;iUpdating...

"); - $("#schedule").val(schedule); - $("#tz").selectpicker("val", tz); - var minutes = parseInt(grace / 60); - $("#update-timeout-grace-cron").val(minutes); - updateCronPreview(); - - kind == "simple" ? showSimple() : showCron(); - $('#update-timeout-modal').modal({"show":true, "backdrop":"static"}); - return false; - - } - - var MINUTE = {name: "minute", nsecs: 60}; var HOUR = {name: "hour", nsecs: MINUTE.nsecs * 60}; var DAY = {name: "day", nsecs: HOUR.nsecs * 24}; @@ -166,7 +142,7 @@ $(function () { var token = $('input[name=csrfmiddlewaretoken]').val(); $.ajax({ - url: "/checks/cron_preview/", + url: base + "/checks/cron_preview/", type: "post", headers: {"X-CSRFToken": token}, data: {schedule: schedule, tz: tz}, diff --git a/templates/base.html b/templates/base.html index 899ee573..460bcc85 100644 --- a/templates/base.html +++ b/templates/base.html @@ -67,7 +67,7 @@ - + {% if request.user.is_authenticated and project %} {{ project }} diff --git a/templates/front/details.html b/templates/front/details.html index 34042088..f78cfc00 100644 --- a/templates/front/details.html +++ b/templates/front/details.html @@ -153,6 +153,7 @@ id="edit-timeout" class="btn btn-sm btn-default timeout-grace" data-code="{{ check.code }}" + data-status-url="{% url 'hc-status-single' check.code %}" data-kind="{{ check.kind }}" data-timeout="{{ check.timeout.total_seconds }}" data-grace="{{ check.grace.total_seconds }}" diff --git a/templates/front/my_checks_desktop.html b/templates/front/my_checks_desktop.html index 8561e5ec..14716ff7 100644 --- a/templates/front/my_checks_desktop.html +++ b/templates/front/my_checks_desktop.html @@ -112,7 +112,7 @@ -
+
{% include "front/last_ping_cell.html" with check=check %}