99 lines
3.0 KiB
Python
99 lines
3.0 KiB
Python
from __future__ import annotations
|
|
|
|
from typing import * # type: ignore
|
|
|
|
import rio
|
|
import datetime
|
|
from mac_vendor_lookup import AsyncMacLookup
|
|
|
|
from db_classes import *
|
|
from .. import components as comps
|
|
import asyncio
|
|
|
|
class CheckinPage(rio.Component):
|
|
code: str = ""
|
|
popup_message: str = ""
|
|
popup_show: bool = False
|
|
popup_color: str = 'warning'
|
|
name: str = ""
|
|
user_code: str = ""
|
|
loc_code: str = ""
|
|
loc: str = ""
|
|
|
|
async def _update_location(self, event: rio.TextInputChangeEvent):
|
|
print("Checking " + self.loc)
|
|
if get_location_id(self.loc) != False:
|
|
self.loc_code = self.loc
|
|
print("Found location " + get_location_id(self.loc).name)
|
|
self.loc = get_location_id(self.loc).name
|
|
|
|
async def _update_user(self, event: rio.TextInputChangeEvent):
|
|
print("Checking " + self.name)
|
|
if get_location_id(self.name) != False:
|
|
self.user_code = self.name
|
|
print("Found user " + get_user(self.name).name)
|
|
self.name = get_user(self.name).name
|
|
|
|
async def _checkin_item_enter(self, event: rio.TextInputConfirmEvent):
|
|
await self.check_in()
|
|
|
|
async def check_in(self):
|
|
if checkin(get_user(self.user_code), self.code, get_location_id(self.loc_code)):
|
|
self.popup_message = "\n Item checked in! \n\n"
|
|
self.popup_show = True
|
|
self.popup_color = 'success'
|
|
self.name: str = ""
|
|
self.user_code: str = ""
|
|
self.code: str = ""
|
|
self.loc_code: str = ""
|
|
self.loc: str = ""
|
|
await asyncio.sleep(2)
|
|
self.popup_show = False
|
|
else:
|
|
self.popup_message = "\n Error! Check item & location! \n\n"
|
|
self.popup_show = True
|
|
self.popup_color = 'warning'
|
|
await asyncio.sleep(2)
|
|
self.popup_show = False
|
|
|
|
def build(self) -> rio.Component:
|
|
return rio.Column(
|
|
rio.Popup(
|
|
anchor=rio.Text(
|
|
text="Check in devices to storage:",
|
|
style='heading1',
|
|
align_x = 0.5
|
|
),
|
|
color=self.bind().popup_color,
|
|
is_open=self.bind().popup_show,
|
|
content=rio.Text(
|
|
text=self.bind().popup_message,
|
|
),
|
|
|
|
),
|
|
rio.TextInput(
|
|
label="Barcode",
|
|
text=self.bind().code
|
|
),
|
|
rio.TextInput(
|
|
label="New location",
|
|
text=self.bind().loc,
|
|
on_change=self._update_location
|
|
),
|
|
rio.TextInput(
|
|
label="User",
|
|
text=self.bind().name,
|
|
on_confirm=self._checkin_item_enter
|
|
),
|
|
rio.Button(
|
|
content="Go"
|
|
),
|
|
|
|
spacing=2,
|
|
min_width=60,
|
|
margin_bottom=4,
|
|
align_x=0.5,
|
|
align_y=0,
|
|
)
|
|
|