From d2ac21a906c89c3a5196c284102db580ac0edca0 Mon Sep 17 00:00:00 2001 From: "mael.daim" Date: Thu, 21 Dec 2023 03:33:24 +0100 Subject: [PATCH] fully implemented the add of members + added style on the page + almost done implementing the remove of members --- front/style/team_panel.css | 125 ++++++++++++++------------ front/views/TeamPanel.tsx | 31 ++++--- public/index.php | 5 +- src/App/Controller/TeamController.php | 43 +++++---- src/App/Views/add_member.html.twig | 27 ++++-- src/Core/Gateway/MemberGateway.php | 6 +- src/Core/Model/TeamModel.php | 27 ++++-- 7 files changed, 154 insertions(+), 110 deletions(-) diff --git a/front/style/team_panel.css b/front/style/team_panel.css index d9104a6..935ed96 100644 --- a/front/style/team_panel.css +++ b/front/style/team_panel.css @@ -1,8 +1,22 @@ #mainDiv { - background-color: lightblue; display: flex; flex-direction: column; align-items: center; + height: 100%; +} + +header{ + display: flex; + justify-content: center; + background-color: #525252; + width: 100%; + margin-bottom: 5px; +} + +header h1 a{ + color: orange; + text-decoration: none; + font-size: 1.5em; } .square { @@ -14,23 +28,51 @@ border: solid; } -section { - background-color: #fff; +#teamInfo{ display: flex; flex-direction: column; align-items: center; width: 60%; + background-color: #8F8F8F; + padding-bottom: 10px; + border-radius: 10px; +} + +#firstPart{ + display: flex; + flex-direction: column; + align-items: center; +} + +#teamName{ + font-size: 2.8em; } #colors{ display: flex; - flex-direction: row; + flex-direction: column; } .color { flex-direction: row; justify-content: space-between; } +#colorsTitle{ + width: 110%; + display: flex; + flex-direction: row; + justify-content: space-between; + font-size: 1.3em; + color: white; +} + + +#actualColors{ + display: flex; + flex-direction: row; + justify-content: space-around; +} + #logo { width: 90%; aspect-ratio: 3/2; @@ -42,84 +84,49 @@ section { border-radius:10px ; background-color: red; color: white; + margin-top: 10px; + margin-bottom: 10px; } -.player{ +#headMembers{ + width: 33%; + display: flex; flex-direction: row; justify-content: space-evenly; } -#profilePicture{ - height:40px; - width:40px; +#addMember{ + height: 30px; + aspect-ratio: 1/1; + border-radius: 100%; + align-self: center; } #Members{ display: flex; flex-direction: column; - background-color: lightcoral; + background-color: #BCBCBC; width: 60%; align-items: center; - justify-content: space-between; - + justify-content: space-around; + border-radius: 10px; } .Member{ width: 60%; - background-color: red; + background-color: white; display: flex; flex-direction: row; justify-content: space-evenly; -} - -#teamInfo{ - display: flex; - flex-direction: column; align-items: center; + border-radius: 10px; + margin-top: 5px; + margin-bottom: 5px; - width: 60%; - align-items: center; - background-color: #666666; } -#headMembers{ - width: 33%; - display: flex; - flex-direction: row; - justify-content: space-between; -} - -#addMember{ - height: 30px; - aspect-ratio: 1/1; - border-radius: 100%; - align-self: center; +#profilePicture{ + height:40px; + width:40px; } -.popup { - display: none; - position: fixed; - top: 0; - left: 0; - width: 100%; - height: 100%; - background-color: rgba(0,0,0,0.7); -} - -.popup-content { - position: absolute; - top: 50%; - left: 50%; - transform: translate(-50%, -50%); - background-color: #fff; - padding: 20px; - text-align: center; -} - -.close { - position: absolute; - top: 10px; - right: 10px; - font-size: 20px; - cursor: pointer; -} \ No newline at end of file diff --git a/front/views/TeamPanel.tsx b/front/views/TeamPanel.tsx index 9b28097..2211145 100644 --- a/front/views/TeamPanel.tsx +++ b/front/views/TeamPanel.tsx @@ -2,7 +2,7 @@ import '../style/team_panel.css'; import {BASE} from "../Constants"; import {Team,TeamInfo,Color,User,Member} from "../model/Team/Team" -export default function TeamPanel({isCoach, team}: {isCoach: boolean, team: Team }){ +export default function TeamPanel({isCoach, team,currentUserId}: {isCoach: boolean, team: Team,currentUserId:number}){ return (
@@ -13,7 +13,7 @@ export default function TeamPanel({isCoach, team}: {isCoach: boolean, team: Team {isCoach && } - +
) } @@ -21,15 +21,19 @@ export default function TeamPanel({isCoach, team}: {isCoach: boolean, team: Team function TeamDisplay({ team}: {team : TeamInfo}) { return (
-
-

{team.name}

+
+

{team.name}

-

Couleur principale

- -

Couleur secondaire

- +
+

Couleur principale

+

Couleur secondaire

+
+
+ + +
) @@ -49,28 +53,31 @@ function CoachOptions ({id}:{id:number}){ ) } -function MembersDisplay({members,isCoach}:{members : Member[], isCoach : boolean}){ +function MembersDisplay({members,isCoach,idTeam,currentUserId}:{members : Member[], isCoach : boolean,idTeam : number,currentUserId:number}){ const listMember = members.map((member) => - + ); return (

Membres :

- + {isCoach && }
{listMember}
) } -function MemberDisplay({member}: {member : Member}){ +function MemberDisplay({member,isCoach,idTeam,currentUserId}: {member : Member,isCoach : boolean,idTeam:number,currentUserId:number}){ return (
Photo de profile

{member.user.name}

{member.role}

{member.user.email}

+ {isCoach && currentUserId !== member.user.id && } + {isCoach && currentUserId == member.user.id && } +
) } diff --git a/public/index.php b/public/index.php index afe7cd6..46da6c5 100644 --- a/public/index.php +++ b/public/index.php @@ -104,10 +104,9 @@ function getRoutes(): AltoRouter { $ar->map("POST", "/team/search", Action::auth(fn(SessionHandle $s) => getTeamController()->listTeamByName($_POST, $s))); $ar->map("GET", "/team/[i:id]", Action::auth(fn(int $id, SessionHandle $s) => getTeamController()->displayTeam($id, $s))); $ar->map("GET", "/team/[i:id]/delete", Action::auth(fn(int $id,SessionHandle $s) => getTeamController()->deleteTeamById($id,$s))); - $ar->map("GET", "/team/members/add", Action::auth(fn(SessionHandle $s) => getTeamController()->displayAddMember($s))); + $ar->map("GET", "/team/[i:id]/addMember", Action::auth(fn(int $id,SessionHandle $s) => getTeamController()->displayAddMember($id,$s))); $ar->map("POST", "/team/[i:id]/addMember", Action::auth(fn(int $id,SessionHandle $s) => getTeamController()->addMember($id,$_POST, $s))); - $ar->map("GET", "/team/members/remove", Action::auth(fn(SessionHandle $s) => getTeamController()->displayDeleteMember($s))); - $ar->map("POST", "/team/members/remove", Action::auth(fn(SessionHandle $s) => getTeamController()->deleteMember($_POST, $s))); + $ar->map("POST", "/team/[i:idTeam]/remove/[i:idMember]", Action::auth(fn(int $idTeam,int $idMember,SessionHandle $s) => getTeamController()->deleteMember($idTeam,$idMember, $s))); return $ar; } diff --git a/src/App/Controller/TeamController.php b/src/App/Controller/TeamController.php index 56ac482..45b14a2 100644 --- a/src/App/Controller/TeamController.php +++ b/src/App/Controller/TeamController.php @@ -31,10 +31,6 @@ class TeamController { return ViewHttpResponse::twig("insert_team.html.twig", []); } - - - - /** * @param SessionHandle $session * @return ViewHttpResponse the team panel to delete a member @@ -137,7 +133,10 @@ class TeamController { 'team' => [ "info" => $result->getInfo(), "members" => $result->listMembers() - ], 'isCoach' => $role]); + ], + 'isCoach' => $role, + 'currentUserId'=>$session->getAccount()->getUser()->getId()] + ); } } @@ -145,8 +144,8 @@ class TeamController { * @param SessionHandle $session * @return ViewHttpResponse the team panel to add a member */ - public function displayAddMember(SessionHandle $session): ViewHttpResponse { - return ViewHttpResponse::twig("add_member.html.twig", []); + public function displayAddMember(int $idTeam,SessionHandle $session): ViewHttpResponse { + return ViewHttpResponse::twig("add_member.html.twig", ['idTeam'=> $idTeam]); } /** @@ -159,12 +158,21 @@ class TeamController { $errors = []; $request = HttpRequest::from($request, $errors, [ - "team" => [Validators::isInteger()], "email" => [Validators::email(), Validators::lenBetween(5, 256)], ]); - - $this->model->addMember($request['email'], $idTeam, $request['role']); - return ViewHttpResponse::redirect('/team/'.$idTeam); + if(!empty($errors)){ + return ViewHttpResponse::twig('add_member.html.twig',['badEmail' => true,'idTeam'=> $idTeam]); + } + $ret = $this->model->addMember($request['email'], $idTeam, $request['role']); + + switch($ret){ + case -1: + return ViewHttpResponse::twig('add_member.html.twig',['notFound' => true,'idTeam'=> $idTeam]); + case -2: + return ViewHttpResponse::twig('add_member.html.twig',['alreadyExisting' => true,'idTeam'=> $idTeam]); + default: + return ViewHttpResponse::redirect('/team/'.$idTeam); + } } /** @@ -173,13 +181,12 @@ class TeamController { * @param SessionHandle $session * @return HttpResponse */ - public function deleteMember(array $request, SessionHandle $session): HttpResponse { - $errors = []; - $request = HttpRequest::from($request, $errors, [ - "team" => [Validators::isInteger()], - "email" => [Validators::email(), Validators::lenBetween(5, 256)], - ]); - return $this->displayTeam($this->model->deleteMember($request['email'], intval($request['team'])), $session); + public function deleteMember(int $idTeam,int $idMember, SessionHandle $session): HttpResponse { + $ret = $this->model->deleteMember($idMember,$idTeam); + if($ret == -1 || $session->getAccount()->getUser()->getId() == $idMember ){ + return ViewHttpResponse::redirect('/'); + } + return $this->displayTeam($ret,$session); } } diff --git a/src/App/Views/add_member.html.twig b/src/App/Views/add_member.html.twig index 2cc9811..cfee16d 100644 --- a/src/App/Views/add_member.html.twig +++ b/src/App/Views/add_member.html.twig @@ -67,26 +67,43 @@ display: flex; justify-content: space-between; } + + .failed{ + color: red; + } +
+

IQBall

+

Ajouter un membre à votre équipe

-
+
- - + + + {% if badEmail %} +

Email invalide

+ {% endif %} + {%if notFound %} +

Cette personne n'a pas été trouvé

+ {% endif %} + {% if alreadyExisting %} +

Cette personne est déjà dans l'équipe

+ {% endif %} +
Rôle du membre dans l'équipe :
- +
- +
diff --git a/src/Core/Gateway/MemberGateway.php b/src/Core/Gateway/MemberGateway.php index f14790c..9fb289a 100644 --- a/src/Core/Gateway/MemberGateway.php +++ b/src/Core/Gateway/MemberGateway.php @@ -94,9 +94,7 @@ class MemberGateway { "team" => [$idTeam, PDO::PARAM_INT], "user" => [$idCurrentUser, PDO::PARAM_INT] ] - )[0]['id_user'] ?? null; - return $result == null; + ); + return !empty($result); } - - } diff --git a/src/Core/Model/TeamModel.php b/src/Core/Model/TeamModel.php index 490da7b..2dc1162 100644 --- a/src/Core/Model/TeamModel.php +++ b/src/Core/Model/TeamModel.php @@ -41,11 +41,18 @@ class TeamModel { * @param string $mail * @param int $teamId * @param string $role - * @return void + * @return int */ - public function addMember(string $mail, int $teamId, string $role): void { - $userId = $this->users->getAccountFromMail($mail)->getUser()->getId(); - $this->members->insert($teamId, $userId, $role); + public function addMember(string $mail, int $teamId, string $role): int { + $user = $this->users->getAccountFromMail($mail); + if($user == null){ + return -1; + } + if(!$this->members->isMemberOfTeam($teamId,$user->getUser()->getId())){ + $this->members->insert($teamId, $user->getUser()->getId(), $role); + return 1; + } + return -2; } /** @@ -63,7 +70,7 @@ class TeamModel { * @return ?Team */ public function getTeam(int $idTeam, int $idCurrentUser): ?Team { - if($this->members->isMemberOfTeam($idTeam,$idCurrentUser)){ + if(!$this->members->isMemberOfTeam($idTeam,$idCurrentUser)){ return null; } $teamInfo = $this->teams->getTeamById($idTeam); @@ -77,14 +84,16 @@ class TeamModel { * @param int $teamId * @return int */ - public function deleteMember(string $mail, int $teamId): int { - $userId = $this->users->getAccountFromMail($mail)->getUser()->getId(); - $this->members->remove($teamId, $userId); + public function deleteMember(int $idMember, int $teamId): int { + $this->members->remove($teamId, $idMember); + if(empty($this->members->getMembersOfTeam($teamId))){ + $this->teams->deleteTeam($teamId); + return -1; + } return $teamId; } public function deleteTeam(string $email, int $idTeam): int{ - $this->members->isCoach($email,$idTeam); if($this->members->isCoach($email,$idTeam)){ $this->teams->deleteTeam($idTeam); return 0;