fully implemented the add of members + added style on the page + almost done implementing the remove of members
continuous-integration/drone/push Build is failing Details

pull/84/head
Maël DAIM 1 year ago
parent c0a02c91c5
commit d2ac21a906

@ -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;
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;
}
border-radius: 10px;
margin-top: 5px;
margin-bottom: 5px;
.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;
#profilePicture{
height:40px;
width:40px;
}
.close {
position: absolute;
top: 10px;
right: 10px;
font-size: 20px;
cursor: pointer;
}

@ -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 (
<div id="mainDiv">
<header>
@ -13,7 +13,7 @@ export default function TeamPanel({isCoach, team}: {isCoach: boolean, team: Team
{isCoach && <CoachOptions id={team.info.id}/>}
<MembersDisplay members={team.members}/>
<MembersDisplay members={team.members} isCoach={isCoach} idTeam={team.info.id} currentUserId={currentUserId}/>
</div>
)
}
@ -21,17 +21,21 @@ export default function TeamPanel({isCoach, team}: {isCoach: boolean, team: Team
function TeamDisplay({ team}: {team : TeamInfo}) {
return (
<div id="teamInfo">
<div>
<h1>{team.name}</h1>
<div id="firstPart">
<h1 id="teamName">{team.name}</h1>
<img id="logo" src={team.picture} alt="Logo d'équipe" />
</div>
<div id="colors">
<div id="colorsTitle">
<p>Couleur principale</p>
<ColorDisplay color={team.mainColor}/>
<p>Couleur secondaire</p>
</div>
<div id="actualColors">
<ColorDisplay color={team.mainColor}/>
<ColorDisplay color={team.secondColor}/>
</div>
</div>
</div>
)
}
@ -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) =>
<MemberDisplay member={member}/>
<MemberDisplay member={member} isCoach={isCoach} idTeam={idTeam} currentUserId={currentUserId}/>
);
return (
<div id="Members">
<div id="headMembers">
<h2>Membres :</h2>
<button id="addMember" onClick={()=> window.location.href=`${BASE}/team//addMember`}>+</button>
{isCoach && <button id="addMember" onClick={()=> window.location.href=`${BASE}/team/${idTeam}/addMember`}>+</button>}
</div>
{listMember}
</div>
)
}
function MemberDisplay({member}: {member : Member}){
function MemberDisplay({member,isCoach,idTeam,currentUserId}: {member : Member,isCoach : boolean,idTeam:number,currentUserId:number}){
return (
<div className="Member">
<img id="profilePicture" src={member.user.profilePicture} alt="Photo de profile"/>
<p>{member.user.name}</p>
<p>{member.role}</p>
<p>{member.user.email}</p>
{isCoach && currentUserId !== member.user.id && <button id="delete" onClick={()=>confirm("Êtes-vous sûr de retirer ce membre de l'équipe?") ? window.location.href=`${BASE}/team/${idTeam}/remove/${member.user.id}` : {}}>Retirer</button>}
{isCoach && currentUserId == member.user.id && <button id="delete" onClick={()=>confirm("Êtes-vous sûr de quitter cette équipe?") ? window.location.href=`${BASE}/team/${idTeam}/remove/${member.user.id}` : {}}>Quitter</button>}
</div>
)
}

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

@ -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,13 +158,22 @@ class TeamController {
$errors = [];
$request = HttpRequest::from($request, $errors, [
"team" => [Validators::isInteger()],
"email" => [Validators::email(), Validators::lenBetween(5, 256)],
]);
if(!empty($errors)){
return ViewHttpResponse::twig('add_member.html.twig',['badEmail' => true,'idTeam'=> $idTeam]);
}
$ret = $this->model->addMember($request['email'], $idTeam, $request['role']);
$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);
}
}
/**
* remove a member from a team
@ -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);
}
}

@ -67,26 +67,43 @@
display: flex;
justify-content: space-between;
}
.failed{
color: red;
}
</style>
</head>
<body>
<header>
<h1><a href="{{ path('/') }}">IQBall</a></h1>
</header>
<div class="container">
<h2>Ajouter un membre à votre équipe</h2>
<form action="{{ path('/team/#/addMember') }}" method="POST">
<form action="{{ path("/team/#{idTeam}/addMember") }}" method="POST">
<div class="form-group">
<label for="mail">Email du membre :</label>
<input type="text" id="mail" name="mail" required>
<label for="email">Email du membre :</label>
{% if badEmail %}
<p class="failed">Email invalide</p>
{% endif %}
{%if notFound %}
<p class="failed">Cette personne n'a pas été trouvé</p>
{% endif %}
{% if alreadyExisting %}
<p class="failed">Cette personne est déjà dans l'équipe</p>
{% endif %}
<input type="text" id="email" name="email" required>
<fieldset class="role">
<legend>Rôle du membre dans l'équipe :</legend>
<div class="radio">
<label for="P">Joueur</label>
<input type="radio" id="P" name="role" value="P" checked />
<input type="radio" id="P" name="role" value="PLAYER" checked />
</div>
<div class="radio">
<label for="C">Coach</label>
<input type="radio" id="C" name="role" value="C" />
<input type="radio" id="C" name="role" value="COACH" />
</div>
</fieldset>

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

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

Loading…
Cancel
Save