- added "today" as selector in date-range dropdown - added feature to prevent auto-select of dropdowns with only one entry - added hint that no changes were detected in batch update - added negative invoice sums are possible (e.g. for credit notes) - fix project list is expanded after submission - fix invalid date parsing causes 500 - fix: prevent auto-select of activities in export and invoice form (in case only one global activity exists) - fix team assignments for customer and project were not saved (using API now) - fix form fieldset with legend styling (e.g. team project assignment) - fix required meta-field were forced to have a value in batch update - fix tomselect meta-field was not disabled in batch update - fix unset internal rate is shown as 0 - fix one minute rounding problem in duration-only mode with "now" being default time - fix column width and label for duration-only mode - tech debt: cleanup invoice template (remove invoice layout) - tech debt: reorder for simpler comparison with invoice form - possible BC for devs: remove unused methods from form trait - bump composer packages (includes new translations for auth screens)
218 lines
7.5 KiB
PHP
218 lines
7.5 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of the Kimai time-tracking app.
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace App\Controller;
|
|
|
|
use App\Entity\Team;
|
|
use App\Form\TeamEditForm;
|
|
use App\Form\Toolbar\TeamToolbarForm;
|
|
use App\Form\Type\CustomerType;
|
|
use App\Form\Type\ProjectType;
|
|
use App\Repository\Query\TeamQuery;
|
|
use App\Repository\TeamRepository;
|
|
use App\Utils\DataTable;
|
|
use App\Utils\PageSetup;
|
|
use Symfony\Component\Form\Extension\Core\Type\FormType;
|
|
use Symfony\Component\Form\FormInterface;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\Routing\Annotation\Route;
|
|
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
|
|
|
#[Route(path: '/admin/teams')]
|
|
#[IsGranted('view_team')]
|
|
final class TeamController extends AbstractController
|
|
{
|
|
public function __construct(private TeamRepository $repository)
|
|
{
|
|
}
|
|
|
|
/**
|
|
* @param TeamRepository $repository
|
|
* @param Request $request
|
|
* @param int $page
|
|
* @return Response
|
|
*/
|
|
#[Route(path: '/', defaults: ['page' => 1], name: 'admin_team', methods: ['GET'])]
|
|
#[Route(path: '/page/{page}', requirements: ['page' => '[1-9]\d*'], name: 'admin_team_paginated', methods: ['GET'])]
|
|
public function listTeams(TeamRepository $repository, Request $request, $page): Response
|
|
{
|
|
$query = new TeamQuery();
|
|
$query->setPage($page);
|
|
$query->setCurrentUser($this->getUser());
|
|
|
|
$form = $this->getToolbarForm($query);
|
|
if ($this->handleSearch($form, $request)) {
|
|
return $this->redirectToRoute('admin_team');
|
|
}
|
|
|
|
$entries = $repository->getPagerfantaForQuery($query);
|
|
|
|
$table = new DataTable('admin_teams', $query);
|
|
$table->setPagination($entries);
|
|
$table->setSearchForm($form);
|
|
$table->setPaginationRoute('admin_team_paginated');
|
|
$table->setReloadEvents('kimai.teamUpdate');
|
|
|
|
$table->addColumn('name', ['class' => 'alwaysVisible']);
|
|
$table->addColumn('teamlead', ['class' => 'd-none badges', 'orderBy' => false]);
|
|
$table->addColumn('teamlead_avatar', ['title' => 'team.member', 'translation_domain' => 'teams', 'class' => 'd-none d-lg-table-cell avatars avatar-list avatar-list-stacked', 'orderBy' => false]);
|
|
$table->addColumn('user', ['class' => 'd-none badges', 'orderBy' => false, 'title' => 'user']);
|
|
$table->addColumn('actions', ['class' => 'actions']);
|
|
|
|
$page = new PageSetup('teams');
|
|
$page->setActionName('teams');
|
|
$page->setHelp('teams.html');
|
|
$page->setDataTable($table);
|
|
|
|
return $this->render('team/index.html.twig', [
|
|
'page_setup' => $page,
|
|
'dataTable' => $table,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @param Request $request
|
|
* @return Response
|
|
*/
|
|
#[Route(path: '/create', name: 'admin_team_create', methods: ['GET', 'POST'])]
|
|
#[IsGranted('create_team')]
|
|
public function createTeam(Request $request): Response
|
|
{
|
|
return $this->renderEditScreen(new Team(''), $request, true);
|
|
}
|
|
|
|
#[Route(path: '/{id}/duplicate', name: 'team_duplicate', methods: ['GET', 'POST'])]
|
|
#[IsGranted('create_team')]
|
|
#[IsGranted('edit', 'team')]
|
|
public function duplicateTeam(Team $team, Request $request): Response
|
|
{
|
|
$newTeam = clone $team;
|
|
|
|
$i = 1;
|
|
do {
|
|
$newName = sprintf('%s (%s)', $team->getName(), $i++);
|
|
} while ($this->repository->count(['name' => $newName]) > 0 && $i < 10);
|
|
$newTeam->setName($newName);
|
|
|
|
return $this->renderEditScreen($newTeam, $request, true);
|
|
}
|
|
|
|
#[Route(path: '/{id}/edit', name: 'admin_team_edit', methods: ['GET', 'POST'])]
|
|
#[IsGranted('edit', 'team')]
|
|
public function editAction(Team $team, Request $request): Response
|
|
{
|
|
return $this->renderEditScreen($team, $request);
|
|
}
|
|
|
|
#[Route(path: '/{id}/edit_member', name: 'admin_team_member', methods: ['GET', 'POST'])]
|
|
#[IsGranted('edit', 'team')]
|
|
public function editMemberAction(Team $team, Request $request): Response
|
|
{
|
|
$editForm = $this->createForm(TeamEditForm::class, $team, [
|
|
'action' => $this->generateUrl('admin_team_member', ['id' => $team->getId()]),
|
|
'method' => 'POST',
|
|
]);
|
|
|
|
$editForm->handleRequest($request);
|
|
|
|
if ($editForm->isSubmitted() && $editForm->isValid()) {
|
|
try {
|
|
$this->repository->saveTeam($team);
|
|
$this->flashSuccess('action.update.success');
|
|
|
|
return $this->redirectToRoute('admin_team_edit', ['id' => $team->getId()]);
|
|
} catch (\Exception $ex) {
|
|
$this->flashUpdateException($ex);
|
|
}
|
|
}
|
|
|
|
$page = new PageSetup('teams');
|
|
$page->setHelp('teams.html');
|
|
|
|
return $this->render('team/edit_member.html.twig', [
|
|
'page_setup' => $page,
|
|
'team' => $team,
|
|
'form' => $editForm->createView(),
|
|
]);
|
|
}
|
|
|
|
private function renderEditScreen(Team $team, Request $request, bool $create = false): Response
|
|
{
|
|
$customerForm = null;
|
|
$projectForm = null;
|
|
|
|
if ($team->getId() === null) {
|
|
$url = $this->generateUrl('admin_team_create');
|
|
} else {
|
|
$url = $this->generateUrl('admin_team_edit', ['id' => $team->getId()]);
|
|
}
|
|
|
|
$editForm = $this->createForm(TeamEditForm::class, $team, [
|
|
'action' => $url,
|
|
'method' => 'POST',
|
|
]);
|
|
|
|
$editForm->handleRequest($request);
|
|
|
|
if ($editForm->isSubmitted() && $editForm->isValid()) {
|
|
try {
|
|
$this->repository->saveTeam($team);
|
|
$this->flashSuccess('action.update.success');
|
|
|
|
if ($create) {
|
|
return $this->redirectToRouteAfterCreate('admin_team_edit', ['id' => $team->getId()]);
|
|
}
|
|
|
|
return $this->redirectToRoute('admin_team_edit', ['id' => $team->getId()]);
|
|
} catch (\Exception $ex) {
|
|
$this->handleFormUpdateException($ex, $editForm);
|
|
}
|
|
}
|
|
|
|
if (null !== $team->getId()) {
|
|
$customerForm = $this->createFormWithName('team_customer_form', FormType::class, $team)
|
|
->add('customers', CustomerType::class, [
|
|
'label' => false,
|
|
'multiple' => true,
|
|
'expanded' => true,
|
|
'query_builder_for_user' => false,
|
|
]);
|
|
|
|
$projectForm = $this->createFormWithName('team_project_form', FormType::class, $team)
|
|
->add('projects', ProjectType::class, [
|
|
'label' => false,
|
|
'multiple' => true,
|
|
'expanded' => true,
|
|
'query_builder_for_user' => false,
|
|
]);
|
|
}
|
|
|
|
$page = new PageSetup('teams');
|
|
$page->setHelp('teams.html');
|
|
|
|
return $this->render('team/edit.html.twig', [
|
|
'page_setup' => $page,
|
|
'team' => $team,
|
|
'form' => $editForm->createView(),
|
|
'customerForm' => $customerForm?->createView(),
|
|
'projectForm' => $projectForm?->createView(),
|
|
]);
|
|
}
|
|
|
|
private function getToolbarForm(TeamQuery $query): FormInterface
|
|
{
|
|
return $this->createSearchForm(TeamToolbarForm::class, $query, [
|
|
'action' => $this->generateUrl('admin_team', [
|
|
'page' => $query->getPage(),
|
|
]),
|
|
]);
|
|
}
|
|
}
|