Can display all tactics in the personal space

pull/81/head
DahmaneYanis 1 year ago committed by d_yanis
parent d816b3b0aa
commit fa49f1cc76

@ -33,7 +33,7 @@
background-color: grey; background-color: grey;
} }
#ps-title { #titlePersonalSpace h2 {
text-align: center; text-align: center;
} }
@ -58,3 +58,12 @@
padding : 1.5%; padding : 1.5%;
margin-bottom: 0px; margin-bottom: 0px;
} }
table {
width: 100%;
}
td {
text-align: center;
border : 3px solid black;
}

@ -7,11 +7,11 @@ interface Tactic {
creation_date : string creation_date : string
} }
export default function Home({ lastTactics } : { lastTactics : Tactic[] }) { export default function Home({ lastTactics, allTactics } : { lastTactics : Tactic[] , allTactics : Tactic[]}) {
return ( return (
<div id="main"> <div id="main">
<Title/> <Title/>
<Body lastTactics={lastTactics}/> <Body lastTactics={lastTactics} allTactics={allTactics}/>
</div> </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 widthPersonalSpace = 67.5;
const widthSideMenu = 100-widthPersonalSpace const widthSideMenu = 100-widthPersonalSpace
return ( return (
<div id="body"> <div id="body">
<PersonalSpace width = {widthPersonalSpace}/> <PersonalSpace width = {widthPersonalSpace} allTactics = {allTactics}/>
<SideMenu width = {widthSideMenu} lastTactics={lastTactics} /> <SideMenu width = {widthSideMenu} lastTactics={lastTactics} />
</div> </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 ( return (
<div id="personal-space" style={{ <div id="personal-space" style={{
width : width + "%", 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> </div>
) )
} }

@ -24,9 +24,11 @@ class UserController {
*/ */
public function home(SessionHandle $session): ViewHttpResponse { public function home(SessionHandle $session): ViewHttpResponse {
$limitNbTactics = 5; $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", [ return ViewHttpResponse::react("views/Home.tsx", [
"lastTactics" => $lastTactic "lastTactics" => $lastTactics,
"allTactics" => $allTactics
]); ]);
// return ViewHttpResponse::react("views/Home.tsx", []); // return ViewHttpResponse::react("views/Home.tsx", []);
} }

@ -50,8 +50,8 @@ class TacticInfoGateway {
"SELECT * "SELECT *
FROM Tactic FROM Tactic
WHERE owner = :ownerId WHERE owner = :ownerId
ORDER BY creation_date ORDER BY creation_date DESC
DESC LIMIT :nb", LIMIT :nb",
[ [
":ownerId" => [$ownerId, PDO::PARAM_INT],":nb" => [$nb, PDO::PARAM_INT] ":ownerId" => [$ownerId, PDO::PARAM_INT],":nb" => [$nb, PDO::PARAM_INT]
] ]
@ -62,6 +62,27 @@ class TacticInfoGateway {
return $res; 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 string $name
* @param int $owner * @param int $owner

@ -66,6 +66,15 @@ class TacticModel {
return $this->tactics->getLast($nb, $ownerId); 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 * Update the name of a tactic
* @param int $id the tactic identifier * @param int $id the tactic identifier

Loading…
Cancel
Save