Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions netbox_floorplan/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

from netbox.tables import NetBoxTable
from .models import Floorplan, FloorplanImage
from functools import cached_property

from dcim.models import Rack
from dcim.models import Rack, Device


class FloorplanImageTable(NetBoxTable):
Expand Down Expand Up @@ -32,14 +33,19 @@ class Meta(NetBoxTable.Meta):


class FloorplanRackTable(NetBoxTable):

name = tables.LinkColumn()
embedded = True

actions = tables.TemplateColumn(template_code="""
<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>
""")

@cached_property
def htmx_url(self):
# no need to check for embedded as this table is always embedded
return "/plugins/floorplan/floorplans/racks/"

class Meta(NetBoxTable.Meta):
model = Rack
fields = ('pk', 'name', 'u_height')
Expand All @@ -50,16 +56,21 @@ class Meta(NetBoxTable.Meta):


class FloorplanDeviceTable(NetBoxTable):

name = tables.LinkColumn()
embedded = True

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

@cached_property
def htmx_url(self):
# no need to check for embedded as this table is always embedded
return "/plugins/floorplan/floorplans/devices/"

class Meta(NetBoxTable.Meta):
model = Rack
model = Device
fields = ('pk', 'name', 'device_type')
default_columns = ('pk', 'name', 'device_type')
row_attrs = {
Expand Down