Added version select in session, removed get_profile_data_ignore_version, renamed scripts file

This commit is contained in:
Wanich Keatkajonjumroen 2023-09-09 06:55:18 +09:00
parent d584b93ca5
commit ed46ea33e3
6 changed files with 52 additions and 32 deletions

View File

@ -21,6 +21,7 @@ class IUserSession(Interface):
userId = Attribute("User's ID") userId = Attribute("User's ID")
current_ip = Attribute("User's current ip address") current_ip = Attribute("User's current ip address")
permissions = Attribute("User's permission level") permissions = Attribute("User's permission level")
ongeki_version = Attribute("User's selected Ongeki Version")
class PermissionOffset(Enum): class PermissionOffset(Enum):
USER = 0 # Regular user USER = 0 # Regular user
@ -36,6 +37,7 @@ class UserSession(object):
self.userId = 0 self.userId = 0
self.current_ip = "0.0.0.0" self.current_ip = "0.0.0.0"
self.permissions = 0 self.permissions = 0
self.ongeki_version = 7
class FrontendServlet(resource.Resource): class FrontendServlet(resource.Resource):

View File

@ -26,7 +26,7 @@ class OngekiFrontend(FE_Base):
yaml.safe_load(open(f"{cfg_dir}/{OngekiConstants.CONFIG_NAME}")) yaml.safe_load(open(f"{cfg_dir}/{OngekiConstants.CONFIG_NAME}"))
) )
self.nav_name = "O.N.G.E.K.I." self.nav_name = "O.N.G.E.K.I."
self.version = 7 self.version_list = OngekiConstants.VERSION_NAMES
def render_GET(self, request: Request) -> bytes: def render_GET(self, request: Request) -> bytes:
template = self.environment.get_template( template = self.environment.get_template(
@ -34,15 +34,14 @@ class OngekiFrontend(FE_Base):
) )
sesh: Session = request.getSession() sesh: Session = request.getSession()
usr_sesh = IUserSession(sesh) usr_sesh = IUserSession(sesh)
self.version = usr_sesh.ongeki_version
if getattr(usr_sesh, "userId", 0) != 0: if getattr(usr_sesh, "userId", 0) != 0:
profile_data =self.data.profile.get_profile_data_ignore_version(usr_sesh.userId) profile_data =self.data.profile.get_profile_data(usr_sesh.userId, self.version)
rival_list = self.data.profile.get_rivals(usr_sesh.userId) rival_list = self.data.profile.get_rivals(usr_sesh.userId)
rival_data = { rival_data = {
"userRivalList": rival_list, "userRivalList": rival_list,
"userId": usr_sesh.userId "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) rival_info = OngekiBase.handle_get_user_rival_data_api_request(self, rival_data)
return template.render( return template.render(
@ -52,6 +51,8 @@ class OngekiFrontend(FE_Base):
gachas=self.game_cfg.gachas.enabled_gachas, gachas=self.game_cfg.gachas.enabled_gachas,
profile_data=profile_data, profile_data=profile_data,
rival_info=rival_info["userRivalDataList"], rival_info=rival_info["userRivalDataList"],
version_list=self.version_list,
version=self.version,
sesh=vars(usr_sesh) sesh=vars(usr_sesh)
).encode("utf-16") ).encode("utf-16")
else: else:
@ -67,12 +68,19 @@ class OngekiFrontend(FE_Base):
self.data.profile.put_rival(usr_sesh.userId, rival_id) self.data.profile.put_rival(usr_sesh.userId, rival_id)
# self.logger.info(f"{usr_sesh.userId} added a rival") # self.logger.info(f"{usr_sesh.userId} added a rival")
return redirectTo(b"/game/ongeki/", request) return redirectTo(b"/game/ongeki/", request)
elif uri == "/game/ongeki/rival.delete": elif uri == "/game/ongeki/rival.delete":
rival_id = request.args[b"rivalUserId"][0].decode() rival_id = request.args[b"rivalUserId"][0].decode()
self.data.profile.delete_rival(usr_sesh.userId, rival_id) self.data.profile.delete_rival(usr_sesh.userId, rival_id)
# self.logger.info(f"{response}") # self.logger.info(f"{response}")
return redirectTo(b"/game/ongeki/", request) return redirectTo(b"/game/ongeki/", request)
elif uri == "/game/ongeki/version.change":
ongeki_version=request.args[b"version"][0].decode()
if(ongeki_version.isdigit()):
usr_sesh.ongeki_version=int(ongeki_version)
return redirectTo(b"/game/ongeki/", request)
else: else:
return b"Something went wrong" return b"Something went wrong"
else: else:

View File

@ -0,0 +1,24 @@
function deleteRival(rivalUserId){
$(document).ready(function () {
$.post("/game/ongeki/rival.delete",
{
rivalUserId
},
function(data,status){
window.location.replace("/game/ongeki/")
})
});
}
function changeVersion(sel){
$(document).ready(function () {
$.post("/game/ongeki/version.change",
{
version: sel.value
},
function(data,status){
window.location.replace("/game/ongeki/")
})
});
}

View File

@ -1,12 +0,0 @@
function deleteRival(rivalUserId){
$(document).ready(function () {
$.post("/game/ongeki/rival.delete",
{
rivalUserId
},
function(data,status){
window.location.replace("/game/ongeki/")
})
});
}

View File

@ -9,15 +9,24 @@
<div class="container"> <div class="container">
<div class="row"> <div class="row">
<h2> Profile </h2> <h2> Profile </h2>
<h3>Version:
<select name="version" id="version" onChange="changeVersion(this)">
{% for ver in version_list %}
<option value={{loop.index0}} {{ "selected" if loop.index0==version else "" }} >{{ver}}</option>
{% endfor %}
</select>
</h3>
<hr>
</div> </div>
<div class="row"> <div class="row">
<div class="col"> <div class="col">
<h2> {{ profile_data.userName }}</h2> <h2> Name: {{ profile_data.userName if profile_data.userName is defined else "Profile not found" }}</h2>
</div> </div>
<div class="col"> <div class="col">
<h4> ID: {{ profile_data.user}}</h4> <h4> ID: {{ profile_data.user if profile_data.user is defined else 'Profile not found' }}</h4>
</div> </div>
</div> </div>
<hr>
<div class="row"> <div class="row">
<h2> Rivals <button class="btn btn-success" data-bs-toggle="modal" data-bs-target="#rival_add">Add</button></h2> <h2> Rivals <button class="btn btn-success" data-bs-toggle="modal" data-bs-target="#rival_add">Add</button></h2>
</div> </div>
@ -66,7 +75,7 @@
</div> </div>
<script> <script>
{% include 'titles/ongeki/frontend/js/rival_scripts.js' %} {% include 'titles/ongeki/frontend/js/ongeki_scripts.js' %}
</script> </script>
{% else %} {% else %}
<h2>Not Currently Logged In</h2> <h2>Not Currently Logged In</h2>

View File

@ -295,17 +295,6 @@ class OngekiProfileData(BaseData):
return None return None
return result.fetchone() 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]: def get_profile_options(self, aime_id: int) -> Optional[Row]:
sql = select(option).where( sql = select(option).where(
and_( and_(