Add README screenshots; fix upside-down labels and status badges
Labels on items rotated by more than 90 degrees are flipped to stay readable (designer and location preview). Status badges use inline colors because NetBox color names are not Bootstrap badge classes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
25e944ada7
commit
4a4bf52a28
11 files changed
+39
-8
No files matched your search
@@ -1,7 +1,7 @@
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from netbox.plugins import PluginConfig
|
||||
|
||||
__version__ = '0.1.4'
|
||||
__version__ = '0.1.5'
|
||||
|
||||
|
||||
class FloorPlannerConfig(PluginConfig):
|
||||
|
||||
@@ -61,8 +61,10 @@ def _item_svg(item):
|
||||
fs = max(6, min(h * 0.3, (w * 1.6) / max(len(text), 3), 60))
|
||||
fill = '#ffffff' if t in FILLED_TYPES else (item.color or 'currentColor') if t == 'label' else _shade(color)
|
||||
anchor, tx, ty = ('start', x + fs * 0.5, y + fs * 1.2) if t == 'area' else ('middle', cx, cy)
|
||||
# Keep text readable on items rotated upside down
|
||||
flip = f' transform="rotate(180 {tx} {ty})"' if 90 < item.rotation % 360 <= 270 else ''
|
||||
parts.append(f'<text x="{tx}" y="{ty}" font-size="{fs:.1f}" font-weight="600" text-anchor="{anchor}" '
|
||||
f'dominant-baseline="middle" fill="{fill}">{escape(text)}</text>')
|
||||
f'dominant-baseline="middle" fill="{fill}"{flip}>{escape(text)}</text>')
|
||||
|
||||
transform = f' transform="rotate({item.rotation} {cx} {cy})"' if item.rotation else ''
|
||||
return f'<g{transform}>{"".join(parts)}</g>'
|
||||
|
||||
@@ -815,10 +815,19 @@
|
||||
'pointer-events': 'none',
|
||||
}, g);
|
||||
tnode.textContent = text;
|
||||
// Keep text readable on items rotated upside down
|
||||
const rot = ((i.rotation || 0) % 360 + 360) % 360;
|
||||
if (rot > 90 && rot <= 270) tnode.setAttribute('transform', `rotate(180 ${tx} ${ty})`);
|
||||
}
|
||||
return g;
|
||||
}
|
||||
|
||||
statusBadge(o) {
|
||||
// Inline colors: NetBox color names (e.g. "green") are not Bootstrap badge classes
|
||||
const bg = COLOR_NAMES[o.status_color] || o.status_color || COLOR_NAMES.gray;
|
||||
return html('span', { class: 'badge', style: `background:${bg};color:#fff`, text: o.status_label });
|
||||
}
|
||||
|
||||
shade(hex) {
|
||||
// Darken a hex color by ~30 % for borders
|
||||
const m = /^#?([0-9a-f]{6})$/i.exec(hex || '');
|
||||
@@ -959,7 +968,7 @@
|
||||
const o = i.object;
|
||||
const rows = [
|
||||
[this.t('Linked object'), html('a', { href: o.url, target: '_blank', text: o.name })],
|
||||
o.status_label ? [this.t('Status'), html('span', { class: 'badge text-bg-' + (o.status_color || 'secondary'), text: o.status_label })] : null,
|
||||
o.status_label ? [this.t('Status'), this.statusBadge(o)] : null,
|
||||
o.role ? [this.t('Role'), o.role] : null,
|
||||
o.tenant ? [this.t('Tenant'), o.tenant] : null,
|
||||
o.u_height ? [this.t('Height (U)'), String(o.u_height)] : null,
|
||||
@@ -1259,7 +1268,7 @@
|
||||
html('strong', { text: this.itemText(i) || this.cfg.types[i.item_type] }),
|
||||
html('div', { class: 'fp-muted', text: this.cfg.types[i.item_type] + ` · ${roomSize(i.width, i.height)} m` }),
|
||||
];
|
||||
if (o.status_label) rows.push(html('div', {}, [this.t('Status') + ': ', html('span', { class: 'badge text-bg-' + (o.status_color || 'secondary'), text: o.status_label })]));
|
||||
if (o.status_label) rows.push(html('div', {}, [this.t('Status') + ': ', this.statusBadge(o)]));
|
||||
if (o.role) rows.push(html('div', { text: this.t('Role') + ': ' + o.role }));
|
||||
if (o.tenant) rows.push(html('div', { text: this.t('Tenant') + ': ' + o.tenant }));
|
||||
if (o.u_height) rows.push(html('div', { text: this.t('Height (U)') + ': ' + o.u_height }));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{% load static %}
|
||||
<link rel="stylesheet" href="{% static 'netbox_floorplanner/floorplanner.css' %}?v=0.1.4">
|
||||
<link rel="stylesheet" href="{% static 'netbox_floorplanner/floorplanner.css' %}?v=0.1.5">
|
||||
<div class="fp-root" data-fp-config="fp-config">{% csrf_token %}</div>
|
||||
{{ designer_config|json_script:"fp-config" }}
|
||||
<script src="{% static 'netbox_floorplanner/floorplanner.js' %}?v=0.1.4"></script>
|
||||
<script src="{% static 'netbox_floorplanner/floorplanner.js' %}?v=0.1.5"></script>
|
||||
@@ -1,6 +1,6 @@
|
||||
{% load static %}
|
||||
{% load i18n %}
|
||||
<link rel="stylesheet" href="{% static 'netbox_floorplanner/floorplanner.css' %}?v=0.1.4">
|
||||
<link rel="stylesheet" href="{% static 'netbox_floorplanner/floorplanner.css' %}?v=0.1.5">
|
||||
<div class="card">
|
||||
<h2 class="card-header">{% trans "Floor Plans" %}</h2>
|
||||
<div class="card-body fp-preview-list">
|
||||
|
||||
Reference in new issue
Block a user