diff --git a/front/components/Popup.tsx b/front/components/Popup.tsx
new file mode 100644
index 0000000..0b59adf
--- /dev/null
+++ b/front/components/Popup.tsx
@@ -0,0 +1,27 @@
+import {ReactNode, useState} from "react";
+import "../style/popup.css"
+
+export interface PopupProps {
+ children: ReactNode[] | ReactNode,
+ displayState: boolean,
+ onClose: () => void
+}
+
+export default function Popup({children, displayState, onClose}: PopupProps) {
+ return (
+
+ )
+}
\ No newline at end of file
diff --git a/front/style/home/personnal_space.css b/front/style/home/personnal_space.css
index 173098e..19edf6b 100644
--- a/front/style/home/personnal_space.css
+++ b/front/style/home/personnal_space.css
@@ -38,3 +38,22 @@
tbody p {
text-align: center;
}
+
+#new-folder-button{
+ padding:1px;
+ background: var(--accent-color);
+ color:white;
+ width: 8.5%;
+}
+
+#new-folder-form{
+ display:flex;
+ flex-direction: column;
+ justify-content: space-around;
+}
+
+#submit-form{
+ width: 40%;
+ align-self: end;
+
+}
\ No newline at end of file
diff --git a/front/style/popup.css b/front/style/popup.css
new file mode 100644
index 0000000..a794718
--- /dev/null
+++ b/front/style/popup.css
@@ -0,0 +1,22 @@
+@import url(theme/dark.css);
+
+#popup-background{
+ background-color: rgba(0, 0, 0, 0.3);
+ color: white;
+ align-items: center;
+ justify-content: center;
+
+}
+
+#content{
+ padding: 5px;
+ border-radius: 5px;
+ background-color: var(--third-color);
+ display:flex;
+ flex-direction: column;
+}
+
+#close-button{
+ border-radius: 100px;
+ align-self: end;
+}
\ No newline at end of file
diff --git a/front/views/Home.tsx b/front/views/Home.tsx
index a9a4b0a..416a776 100644
--- a/front/views/Home.tsx
+++ b/front/views/Home.tsx
@@ -3,6 +3,9 @@ import "../style/home/home.css"
// import AccountSvg from "../assets/account.svg?react"
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
@@ -23,19 +26,22 @@ export default function Home({
allTactics,
teams,
username,
+ currentFolder
}: {
lastTactics: Tactic[]
allTactics: Tactic[]
teams: Team[]
username: string
+ currentFolder: number
}) {
return (
)
@@ -43,18 +49,20 @@ export default function Home({
function Body({
lastTactics,
- allTactics,
+ tactics,
teams,
+ currentFolder
}: {
lastTactics: Tactic[]
- allTactics: Tactic[]
+ tactics: Tactic[]
teams: Team[]
+ currentFolder: number
}) {
const widthPersonalSpace = 78
const widthSideMenu = 100 - widthPersonalSpace
return (
+ )
+}
+
+function NewFolder({
+ showPopup,
+ setShowPopup,
+ currentFolder
+ }: { showPopup, setShowPopup: (newVal: boolean) => void, currentFolder: number }) {
+ return (
+
+
setShowPopup(true)}
+ >Nouveau dossier
+
setShowPopup(false)}>
+ Nouveau dossier
+
+
)
}
@@ -114,15 +149,15 @@ function TitlePersonalSpace() {
)
}
-function TableData({ allTactics }: { allTactics: Tactic[] }) {
- const nbRow = Math.floor(allTactics.length / 3) + 1
+function TableData({ tactics }: { tactics: Tactic[] }) {
+ const nbRow = Math.floor(tactics.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) => {
+ tactics.forEach((tactic) => {
listTactic[i].push(tactic)
j++
if (j === 3) {
@@ -159,12 +194,12 @@ function TableData({ allTactics }: { allTactics: Tactic[] }) {
return data
}
-function BodyPersonalSpace({ allTactics }: { allTactics: Tactic[] }) {
+function BodyPersonalSpace({ tactics }: { tactics: Tactic[] }) {
let data
- if (allTactics.length == 0) {
+ if (tactics.length == 0) {
data = Aucune tactique créée !
} else {
- data =
+ data =
}
return (
diff --git a/public/index.php b/public/index.php
index 82dd37f..5effb23 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())));
+ 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())));
}
function getVisualizerController(): VisualizerController {
@@ -86,6 +86,8 @@ function getRoutes(): AltoRouter {
$ar->map("GET", "/settings", Action::auth(fn(SessionHandle $s) => getUserController()->settings($s)));
$ar->map("GET", "/disconnect", Action::auth(fn(MutableSessionHandle $s) => getUserController()->disconnect($s)));
+ //folder-related
+ $ar->map("POST", "/folder/[i:idParent]/new", Action::auth(fn(int $id,SessionHandle $s) => getUserController()->createFolder($s,$_POST,$id)));
//tactic-related
$ar->map("GET", "/tactic/[i:id]/view", Action::auth(fn(int $id, SessionHandle $s) => getVisualizerController()->openVisualizer($id, $s)));
diff --git a/sql/setup-tables.sql b/sql/setup-tables.sql
index c827bd0..8d1031e 100644
--- a/sql/setup-tables.sql
+++ b/sql/setup-tables.sql
@@ -4,6 +4,9 @@ DROP TABLE IF EXISTS Tactic;
DROP TABLE IF EXISTS Team;
DROP TABLE IF EXISTS User;
DROP TABLE IF EXISTS Member;
+DROP TABLE IF EXISTS TacticFolder;
+DROP TABLE IF EXISTS TacticFolderLink;
+--
CREATE TABLE Account
(
id integer PRIMARY KEY AUTOINCREMENT,
@@ -30,17 +33,17 @@ CREATE TABLE TacticFolder
id integer PRIMARY KEY AUTOINCREMENT,
name varchar NOT NULL,
owner integer NOT NULL,
- tacticFolderParent integer,
+ tactic_folder_parent integer,
FOREIGN KEY (owner) REFERENCES Account,
- FOREIGN KEY (tacticFolderParent) REFERENCES TacticFolder
+ FOREIGN KEY (tactic_folder_parent) REFERENCES TacticFolder
);
CREATE TABLE TacticFolderLink
(
- idFolder integer NOT NULL,
- idTactic integer NOT NULL,
- FOREIGN KEY (idFolder) REFERENCES TacticFolder,
- FOREIGN KEY (idTactic) REFERENCES Tactic
+ id_folder integer NOT NULL,
+ id_tactic integer NOT NULL,
+ FOREIGN KEY (id_folder) REFERENCES TacticFolder,
+ FOREIGN KEY (id_tactic) REFERENCES Tactic
);
CREATE TABLE Team
diff --git a/src/App/Controller/UserController.php b/src/App/Controller/UserController.php
index 6f56128..bf996fb 100644
--- a/src/App/Controller/UserController.php
+++ b/src/App/Controller/UserController.php
@@ -5,22 +5,27 @@ namespace IQBall\App\Controller;
use IQBall\App\Session\MutableSessionHandle;
use IQBall\App\Session\SessionHandle;
use IQBall\App\ViewHttpResponse;
+use IQBall\Core\Http\HttpRequest;
use IQBall\Core\Http\HttpResponse;
+use IQBall\Core\Model\PersonalSpaceModel;
use IQBall\Core\Model\TacticModel;
use IQBall\Core\Model\TeamModel;
+use IQBall\Core\Validation\DefaultValidators;
class UserController {
private TacticModel $tactics;
private ?TeamModel $teams;
-
+ private PersonalSpaceModel $personalSpace;
/**
* @param TacticModel $tactics
* @param TeamModel|null $teams
+ * @param PersonalSpaceModel $personalSpace
*/
- public function __construct(TacticModel $tactics, ?TeamModel $teams = null) {
+ public function __construct(TacticModel $tactics, ?TeamModel $teams, PersonalSpaceModel $personalSpace) {
$this->tactics = $tactics;
$this->teams = $teams;
+ $this->personalSpace = $personalSpace;
}
/**
@@ -28,12 +33,13 @@ class UserController {
* @return ViewHttpResponse the home page view
*/
public function home(SessionHandle $session): ViewHttpResponse {
+ $rootFolder = 0;
$limitNbTactics = 5;
$user = $session->getAccount()->getUser();
$lastTactics = $this->tactics->getLast($limitNbTactics, $user->getId());
- $allTactics = $this->tactics->getAll($user->getId());
+ $rootTactics = $this->tactics->getFolderTactic($user->getId());
$name = $user->getName();
if ($this->teams != null) {
@@ -44,9 +50,10 @@ class UserController {
return ViewHttpResponse::react("views/Home.tsx", [
"lastTactics" => $lastTactics,
- "allTactics" => $allTactics,
+ "allTactics" => $rootTactics,
"teams" => $teams,
"username" => $name,
+ "currentFolder" => $rootFolder
]);
}
@@ -62,4 +69,11 @@ class UserController {
return HttpResponse::redirect("/");
}
+ public function createFolder(SessionHandle $session,array $request,int $idParentFolder): HttpResponse{
+ $this->personalSpace->createFolder($request['folderName'],$session->getAccount()->getUser()->getId(),$idParentFolder);
+ return HttpResponse::redirect("/");
+ }
+
+
+
}
diff --git a/src/Core/Gateway/PersonalSpaceGateway.php b/src/Core/Gateway/PersonalSpaceGateway.php
new file mode 100644
index 0000000..e472743
--- /dev/null
+++ b/src/Core/Gateway/PersonalSpaceGateway.php
@@ -0,0 +1,23 @@
+con = $con;
+ }
+
+ public function addFolder(string $folderName,int $ownerId,int $parentId): void{
+ $this->con->exec("INSERT INTO TacticFolder(name,owner,tactic_folder_parent) VALUES(:name,:owner,:parent)",
+ [
+ "name" =>[$folderName,\PDO::PARAM_STR],
+ "owner"=>[$ownerId,\PDO::PARAM_INT],
+ "parent"=>[$parentId,\PDO::PARAM_INT]
+ ]
+ );
+ }
+}
\ No newline at end of file
diff --git a/src/Core/Gateway/TacticInfoGateway.php b/src/Core/Gateway/TacticInfoGateway.php
index e96d807..06475a0 100644
--- a/src/Core/Gateway/TacticInfoGateway.php
+++ b/src/Core/Gateway/TacticInfoGateway.php
@@ -141,14 +141,14 @@ class TacticInfoGateway {
public function getFolderTactic(int $accountId,int $folderId): array {
if($folderId == 0){
$query = "SELECT t.*
- FROM Tactic t, TacticFolderLink tfl
- WHERE t.owner = :ownerId AND t.id NOT IN (SELECT idTactic FROM TacticFolderLink)";
+ FROM Tactic t
+ WHERE t.owner = :ownerId AND t.id NOT IN (SELECT id_tactic FROM TacticFolderLink)";
$args = ["ownerId" => [$accountId, PDO::PARAM_INT]];
}else {
$query = "SELECT t.*
FROM Tactic t, TacticFolderLink tfl
- WHERE t.owner = :ownerId AND tfl.idTactic = :folderId";
+ WHERE t.owner = :ownerId AND tfl.id_tactic = :folderId";
$args = ["ownerId" => [$accountId, PDO::PARAM_INT],
"folderId" => [$folderId, PDO::PARAM_INT]];
}
diff --git a/src/Core/Model/PersonalSpaceModel.php b/src/Core/Model/PersonalSpaceModel.php
new file mode 100644
index 0000000..622a8fb
--- /dev/null
+++ b/src/Core/Model/PersonalSpaceModel.php
@@ -0,0 +1,21 @@
+gateway = $gateway;
+ }
+
+ public function createFolder(string $folderName,int $ownerId,int $parentFolder): void{
+ $this->gateway->addFolder($folderName,$ownerId,$parentFolder);
+ }
+
+}
\ No newline at end of file