From fa49f1cc769b33280cc5b82b905dc2b1bc3d40e1 Mon Sep 17 00:00:00 2001 From: DahmaneYanis Date: Tue, 19 Dec 2023 10:54:20 +0100 Subject: [PATCH] Can display all tactics in the personal space --- front/style/home.css | 11 ++++- front/views/Home.tsx | 63 +++++++++++++++++++++++--- src/App/Controller/UserController.php | 6 ++- src/Core/Gateway/TacticInfoGateway.php | 25 +++++++++- src/Core/Model/TacticModel.php | 9 ++++ 5 files changed, 103 insertions(+), 11 deletions(-) diff --git a/front/style/home.css b/front/style/home.css index ed496dc..19067f8 100644 --- a/front/style/home.css +++ b/front/style/home.css @@ -33,7 +33,7 @@ background-color: grey; } -#ps-title { +#titlePersonalSpace h2 { text-align: center; } @@ -57,4 +57,13 @@ background-color: black; padding : 1.5%; margin-bottom: 0px; +} + +table { + width: 100%; +} + +td { + text-align: center; + border : 3px solid black; } \ No newline at end of file diff --git a/front/views/Home.tsx b/front/views/Home.tsx index 43de571..b0442ef 100644 --- a/front/views/Home.tsx +++ b/front/views/Home.tsx @@ -7,11 +7,11 @@ interface Tactic { creation_date : string } -export default function Home({ lastTactics } : { lastTactics : Tactic[] }) { +export default function Home({ lastTactics, allTactics } : { lastTactics : Tactic[] , allTactics : Tactic[]}) { return (
- <Body lastTactics={lastTactics}/> + <Body lastTactics={lastTactics} allTactics={allTactics}/> </div> ) } @@ -24,12 +24,12 @@ export function Title() { ) } -export function Body({ lastTactics } : { lastTactics : Tactic[] }) { +export function Body({ lastTactics, allTactics } : { lastTactics : Tactic[], allTactics : Tactic[]}) { const widthPersonalSpace = 67.5; const widthSideMenu = 100-widthPersonalSpace return ( <div id="body"> - <PersonalSpace width = {widthPersonalSpace}/> + <PersonalSpace width = {widthPersonalSpace} allTactics = {allTactics}/> <SideMenu width = {widthSideMenu} lastTactics={lastTactics} /> </div> @@ -49,12 +49,63 @@ export function SideMenu({ width, lastTactics } : { width : number, lastTactics } -export function PersonalSpace({ width }: { width : number }) { +export function PersonalSpace({ width, allTactics }: { width : number, allTactics : Tactic[] }) { return ( <div id="personal-space" style={{ width : width + "%", }}> - <h2 id="ps-title">Espace Personnel</h2> + <TitlePersonalSpace/> + <BodyPersonalSpace allTactics = {allTactics}/> + </div> + ) +} + +function TitlePersonalSpace() { + return ( + <div id="titlePersonalSpace"> + <h2>Espace Personnel</h2> + </div> + ) +} + +function BodyPersonalSpace({ allTactics } : { allTactics : Tactic[]}) { + const nbRow = Math.floor(allTactics.length/3)+1; + let listTactic = Array(nbRow); + for (let i = 0; i < nbRow; i++) { + listTactic[i] = Array(0); + } + let i = 0; + let j = 0; + allTactics.forEach(tactic => { + listTactic[i].push(tactic); + j++; + if (j === 3) { + i++; + j = 0; + } + }) + + i = 0; + while (i < nbRow) { + listTactic[i] = listTactic[i].map((tactic : Tactic) => + <td key={tactic.id}>{tactic.name}</td> + ); + i++; + } + + const data = listTactic.map((tactic, rowIndex) => + <tr key={rowIndex+"row"}> + {tactic} + </tr> + ); + return ( + <div id="bodyPersonalSpace"> + <table> + <tbody key="tbody"> + {data} + </tbody> + </table> + </div> ) } diff --git a/src/App/Controller/UserController.php b/src/App/Controller/UserController.php index bc4e91d..0af4214 100644 --- a/src/App/Controller/UserController.php +++ b/src/App/Controller/UserController.php @@ -24,9 +24,11 @@ class UserController { */ public function home(SessionHandle $session): ViewHttpResponse { $limitNbTactics = 5; - $lastTactic = $this->tactics->getLast($limitNbTactics, $session->getAccount()->getId()); + $lastTactics = $this->tactics->getLast($limitNbTactics, $session->getAccount()->getId()); + $allTactics = $this->tactics->getAll($session->getAccount()->getId()); return ViewHttpResponse::react("views/Home.tsx", [ - "lastTactics" => $lastTactic + "lastTactics" => $lastTactics, + "allTactics" => $allTactics ]); // return ViewHttpResponse::react("views/Home.tsx", []); } diff --git a/src/Core/Gateway/TacticInfoGateway.php b/src/Core/Gateway/TacticInfoGateway.php index 781c525..1714aba 100644 --- a/src/Core/Gateway/TacticInfoGateway.php +++ b/src/Core/Gateway/TacticInfoGateway.php @@ -50,8 +50,8 @@ class TacticInfoGateway { "SELECT * FROM Tactic WHERE owner = :ownerId - ORDER BY creation_date - DESC LIMIT :nb", + ORDER BY creation_date DESC + LIMIT :nb", [ ":ownerId" => [$ownerId, PDO::PARAM_INT],":nb" => [$nb, PDO::PARAM_INT] ] @@ -62,6 +62,27 @@ class TacticInfoGateway { return $res; } + /** + * Get all the tactics of the owner + * + * @return array<array<string,mixed>> + */ + public function getAll(int $ownerId): ?array { + $res = $this->con->fetch( + "SELECT * + FROM Tactic + WHERE owner = :ownerId + ORDER BY name DESC", + [ + ":ownerId" => [$ownerId, PDO::PARAM_INT] + ] + ); + if (count($res) == 0) { + return []; + } + return $res; + } + /** * @param string $name * @param int $owner diff --git a/src/Core/Model/TacticModel.php b/src/Core/Model/TacticModel.php index fd8764f..2ee3adb 100644 --- a/src/Core/Model/TacticModel.php +++ b/src/Core/Model/TacticModel.php @@ -66,6 +66,15 @@ class TacticModel { return $this->tactics->getLast($nb, $ownerId); } + /** + * Get all the tactics of the owner + * + * @param integer $ownerId + * @return array|null + */ + public function getAll(int $ownerId): ?array { + return $this->tactics->getAll($ownerId); + } /** * Update the name of a tactic * @param int $id the tactic identifier