Skip to content
This repository has been archived by the owner on Jun 7, 2024. It is now read-only.

Commit

Permalink
Merge pull request #11 from justin-davisibm/rack-size
Browse files Browse the repository at this point in the history
Rack sizes from Netbox
  • Loading branch information
tbotnz authored Sep 22, 2023
2 parents 5d757d4 + e7e637d commit d97fdad
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 9 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
.vscode/settings.json
.idea
*.pyc
venv
venv
build/**
netbox_floorplan.egg-info/**
2 changes: 1 addition & 1 deletion netbox_floorplan/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class FloorplanConfig(PluginConfig):
name = "netbox_floorplan"
verbose_name = "Netbox Floorplan"
description = ""
version = "0.1"
version = "0.1.1"
base_url = "floorplan"
min_version = "3.4.1"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,37 @@ function add_text() {
}
window.add_text = add_text;

function add_floorplan_object(top, left, width, height, fill, rotation, object_id, object_name, object_type, status) {
function add_floorplan_object(top, left, width, height, unit, fill, rotation, object_id, object_name, object_type, status) {
var object_width;
var object_height;
if ( !width || !height || !unit ){
object_width = 60;
object_height = 91;
} else {
var conversion_scale = 100;
console.log("width: " + width)
console.log("unit: " + unit)
console.log("height: " + height)
if (unit == "in") {
var new_width = (width * 0.0254) * conversion_scale;
var new_height = (height * 0.0254) * conversion_scale;
} else {
var new_width = (width / 1000) * conversion_scale;
var new_height = (height / 1000) * conversion_scale;
}

object_width = parseFloat(new_width.toFixed(2));
console.log(object_width)
object_height = parseFloat(new_height.toFixed(2));
console.log(object_height)
}
document.getElementById(`object_${object_type}_${object_id}`).remove();
var rect = new fabric.Rect({
top: top,
name: "rectangle",
left: left,
width: width,
height: height,
width: object_width,
height: object_height,
fill: fill,
opacity: 0.8,
lockRotation: false,
Expand Down Expand Up @@ -296,6 +319,7 @@ function add_floorplan_object(top, left, width, height, fill, rotation, object_i

canvas.add(group);
canvas.centerObject(group);
//canvas.bringToFront(group);
}
window.add_floorplan_object = add_floorplan_object;

Expand Down
4 changes: 2 additions & 2 deletions netbox_floorplan/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class FloorplanRackTable(NetBoxTable):
name = tables.LinkColumn()

actions = tables.TemplateColumn(template_code="""
<a type="button" class="btn btn-sm btn-outline-info" onclick="add_floorplan_object(300, 500, 60, 91, '#ea8fe', 30, '{{ record.id }}', '{{ record.name }}', 'rack', '{{ record.status }}')">Add Rack
<a type="button" class="btn btn-sm btn-outline-info" onclick="add_floorplan_object(300, 500, '{{ record.outer_width }}', '{{ record.outer_depth}}', '{{ record.outer_unit }}', '#ea8fe', 30, '{{ record.id }}', '{{ record.name }}', 'rack', '{{ record.status }}')">Add Rack
</a>
""")

Expand All @@ -38,7 +38,7 @@ class FloorplanDeviceTable(NetBoxTable):
name = tables.LinkColumn()

actions = tables.TemplateColumn(template_code="""
<a type="button" class="btn btn-sm btn-outline-info" onclick="add_floorplan_object(30, 50, 60, 91, '#ea8fe', 30, '{{ record.id }}', '{{ record.name }}', 'device', '{{ record.status }}')">Add Device
<a type="button" class="btn btn-sm btn-outline-info" onclick="add_floorplan_object(30, 50, 60, 91, '{{ record.outer_unit }}', '#ea8fe', 30, '{{ record.id }}', '{{ record.name }}', 'device', '{{ record.status }}')">Add Device
</a>
""")

Expand Down
2 changes: 1 addition & 1 deletion netbox_floorplan/templatetags/template_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

@register.simple_tag()
def denormalize_measurement(unit, value):
print(unit, value)
# print(unit, value)

if unit == 'ft':
return round(
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="netbox_floorplan",
version="0.1",
version="0.1.1",
author="Tony Nealon",
author_email="tony@worksystems.co.nz",
description="Netbox Plugin to support graphical floorplans",
Expand Down

0 comments on commit d97fdad

Please sign in to comment.