From 56b6b4351cbec3ce3ff06598e242aeb52a8a09a1 Mon Sep 17 00:00:00 2001
From: "mael.daim"
Date: Thu, 25 Jan 2024 11:39:10 +0100
Subject: [PATCH] WIP resume the implementation of folders
---
front/assets/folder.svg | 1 +
front/views/Home.tsx | 79 +++++++++++++++----
public/index.php | 2 +-
src/App/Controller/UserController.php | 5 +-
.../PersonalSpace/PersonalSpaceFolder.php | 2 +-
.../Data/PersonalSpace/PersonalSpaceItem.php | 2 +-
src/Core/Data/TacticInfo.php | 1 +
src/Core/Gateway/PersonalSpaceGateway.php | 46 +++++++----
src/Core/Model/PersonalSpaceModel.php | 7 +-
9 files changed, 107 insertions(+), 38 deletions(-)
create mode 100644 front/assets/folder.svg
diff --git a/front/assets/folder.svg b/front/assets/folder.svg
new file mode 100644
index 0000000..e6b86d5
--- /dev/null
+++ b/front/assets/folder.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/front/views/Home.tsx b/front/views/Home.tsx
index 416a776..a77dc42 100644
--- a/front/views/Home.tsx
+++ b/front/views/Home.tsx
@@ -1,11 +1,10 @@
import "../style/home/home.css"
// import AccountSvg from "../assets/account.svg?react"
-import { Header } from "./template/Header"
-import { BASE } from "../Constants"
+import {Header} from "./template/Header"
+import {BASE} from "../Constants"
import Popup from "../components/Popup";
import {useState} from "react";
-import * as path from "path";
interface Tactic {
id: number
@@ -21,15 +20,22 @@ interface Team {
second_color: string
}
+interface Folder{
+ id:number
+ name:string
+}
+
export default function Home({
lastTactics,
allTactics,
+ folders,
teams,
username,
currentFolder
}: {
lastTactics: Tactic[]
allTactics: Tactic[]
+ folders: Folder[]
teams: Team[]
username: string
currentFolder: number
@@ -40,6 +46,7 @@ export default function Home({
@@ -50,11 +57,13 @@ export default function Home({
function Body({
lastTactics,
tactics,
+ folders,
teams,
currentFolder
}: {
lastTactics: Tactic[]
tactics: Tactic[]
+ folders: Folder[]
teams: Team[]
currentFolder: number
}) {
@@ -62,7 +71,7 @@ function Body({
const widthSideMenu = 100 - widthPersonalSpace
return (
)
}
@@ -149,12 +160,17 @@ function TitlePersonalSpace() {
)
}
-function TableData({ tactics }: { tactics: Tactic[] }) {
- const nbRow = Math.floor(tactics.length / 3) + 1
- let listTactic = Array(nbRow)
- for (let i = 0; i < nbRow; i++) {
+function TableData({ tactics,folders }: { tactics: Tactic[],folders: Folder[]}) {
+ const nbTacticRow = Math.floor(tactics.length / 3) + 1
+ const nbFolderRow = Math.floor(folders.length / 3) + 1
+ let listTactic = Array(nbTacticRow)
+ let listFolder = Array(nbFolderRow)
+ for (let i = 0; i < nbTacticRow; i++) {
listTactic[i] = Array(0)
}
+ for (let i = 0; i < nbFolderRow ; i++) {
+ listFolder[i] = Array(0)
+ }
let i = 0
let j = 0
tactics.forEach((tactic) => {
@@ -165,9 +181,17 @@ function TableData({ tactics }: { tactics: Tactic[] }) {
j = 0
}
})
+ folders.forEach((folder) => {
+ listFolder[i].push(folder)
+ j++
+ if (j === 3) {
+ i++
+ j = 0
+ }
+ })
i = 0
- while (i < nbRow) {
+ while (i < nbTacticRow) {
listTactic[i] = listTactic[i].map((tactic: Tactic) => (
(
+ | {
+ location.pathname = BASE + "/tactic/" + folder.id + "/edit"
+ }}>
+ {truncateString(folder.name, 25)}
+ |
+ ))
+ i++
+ }
+
+ if (nbTacticRow == 1) {
if (listTactic[0].length < 3) {
for (let i = 0; i <= 3 - listTactic[0].length; i++) {
listTactic[0].push( | )
}
}
}
+ if (nbFolderRow == 1) {
+ if (listFolder[0].length < 3) {
+ for (let i = 0; i <= 3 - listFolder[0].length; i++) {
+ listFolder[0].push( | )
+ }
+ }
+ }
- const data = listTactic.map((tactic, rowIndex) => (
+ return listTactic.map((tactic, rowIndex) => (
{tactic}
- ))
- return data
+ )).concat(listFolder.map((folder, rowIndex) => (
+ {folder}
+ )))
}
-function BodyPersonalSpace({ tactics }: { tactics: Tactic[] }) {
+function BodyPersonalSpace({ tactics,folders }: { tactics: Tactic[],folders: Folder[]}) {
let data
if (tactics.length == 0) {
data = Aucune tactique créée !
} else {
- data =
+ data =
}
return (
diff --git a/public/index.php b/public/index.php
index 5effb23..db1ac84 100644
--- a/public/index.php
+++ b/public/index.php
@@ -38,7 +38,7 @@ function getConnection(): Connection {
}
function getUserController(): UserController {
- return new UserController(new TacticModel(new TacticInfoGateway(getConnection())), new TeamModel(new TeamGateway(getConnection()), new MemberGateway(getConnection()), new AccountGateway(getConnection())),new \IQBall\Core\Model\PersonalSpaceModel(new \IQBall\Core\Gateway\PersonalSpaceGateway(getConnection())));
+ return new UserController(new TacticModel(new TacticInfoGateway(getConnection())), new TeamModel(new TeamGateway(getConnection()), new MemberGateway(getConnection()), new AccountGateway(getConnection())),new \IQBall\Core\Model\PersonalSpaceModel(new \IQBall\Core\Gateway\PersonalSpaceGateway(getConnection()),new TacticInfoGateway(getConnection())));
}
function getVisualizerController(): VisualizerController {
diff --git a/src/App/Controller/UserController.php b/src/App/Controller/UserController.php
index 68419cb..9f39f91 100644
--- a/src/App/Controller/UserController.php
+++ b/src/App/Controller/UserController.php
@@ -39,9 +39,9 @@ class UserController {
$user = $session->getAccount()->getUser();
$lastTactics = $this->tactics->getLast($limitNbTactics, $user->getId());
- $rootTactics = $this->tactics->getFoldefrTactic($user->getId());
+ $rootTactics = $this->personalSpace->getTacticFromFolder($user->getId());
+ $rootFolders = $this->personalSpace->getFolderFromFolder($user->getId());
$name = $user->getName();
-
if ($this->teams != null) {
$teams = $this->teams->getAll($user->getId());
} else {
@@ -51,6 +51,7 @@ class UserController {
return ViewHttpResponse::react("views/Home.tsx", [
"lastTactics" => $lastTactics,
"allTactics" => $rootTactics,
+ "folders" => $rootFolders,
"teams" => $teams,
"username" => $name,
"currentFolder" => $rootFolder
diff --git a/src/Core/Data/PersonalSpace/PersonalSpaceFolder.php b/src/Core/Data/PersonalSpace/PersonalSpaceFolder.php
index fbf8c57..77a2d53 100644
--- a/src/Core/Data/PersonalSpace/PersonalSpaceFolder.php
+++ b/src/Core/Data/PersonalSpace/PersonalSpaceFolder.php
@@ -1,6 +1,6 @@
getTacticFromRoot($accountId);
- $content = array_merge($this->getFolderFromRoot($accountId), $content);
+ $folders = $this->getFolderFromRoot($accountId);
} else {
- $content = $this->getTacticFromFolder($accountId, $folderId);
- $content = array_merge($this->getFolderFromFolder($accountId, $folderId), $content);
+ $folders = $this->getFolderFromFolder($accountId, $folderId);
}
- return $content;
+ return $folders;
+ }
+
+ public function getTactic(int $accountId, int $folderId):array{
+ if ($folderId == 0) {
+ $tactics = $this->getTacticFromRoot($accountId);
+ } else {
+ $tactics = $this->getTacticFromFolder($accountId, $folderId);
+ }
+ return $tactics;
}
- public function getTacticFromRoot(int $accountId): array {
- return $this->con->fetch(
+ private function getTacticFromRoot(int $accountId): array {
+ $result = $this->con->fetch(
"SELECT t.*
FROM Tactic t
WHERE t.owner = :ownerId AND t.id NOT IN (SELECT id_tactic FROM TacticFolderLink)",
["ownerId" => [$accountId, PDO::PARAM_INT]]
);
+ return array_map(fn($row) => new TacticInfo($row['id'],$row['name'],$row['creation_date'],$row['owner'],CourtType::fromName($row['court_type']),$row['content']),$result);
}
- public function getFolderFromRoot(int $accountId): array {
- return $this->con->fetch(
+ private function getFolderFromRoot(int $accountId): array {
+ $result = $this->con->fetch(
"SELECT *
FROM TacticFolder
WHERE owner = :owner AND tactic_folder_parent IS NULL",
["ownerId" => [$accountId, PDO::PARAM_INT]]
);
+ var_dump($result);
+ return array_map(fn($row) => new PersonalSpaceFolder($row['id'],$row['name']),$result);
}
- public function getTacticFromFolder(int $accountId, int $folderId): array {
- return $this->con->fetch(
+ private function getTacticFromFolder(int $accountId, int $folderId): array {
+ $result = $this->con->fetch(
"SELECT t.*
FROM Tactic t, TacticFolderLink tfl
WHERE t.owner = :ownerId AND tfl.id_tactic = :folderId",
@@ -68,10 +81,12 @@ class PersonalSpaceGateway {
"folderId" => [$folderId, PDO::PARAM_INT]
]
);
+ return array_map(fn($row) => new TacticInfo($row['id'],$row['name'],$row['creation_date'],$row['owner'],CourtType::fromName($row['court_type']),$row['content']),$result);
+
}
- public function getFolderFromFolder(int $accountId, int $folderId): array {
- return $this->con->fetch(
+ private function getFolderFromFolder(int $accountId, int $folderId): array {
+ $result = $this->con->fetch(
"SELECT *
FROM TacticFolder
WHERE owner = :ownerId AND tactic_folder_parent = :folderId",
@@ -80,5 +95,6 @@ class PersonalSpaceGateway {
"folderId" => [$folderId, PDO::PARAM_INT]
]
);
+ return array_map(fn($row) => new PersonalSpaceFolder($row['id'],$row['name']),$result);
}
}
\ No newline at end of file
diff --git a/src/Core/Model/PersonalSpaceModel.php b/src/Core/Model/PersonalSpaceModel.php
index 9b28457..2dc3964 100644
--- a/src/Core/Model/PersonalSpaceModel.php
+++ b/src/Core/Model/PersonalSpaceModel.php
@@ -22,9 +22,12 @@ class PersonalSpaceModel {
$this->personalSpaces->addFolder($folderName,$ownerId,$parentFolder);
}
- public function getFolderContent(int $acountId,int $folderId = 0): array{
- $tactics = $this->personalSpaces->getFolderTactic($acountId,$folderId);
+ public function getFolderFromFolder(int $accountId,int $folderId = 0): array{
+ return $this->personalSpaces->getFolder($accountId,$folderId);
+ }
+ public function getTacticFromFolder(int $accountId,int $folderId = 0): array{
+ return $this->personalSpaces->getTactic($accountId,$folderId);
}
}
\ No newline at end of file