From 5ef36b754cb94fc33f27780abcc0c09409b9612d Mon Sep 17 00:00:00 2001 From: d_yanis Date: Mon, 4 Dec 2023 16:17:49 +0100 Subject: [PATCH 01/13] Add a basic react view with html component --- .vscode/launch.json | 38 +++++++++++++++++++++++++++ config.php | 3 +-- front/views/Home.tsx | 7 +++++ public/index.php | 4 +-- src/App/Controller/UserController.php | 4 +-- 5 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 front/views/Home.tsx diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..0aaa092 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,38 @@ +{ + // Utilisez IntelliSense pour en savoir plus sur les attributs possibles. + // Pointez pour afficher la description des attributs existants. + // Pour plus d'informations, visitez : https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Launch built-in server and debug", + "type": "php", + "request": "launch", + "runtimeArgs": [ + "-S", + "localhost:8080", + "-t", + "./public" + ], + "port": 8080, + "serverReadyAction": { + "action": "openExternally" + } + }, + { + "name": "Debug current script in console", + "type": "php", + "request": "launch", + "program": "${file}", + "cwd": "${fileDirname}", + "externalConsole": false, + "port": 9003 + }, + { + "name": "Listen for Xdebug", + "type": "php", + "request": "launch", + "port": 9003 + } + ] +} \ No newline at end of file diff --git a/config.php b/config.php index 6e510c8..c65c3db 100644 --- a/config.php +++ b/config.php @@ -10,7 +10,6 @@ const SUPPORTS_FAST_REFRESH = _SUPPORTS_FAST_REFRESH; /** * Maps the given relative source uri (relative to the `/front` folder) to its actual location depending on imported profile. * @param string $assetURI relative uri path from `/front` folder - * @return string valid url that points to the given uri */ function asset(string $assetURI): string { return _asset($assetURI); @@ -19,4 +18,4 @@ function asset(string $assetURI): string { global $_data_source_name; $data_source_name = $_data_source_name; const DATABASE_USER = _DATABASE_USER; -const DATABASE_PASSWORD = _DATABASE_PASSWORD; +const DATABASE_PASSWORD = _DATABASE_PASSWORD; \ No newline at end of file diff --git a/front/views/Home.tsx b/front/views/Home.tsx new file mode 100644 index 0000000..9e506fa --- /dev/null +++ b/front/views/Home.tsx @@ -0,0 +1,7 @@ +export default function Home(){ + return ( +
+

Home

+
+ ) +} \ No newline at end of file diff --git a/public/index.php b/public/index.php index 78ee4d6..964abcd 100644 --- a/public/index.php +++ b/public/index.php @@ -1,6 +1,5 @@ match(), PhpSessionHandle::init()), fn() => getTwig()); +App::render(runMatch(getRoutes()->match(), PhpSessionHandle::init()), fn() => getTwig()); \ No newline at end of file diff --git a/src/App/Controller/UserController.php b/src/App/Controller/UserController.php index d6f9f89..2f7485d 100644 --- a/src/App/Controller/UserController.php +++ b/src/App/Controller/UserController.php @@ -21,9 +21,7 @@ class UserController { * @return ViewHttpResponse the home page view */ public function home(SessionHandle $session): ViewHttpResponse { - //TODO use session's account to get the last 5 tactics of the logged-in account - $listTactic = $this->tactics->getLast(5); - return ViewHttpResponse::twig("home.twig", ["recentTactic" => $listTactic]); + return ViewHttpResponse::react("views/Home.tsx", []); } /** From 3aa7919393e55862f19e3b6ba5a6cc5ef9fb8635 Mon Sep 17 00:00:00 2001 From: d_yanis Date: Mon, 4 Dec 2023 18:13:02 +0100 Subject: [PATCH 02/13] Add the css of the page --- front/style/home.css | 7 +++++++ front/views/Home.tsx | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 front/style/home.css diff --git a/front/style/home.css b/front/style/home.css new file mode 100644 index 0000000..d9c37f9 --- /dev/null +++ b/front/style/home.css @@ -0,0 +1,7 @@ +#IQ { + color : red; +} + +#B { + color : blue; +} \ No newline at end of file diff --git a/front/views/Home.tsx b/front/views/Home.tsx index 9e506fa..fb50fb7 100644 --- a/front/views/Home.tsx +++ b/front/views/Home.tsx @@ -1,7 +1,9 @@ +import "../style/home.css" + export default function Home(){ return (
-

Home

+

IQBall

) } \ No newline at end of file From 23a0039fe44de7da0710e8b7c85e137157b24836 Mon Sep 17 00:00:00 2001 From: d_yanis Date: Mon, 4 Dec 2023 19:02:56 +0100 Subject: [PATCH 03/13] WIP Page Home integration img --- front/style/home.css | 4 ++++ front/views/Home.tsx | 22 ++++++++++++++++++++-- public/index.php | 2 ++ src/App/Controller/UserController.php | 4 ++++ 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/front/style/home.css b/front/style/home.css index d9c37f9..4f11371 100644 --- a/front/style/home.css +++ b/front/style/home.css @@ -4,4 +4,8 @@ #B { color : blue; +} + +#IQBall { + text-align: center; } \ No newline at end of file diff --git a/front/views/Home.tsx b/front/views/Home.tsx index fb50fb7..2d2d0be 100644 --- a/front/views/Home.tsx +++ b/front/views/Home.tsx @@ -2,8 +2,26 @@ import "../style/home.css" export default function Home(){ return ( -
-

IQBall

+
+ + <Body/> + </div> + ) +} + +export function Title(){ + return( + <div id="title"> + <h1 id="IQBall"><span id="IQ">IQ</span><span id="B">B</span>all</h1> + <img src=""></img> + </div> + ) +} + +export function Body(){ + return( + <div id="body"> + </div> ) } \ No newline at end of file diff --git a/public/index.php b/public/index.php index 964abcd..c42c889 100644 --- a/public/index.php +++ b/public/index.php @@ -102,6 +102,8 @@ function getRoutes(): AltoRouter { $ar->map("GET", "/team/members/remove", Action::auth(fn(SessionHandle $s) => getTeamController()->displayDeleteMember($s))); $ar->map("POST", "/team/members/remove", Action::auth(fn(SessionHandle $s) => getTeamController()->deleteMember($_POST, $s))); + //temp + $ar->map("GET", "/test", Action::auth(fn(SessionHandle $s) => getUserController()->homeTwig($s))); return $ar; } diff --git a/src/App/Controller/UserController.php b/src/App/Controller/UserController.php index 2f7485d..37aae73 100644 --- a/src/App/Controller/UserController.php +++ b/src/App/Controller/UserController.php @@ -24,6 +24,10 @@ class UserController { return ViewHttpResponse::react("views/Home.tsx", []); } + public function homeTwig(SessionHandle $session): ViewHttpResponse { + return ViewHttpResponse::twig("home.twig", []); + } + /** * @return ViewHttpResponse account settings page */ From 6d36115204ecf52a322ac00a4fefe52bbca0b762 Mon Sep 17 00:00:00 2001 From: d_yanis <dahmane.yanis.2004@gmail.com> Date: Tue, 5 Dec 2023 17:31:31 +0100 Subject: [PATCH 04/13] WIP page home --- front/style/home/global.css | 5 +++ front/style/home/tactic.css | 10 ++++++ front/style/{home.css => home/titre.css} | 4 +++ front/views/Home.tsx | 40 +++++++++++++++++++----- 4 files changed, 51 insertions(+), 8 deletions(-) create mode 100644 front/style/home/global.css create mode 100644 front/style/home/tactic.css rename front/style/{home.css => home/titre.css} (67%) diff --git a/front/style/home/global.css b/front/style/home/global.css new file mode 100644 index 0000000..f215ab7 --- /dev/null +++ b/front/style/home/global.css @@ -0,0 +1,5 @@ +#main { + margin-left:10%; + margin-right:10%; + background-color: grey; +} \ No newline at end of file diff --git a/front/style/home/tactic.css b/front/style/home/tactic.css new file mode 100644 index 0000000..7dea75e --- /dev/null +++ b/front/style/home/tactic.css @@ -0,0 +1,10 @@ +#titreTactic { + background-color: red; + padding-right : 10px; + margin-top : 10px; +} + +#titreTactic h2 { + display: inline; + padding-right : 25px; +} \ No newline at end of file diff --git a/front/style/home.css b/front/style/home/titre.css similarity index 67% rename from front/style/home.css rename to front/style/home/titre.css index 4f11371..199c9bc 100644 --- a/front/style/home.css +++ b/front/style/home/titre.css @@ -8,4 +8,8 @@ #IQBall { text-align: center; +} + +#title { + background-color: aqua; } \ No newline at end of file diff --git a/front/views/Home.tsx b/front/views/Home.tsx index 2d2d0be..72643ab 100644 --- a/front/views/Home.tsx +++ b/front/views/Home.tsx @@ -1,16 +1,18 @@ -import "../style/home.css" +import "../style/home/global.css" +import "../style/home/tactic.css" +import "../style/home/titre.css" -export default function Home(){ +export default function Home() { return ( - <div id="main-div"> + <div id="main"> <Title/> <Body/> </div> ) } -export function Title(){ - return( +export function Title() { + return ( <div id="title"> <h1 id="IQBall"><span id="IQ">IQ</span><span id="B">B</span>all</h1> <img src=""></img> @@ -18,10 +20,32 @@ export function Title(){ ) } -export function Body(){ - return( + +export function Body() { + return ( <div id="body"> - + <Team/> + <Tactic/> + </div> + ) +} + +export function Team() { + return ( + <div id="team"> + <h2>Mes équipes</h2> + <button id="createTeam">+</button> + </div> + ) +} + +export function Tactic() { + return ( + <div id="tactic"> + <div id="titreTactic"> + <h2>Mes stratégies</h2> + <button id="createTactic" onClick={location.pathname = "/tactic/new"}>+</button> + </div> </div> ) } \ No newline at end of file From 86230fc702231743681b4b77ca473569dc536c41 Mon Sep 17 00:00:00 2001 From: d_yanis <dahmane.yanis.2004@gmail.com> Date: Tue, 5 Dec 2023 23:18:30 +0100 Subject: [PATCH 05/13] WIP : Trying to give some argument to the JSView Home --- front/views/Home.tsx | 2 +- src/App/Controller/UserController.php | 18 +++++++++++++++++- src/Core/Model/TacticModel.php | 4 ++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/front/views/Home.tsx b/front/views/Home.tsx index 72643ab..de4eb87 100644 --- a/front/views/Home.tsx +++ b/front/views/Home.tsx @@ -44,7 +44,7 @@ export function Tactic() { <div id="tactic"> <div id="titreTactic"> <h2>Mes stratégies</h2> - <button id="createTactic" onClick={location.pathname = "/tactic/new"}>+</button> + <button id="createTactic" onClick={() => (location.pathname = "/tactic/new")}>+</button> </div> </div> ) diff --git a/src/App/Controller/UserController.php b/src/App/Controller/UserController.php index 37aae73..e5679d3 100644 --- a/src/App/Controller/UserController.php +++ b/src/App/Controller/UserController.php @@ -21,7 +21,23 @@ class UserController { * @return ViewHttpResponse the home page view */ public function home(SessionHandle $session): ViewHttpResponse { - return ViewHttpResponse::react("views/Home.tsx", []); + $lastTactic = $this->tactics->getLast(5); + return ViewHttpResponse::react("views/Home.tsx", $this->listTacticToJson($lastTactic)); + } + + private function listTacticToJson(array $listTactic) : array { + $jsonReturn = []; + foreach ($listTactic as $tactic){ + //var_dump($tactic); + $jsonTactic = [ + "id" => $tactic["id"], + "name" => $tactic["name"], + "creationDate" => $tactic["creation_date"] + ]; + array_push($jsonReturn, $jsonTactic); + } + var_dump($jsonReturn); + return $jsonReturn; } public function homeTwig(SessionHandle $session): ViewHttpResponse { diff --git a/src/Core/Model/TacticModel.php b/src/Core/Model/TacticModel.php index 136b27d..9a71f4f 100644 --- a/src/Core/Model/TacticModel.php +++ b/src/Core/Model/TacticModel.php @@ -54,6 +54,10 @@ class TacticModel { * @param integer $nb * @return array<array<string,mixed>> */ + + /** + * Return the nb last tactics + */ public function getLast(int $nb): ?array { return $this->tactics->getLast($nb); } From 5668519c335b69d3aa15505c9eac6134d85efd02 Mon Sep 17 00:00:00 2001 From: d_yanis <dahmane.yanis.2004@gmail.com> Date: Mon, 11 Dec 2023 17:29:20 +0100 Subject: [PATCH 06/13] Add the display of tactic name --- front/style/home.css | 10 ++++++++++ front/style/home/global.css | 5 ----- front/style/home/tactic.css | 10 ---------- front/style/home/titre.css | 15 --------------- front/views/Home.tsx | 23 +++++++++++++++++------ src/App/Controller/UserController.php | 7 +++++-- 6 files changed, 32 insertions(+), 38 deletions(-) create mode 100644 front/style/home.css delete mode 100644 front/style/home/global.css delete mode 100644 front/style/home/tactic.css delete mode 100644 front/style/home/titre.css diff --git a/front/style/home.css b/front/style/home.css new file mode 100644 index 0000000..e175e68 --- /dev/null +++ b/front/style/home.css @@ -0,0 +1,10 @@ +/* #header { + background-color: var(--white); + transition: box-shadow .3s linear; + outline: 0; + box-shadow: 0 10px 15px #00000026; +} */ + +#header { + +} \ No newline at end of file diff --git a/front/style/home/global.css b/front/style/home/global.css deleted file mode 100644 index f215ab7..0000000 --- a/front/style/home/global.css +++ /dev/null @@ -1,5 +0,0 @@ -#main { - margin-left:10%; - margin-right:10%; - background-color: grey; -} \ No newline at end of file diff --git a/front/style/home/tactic.css b/front/style/home/tactic.css deleted file mode 100644 index 7dea75e..0000000 --- a/front/style/home/tactic.css +++ /dev/null @@ -1,10 +0,0 @@ -#titreTactic { - background-color: red; - padding-right : 10px; - margin-top : 10px; -} - -#titreTactic h2 { - display: inline; - padding-right : 25px; -} \ No newline at end of file diff --git a/front/style/home/titre.css b/front/style/home/titre.css deleted file mode 100644 index 199c9bc..0000000 --- a/front/style/home/titre.css +++ /dev/null @@ -1,15 +0,0 @@ -#IQ { - color : red; -} - -#B { - color : blue; -} - -#IQBall { - text-align: center; -} - -#title { - background-color: aqua; -} \ No newline at end of file diff --git a/front/views/Home.tsx b/front/views/Home.tsx index de4eb87..f757a30 100644 --- a/front/views/Home.tsx +++ b/front/views/Home.tsx @@ -1,19 +1,30 @@ -import "../style/home/global.css" -import "../style/home/tactic.css" -import "../style/home/titre.css" +import "../style/home.css" -export default function Home() { +interface Tactic { + id : number + name : string + creationDate : number +} + +export default function Home({ + tactics +} : { + tactics : Tactic[] +}) { + console.log(tactics); return ( <div id="main"> <Title/> - <Body/> + {tactics.map(tactic => ( + <div>{tactic.name}</div> + ))} </div> ) } export function Title() { return ( - <div id="title"> + <div id="header"> <h1 id="IQBall"><span id="IQ">IQ</span><span id="B">B</span>all</h1> <img src=""></img> </div> diff --git a/src/App/Controller/UserController.php b/src/App/Controller/UserController.php index e5679d3..be5c28f 100644 --- a/src/App/Controller/UserController.php +++ b/src/App/Controller/UserController.php @@ -22,7 +22,10 @@ class UserController { */ public function home(SessionHandle $session): ViewHttpResponse { $lastTactic = $this->tactics->getLast(5); - return ViewHttpResponse::react("views/Home.tsx", $this->listTacticToJson($lastTactic)); + return ViewHttpResponse::react("views/Home.tsx", [ + "tactics" => $lastTactic + ]); + // return ViewHttpResponse::react("views/Home.tsx", []); } private function listTacticToJson(array $listTactic) : array { @@ -36,7 +39,7 @@ class UserController { ]; array_push($jsonReturn, $jsonTactic); } - var_dump($jsonReturn); + // var_dump($jsonReturn); return $jsonReturn; } From 4a2424ac225c9d7f21413252857f9d7aa716debc Mon Sep 17 00:00:00 2001 From: DahmaneYanis <dahmane.yanis.2004@gmail.com> Date: Sun, 17 Dec 2023 22:20:28 +0100 Subject: [PATCH 07/13] WIP Home --- front/views/Home.tsx | 19 ++++++++++++++++--- src/App/Controller/UserController.php | 1 + src/Core/Gateway/TacticInfoGateway.php | 2 +- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/front/views/Home.tsx b/front/views/Home.tsx index f757a30..1deedec 100644 --- a/front/views/Home.tsx +++ b/front/views/Home.tsx @@ -18,6 +18,7 @@ export default function Home({ {tactics.map(tactic => ( <div>{tactic.name}</div> ))} + <Body tactics={tactics}/> </div> ) } @@ -32,11 +33,12 @@ export function Title() { } -export function Body() { + +export function Body({tactics} : {tactics : Tactic[]}) { return ( <div id="body"> <Team/> - <Tactic/> + <Tactic tactics={tactics}/> </div> ) } @@ -50,12 +52,23 @@ export function Team() { ) } -export function Tactic() { +export function Tactic({tactics} : { tactics : Tactic[]}) { + const listTactic = tactics.map(tactic => + <li + key = {tactic.id} + > + {tactic.name} : {tactic.creationDate} + </li> + ); return ( <div id="tactic"> <div id="titreTactic"> <h2>Mes stratégies</h2> <button id="createTactic" onClick={() => (location.pathname = "/tactic/new")}>+</button> + <ul> + {listTactic} + </ul> + </div> </div> ) diff --git a/src/App/Controller/UserController.php b/src/App/Controller/UserController.php index be5c28f..84e9440 100644 --- a/src/App/Controller/UserController.php +++ b/src/App/Controller/UserController.php @@ -22,6 +22,7 @@ class UserController { */ public function home(SessionHandle $session): ViewHttpResponse { $lastTactic = $this->tactics->getLast(5); + var_dump($lastTactic); return ViewHttpResponse::react("views/Home.tsx", [ "tactics" => $lastTactic ]); diff --git a/src/Core/Gateway/TacticInfoGateway.php b/src/Core/Gateway/TacticInfoGateway.php index 447c7a5..985c58a 100644 --- a/src/Core/Gateway/TacticInfoGateway.php +++ b/src/Core/Gateway/TacticInfoGateway.php @@ -49,7 +49,7 @@ class TacticInfoGateway { [":nb" => [$nb, PDO::PARAM_INT]] ); if (count($res) == 0) { - return null; + return []; } return $res; } From 45f2cf3817b8175a5b763e7d85367d81069a50ad Mon Sep 17 00:00:00 2001 From: DahmaneYanis <dahmane.yanis.2004@gmail.com> Date: Mon, 18 Dec 2023 12:01:47 +0100 Subject: [PATCH 08/13] Add the structure and some style --- front/style/home.css | 54 +++++++++++++++++++----- front/views/Home.tsx | 61 +++++++++++++++++---------- front/views/ProfilPage.tsx | 1 + src/App/Controller/UserController.php | 19 +-------- 4 files changed, 86 insertions(+), 49 deletions(-) create mode 100644 front/views/ProfilPage.tsx diff --git a/front/style/home.css b/front/style/home.css index e175e68..198c2af 100644 --- a/front/style/home.css +++ b/front/style/home.css @@ -1,10 +1,44 @@ -/* #header { - background-color: var(--white); - transition: box-shadow .3s linear; - outline: 0; - box-shadow: 0 10px 15px #00000026; -} */ - -#header { - -} \ No newline at end of file + +#main { + margin-left : 2%; + margin-right: 2%; + border : solid 2px purple; + display: flex; + flex-direction: column; + +} + +button { + border-radius: 100%; +} + +#header { + text-align: center; + background-color: green; + margin : 0px; +} + +#body { + display: flex; + flex-direction: row; + border : solid 10px yellow; + margin:0px + } + +#personal-space { + background-color: red; +} + +#sideMenu { + background-color: blue; + +} + +#ps-title { + text-align: center; +} + +#sideMenu h2 { + display: inline-block; + margin-right : 5%; +} diff --git a/front/views/Home.tsx b/front/views/Home.tsx index 1deedec..8a4efb7 100644 --- a/front/views/Home.tsx +++ b/front/views/Home.tsx @@ -1,24 +1,17 @@ import "../style/home.css" +import { CSSProperties } from "react" interface Tactic { id : number name : string - creationDate : number + creation_date : string } -export default function Home({ - tactics -} : { - tactics : Tactic[] -}) { - console.log(tactics); +export default function Home({ lastTactics } : { lastTactics : Tactic[] }) { return ( <div id="main"> <Title/> - {tactics.map(tactic => ( - <div>{tactic.name}</div> - ))} - <Body tactics={tactics}/> + <Body lastTactics={lastTactics}/> </div> ) } @@ -27,18 +20,41 @@ export function Title() { return ( <div id="header"> <h1 id="IQBall"><span id="IQ">IQ</span><span id="B">B</span>all</h1> - <img src=""></img> </div> ) } +export function Body({ lastTactics } : { lastTactics : Tactic[] }) { + const widthPersonalSpace = 70; + const widthSideMenu = 100-widthPersonalSpace + return ( + <div id="body"> + <PersonalSpace width = {widthPersonalSpace}/> + <SideMenu width = {widthSideMenu} lastTactics={lastTactics} /> + + </div> + ) +} +export function SideMenu({ width, lastTactics } : { width : number, lastTactics : Tactic[] }) { -export function Body({tactics} : {tactics : Tactic[]}) { return ( - <div id="body"> + <div id="sideMenu" style={{ + width : width + "%", + }}> <Team/> - <Tactic tactics={tactics}/> + <Tactic lastTactics={lastTactics}/> + </div> + ) +} + + +export function PersonalSpace({ width }: { width : number }) { + return ( + <div id="personal-space" style={{ + width : width + "%", + }}> + <h2 id="ps-title">Espace Personnel</h2> </div> ) } @@ -47,28 +63,29 @@ export function Team() { return ( <div id="team"> <h2>Mes équipes</h2> - <button id="createTeam">+</button> + <button onClick={() => location.pathname="/tactic/new"}>+</button> </div> ) } -export function Tactic({tactics} : { tactics : Tactic[]}) { - const listTactic = tactics.map(tactic => +export function Tactic({lastTactics} : { lastTactics : Tactic[]}) { + + const listTactic = lastTactics.map(tactic => <li key = {tactic.id} > - {tactic.name} : {tactic.creationDate} + {tactic.name} : {tactic.creation_date} + <button onClick={() => {location.pathname="/tactic/"+tactic.id+"/edit"}}>open</button> </li> - ); + ); return ( <div id="tactic"> <div id="titreTactic"> - <h2>Mes stratégies</h2> + <h2>Mes cinq dernières stratégies</h2> <button id="createTactic" onClick={() => (location.pathname = "/tactic/new")}>+</button> <ul> {listTactic} </ul> - </div> </div> ) diff --git a/front/views/ProfilPage.tsx b/front/views/ProfilPage.tsx new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/front/views/ProfilPage.tsx @@ -0,0 +1 @@ + diff --git a/src/App/Controller/UserController.php b/src/App/Controller/UserController.php index 84e9440..e17b357 100644 --- a/src/App/Controller/UserController.php +++ b/src/App/Controller/UserController.php @@ -22,28 +22,13 @@ class UserController { */ public function home(SessionHandle $session): ViewHttpResponse { $lastTactic = $this->tactics->getLast(5); - var_dump($lastTactic); + // var_dump($lastTactic); return ViewHttpResponse::react("views/Home.tsx", [ - "tactics" => $lastTactic + "lastTactics" => $lastTactic ]); // return ViewHttpResponse::react("views/Home.tsx", []); } - private function listTacticToJson(array $listTactic) : array { - $jsonReturn = []; - foreach ($listTactic as $tactic){ - //var_dump($tactic); - $jsonTactic = [ - "id" => $tactic["id"], - "name" => $tactic["name"], - "creationDate" => $tactic["creation_date"] - ]; - array_push($jsonReturn, $jsonTactic); - } - // var_dump($jsonReturn); - return $jsonReturn; - } - public function homeTwig(SessionHandle $session): ViewHttpResponse { return ViewHttpResponse::twig("home.twig", []); } From 7bb93be50c4c2eb5100a12f8c0a830e918f6624f Mon Sep 17 00:00:00 2001 From: DahmaneYanis <dahmane.yanis.2004@gmail.com> Date: Mon, 18 Dec 2023 12:13:53 +0100 Subject: [PATCH 09/13] WIP --- front/style/home.css | 2 +- front/views/Home.tsx | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/front/style/home.css b/front/style/home.css index 198c2af..cc773e6 100644 --- a/front/style/home.css +++ b/front/style/home.css @@ -8,7 +8,7 @@ } -button { +.new { border-radius: 100%; } diff --git a/front/views/Home.tsx b/front/views/Home.tsx index 8a4efb7..4a6425c 100644 --- a/front/views/Home.tsx +++ b/front/views/Home.tsx @@ -63,7 +63,7 @@ export function Team() { return ( <div id="team"> <h2>Mes équipes</h2> - <button onClick={() => location.pathname="/tactic/new"}>+</button> + <button className="new" onClick={() => location.pathname="/tactic/new"}>+</button> </div> ) } @@ -82,7 +82,7 @@ export function Tactic({lastTactics} : { lastTactics : Tactic[]}) { <div id="tactic"> <div id="titreTactic"> <h2>Mes cinq dernières stratégies</h2> - <button id="createTactic" onClick={() => (location.pathname = "/tactic/new")}>+</button> + <button className="new" id="createTactic" onClick={() => (location.pathname = "/tactic/new")}>+</button> <ul> {listTactic} </ul> From fdea80ce87797672f06d391103464b3e328f2c35 Mon Sep 17 00:00:00 2001 From: DahmaneYanis <dahmane.yanis.2004@gmail.com> Date: Mon, 18 Dec 2023 17:39:04 +0100 Subject: [PATCH 10/13] WIP update the tactic research --- front/style/home.css | 26 +++++++++++++++++++++----- front/views/Home.tsx | 18 +++++++++--------- src/App/Controller/UserController.php | 2 +- 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/front/style/home.css b/front/style/home.css index cc773e6..c6989e9 100644 --- a/front/style/home.css +++ b/front/style/home.css @@ -1,11 +1,11 @@ #main { - margin-left : 2%; - margin-right: 2%; + margin-left : 10%; + margin-right: 10%; border : solid 2px purple; display: flex; flex-direction: column; - + font-family: Helvetica,; } .new { @@ -30,8 +30,7 @@ } #sideMenu { - background-color: blue; - + background-color: grey; } #ps-title { @@ -42,3 +41,20 @@ display: inline-block; margin-right : 5%; } + +.titreSideMenu { + border-bottom: black solid 2px; + width: 95%; + +} + +#sideMenu .title { + font-size: 13px; + font-weight: bold; + color : #FFFFFF; + letter-spacing: 1px; + text-transform: uppercase; + background-color: black; + padding : 1.5%; + margin-bottom: 0px; +} \ No newline at end of file diff --git a/front/views/Home.tsx b/front/views/Home.tsx index 4a6425c..43de571 100644 --- a/front/views/Home.tsx +++ b/front/views/Home.tsx @@ -25,7 +25,7 @@ export function Title() { } export function Body({ lastTactics } : { lastTactics : Tactic[] }) { - const widthPersonalSpace = 70; + const widthPersonalSpace = 67.5; const widthSideMenu = 100-widthPersonalSpace return ( <div id="body"> @@ -61,8 +61,8 @@ export function PersonalSpace({ width }: { width : number }) { export function Team() { return ( - <div id="team"> - <h2>Mes équipes</h2> + <div className="titreSideMenu"> + <h2 className="title">Mes équipes</h2> <button className="new" onClick={() => location.pathname="/tactic/new"}>+</button> </div> ) @@ -80,13 +80,13 @@ export function Tactic({lastTactics} : { lastTactics : Tactic[]}) { ); return ( <div id="tactic"> - <div id="titreTactic"> - <h2>Mes cinq dernières stratégies</h2> + <div className="titreSideMenu"> + <h2 className="title">Mes cinq dernières stratégies</h2> <button className="new" id="createTactic" onClick={() => (location.pathname = "/tactic/new")}>+</button> - <ul> - {listTactic} - </ul> - </div> + </div> + <ul> + {listTactic} + </ul> </div> ) } \ No newline at end of file diff --git a/src/App/Controller/UserController.php b/src/App/Controller/UserController.php index e17b357..38b8567 100644 --- a/src/App/Controller/UserController.php +++ b/src/App/Controller/UserController.php @@ -22,7 +22,7 @@ class UserController { */ public function home(SessionHandle $session): ViewHttpResponse { $lastTactic = $this->tactics->getLast(5); - // var_dump($lastTactic); + var_dump($session->getAccount()); return ViewHttpResponse::react("views/Home.tsx", [ "lastTactics" => $lastTactic ]); From 7a04924617e867f7c1402f74ec4cb23a24573377 Mon Sep 17 00:00:00 2001 From: DahmaneYanis <dahmane.yanis.2004@gmail.com> Date: Tue, 19 Dec 2023 08:43:00 +0100 Subject: [PATCH 11/13] Fix the owner issue --- front/style/home.css | 4 ++-- src/App/Controller/UserController.php | 4 ++-- src/Core/Gateway/TacticInfoGateway.php | 12 +++++++++--- src/Core/Model/TacticModel.php | 5 +++-- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/front/style/home.css b/front/style/home.css index c6989e9..ed496dc 100644 --- a/front/style/home.css +++ b/front/style/home.css @@ -21,12 +21,12 @@ #body { display: flex; flex-direction: row; - border : solid 10px yellow; + border : solid 10px violet; margin:0px } #personal-space { - background-color: red; + background-color: orange; } #sideMenu { diff --git a/src/App/Controller/UserController.php b/src/App/Controller/UserController.php index 38b8567..eaa0120 100644 --- a/src/App/Controller/UserController.php +++ b/src/App/Controller/UserController.php @@ -21,8 +21,8 @@ class UserController { * @return ViewHttpResponse the home page view */ public function home(SessionHandle $session): ViewHttpResponse { - $lastTactic = $this->tactics->getLast(5); - var_dump($session->getAccount()); + $limitNbTactics = 5; + $lastTactic = $this->tactics->getLast($limitNbTactics, $session->getAccount()->getId()); return ViewHttpResponse::react("views/Home.tsx", [ "lastTactics" => $lastTactic ]); diff --git a/src/Core/Gateway/TacticInfoGateway.php b/src/Core/Gateway/TacticInfoGateway.php index 985c58a..5721f6f 100644 --- a/src/Core/Gateway/TacticInfoGateway.php +++ b/src/Core/Gateway/TacticInfoGateway.php @@ -43,10 +43,16 @@ class TacticInfoGateway { * @param integer $nb * @return array<array<string,mixed>> */ - public function getLast(int $nb): ?array { + public function getLast(int $nb, int $ownerId): ?array { $res = $this->con->fetch( - "SELECT * FROM Tactic ORDER BY creation_date DESC LIMIT :nb ", - [":nb" => [$nb, PDO::PARAM_INT]] + "SELECT * + FROM Tactic + WHERE owner = :ownerId + ORDER BY creation_date + DESC LIMIT :nb", + [ + ":ownerId" => [$ownerId, PDO::PARAM_INT],":nb" => [$nb, PDO::PARAM_INT] + ] ); if (count($res) == 0) { return []; diff --git a/src/Core/Model/TacticModel.php b/src/Core/Model/TacticModel.php index 9a71f4f..d9e783e 100644 --- a/src/Core/Model/TacticModel.php +++ b/src/Core/Model/TacticModel.php @@ -2,6 +2,7 @@ namespace IQBall\Core\Model; +use IQBall\App\Session\SessionHandle; use IQBall\Core\Data\TacticInfo; use IQBall\Core\Gateway\TacticInfoGateway; use IQBall\Core\Validation\ValidationFail; @@ -58,8 +59,8 @@ class TacticModel { /** * Return the nb last tactics */ - public function getLast(int $nb): ?array { - return $this->tactics->getLast($nb); + public function getLast(int $nb, int $ownerId): ?array { + return $this->tactics->getLast($nb, $ownerId); } /** From 9febc0f29e3e7f61d7fbea9bed64100defd4dcee Mon Sep 17 00:00:00 2001 From: DahmaneYanis <dahmane.yanis.2004@gmail.com> Date: Tue, 19 Dec 2023 10:54:20 +0100 Subject: [PATCH 12/13] 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 ( <div id="main"> <Title/> - <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 eaa0120..f292cb6 100644 --- a/src/App/Controller/UserController.php +++ b/src/App/Controller/UserController.php @@ -22,9 +22,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 5721f6f..a7f1f7b 100644 --- a/src/Core/Gateway/TacticInfoGateway.php +++ b/src/Core/Gateway/TacticInfoGateway.php @@ -48,8 +48,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] ] @@ -60,6 +60,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 d9e783e..f605155 100644 --- a/src/Core/Model/TacticModel.php +++ b/src/Core/Model/TacticModel.php @@ -63,6 +63,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 From b4bbbbaad50067acac4c17097596fbd409746376 Mon Sep 17 00:00:00 2001 From: DahmaneYanis <dahmane.yanis.2004@gmail.com> Date: Tue, 19 Dec 2023 11:19:11 +0100 Subject: [PATCH 13/13] Open a tactic in the personal space --- front/style/home.css | 21 +++++++++++++++++++-- front/views/Home.tsx | 2 +- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/front/style/home.css b/front/style/home.css index 19067f8..c053198 100644 --- a/front/style/home.css +++ b/front/style/home.css @@ -27,6 +27,9 @@ #personal-space { background-color: orange; + display: flex; + flex-direction: column; + } #sideMenu { @@ -59,11 +62,25 @@ margin-bottom: 0px; } -table { +#bodyPersonalSpace { + width: 95%; + border : 1px red solid; + align-self: center; +} +#bodyPersonalSpace table{ width: 100%; + border-collapse : separate; + border-spacing : 1em; } td { - text-align: center; border : 3px solid black; + padding-bottom : 1%; + padding-top : 1%; + margin: 80px; + text-align: center; +} + +td:hover { + background-color: red; } \ No newline at end of file diff --git a/front/views/Home.tsx b/front/views/Home.tsx index b0442ef..4792f5f 100644 --- a/front/views/Home.tsx +++ b/front/views/Home.tsx @@ -88,7 +88,7 @@ function BodyPersonalSpace({ allTactics } : { allTactics : Tactic[]}) { i = 0; while (i < nbRow) { listTactic[i] = listTactic[i].map((tactic : Tactic) => - <td key={tactic.id}>{tactic.name}</td> + <td key={tactic.id} onClick={() => {location.pathname="/tactic/"+tactic.id+"/edit"}}>{tactic.name}</td> ); i++; }