Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1280: Simplified planning form. Added default value #112

Merged
merged 21 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ APP_INVOICE_SUPPLIER_ACCOUNT=APP_INVOICE_SUPPLIER_ACCOUNT
APP_INVOICE_RECEIVER_DEFAULT_ACCOUNT=APP_INVOICE_DEFAULT_RECEIVER_ACCOUNT
APP_INVOICE_DESCRIPTION_TEMPLATE="Spørgsmål vedrørende fakturaen rettes til %name%, %email%."
APP_PROJECT_BILLING_DEFAULT_DESCRIPTION=
APP_DEFAULT_PLANNING_DATA_PROVIDER=
###< Planning ###

###> itk-dev/openid-connect-bundle ###
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

* [PR-114](https://github.com/itk-dev/economics/pull/114)
1258: Clean up planning view ui and add scroll to active sprint.
* [PR-112](https://github.com/itk-dev/economics/pull/112)
1280: Simplified planning form. Added default value.
* [PR-113](https://github.com/itk-dev/economics/pull/113)
Worklog period filter
* [PR-110](https://github.com/itk-dev/economics/pull/110)
Expand Down
7 changes: 5 additions & 2 deletions assets/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
* (and its CSS file) in your base layout (base.html.twig).
*/

// any CSS you import will output into a single css file (app.css in this case)
// Any CSS you import will output into a single css file (app.css in this case)
import "./styles/app.css";

// start the Stimulus application
// Start the Stimulus application
import "./bootstrap";

// Start the Font Awesome icon to svg replacements
import "./fontawesome";
32 changes: 32 additions & 0 deletions assets/controllers/planning-scroll_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Controller } from "@hotwired/stimulus";

/** Scroll to active sprint in planning view */
export default class extends Controller {
static targets = ["column"];

connect() {
const activeColumn = this.columnTargets.find((el) => el.dataset.active);

if (!activeColumn) {
return;
}

const activeIndex = activeColumn.dataset.index;
const scrollToIndex = Math.max(0, activeIndex - 1);
const scrollToColumn = this.columnTargets.find(
(el) => el.dataset.index == scrollToIndex,
);
const firstColumn = this.columnTargets.find(
(el) => el.dataset.index == 1,
);

if (!scrollToColumn || !firstColumn) {
return;
}

const { x } = scrollToColumn.getBoundingClientRect();
const { x: firstColumnX } = firstColumn.getBoundingClientRect();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It took me a while to actually understand what's going on here.

Suggested change
const { x } = scrollToColumn.getBoundingClientRect();
const { x: firstColumnX } = firstColumn.getBoundingClientRect();
const x = scrollToColumn.getBoundingClientRect().x;
const firstColumnX = firstColumn.getBoundingClientRect().x;

is much easier to understand.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed it. Thanks for the suggestion.


scrollContainer.scrollTo(x - firstColumnX, 0);
}
}
12 changes: 12 additions & 0 deletions assets/fontawesome.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Import the svg core library
import { library, dom } from "@fortawesome/fontawesome-svg-core";

// Import the icons from the free solid package.
import {
faMaximize,
faEyeSlash,
faMinimize,
} from "@fortawesome/free-solid-svg-icons";

library.add(faMaximize, faEyeSlash, faMinimize);
dom.i2svg();
1 change: 1 addition & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ services:
$invoiceSupplierAccount: '%env(string:APP_INVOICE_SUPPLIER_ACCOUNT)%'
$invoiceDefaultReceiverAccount: '%env(string:APP_INVOICE_RECEIVER_DEFAULT_ACCOUNT)%'
$projectBillingDefaultDescription: '%env(string:APP_PROJECT_BILLING_DEFAULT_DESCRIPTION)%'
$planningDefaultDataProvider: '%env(string:APP_DEFAULT_PLANNING_DATA_PROVIDER)%'

# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name
Expand Down
98 changes: 98 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
},
"dependencies": {
"@babel/core": "^7.23.9",
"@fortawesome/fontawesome-svg-core": "^6.5.2",
"@fortawesome/free-brands-svg-icons": "^6.5.2",
"@fortawesome/free-regular-svg-icons": "^6.5.2",
"@fortawesome/free-solid-svg-icons": "^6.5.2",
"@hotwired/stimulus": "^3.0.0",
"@symfony/stimulus-bridge": "^3.2.0",
"@symfony/stimulus-bundle": "file:vendor/symfony/stimulus-bundle/assets",
Expand Down
91 changes: 49 additions & 42 deletions src/Controller/PlanningController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,63 @@
use App\Service\ViewService;
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\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Contracts\Translation\TranslatorInterface;

#[Route('/admin/planning')]
class PlanningController extends AbstractController
{
public function __construct(
private readonly DataProviderService $dataProviderService,
private readonly DataProviderRepository $dataProviderRepository,
private readonly TranslatorInterface $translator,
private readonly ViewService $viewService,
private readonly ?string $planningDefaultDataProvider,
) {
}

#[Route('/', name: 'app_planning')]
public function index(Request $request): Response
{
return $this->redirectToRoute('app_planning_users');
}

/**
* @throws UnsupportedDataProviderException
* @throws EconomicsException
*/
#[Route('/', name: 'app_planning')]
public function index(Request $request): Response
#[Route('/users', name: 'app_planning_users')]
public function planningUsers(Request $request): Response
{
return $this->createResponse($request, 'users');
}

/**
* @throws UnsupportedDataProviderException
* @throws EconomicsException
*/
#[Route('/projects', name: 'app_planning_projects')]
public function planningProjects(Request $request): Response
{
return $this->createResponse($request, 'projects');
}

/**
* @throws UnsupportedDataProviderException
* @throws EconomicsException
*/
private function createResponse(Request $request, string $mode): Response
{
$planningFormData = new PlanningFormData();
$form = $this->createForm(PlanningType::class, $planningFormData);

$dataProviders = $this->dataProviderRepository->findAll();
$defaultProvider = $this->dataProviderRepository->find($this->planningDefaultDataProvider);

if (null === $defaultProvider && count($dataProviders) > 0) {
$defaultProvider = $dataProviders[0];
}

$form->add('dataProvider', EntityType::class, [
'class' => DataProvider::class,
'required' => true,
Expand All @@ -48,56 +78,33 @@ public function index(Request $request): Response
'class' => 'form-element',
],
'help' => 'planning.data_provider_helptext',
'choices' => $this->dataProviderRepository->findAll(),
]);

$form->add('viewType', ChoiceType::class, [
'required' => true,
'label' => 'planning.view_type',
'label_attr' => ['class' => 'label'],
'attr' => [
'class' => 'form-element',
],
'help' => 'planning.data_provider_helptext',
'choices' => $this->getTypeChoices(),
'data' => $this->dataProviderRepository->find($this->planningDefaultDataProvider),
'choices' => $dataProviders,
]);

$form->handleRequest($request);

$planningData = null;
$template = 'planning/index.html.twig';
$service = null;

if ($form->isSubmitted() && $form->isValid()) {
$service = $this->dataProviderService->getService($planningFormData->dataProvider);
$viewType = $form->getData()->viewType;
} elseif (null !== $defaultProvider) {
$service = $this->dataProviderService->getService($defaultProvider);
}

switch ($viewType) {
case 'week':
$planningData = $service->getPlanningDataWeeks();
$template = 'planning/planning-weeks.html.twig';
break;
case 'sprint':
$planningData = $service->getPlanningDataSprints();
$template = 'planning/planning-sprints.html.twig';
break;
default:
$planningData = $service->getPlanningDataSprints();
break;
}
try {
$planningData = $service?->getPlanningDataWeeks();
} catch (\Exception $e) {
$error = $e->getMessage();
$planningData = null;
}

return $this->render($template, $this->viewService->addView([
return $this->render('planning/planning.html.twig', $this->viewService->addView([
'controller_name' => 'PlanningController',
'planningData' => $planningData,
'error' => $error ?? null,
'form' => $form,
'mode' => $mode,
]));
}

private function getTypeChoices()
{
return [
$this->translator->trans('planning.week_view') => 'week',
$this->translator->trans('planning.sprint_view') => 'sprint',
];
}
}
11 changes: 5 additions & 6 deletions src/DataFixtures/AppFixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ public function load(ObjectManager $manager): void
$dataProvider1->setUrl('http://localhost/');
$dataProvider1->setSecret('Not so secret');

$manager->persist($dataProvider1);

$dataProviders[] = $dataProvider1;

$dataProvider2 = new DataProvider();
Expand All @@ -38,11 +36,11 @@ public function load(ObjectManager $manager): void
$dataProvider2->setUrl('http://localhost/');
$dataProvider2->setSecret('Not so secret');

$manager->persist($dataProvider2);

$dataProviders[] = $dataProvider2;

foreach ($dataProviders as $key => $dataProvider) {
$manager->persist($dataProvider);

for ($c = 0; $c < 2; ++$c) {
$client = new Client();
$client->setName("client $key-$c");
Expand Down Expand Up @@ -126,8 +124,9 @@ public function load(ObjectManager $manager): void
$manager->flush();
}
}
}

$manager->flush();
$manager->flush();
$manager->clear();
}
}
}
1 change: 0 additions & 1 deletion src/Form/PlanningType.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('dataProvider')
->add('viewType')
;
}

Expand Down
Loading
Loading