Add edit page, dialog based item page. Consider switching to popups.
This commit is contained in:
@@ -10,7 +10,14 @@ from mac_vendor_lookup import AsyncMacLookup
|
||||
from db_classes import *
|
||||
from .. import components as comps
|
||||
|
||||
import asyncio
|
||||
|
||||
class AddPage(rio.Component):
|
||||
|
||||
"""
|
||||
A set of fields for adding/editing items.
|
||||
"""
|
||||
|
||||
partnum: str = ""
|
||||
mac: str = ""
|
||||
serial: str = ""
|
||||
@@ -27,6 +34,9 @@ class AddPage(rio.Component):
|
||||
manu: str = ""
|
||||
manufield: str = ""
|
||||
office: str = ""
|
||||
description: str = ""
|
||||
location: str = ""
|
||||
location_code: str = ""
|
||||
|
||||
@rio.event.periodic(1)
|
||||
def set_office_init(self):
|
||||
@@ -60,12 +70,16 @@ class AddPage(rio.Component):
|
||||
self.popup_message = "\n Missing barcode! \n\n"
|
||||
self.popup_show = True
|
||||
self.popup_color = 'danger'
|
||||
await asyncio.sleep(2)
|
||||
self.popup_show = False
|
||||
else:
|
||||
# OK, add part
|
||||
if create_item(self.partnum, self.serial, self.office, self.code, location=None, description=None, manufacturer=self.manu, mac=self.mac, fwver=self.fwver) == False:
|
||||
if create_item(self.partnum, self.serial, self.office, self.code, locationid=self.location_code, description=self.description, manufacturer=self.manu, mac=self.mac, fwver=self.fwver) == False:
|
||||
self.popup_message = "\n Duplicate barcode! \n\n"
|
||||
self.popup_show = True
|
||||
self.popup_color = 'warning'
|
||||
await asyncio.sleep(2)
|
||||
self.popup_show = False
|
||||
else:
|
||||
self.popup_message = "\n Part added! \n\n"
|
||||
self.popup_show = True
|
||||
@@ -79,6 +93,11 @@ class AddPage(rio.Component):
|
||||
self.macvendor: str = ""
|
||||
self.manu: str = ""
|
||||
self.manufield: str = ""
|
||||
self.description: str = ""
|
||||
self.location: str = ""
|
||||
self.location_code: str = ""
|
||||
await asyncio.sleep(2)
|
||||
self.popup_show = False
|
||||
|
||||
|
||||
async def _add_part_enter(self, event: rio.TextInputConfirmEvent):
|
||||
@@ -107,8 +126,16 @@ class AddPage(rio.Component):
|
||||
async def _update_mac(self, event: rio.TextInputChangeEvent):
|
||||
await self.check_mac(event.text)
|
||||
|
||||
async def _update_location(self, event: rio.TextInputChangeEvent):
|
||||
print("Checking " + self.location)
|
||||
if get_location_id(self.location) != False:
|
||||
self.location_code = self.location
|
||||
print("Found location " + get_location_id(self.location).name)
|
||||
self.location = get_location_id(self.location).name
|
||||
|
||||
|
||||
def _update_partnum(self, event: rio.TextInputChangeEvent):
|
||||
def __find_hm_header(txt):
|
||||
def __find_hm_header_static(txt):
|
||||
searchlist = ["RSPS", "RSPE", "RSP", "RSB", "LRS", "RS", "OS", "RED", "MSP", "MSM", "MS", "MM", "EESX", "EES", "OZD", "OBR"]
|
||||
for header in searchlist:
|
||||
if txt.find(header) >= 0:
|
||||
@@ -129,6 +156,8 @@ class AddPage(rio.Component):
|
||||
|
||||
if dash and acount <= 5 and ncount <= 5:
|
||||
return acount+ncount
|
||||
elif dash and acount >5 and acount <= 10 and ncount == 0:
|
||||
return acount+ncount
|
||||
return -1
|
||||
|
||||
def __find_hm_fwver(txt):
|
||||
@@ -143,7 +172,7 @@ class AddPage(rio.Component):
|
||||
if txt.find("BRS") == 0:
|
||||
a -= 1
|
||||
if txt[a] in ['S', 'A']:
|
||||
return txt[a]
|
||||
return '2' + txt[a]
|
||||
a = __find_hm_fwver(txt)
|
||||
if txt.find("GRS") == 0:
|
||||
a -= 4
|
||||
@@ -162,7 +191,7 @@ class AddPage(rio.Component):
|
||||
print(txt,txt[a])
|
||||
|
||||
if txt[a] in ['P', 'E']:
|
||||
return txt[a]
|
||||
return '2' + txt[a]
|
||||
a = __find_hm_fwver(txt)
|
||||
if txt.find("EAGLE") == 0:
|
||||
a -= 2
|
||||
@@ -179,7 +208,7 @@ class AddPage(rio.Component):
|
||||
if __find_hm_fwver(pn) >= 0:
|
||||
self.fwver = pn[__find_hm_fwver(pn):]
|
||||
if len(__find_hm_fwmode(pn)) > 0:
|
||||
self.fwver += " SWL-" + __find_hm_fwmode(pn)
|
||||
self.fwver += " SW-L" + __find_hm_fwmode(pn)
|
||||
|
||||
def build(self) -> rio.Component:
|
||||
return rio.Column(
|
||||
@@ -207,33 +236,39 @@ class AddPage(rio.Component):
|
||||
),
|
||||
rio.TextInput(
|
||||
label="Serial",
|
||||
text=self.bind().serial
|
||||
text=self.bind().serial,
|
||||
on_confirm=self._add_part_enter
|
||||
),
|
||||
rio.TextInput(
|
||||
label="MAC",
|
||||
text=self.bind().mac,
|
||||
on_change=self._update_mac
|
||||
on_change=self._update_mac,
|
||||
on_confirm=self._add_part_enter
|
||||
),
|
||||
rio.TextInput(
|
||||
label="Location (optional)",
|
||||
text=self.bind().location,
|
||||
on_change=self._update_location,
|
||||
on_confirm=self._add_part_enter
|
||||
),
|
||||
rio.TextInput(
|
||||
label="Manufacturer",
|
||||
text=self.bind().manufield
|
||||
text=self.bind().manufield,
|
||||
on_confirm=self._add_part_enter
|
||||
),
|
||||
rio.TextInput(
|
||||
label="FW Ver",
|
||||
text=self.bind().fwver,
|
||||
on_confirm=self._add_part_enter
|
||||
text=self.bind().fwver
|
||||
),
|
||||
rio.Row(
|
||||
# rio.DateInput(
|
||||
# label="Timestamp",
|
||||
# value=self.bind().date
|
||||
# ),
|
||||
rio.TextInput(
|
||||
#text=
|
||||
is_sensitive=False,
|
||||
text = self.bind().time_start,
|
||||
#on_change=self._set_time
|
||||
)
|
||||
rio.MultiLineTextInput(
|
||||
label="Description (optional)",
|
||||
text=self.bind().description
|
||||
),
|
||||
rio.TextInput(
|
||||
label="Timestamp",
|
||||
is_sensitive=False,
|
||||
text = self.bind().time_start,
|
||||
#on_change=self._set_time
|
||||
),
|
||||
rio.Button(
|
||||
content="Add",
|
||||
@@ -241,7 +276,7 @@ class AddPage(rio.Component):
|
||||
),
|
||||
|
||||
spacing=2,
|
||||
width=60,
|
||||
min_width=60,
|
||||
margin_bottom=4,
|
||||
align_x=0.5,
|
||||
align_y=0,
|
||||
|
||||
Reference in New Issue
Block a user