From aa17f99252e931556dddda068500027863bc5801 Mon Sep 17 00:00:00 2001 From: Kevin Trocolli Date: Tue, 19 Sep 2023 02:31:29 -0400 Subject: [PATCH] frontend: add placeholders, arcade search by IP --- core/data/schema/arcade.py | 11 +++++++++-- core/frontend.py | 30 ++++++++++++++++++++---------- core/frontend/sys/index.jinja | 11 ++++++++--- 3 files changed, 37 insertions(+), 15 deletions(-) diff --git a/core/data/schema/arcade.py b/core/data/schema/arcade.py index 31d48f6..ce7c30a 100644 --- a/core/data/schema/arcade.py +++ b/core/data/schema/arcade.py @@ -218,9 +218,16 @@ class ArcadeData(BaseData): return True - def find_arcade_by_name(self, name: str) -> List[Row]: + def get_arcade_by_name(self, name: str) -> Optional[List[Row]]: sql = arcade.select(or_(arcade.c.name.like(f"%{name}%"), arcade.c.nickname.like(f"%{name}%"))) result = self.execute(sql) if result is None: - return False + return None + return result.fetchall() + + def get_arcades_by_ip(self, ip: str) -> Optional[List[Row]]: + sql = arcade.select().where(arcade.c.ip == ip) + result = self.execute(sql) + if result is None: + return None return result.fetchall() diff --git a/core/frontend.py b/core/frontend.py index 7b028ee..d091ed4 100644 --- a/core/frontend.py +++ b/core/frontend.py @@ -304,9 +304,9 @@ class FE_System(FE_Base): def render_GET(self, request: Request): uri = request.uri.decode() template = self.environment.get_template("core/frontend/sys/index.jinja") - usrlist = [] - aclist = [] - cablist = [] + usrlist: List[Dict] = [] + aclist: List[Dict] = [] + cablist: List[Dict] = [] sesh: Session = request.getSession() usr_sesh = IUserSession(sesh) @@ -339,21 +339,31 @@ class FE_System(FE_Base): ac_id_search = uri_parse.get("arcadeId") ac_name_search = uri_parse.get("arcadeName") ac_user_search = uri_parse.get("arcadeUser") + ac_ip_search = uri_parse.get("arcadeIp") if ac_id_search is not None: u = self.data.arcade.get_arcade(ac_id_search[0]) - if u is not None: - aclist.append(u._asdict()) + if ul is not None: + if u is not None: + aclist.append(u._asdict()) elif ac_name_search is not None: - ul = self.data.arcade.find_arcade_by_name(ac_name_search[0]) - for u in ul: - aclist.append(u._asdict()) + ul = self.data.arcade.get_arcade_by_name(ac_name_search[0]) + if ul is not None: + for u in ul: + aclist.append(u._asdict()) elif ac_user_search is not None: ul = self.data.arcade.get_arcades_managed_by_user(ac_user_search[0]) - for u in ul: - aclist.append(u._asdict()) + if ul is not None: + for u in ul: + aclist.append(u._asdict()) + + elif ac_ip_search is not None: + ul = self.data.arcade.get_arcades_by_ip(ac_ip_search[0]) + if ul is not None: + for u in ul: + aclist.append(u._asdict()) elif uri.startswith("/sys/lookup.cab?"): uri_parse = parse.parse_qs(uri.replace("/sys/lookup.cab?", "")) # lop off the first bit diff --git a/core/frontend/sys/index.jinja b/core/frontend/sys/index.jinja index 2da821e..d053d3e 100644 --- a/core/frontend/sys/index.jinja +++ b/core/frontend/sys/index.jinja @@ -44,6 +44,11 @@ + OR +
+ + +

@@ -75,19 +80,19 @@ {% if sesh.permissions >= 2 %}
{% for usr in usrlist %} -
{{ usr.id }} | {{ usr.username }}
+
{{ usr.id }} | {{ usr.username if usr.username is defined else "No Name Set"}}
{% endfor %}
{% endif %} {% if sesh.permissions >= 4 %}
{% for ac in aclist %} -
{{ ac.id }} | {{ ac.name }}
+
{{ ac.id }} | {{ ac.name if ac.name is defined else "No Name Set" }} | {{ ac.ip if ac.ip is defined else "No IP Assigned"}}
{% endfor %}
{% for cab in cablist %} -
{{ cab.id }} | {{ cab.game if cab.game is defined else "ANY "  }} | {{ cab.serial }}
+
{{ cab.id }} | {{ cab.game if cab.game is defined else "No Game Assigned" }} | {{ cab.serial }}
{% endfor %}
{% endif %}