frontend: add placeholders, arcade search by IP

This commit is contained in:
Hay1tsme 2023-09-19 02:31:29 -04:00
parent 50de0916d4
commit aa17f99252
3 changed files with 37 additions and 15 deletions

View File

@ -218,9 +218,16 @@ class ArcadeData(BaseData):
return True 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}%"))) sql = arcade.select(or_(arcade.c.name.like(f"%{name}%"), arcade.c.nickname.like(f"%{name}%")))
result = self.execute(sql) result = self.execute(sql)
if result is None: 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() return result.fetchall()

View File

@ -304,9 +304,9 @@ class FE_System(FE_Base):
def render_GET(self, request: Request): def render_GET(self, request: Request):
uri = request.uri.decode() uri = request.uri.decode()
template = self.environment.get_template("core/frontend/sys/index.jinja") template = self.environment.get_template("core/frontend/sys/index.jinja")
usrlist = [] usrlist: List[Dict] = []
aclist = [] aclist: List[Dict] = []
cablist = [] cablist: List[Dict] = []
sesh: Session = request.getSession() sesh: Session = request.getSession()
usr_sesh = IUserSession(sesh) usr_sesh = IUserSession(sesh)
@ -339,21 +339,31 @@ class FE_System(FE_Base):
ac_id_search = uri_parse.get("arcadeId") ac_id_search = uri_parse.get("arcadeId")
ac_name_search = uri_parse.get("arcadeName") ac_name_search = uri_parse.get("arcadeName")
ac_user_search = uri_parse.get("arcadeUser") ac_user_search = uri_parse.get("arcadeUser")
ac_ip_search = uri_parse.get("arcadeIp")
if ac_id_search is not None: if ac_id_search is not None:
u = self.data.arcade.get_arcade(ac_id_search[0]) u = self.data.arcade.get_arcade(ac_id_search[0])
if u is not None: if ul is not None:
aclist.append(u._asdict()) if u is not None:
aclist.append(u._asdict())
elif ac_name_search is not None: elif ac_name_search is not None:
ul = self.data.arcade.find_arcade_by_name(ac_name_search[0]) ul = self.data.arcade.get_arcade_by_name(ac_name_search[0])
for u in ul: if ul is not None:
aclist.append(u._asdict()) for u in ul:
aclist.append(u._asdict())
elif ac_user_search is not None: elif ac_user_search is not None:
ul = self.data.arcade.get_arcades_managed_by_user(ac_user_search[0]) ul = self.data.arcade.get_arcades_managed_by_user(ac_user_search[0])
for u in ul: if ul is not None:
aclist.append(u._asdict()) 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?"): elif uri.startswith("/sys/lookup.cab?"):
uri_parse = parse.parse_qs(uri.replace("/sys/lookup.cab?", "")) # lop off the first bit uri_parse = parse.parse_qs(uri.replace("/sys/lookup.cab?", "")) # lop off the first bit

View File

@ -44,6 +44,11 @@
<label for="arcadeUser">Owner User ID</label> <label for="arcadeUser">Owner User ID</label>
<input type="number" class="form-control" id="arcadeUser" name="arcadeUser"> <input type="number" class="form-control" id="arcadeUser" name="arcadeUser">
</div> </div>
OR
<div class="form-group">
<label for="arcadeIp">Assigned IP Address</label>
<input type="text" class="form-control" id="arcadeIp" name="arcadeIp">
</div>
<br /> <br />
<button type="submit" class="btn btn-primary">Search</button> <button type="submit" class="btn btn-primary">Search</button>
</form> </form>
@ -75,19 +80,19 @@
{% if sesh.permissions >= 2 %} {% if sesh.permissions >= 2 %}
<div id="userSearchResult" class="col-sm-6" style="max-width: 25%;"> <div id="userSearchResult" class="col-sm-6" style="max-width: 25%;">
{% for usr in usrlist %} {% for usr in usrlist %}
<pre><a href=/user/{{ usr.id }}>{{ usr.id }} | {{ usr.username }}</a></pre> <a href=/user/{{ usr.id }}><pre>{{ usr.id }} | {{ usr.username if usr.username is defined else "<i>No Name Set</i>"}}</pre></a>
{% endfor %} {% endfor %}
</div> </div>
{% endif %} {% endif %}
{% if sesh.permissions >= 4 %} {% if sesh.permissions >= 4 %}
<div id="arcadeSearchResult" class="col-sm-6" style="max-width: 25%;"> <div id="arcadeSearchResult" class="col-sm-6" style="max-width: 25%;">
{% for ac in aclist %} {% for ac in aclist %}
<pre><a href=/arcade/{{ ac.id }}>{{ ac.id }} | {{ ac.name }}</a></pre> <pre><a href=/arcade/{{ ac.id }}>{{ ac.id }} | {{ ac.name if ac.name is defined else "<i>No Name Set</i>" }} | {{ ac.ip if ac.ip is defined else "<i>No IP Assigned</i>"}}</pre></a>
{% endfor %} {% endfor %}
</div </div
><div id="cabSearchResult" class="col-sm-6" style="max-width: 25%;"> ><div id="cabSearchResult" class="col-sm-6" style="max-width: 25%;">
{% for cab in cablist %} {% for cab in cablist %}
<a href=/cab/{{ cab.id }}><pre>{{ cab.id }} | {{ cab.game if cab.game is defined else "ANY " }} | {{ cab.serial }}</pre></a> <a href=/cab/{{ cab.id }}><pre>{{ cab.id }} | {{ cab.game if cab.game is defined else "<i>No Game Assigned</i>" }} | {{ cab.serial }}</pre></a>
{% endfor %} {% endfor %}
</div> </div>
{% endif %} {% endif %}