Skip to content

Commit

Permalink
#181: Added data provider choice to sprint report
Browse files Browse the repository at this point in the history
  • Loading branch information
tuj committed Jan 4, 2024
1 parent ef7c95b commit 4442457
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 43 deletions.
94 changes: 60 additions & 34 deletions src/Controller/SprintReportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Controller;

use App\Entity\DataProvider;
use App\Exception\UnsupportedDataProviderException;
use App\Form\SprintReportType;
use App\Interface\DataProviderServiceInterface;
Expand All @@ -11,6 +12,7 @@
use App\Service\SprintReportService;
use Mpdf\Mpdf;
use Mpdf\MpdfException;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\HttpFoundation\JsonResponse;
Expand All @@ -22,8 +24,6 @@
#[Route('/admin/sprint-report')]
class SprintReportController extends AbstractController
{
private DataProviderServiceInterface $service;

/**
* @throws UnsupportedDataProviderException
*/
Expand All @@ -32,11 +32,11 @@ public function __construct(
private readonly DataProviderService $dataProviderService,
private readonly DataProviderRepository $dataProviderRepository,
) {
// TODO: Data provider should be selectable.
$dataProvider = $this->dataProviderRepository->find(1);
$this->service = $this->dataProviderService->getService($dataProvider);
}

/**
* @throws UnsupportedDataProviderException
*/
#[Route('/', name: 'app_sprint_report')]
public function index(Request $request): Response
{
Expand All @@ -50,25 +50,18 @@ public function index(Request $request): Response
'csrf_protection' => false,
]);

$projectCollection = $this->service->getSprintReportProjects();

$projectChoices = [];

foreach ($projectCollection->projects as $project) {
$projectChoices[$project->name] = $project->id;
}

// Override projectId with element with choices.
$form->add('projectId', ChoiceType::class, [
'placeholder' => 'sprint_report.select_an_option',
'choices' => $projectChoices,
'required' => true,
'label' => 'sprint_report.select_project',
$form->add('dataProvider', EntityType::class, [
'class' => DataProvider::class,
'required' => false,
'label' => 'sprint_report.data_provider',
'label_attr' => ['class' => 'label'],
'row_attr' => ['class' => 'form-row'],
'attr' => [
'data-sprint-report-target' => 'project',
'data-action' => 'sprint-report#submitFormProjectId',
'class' => 'form-element',
],
'help' => 'sprint_report.data_provider_helptext',
'choices' => $this->dataProviderRepository->findAll(),
]);

$requestData = $request->query->all();
Expand All @@ -77,26 +70,56 @@ public function index(Request $request): Response
$requestData = $requestData['sprint_report'];
}

if (!empty($requestData['projectId'])) {
$versionCollection = $this->service->getSprintReportProjectVersions($requestData['projectId']);
if (!empty($requestData['dataProvider'])) {
$dataProvider = $this->dataProviderRepository->find($requestData['dataProvider']);
$service = $this->dataProviderService->getService($dataProvider);

Check failure on line 75 in src/Controller/SprintReportController.php

View workflow job for this annotation

GitHub Actions / Psalm static analysis (8.1)

PossiblyNullArgument

src/Controller/SprintReportController.php:75:63: PossiblyNullArgument: Argument 1 of App\Service\DataProviderService::getService cannot be null, possibly null value provided (see https://psalm.dev/078)

$projectCollection = $service->getSprintReportProjects();

$projectChoices = [];

$versionChoices = [];
foreach ($versionCollection->versions as $version) {
$versionChoices[$version->headline] = $version->id;
foreach ($projectCollection->projects as $project) {
$projectChoices[$project->name] = $project->id;
}

// Override versionId with element with choices.
$form->add('versionId', ChoiceType::class, [
// Override projectId with element with choices.
$form->add('projectId', ChoiceType::class, [
'placeholder' => 'sprint_report.select_an_option',
'choices' => $versionChoices,
'required' => true,
'label' => 'sprint_report.select_version',
'choices' => $projectChoices,
'required' => false,
'label' => 'sprint_report.select_project',
'label_attr' => ['class' => 'label'],
'row_attr' => ['class' => 'form-row form-choices'],
'attr' => [
'data-sprint-report-target' => 'version',
'data-action' => 'sprint-report#submitForm',
'data-sprint-report-target' => 'project',
'data-action' => 'sprint-report#submitFormProjectId',
'data-choices-target' => 'choices',
],
]);

if (!empty($requestData['projectId'])) {
$versionCollection = $service->getSprintReportProjectVersions($requestData['projectId']);

$versionChoices = [];
foreach ($versionCollection->versions as $version) {
$versionChoices[$version->headline] = $version->id;
}

// Override versionId with element with choices.
$form->add('versionId', ChoiceType::class, [
'placeholder' => 'sprint_report.select_an_option',
'choices' => $versionChoices,
'required' => true,
'label' => 'sprint_report.select_version',
'label_attr' => ['class' => 'label'],
'row_attr' => ['class' => 'form-row form-choices'],
'attr' => [
'data-choices-target' => 'choices',
'data-sprint-report-target' => 'version',
'data-action' => 'sprint-report#submitForm',
],
]);
}
}

$form->handleRequest($request);
Expand All @@ -106,9 +129,12 @@ public function index(Request $request): Response

$projectId = $form->get('projectId')->getData();
$versionId = $form->get('versionId')->getData();
$dataProvider = $form->get('dataProvider')->getData();

if (!empty($projectId) && !empty($versionId) && !empty($dataProvider)) {
$service = $this->dataProviderService->getService($dataProvider);

if (!empty($projectId) && !empty($versionId)) {
$reportData = $this->service->getSprintReportData($projectId, $versionId);
$reportData = $service->getSprintReportData($projectId, $versionId);

$budget = $this->sprintReportService->getBudget($projectId, $versionId);
}
Expand Down
5 changes: 5 additions & 0 deletions src/Entity/DataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,9 @@ public function setEnableAccountSync(bool $enableAccountSync): static

return $this;
}

public function __toString(): string

Check failure on line 101 in src/Entity/DataProvider.php

View workflow job for this annotation

GitHub Actions / Psalm static analysis (8.1)

InvalidToString

src/Entity/DataProvider.php:101:35: InvalidToString: __toString methods must return a string, null|string returned (see https://psalm.dev/055)
{
return $this->getName();

Check failure on line 103 in src/Entity/DataProvider.php

View workflow job for this annotation

GitHub Actions / Psalm static analysis (8.1)

NullableReturnStatement

src/Entity/DataProvider.php:103:16: NullableReturnStatement: The declared return type 'string' for App\Entity\DataProvider::__toString is not nullable, but the function returns 'null|string' (see https://psalm.dev/139)
}
}
1 change: 1 addition & 0 deletions src/Form/SprintReportType.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class SprintReportType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('dataProvider')
->add('projectId', ChoiceType::class, [
'placeholder' => 'sprint_report.select_an_option',
'required' => true,
Expand Down
3 changes: 3 additions & 0 deletions src/Model/SprintReport/SprintReportFormData.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

namespace App\Model\SprintReport;

use App\Entity\DataProvider;

class SprintReportFormData
{
public DataProvider $dataProvider;
public string $projectId;
public string $versionId;
}
2 changes: 1 addition & 1 deletion templates/sprint_report/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@
{% endif %}
</div>
</div>
{% endblock %}
{% endblock %}
18 changes: 10 additions & 8 deletions translations/messages.da.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ create_project_submitted:
text: For at knytte projektet til dit team skal du følge linket herunder og klikke "Add Project Link" under "Links to Projects", find og vælg dit nye projekt på listen.

sprint_report:
data_provider_helptext: ''
data_provider: 'Vælg datakilde'
select_project: Vælg projekt
select_version: Vælg version
select_an_option: Vælg en mulighed
Expand Down Expand Up @@ -90,19 +92,19 @@ sprint_report:

navigation:
home: Forside
create_project: Projektopretter
invoices: Faktura
planning: Planlægning
sprint_report: Sprintrapport
create_project: 'Projektopretter'
invoices: 'Faktura'
planning: 'Planlægning'
sprint_report: 'Sprintrapport'
title: 'Economics'
accounts: Konto
accounts: 'Konto'
project_billing: 'Projektfakturering'
projects: 'Projekter'

planning:
title: Planlægning
assignees: Brugere
projects: Projekter
title: 'Planlægning'
assignees: 'Brugere'
projects: 'Projekter'
hidden-entries: 'Skjulte brugere'

invoices:
Expand Down

0 comments on commit 4442457

Please sign in to comment.