From b569c06cba59769915c2d2aa0bd2d828f2a1f7e9 Mon Sep 17 00:00:00 2001 From: Stuart Weickgenant Date: Wed, 17 Sep 2025 23:30:01 +0000 Subject: [PATCH 1/2] Remove changes for pagination and table sorting fixes. Fixed in PR 85 instead --- .../static/netbox_floorplan/floorplan/edit.js | 86 +------------------ 1 file changed, 4 insertions(+), 82 deletions(-) diff --git a/netbox_floorplan/static/netbox_floorplan/floorplan/edit.js b/netbox_floorplan/static/netbox_floorplan/floorplan/edit.js index a939364..9810a0b 100644 --- a/netbox_floorplan/static/netbox_floorplan/floorplan/edit.js +++ b/netbox_floorplan/static/netbox_floorplan/floorplan/edit.js @@ -23,83 +23,9 @@ var record_type = document.getElementById('record_type').value; var site_id = document.getElementById('site_id').value; var location_id = document.getElementById('location_id').value; -// Wait for DOM to be ready before making htmx calls -document.addEventListener('DOMContentLoaded', function() { - // Check if target elements exist before making htmx requests - if (document.getElementById('rack-card')) { - htmx.ajax('GET', `/plugins/floorplan/floorplans/racks/?floorplan_id=${obj_pk}`, { - source: '#rack-card', - target: '#rack-card', - swap: 'innerHTML', - trigger: 'load' - }); - } - - if (document.getElementById('unrack-card')) { - htmx.ajax('GET', `/plugins/floorplan/floorplans/devices/?floorplan_id=${obj_pk}`, { - source: '#unrack-card', - target: '#unrack-card', - swap: 'innerHTML', - trigger: 'load' - }); - } -}); -// Add a click event listener as a backup to handle pagination (?per_page=) -// and multiple result links query parameters (e.g ?page=2) -// Fixes issue where attempting to click on pagination links or sort rack/device table -// resulted in the table being malformed or not loading at all. -// The function works by intercepting clicks on pagination links within the rack or device cards, -// preventing the default action, and then constructing the correct URL (with any query parameters) -// to fetch the updated table data using htmx. It ensures that the correct floorplan_id is -// always included in the request. -// This approach handles both relative URLs (e.g., ?page=2) and incorrect absolute URLs -// (e.g., /plugins/floorplan/floorplans//edit/?page=2) that may be generated by htmx. -// Assistance from Github Copilot used to help create this function -document.addEventListener('click', function(evt) { - // Check if the clicked element is within a rack or device card and is a pagination link - const link = evt.target?.closest('a[href]'); - // Check if the link has an htmx request or a relative URL - if (link && link.getAttribute('hx-get')) { - // Get the container element (rack-card or unrack-card) - const container = link.closest('#rack-card, #unrack-card'); - if (container) { - // Get the href attribute from the link - const href = link.getAttribute('hx-get') || link.getAttribute('href'); - - // Check if it's a relative URL or incorrect absolute URL - if (href && (href.startsWith('?') || href.includes('/plugins/floorplan/floorplans/' + obj_pk + '/edit/'))) { - evt.preventDefault(); - - // Extract query parameters - const url = new URL(href, window.location.origin); - const params = url.searchParams; - - // Determine correct endpoint (rack or device) - const baseEndpoint = container.id === 'rack-card' ? '/plugins/floorplan/floorplans/racks/' : '/plugins/floorplan/floorplans/devices/'; - - // Build correct URL - const correctedUrl = new URL(baseEndpoint, window.location.origin); - correctedUrl.searchParams.set('floorplan_id', obj_pk); - - // Add other query parameters (e.g page or per_page) except 'floorplan_id' - params.forEach((value, key) => { - if (key !== 'floorplan_id') { - correctedUrl.searchParams.set(key, value); - } - }); - - // Make the corrected htmx request to the rack or device page to grab the table data - if (document.getElementById(container.id)) { - htmx.ajax('GET', correctedUrl.toString(), { - target: '#' + container.id, - swap: 'innerHTML' - }); - } - } - } - } -}); +htmx.ajax('GET', `/plugins/floorplan/floorplans/racks/?floorplan_id=${obj_pk}`, { source: '#rack-card', target: '#rack-card', swap: 'innerHTML', trigger: 'load' }) +htmx.ajax('GET', `/plugins/floorplan/floorplans/devices/?floorplan_id=${obj_pk}`, { source: '#unrack-card', target: '#unrack-card', swap: 'innerHTML', trigger: 'load' }) fabric.Object.prototype.set({ @@ -529,12 +455,8 @@ function delete_floorplan_object() { } save_floorplan(); setTimeout(() => { - if (document.getElementById('rack-card')) { - htmx.ajax('GET', `/plugins/floorplan/floorplans/racks/?floorplan_id=${obj_pk}`, { target: '#rack-card', swap: 'innerHTML' }); - } - if (document.getElementById('unrack-card')) { - htmx.ajax('GET', `/plugins/floorplan/floorplans/devices/?floorplan_id=${obj_pk}`, { target: '#unrack-card', swap: 'innerHTML' }); - } + htmx.ajax('GET', `/plugins/floorplan/floorplans/racks/?floorplan_id=${obj_pk}`, { target: '#rack-card', swap: 'innerHTML' }); + htmx.ajax('GET', `/plugins/floorplan/floorplans/devices/?floorplan_id=${obj_pk}`, { target: '#unrack-card', swap: 'innerHTML' }); }, 1500); }); // Clear the selection after deletion From 0895ad62d46da5f67d22074ae5e9b505411ab956 Mon Sep 17 00:00:00 2001 From: Stuart Weickgenant Date: Wed, 17 Sep 2025 23:32:34 +0000 Subject: [PATCH 2/2] revert version update per comment from maintainer cruse1977 --- netbox_floorplan/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netbox_floorplan/version.py b/netbox_floorplan/version.py index 3e2f46a..777f190 100644 --- a/netbox_floorplan/version.py +++ b/netbox_floorplan/version.py @@ -1 +1 @@ -__version__ = "0.9.0" +__version__ = "0.8.0"