Skip to content

Commit

Permalink
Add + Patch Port button to switch page
Browse files Browse the repository at this point in the history
This allows to add a patch port without the indirection of having to
go to the switch room.

Refs #335
  • Loading branch information
lukasjuhrich committed Jan 28, 2024
1 parent a39324c commit c1c1d6c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
5 changes: 4 additions & 1 deletion web/blueprints/infrastructure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ def switch_show(switch_id: int) -> ResponseValue:
switch=switch,
port_table=PortTable(
data_url=url_for('.switch_show_json', switch_id=switch.host_id),
switch_id=switch_id))
switch_id=switch_id,
switch_room_id=switch.host.room_id,
),
)


@bp.route('/switch/show/<int:switch_id>/json')
Expand Down
19 changes: 14 additions & 5 deletions web/blueprints/infrastructure/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from flask_login import current_user
from pydantic import BaseModel, ConfigDict

from web.table.lazy_join import HasDunderStr
from web.table.lazy_join import HasDunderStr, lazy_join
from web.table.table import (
BootstrapTable,
Column,
Expand Down Expand Up @@ -85,9 +85,10 @@ class Meta:
'data-sort-name': 'switchport_name',
}

def __init__(self, *, switch_id: int | None = None, **kw: t.Any) -> None:
def __init__(self, *, switch_id: int, switch_room_id: int, **kw: t.Any) -> None:
super().__init__(**kw)
self.switch_id = switch_id
self.switch_room_id = switch_room_id

switchport_name = Column("Name", width=2, col_args={'data-sorter': 'table.sortPort'})
patchport_name = Column("→ Patchport", width=2, col_args={'data-sorter': 'table.sortPatchPort'})
Expand All @@ -96,11 +97,19 @@ def __init__(self, *, switch_id: int | None = None, **kw: t.Any) -> None:
delete_link = BtnColumn('Löschen', hide_if=no_inf_change)

@property
def toolbar(self) -> HasDunderStr | None:
@lazy_join
def toolbar(self) -> t.Iterator[HasDunderStr | None]:
if no_inf_change():
return None
href = url_for(".switch_port_create", switch_id=self.switch_id)
return button_toolbar("Switch-Port", href)

yield from button_toolbar(
"Switch-Port",
url_for(".switch_port_create", switch_id=self.switch_id),
)
yield from button_toolbar(
"Patch-Port",
url_for("facilities.patch_port_create", switch_room_id=self.switch_room_id),
)


class PortRow(BaseModel):
Expand Down

0 comments on commit c1c1d6c

Please sign in to comment.