From 147d7adaafc77f43c045794637c6a0be65f9e06d Mon Sep 17 00:00:00 2001 From: Wanich Keatkajonjumroen Date: Sat, 2 Sep 2023 06:21:02 +0900 Subject: [PATCH] Frontend for adding rivals, versionless backend function to support --- core/frontend/index.jinja | 3 + titles/ongeki/frontend.py | 54 ++++++++++++++---- titles/ongeki/frontend/ongeki_index.jinja | 69 ++++++++++++++++++++++- titles/ongeki/schema/profile.py | 15 ++++- 4 files changed, 127 insertions(+), 14 deletions(-) diff --git a/core/frontend/index.jinja b/core/frontend/index.jinja index 7e4a1ca..fa89fc3 100644 --- a/core/frontend/index.jinja +++ b/core/frontend/index.jinja @@ -77,6 +77,9 @@ margin-bottom: 10px; width: 15%; } + .modal-content { + background-color: #181a1b; + } diff --git a/titles/ongeki/frontend.py b/titles/ongeki/frontend.py index 0ec05c1..02fe5bf 100644 --- a/titles/ongeki/frontend.py +++ b/titles/ongeki/frontend.py @@ -2,6 +2,7 @@ import yaml import jinja2 from twisted.web.http import Request from os import path +from twisted.web.util import redirectTo from twisted.web.server import Session from core.frontend import FE_Base, IUserSession @@ -10,6 +11,7 @@ from core.config import CoreConfig from titles.ongeki.config import OngekiConfig from titles.ongeki.const import OngekiConstants from titles.ongeki.database import OngekiData +from titles.ongeki.base import OngekiBase class OngekiFrontend(FE_Base): @@ -24,19 +26,51 @@ class OngekiFrontend(FE_Base): yaml.safe_load(open(f"{cfg_dir}/{OngekiConstants.CONFIG_NAME}")) ) self.nav_name = "O.N.G.E.K.I." - self.geki_version = OngekiConstants.VERSION_NAMES[-1]+"?" - print(OngekiConstants.VERSION_NAMES[-1]) + self.version = 7 + def render_GET(self, request: Request) -> bytes: template = self.environment.get_template( "titles/ongeki/frontend/ongeki_index.jinja" ) sesh: Session = request.getSession() usr_sesh = IUserSession(sesh) - - return template.render( - title=f"{self.core_config.server.name} | {self.nav_name}", - game_list=self.environment.globals["game_list"], - gachas=self.game_cfg.gachas.enabled_gachas, - version= self.geki_version, - sesh=vars(usr_sesh) - ).encode("utf-16") + if getattr(usr_sesh, "userId", 0) != 0: + profile_data =self.data.profile.get_profile_data_ignore_version(usr_sesh.userId) + rival_list = self.data.profile.get_rivals(usr_sesh.userId) + rival_data = { + "userRivalList": rival_list, + "userId": usr_sesh.userId + } + self.version = getattr(profile_data, "version" , 7) + if len(rival_list) > 0: + rival_info = OngekiBase.handle_get_user_rival_data_api_request(self, rival_data) + + return template.render( + data=self.data.profile, + title=f"{self.core_config.server.name} | {self.nav_name}", + game_list=self.environment.globals["game_list"], + gachas=self.game_cfg.gachas.enabled_gachas, + profile_data=profile_data, + rival_info=rival_info["userRivalDataList"], + sesh=vars(usr_sesh) + ).encode("utf-16") + else: + return redirectTo(b"/gate/", request) + + def render_POST(self, request: Request): + uri = request.uri.decode() + sesh: Session = request.getSession() + usr_sesh = IUserSession(sesh) + if hasattr(usr_sesh, "userId"): + if uri == "/game/ongeki/rival.add": + rival_id = request.args[b"rivalUserId"][0].decode() + self.data.profile.put_rival(usr_sesh.userId, rival_id) + self.logger.info(f"{usr_sesh.userId} added a rival") + return redirectTo(b"/game/ongeki/", request) + elif uri == "/game/ongeki/rival.delete": + return b"" + + else: + return b"" + else: + return b"User is not logged in" diff --git a/titles/ongeki/frontend/ongeki_index.jinja b/titles/ongeki/frontend/ongeki_index.jinja index ddcdd05..0eb271b 100644 --- a/titles/ongeki/frontend/ongeki_index.jinja +++ b/titles/ongeki/frontend/ongeki_index.jinja @@ -1,8 +1,73 @@ {% extends "core/frontend/index.jinja" %} {% block content %} + +{% if sesh is defined and sesh["userId"] > 0 %}


-

{{ title }}

-Version: {{version}} + +
+
+

Profile

+
+
+
+

{{ profile_data.userName }}

+
+
+

ID: {{ profile_data.user}}

+
+
+
+

Rivals

+
+
+ + + + + + + + + + {% for rival in rival_info%} + + + + + + {% endfor %} + +
IDNameDelete
{{rival.rivalUserId}}{{rival.rivalUserName}}
+
+ +
+ +{# #} +{% else %} +

Not Currently Logged In

+{% endif %} {% endblock content %} \ No newline at end of file diff --git a/titles/ongeki/schema/profile.py b/titles/ongeki/schema/profile.py index f6eeef2..a5bce97 100644 --- a/titles/ongeki/schema/profile.py +++ b/titles/ongeki/schema/profile.py @@ -269,7 +269,7 @@ class OngekiProfileData(BaseData): return None return row["userName"] - + def get_profile_preview(self, aime_id: int, version: int) -> Optional[Row]: sql = ( select([profile, option]) @@ -295,6 +295,17 @@ class OngekiProfileData(BaseData): return None return result.fetchone() + def get_profile_data_ignore_version(self, aime_id: int) -> Optional[Row]: + sql = select(profile).where( + and_( + profile.c.user == aime_id, + ) + ) + + result = self.execute(sql) + if result is None: + return None + return result.fetchone() def get_profile_options(self, aime_id: int) -> Optional[Row]: sql = select(option).where( and_( @@ -499,7 +510,7 @@ class OngekiProfileData(BaseData): def put_rival(self, aime_id: int, rival_id: int) -> Optional[int]: sql = insert(rival).values(user=aime_id, rivalUserId=rival_id) - conflict = sql.on_duplicate_key_update(rival=rival_id) + conflict = sql.on_duplicate_key_update(rivalUserId=rival_id) result = self.execute(conflict) if result is None: