Skip to content

Various fixes #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
May 5, 2025
Merged

Various fixes #42

merged 20 commits into from
May 5, 2025

Conversation

cmcknz77
Copy link
Collaborator

@cmcknz77 cmcknz77 commented May 2, 2025

Fixes all 4 of the problems identified in: #41
And the 2nd of the issues identified in: #39

cmcknz77 added 16 commits April 11, 2025 02:29
…yle string

Observed: `style="grid-area: 1-1-1; "` (The trailing semicolon and space here are suspicious).
That trailing '; ' is almost certainly the problem, preventing the browser from correctly interpreting the grid-area property.
The template always puts grid-area: `{{ int.stylename }};` (with the semicolon). The background-color part is only added if the cable_colors option is on and the cable has a color specified. If those conditions aren't met, the background-color part is omitted, leaving you with just `style="grid-area: 1-1-1; "` - exactly what was observed.

Explanation of the fix:

1. We remove the semicolon that was immediately after {{ int.stylename }}.
2. We add the semicolon only if the background-color property is actually being added (i.e., inside the {% if ... %} block, right before background-color).
3. This ensures that if background-color isn't added, the style attribute will correctly be style="grid-area: 1-1-1", and if it is added, it will be style="grid-area: 1-1-1; background-color: #xxxxxx".
4. Removed the unnecessary line breaks within the style attribute definition for clarity, which shouldn't affect functionality
Stylename interface identifications not working correctly for interfaces like 1/1/1 or 1/1 as the '/'s are not digits so reworked that prefixing logic fo a 'p' to be added to the start of stylenames that start with a digit.
Update deviceview.html to correct malformed int.stylename value in st…
Revert "Update deviceview.html to correct malformed int.stylename value in st…"
…ndividual Ports.

The HTML generated for individual port links ( tags) often includes a trailing semicolon and space within the style attribute (e.g., style="grid-area: 1-1-1; ") even when it's the only style property. This trailing ; can prevent the browser from correctly applying the grid-area property, causing the port to not be placed in its intended grid cell. This was particularly apparent when the conditional background-color style was not applied.

File(s) Involved: The Django template responsible for rendering the device view, likely netbox_device_view/templates/netbox_device_view/deviceview.html.

Proposed Solution: Modify the template logic to ensure the semicolon is only included in the style attribute if there are multiple style properties being added (e.g., both grid-area and background-color). The fix would involve moving the semicolon inside the conditional block that adds the background-color.
…Specific Naming Conventions (e.g., X/Y/Z). -Update utils.py

Description: The Python code that generates the stylename (which is then used for the grid-area CSS property) for interfaces uses a regular expression that incorrectly parses certain naming formats, specifically names like 1/1/15. Instead of producing a stylename like 1-1-15 (which matches the likely format used in grid-template-areas), it generates 1-15.

File(s) Involved: The utility function responsible for processing interfaces, netbox_device_view/utils.py (specifically the process_interfaces function).

Proposed Solution: Modify the stylename generation logic within the process_interfaces function to correctly parse common interface naming conventions (like X/Y/Z, EthX/Y, etc.) and reliably produce a stylename format that matches the expected names used in the grid-template-areas CSS (e.g., converting 1/1/15 to 1-1-15). A simpler string manipulation method (like splitting and joining with hyphens) might be more robust than the current regex.

Convert the entire interface name to lowercase.
Replace common separators found in interface names (such as slashes /, dots ., and spaces \s) with a consistent single separator, like a hyphen (-). This can be done using a simple regular expression substitution.
Clean up the resulting string to remove any potential multiple consecutive hyphens or leading/trailing hyphens that might have been introduced.
… CSS Identifier. - Update utils.py

Description: The code checks if the generated stylename isdigit() and prepends a p if it is. However, CSS identifiers cannot start with a digit or a hyphen, not just be entirely digits. This check misses cases like 1-1-15 (starts with a digit but includes hyphens) or names starting with a hyphen, which are also invalid CSS identifiers. If an invalid stylename is generated and not caught, the corresponding grid-area style will be ignored by the browser.

File(s) Involved: The utility functions generating stylenames, primarily netbox_device_view/utils.py (process_interfaces and potentially process_ports).

Proposed Solution: Replace the narrow isdigit() check with a more robust validation that checks if the stylename is empty or if its first character is a digit or a hyphen. If it is, prepend a valid character (like p) to ensure it becomes a valid CSS identifier before being used in the HTML and CSS.
Alpha version
@cmcknz77
Copy link
Collaborator Author

cmcknz77 commented May 4, 2025

Never done this before @peterbaumert
Now that the tests pass, I assume that you would prefer that I request a review from you before merging?

@cmcknz77 cmcknz77 requested a review from peterbaumert May 4, 2025 03:22
@cmcknz77 cmcknz77 requested a review from peterbaumert May 4, 2025 13:18
@cmcknz77 cmcknz77 merged commit e5771d3 into peterbaumert:main May 5, 2025
2 checks passed
@peterbaumert
Copy link
Owner

Thanks for your great work and help!

@joeladria
Copy link
Collaborator

I agree this improves the naming scheme and predictability, it does seem to breaks compatibility with existing port maps, specifically with stacks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants