From d9d2b2485925dacedc249d2a303d4fb2584e9e33 Mon Sep 17 00:00:00 2001
From: Thomas Rubini <74205383+ThomasRubini@users.noreply.github.com>
Date: Thu, 23 Mar 2023 21:06:11 +0100
Subject: [PATCH 01/12] fix css resource path
---
truthinquiry/templates/admin/npc.html | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/truthinquiry/templates/admin/npc.html b/truthinquiry/templates/admin/npc.html
index f4a03b7..edb233f 100644
--- a/truthinquiry/templates/admin/npc.html
+++ b/truthinquiry/templates/admin/npc.html
@@ -3,7 +3,7 @@
NPC
-
+
From 1862ef9274811b4dba8872461e15898cadd6cd84 Mon Sep 17 00:00:00 2001
From: Thomas Rubini <74205383+ThomasRubini@users.noreply.github.com>
Date: Fri, 24 Mar 2023 11:42:55 +0100
Subject: [PATCH 02/12] Remove debug calls to print()
---
truthinquiry/logic/game_logic.py | 1 -
truthinquiry/routes/routes_api.py | 3 ---
truthinquiry/routes/routes_ui.py | 1 -
3 files changed, 5 deletions(-)
diff --git a/truthinquiry/logic/game_logic.py b/truthinquiry/logic/game_logic.py
index 1e2b126..2e7bcb8 100644
--- a/truthinquiry/logic/game_logic.py
+++ b/truthinquiry/logic/game_logic.py
@@ -132,7 +132,6 @@ class Game:
:param npc_id: the id of the npc, to get the reactions from, must be in the current game
:return: the reaction image as bytes
"""
- print(self.reaction_table)
if npc_id not in self.reaction_table:
return None
trait_id = self.reaction_table[npc_id]
diff --git a/truthinquiry/routes/routes_api.py b/truthinquiry/routes/routes_api.py
index 25ed9ee..c3728a0 100644
--- a/truthinquiry/routes/routes_api.py
+++ b/truthinquiry/routes/routes_api.py
@@ -35,9 +35,6 @@ def create_game():
@routes_api.route("/getGameMembers", methods=["GET", "POST"])
def get_members():
game_id = flask.request.values.get("game_id")
- print(50 * "#")
- print(game_id)
- print(50*"_")
game = game_logic.get_game(game_id)
if game is None:
return {"error": 1, "msg": "this game doesn't exist"}
diff --git a/truthinquiry/routes/routes_ui.py b/truthinquiry/routes/routes_ui.py
index a1410fe..e2ffd18 100644
--- a/truthinquiry/routes/routes_ui.py
+++ b/truthinquiry/routes/routes_ui.py
@@ -34,7 +34,6 @@ def lobbyRedirect():
@routes_ui.route("/lobby/")
def lobby(game_id):
# rendered by the javascript client-side
- print(game_id)
if game_id is None:
return flask.redirect("")
return flask.render_template("lobby.html", gameid=game_id)
From 55018c90bb4dd192f2c8ccad3c101e8ebb3fd7ad Mon Sep 17 00:00:00 2001
From: Thomas Rubini <74205383+ThomasRubini@users.noreply.github.com>
Date: Sat, 25 Mar 2023 20:16:48 +0100
Subject: [PATCH 03/12] add utility fucntions to query texts from locales
---
truthinquiry/ext/database/models.py | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/truthinquiry/ext/database/models.py b/truthinquiry/ext/database/models.py
index f47cb99..c872d9b 100644
--- a/truthinquiry/ext/database/models.py
+++ b/truthinquiry/ext/database/models.py
@@ -50,6 +50,27 @@ class Locale(Base):
def __repr__(self) -> str:
return self.__str__()
+ def get_texts(self, lang):
+ texts = []
+ for text in self.TEXTS:
+ if text.LANG == lang:
+ texts.append(text)
+ return texts
+
+ def get_text(self, lang, auto_create):
+ for text in self.TEXTS:
+ if text.LANG == lang:
+ return text
+
+ if auto_create:
+ text = Text(None, None, lang, None)
+ self.TEXTS.append(text)
+ return text
+ else:
+ return None
+
+
+
class Place(Base):
"""
From ccac9c302cb642ffd46802cd6c02b70a918fc880 Mon Sep 17 00:00:00 2001
From: Thomas Rubini <74205383+ThomasRubini@users.noreply.github.com>
Date: Sat, 25 Mar 2023 20:17:05 +0100
Subject: [PATCH 04/12] Connect npc view to backend
---
truthinquiry/routes/routes_admin.py | 1 +
truthinquiry/routes/routes_api_admin.py | 24 +++++++++++++++++++
truthinquiry/static/js/admin.js | 24 +++++++++++++++++++
truthinquiry/templates/admin/npc.html | 32 +++++++++++++++----------
4 files changed, 68 insertions(+), 13 deletions(-)
diff --git a/truthinquiry/routes/routes_admin.py b/truthinquiry/routes/routes_admin.py
index a48ec4b..e20db2b 100644
--- a/truthinquiry/routes/routes_admin.py
+++ b/truthinquiry/routes/routes_admin.py
@@ -25,6 +25,7 @@ def npc(npc_id):
npc_answers.append(answer_list)
npc_dict = {
+ "id": npc_obj.NPC_ID,
"name": npc_obj.LOCALE.TEXTS[0].TEXT,
"img": npc_obj.NPC_ID,
"answers": npc_answers,
diff --git a/truthinquiry/routes/routes_api_admin.py b/truthinquiry/routes/routes_api_admin.py
index 42a29db..87a052a 100644
--- a/truthinquiry/routes/routes_api_admin.py
+++ b/truthinquiry/routes/routes_api_admin.py
@@ -121,4 +121,28 @@ def set_places():
db.session.commit()
+ return {"error": 0}
+
+@routes_api_admin.route("/setNpc", methods=["GET", "POST"])
+def set_npc():
+ input_lang = flask.request.json["lang"]
+ input_npc = flask.request.json["npc"]
+
+ if input_npc["id"] == None:
+ npc_obj = Npc(None, None)
+ db.session.add(npc_obj)
+ else:
+ npc_obj = db.session.get(Npc, input_npc["id"])
+
+ npc_obj.LOCALE.get_text(input_lang, True).TEXT = input_npc["name"]
+
+ for answer_type, input_answer_type in zip(npc_obj.ANSWERS, input_npc["allAnswers"]):
+ for text in answer_type.LOCALE.get_texts(input_lang):
+ db.session.delete(text)
+ for input_answer in input_answer_type["answers"]:
+ answer_type.LOCALE.TEXTS.append(Text(None, None, input_lang, input_answer["text"]))
+
+
+ db.session.commit()
+
return {"error": 0}
\ No newline at end of file
diff --git a/truthinquiry/static/js/admin.js b/truthinquiry/static/js/admin.js
index 1923bd7..d8e30cb 100644
--- a/truthinquiry/static/js/admin.js
+++ b/truthinquiry/static/js/admin.js
@@ -92,3 +92,27 @@ function changeLang(){
}
+//functions for npc.html
+
+function saveFormNpc(){
+ let data = {}
+
+ data["id"] = npc.querySelector("#npc_id").value;
+ data["name"] = npc.querySelector("#npc_name").value;
+
+ let allAnswersJson = [];
+ data["allAnswers"] = allAnswersJson;
+
+ for(let answerTypeNode of npc.querySelectorAll(".answerType")){
+ let answersJson = [];
+ let answerTypeJson = {"answers": answersJson};
+ allAnswersJson.push(answerTypeJson);
+
+ for(let answerNode of answerTypeNode.querySelectorAll("input")){
+ answersJson.push({"text": answerNode.value})
+ }
+ }
+
+ makeAPIRequest("admin/setNpc", {"npc": data, "lang": "FR"}, {"content": "json"})
+}
+
diff --git a/truthinquiry/templates/admin/npc.html b/truthinquiry/templates/admin/npc.html
index edb233f..3f04ba7 100644
--- a/truthinquiry/templates/admin/npc.html
+++ b/truthinquiry/templates/admin/npc.html
@@ -4,26 +4,32 @@
NPC
+
go Back
-
-
-
- Answers:
- {%for answer_type in npc.get("answers") or []%}
-