22
33from netbox .tables import NetBoxTable
44from .models import Floorplan , FloorplanImage
5+ from functools import cached_property
56
6- from dcim .models import Rack
7+ from dcim .models import Rack , Device
78
89
910class FloorplanImageTable (NetBoxTable ):
@@ -32,14 +33,19 @@ class Meta(NetBoxTable.Meta):
3233
3334
3435class FloorplanRackTable (NetBoxTable ):
35-
3636 name = tables .LinkColumn ()
37+ embedded = True
3738
3839 actions = tables .TemplateColumn (template_code = """
3940 <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
4041 </a>
4142 """ )
4243
44+ @cached_property
45+ def htmx_url (self ):
46+ # no need to check for embedded as this table is always embedded
47+ return "/plugins/floorplan/floorplans/racks/"
48+
4349 class Meta (NetBoxTable .Meta ):
4450 model = Rack
4551 fields = ('pk' , 'name' , 'u_height' )
@@ -50,16 +56,21 @@ class Meta(NetBoxTable.Meta):
5056
5157
5258class FloorplanDeviceTable (NetBoxTable ):
53-
5459 name = tables .LinkColumn ()
60+ embedded = True
5561
5662 actions = tables .TemplateColumn (template_code = """
5763 <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
5864 </a>
5965 """ )
6066
67+ @cached_property
68+ def htmx_url (self ):
69+ # no need to check for embedded as this table is always embedded
70+ return "/plugins/floorplan/floorplans/devices/"
71+
6172 class Meta (NetBoxTable .Meta ):
62- model = Rack
73+ model = Device
6374 fields = ('pk' , 'name' , 'device_type' )
6475 default_columns = ('pk' , 'name' , 'device_type' )
6576 row_attrs = {
0 commit comments