implemented tha add of a folder in personal space
continuous-integration/drone/push Build is failing Details

folder
Maël DAIM 1 year ago
parent e259d64387
commit 6875c500f2

@ -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 (
<div id="popup-background"
style={{
display: displayState ? 'flex' : 'none',
position: "absolute",
width: "78%",
height: "79%",
overflow:"hidden"
}}
onClick={onClose}>
<div id="content" onClick={event => event.stopPropagation()}>
<button id="close-button" onClick={onClose}>X</button>
{children}
</div>
</div>
)
}

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

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

@ -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 (
<div id="main">
<Header username={username} />
<Body
lastTactics={lastTactics}
allTactics={allTactics}
tactics={allTactics}
teams={teams}
currentFolder={currentFolder}
/>
</div>
)
@ -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 (
<div id="body">
<PersonalSpace width={widthPersonalSpace} allTactics={allTactics} />
<PersonalSpace width={widthPersonalSpace} tactics={tactics} currentFolder={currentFolder}/>
<SideMenu
width={widthSideMenu}
lastTactics={lastTactics}
@ -89,11 +97,14 @@ function SideMenu({
function PersonalSpace({
width,
allTactics,
tactics,
currentFolder
}: {
width: number
allTactics: Tactic[]
tactics: Tactic[]
currentFolder: number
}) {
const [showPopup, setShowPopup] = useState(false)
return (
<div
id="personal-space"
@ -101,7 +112,31 @@ function PersonalSpace({
width: width + "%",
}}>
<TitlePersonalSpace />
<BodyPersonalSpace allTactics={allTactics} />
<NewFolder showPopup={showPopup} setShowPopup={setShowPopup} currentFolder={currentFolder}/>
<BodyPersonalSpace tactics={tactics} />
</div>
)
}
function NewFolder({
showPopup,
setShowPopup,
currentFolder
}: { showPopup, setShowPopup: (newVal: boolean) => void, currentFolder: number }) {
return (
<div>
<div
id="new-folder-button"
onClick={() => setShowPopup(true)}
>Nouveau dossier</div>
<Popup displayState={showPopup} onClose={() => setShowPopup(false)}>
<h2>Nouveau dossier</h2>
<form action={location.pathname + BASE + "folder/" + currentFolder + "/new"} method="post" id="new-folder-form">
<label for="folderName">Nom du dossier</label>
<input type="text" id="folderName" name="folderName" required/>
<input type="submit" value="Confirmer" id="submit-form"/>
</form>
</Popup>
</div>
)
}
@ -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 = <p>Aucune tactique créée !</p>
} else {
data = <TableData allTactics={allTactics} />
data = <TableData tactics={tactics} />
}
return (

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

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

@ -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("/");
}
}

@ -0,0 +1,23 @@
<?php
namespace IQBall\Core\Gateway;
use IQBall\Core\Connection;
class PersonalSpaceGateway {
private Connection $con;
public function __construct(Connection $con) {
$this->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]
]
);
}
}

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

@ -0,0 +1,21 @@
<?php
namespace IQBall\Core\Model;
use IQBall\Core\Gateway\PersonalSpaceGateway;
class PersonalSpaceModel {
private PersonalSpaceGateway $gateway;
/**
* @param PersonalSpaceGateway $gateway
*/
public function __construct(PersonalSpaceGateway $gateway) {
$this->gateway = $gateway;
}
public function createFolder(string $folderName,int $ownerId,int $parentFolder): void{
$this->gateway->addFolder($folderName,$ownerId,$parentFolder);
}
}
Loading…
Cancel
Save