Skip to content
This repository has been archived by the owner on Feb 24, 2021. It is now read-only.

Commit

Permalink
Team managment
Browse files Browse the repository at this point in the history
  • Loading branch information
pajasry committed Mar 6, 2020
1 parent 5394a46 commit 1dd2fb2
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 8 deletions.
1 change: 1 addition & 0 deletions public/css/niners.css
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
box-sizing: border-box;
}


html {
font-family: sans-serif;
line-height: 1.15;
Expand Down
36 changes: 36 additions & 0 deletions public/js/user_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,40 @@ $(".team-points").click((e)=>{
})
})
location.reload()
})

$(".addTeam").click((e)=>{
e.preventDefault()
let a = $(e.target);
if(!a.attr('href'))
a = $(a.parent('a'));
const modal = $('#addTeamModal').modal('show')
modal.append(`<span id="a${a.attr('id')}" class="userId"></span>`);
})

$('.newBadget').click((e)=>{
const badget =$(e.target)
if(badget.parent().attr('id')=="selectedBadges")
$('#badgeSelection').append(badget);
else
$('#selectedBadges').append(badget);
})

$('#addTeamModalSave').click((e)=>{
e.preventDefault();
let badges = $('#selectedBadges').find('.badge').toArray().map(x=>x.innerText);
const userId= $("#addTeamModal").find('.userId').attr('id').substring(1);
$.ajax({
url: $('#'+userId).attr('href'),
type: "post",
dataType:"json",
data: JSON.stringify(badges),
success:(r)=>{
console.log(r)
location.reload();
},
error:(e)=>{
console.log(e)
}
})
})
3 changes: 1 addition & 2 deletions src/Controller/ApiTeamController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public function changePoints(Team $team,Request $request, EntityManagerInterface
return new JsonResponse('Karma of all team member was updated',200);
}
return new JsonResponse("Something bad happens. Because dev was lazy and under pressure he wasnt make proper error message",500);


}

}
17 changes: 16 additions & 1 deletion src/Controller/ApiUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Controller;

use App\Entity\User;
use App\Repository\TeamRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
Expand Down Expand Up @@ -44,7 +45,21 @@ public function updateUser(User $user = null, Request $request, UserPasswordEnco
}
$manager->flush();
return new JsonResponse('OK');
}


/**
* @Route("/api/user/{id}/addTeams", name="api_user_addTeams")
*/
public function addTeams(User $user = null, Request $request, EntityManagerInterface $manager, TeamRepository $teamRepository){
if(empty($user))
return new JsonResponse('User not found',404);
$teams = json_decode($request->getContent());
foreach ($teams as $t){
$sel = $teamRepository->findOneBy(['name'=>$t]);
if(!empty($sel))
$user->addTeam($sel);
}
$manager->flush();
return new JsonResponse('OK');
}
}
6 changes: 3 additions & 3 deletions templates/main/home.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
<img class="card-img-top rounded-circle p-3" src="{{ asset('img/knespl_rect.png') }}" alt="Card image cap">
<div class="card-body text-center">
<h3 class="text-primary">Martin <br>Knespl</h3>
<p class="card-text">Design</p>
<p class="card-text">Design, 3D tisk </p>
<a class="btn btn-outline-primary btn-social" href="https://www.facebook.com/profile.php?id=100008251950290">
<i class="fab fa-fw fa-facebook-f"></i>
</a>
Expand All @@ -139,7 +139,7 @@
<img class="card-img-top rounded-circle p-3" src="{{ asset('img/roubova_rect.png') }}" alt="Card image cap">
<div class="card-body text-center">
<h3 class="text-primary">Jana <br>Roubová</h3>
<p class="card-text">Didaktické materiály</p>
<p class="card-text">Didaktické materiály </p>
<a class="btn btn-outline-primary btn-social mx-1" href="https://instagram.com/janaroubova?igshid=wgkn81mu1rai">
<i class="fab fa-fw fa-instagram"></i>
</a>
Expand All @@ -150,7 +150,7 @@
<img class="card-img-top rounded-circle p-3" src="{{asset('img/srytr_rect.png')}}" alt="Card image cap">
<div class="card-body text-center">
<h3 class="text-primary">Pavel <br>Šrytr</h3>
<p class="card-text">Návrh DPS, programování</p>
<p class="card-text text-nowrap">Návrh DPS, programování</p>
<a class="btn btn-outline-primary btn-social" href="https://github.com/pajasry">
<i class="fab fa-fw fa-github"></i>
</a>
Expand Down
33 changes: 31 additions & 2 deletions templates/user/list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<th scope="col">#</th>
<th scope="col"></th>
<th scope="col">Jméno</th>
<th scope="col">Týmy</th>
<th scope="col" class="d-lg-block d-md-none">Týmy</th>
<th scope="col">Karma</th>
<th scope="col"></th>
</tr>
Expand All @@ -52,12 +52,15 @@
<img src="{{ u.avatar }}" class="img img-fluid rounded-circle" width="50" alt="User avatar">
</td>
<td scope="col"><a href="{{ path("user_profile",{'slug':u.slug}) }}"> {{ u }}</a></td>
<td scope="col" style="max-width: 200px">
<td scope="col" class="d-lg-block d-md-none" style="max-width: 200px">
{% for t in u.teams %}
<div class="badge" style="background-color: rgb({{ t.color }})">
{{ t.name }}
</div>
{% endfor %}
<a id="a{{ u.id }}" class="badge badge-dark addTeam" href="{{ path('api_user_addTeams',{'id':u.id}) }}">
<i class="fas fa-plus"></i>
</a>
</td>
<td scope="col" class="karma">
{{ u.karma }}
Expand All @@ -74,4 +77,30 @@
</table>
</div>
</div>
<div id ="addTeamModal" class="modal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Přidat do týmu</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div id="badgeSelection">
{% for t in teams %}
<div id = "{{ t.id }}" class="badge my-2 newBadget" style="background-color: rgb({{ t.color }})">
{{ t.name }}
</div>
{% endfor %}
</div>
<div id='selectedBadges' class="border-top border-dark"></div>
</div>
<div class="modal-footer">
<button id="addTeamModalSave" type="button" class="btn btn-primary">Uložit</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Zavřít</button>
</div>
</div>
</div>
</div>
{% endblock %}

0 comments on commit 1dd2fb2

Please sign in to comment.