diff --git a/inventory/pages/browse_page.py b/inventory/pages/browse_page.py index 08a1bac..8280848 100644 --- a/inventory/pages/browse_page.py +++ b/inventory/pages/browse_page.py @@ -11,6 +11,7 @@ from .add_page import AddPage from db_classes import * import functools import asyncio +from time import time class BrowsePage(rio.Component): searchtext: str = "" @@ -48,16 +49,27 @@ class BrowsePage(rio.Component): icheckout_times: str ="" ibarcode: str ="" idesc: str ="" + + loading_text: str = "Loading..." @rio.event.on_populate async def _search(self, query=searchtext): + self.loading_text = "Searching..." + start = time() self.office = self.session[comps.Settings].office #print("Office:",self.office) self.filters['office'] = self.office - self.items = search_item(query, self.filters) + mid = time() + self.loading_text = "Loading data..." await self.force_refresh() + end = time() + self.loading_text = "" + render = str(int((end - mid) * 1000)) + "ms" + search = str(int((mid - start) * 1000)) + "ms" + + self.loading_text = search + " search, " + render + " load and render" @rio.event.periodic(1) async def set_office_init(self): @@ -68,6 +80,7 @@ class BrowsePage(rio.Component): await self._search() async def _search_trigger(self, event: rio.TextInputChangeEvent): + self.loading_text = "Loading..." await self._search(event.text) async def copy_info(self, text: str): @@ -220,8 +233,20 @@ class BrowsePage(rio.Component): self.elocation = get_location_id(self.elocation).name def build(self) -> rio.Component: - searchview: rio.ListView = rio.ListView(grow_y=True) + searchview: rio.ListView = rio.ListView(grow_y=True) + check = False + if len(self.searchtext) > 2: + check = True + ref = self.searchtext.lower() + icon_ref = rio.Icon("material/stars", fill=rio.Color.from_hex("#3FBF3F")) + for item in self.items: + icon = None + if check: + # if the search has an exact match anywhere + for val in item.values(): + if type(val) is str and val.lower() == ref: + icon=icon_ref try: loc = item["location"] except: @@ -230,46 +255,50 @@ class BrowsePage(rio.Component): checkout = item["checkout_user"] + " - " + loc else: checkout = loc - icon = None - if len(self.searchtext) > 2: - for key, val in item.items(): - if val == self.searchtext: - # if the search has an exact match anywhere - icon=rio.Icon("material/stars", fill=rio.Color.from_hex("#3FBF3F")) - - searchview.add(rio.SimpleListItem(text=item["fullname"],secondary_text=(item["manufacturer"] + " - Serial: " + item["serial"] + "\n" + checkout), left_child=icon, on_press=functools.partial( - self.click_item_dialog, - code=item["barcode"]))) + + searchview.add(rio.SimpleListItem(text=item["fullname"], + secondary_text=(item["manufacturer"] + " - Serial: " + item["serial"] + "\n" + checkout), + left_child=icon, + on_press=functools.partial( + self.click_item_dialog, + code=item["barcode"] + ) + ) + ) details = rio.ListView(grow_y=True, min_width=40) - - details.add(rio.SimpleListItem(text=self.iname, on_press=functools.partial(self.copy_info, text=self.iname))) - details.add(rio.SimpleListItem(text=self.imanu, on_press=functools.partial(self.copy_info, text=self.imanu))) - details.add(rio.SimpleListItem(text="Serial",secondary_text=self.iserial, on_press=functools.partial(self.copy_info, text=self.iserial))) - details.add(rio.SimpleListItem(text="MAC",secondary_text=self.imac, on_press=functools.partial(self.copy_info, text=self.imac))) - details.add(rio.SimpleListItem(text="FW Version",secondary_text=self.ifw, on_press=functools.partial(self.copy_info, text=self.ifw))) - details.add(rio.SimpleListItem(text="Location",secondary_text=self.iloc, on_press=functools.partial(self.copy_info, text=self.iloc))) - details.add(rio.SimpleListItem(text="Checked out?",secondary_text=self.icheckouts, on_press=functools.partial(self.copy_info, text=self.icheckouts))) - details.add(rio.SimpleListItem(text="Checkout start/end",secondary_text=self.icheckout_times, on_press=functools.partial(self.copy_info, text=self.icheckout_times))) - #details.add(rio.SimpleListItem(text="Office",secondary_text=office, on_press=functools.partial(copy_info, text=office))) - details.add(rio.SimpleListItem(text="Barcode",secondary_text=self.ibarcode, on_press=functools.partial(self.copy_info, text=self.ibarcode))) - details.add(rio.SimpleListItem(text="Description",secondary_text=self.idesc, on_press=functools.partial(self.copy_info, text=self.idesc))) - + if self.info_show: + details.add(rio.SimpleListItem(text=self.iname, on_press=functools.partial(self.copy_info, text=self.iname))) + details.add(rio.SimpleListItem(text=self.imanu, on_press=functools.partial(self.copy_info, text=self.imanu))) + details.add(rio.SimpleListItem(text="Serial",secondary_text=self.iserial, on_press=functools.partial(self.copy_info, text=self.iserial))) + details.add(rio.SimpleListItem(text="MAC",secondary_text=self.imac, on_press=functools.partial(self.copy_info, text=self.imac))) + details.add(rio.SimpleListItem(text="FW Version",secondary_text=self.ifw, on_press=functools.partial(self.copy_info, text=self.ifw))) + details.add(rio.SimpleListItem(text="Location",secondary_text=self.iloc, on_press=functools.partial(self.copy_info, text=self.iloc))) + details.add(rio.SimpleListItem(text="Checked out?",secondary_text=self.icheckouts, on_press=functools.partial(self.copy_info, text=self.icheckouts))) + details.add(rio.SimpleListItem(text="Checkout start/end",secondary_text=self.icheckout_times, on_press=functools.partial(self.copy_info, text=self.icheckout_times))) + #details.add(rio.SimpleListItem(text="Office",secondary_text=office, on_press=functools.partial(copy_info, text=office))) + details.add(rio.SimpleListItem(text="Barcode",secondary_text=self.ibarcode, on_press=functools.partial(self.copy_info, text=self.ibarcode))) + details.add(rio.SimpleListItem(text="Description",secondary_text=self.idesc, on_press=functools.partial(self.copy_info, text=self.idesc))) + return rio.Column( - rio.Row( - rio.TextInput( - text=self.bind().searchtext, - on_change=self._search_trigger, - label="Search" - ) + rio.TextInput( + text=self.bind().searchtext, + on_change=self._search_trigger, + label="Search" ), + rio.Text( + text=self.bind().loading_text, + style='heading3', + align_x = 0.5, + align_y = 0, + ), rio.Popup( anchor=rio.Text( text="", - style='heading1', + style='heading3', align_x = 0.5, align_y = 0, ), @@ -304,7 +333,7 @@ class BrowsePage(rio.Component): rio.Popup( anchor=rio.Text( text="", - style='heading1', + style='heading3', align_x = 0.5, align_y = 0, ), @@ -380,7 +409,7 @@ class BrowsePage(rio.Component): rio.Popup( anchor=rio.Text( text="", - style='heading1', + style='heading3', align_x = 0.5 ), color=self.popup_color,