Can display all tactics in the personal space
continuous-integration/drone/push Build is failing Details

pull/81/head
DahmaneYanis 1 year ago
parent 7a04924617
commit 9febc0f29e

@ -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;
}

@ -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>
)
}

@ -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", []);
}

@ -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

@ -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

Loading…
Cancel
Save