Skip to content

Commit

Permalink
Updated charts.
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentmuller committed Dec 10, 2024
1 parent 76f7228 commit 1dcbf70
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 95 deletions.
28 changes: 14 additions & 14 deletions composer.lock

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

4 changes: 2 additions & 2 deletions src/Security/LoginFormAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct(

public function authenticate(Request $request): Passport
{
$this->validateCaptcha($request);
$this->validatePassport($request);

$userIdentifier = $this->getUserIdentifier($request);
$password = $this->getPassword($request);
Expand Down Expand Up @@ -109,7 +109,7 @@ private function getUserIdentifier(Request $request): string
return $userIdentifier;
}

private function validateCaptcha(Request $request): void
private function validatePassport(Request $request): void
{
if (!$this->applicationService->isDisplayCaptcha()) {
return;
Expand Down
75 changes: 39 additions & 36 deletions templates/chart/chart_month.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@
<th class="text-nowrap">{{ 'chart.month.fields.month'|trans }}</th>
<th class="text-currency">{{ 'calculation.list.title'|trans }}</th>
<th class="text-center">
<div class="d-inline-flex align-items-baseline justify-content-center">
<div class="d-flex align-items-center justify-content-center">
<span class="border me-1" style="width: 1.25rem; height: 0.75rem; background: {{ color_amount }};"></span>
<span class="ms-auto">{{ 'calculationgroup.fields.amount'|trans }}</span>
</div>
</th>
<th class="text-center" colspan="2">
<div class="d-inline-flex align-items-baseline justify-content-center">
<div class="d-flex align-items-center justify-content-center">
<span class="border me-1" style="width: 1.25rem; height: 0.75rem; background: {{ color_margin }};"></span>
<span>{{ 'calculation.fields.margin'|trans }}</span>
</div>
Expand All @@ -71,43 +71,46 @@
</thead>
<tbody data-link="row" class="rowlink">
{% for item in data -%}
{%- set month = item.date|locale_date('none', 'MMMM Y') -%}
{%- set parameters = {search: item.date|locale_date('none', 'MM.Y')} -%}
<tr title="{{ 'chart.month.row'|trans({'%name%': month}) }}">
<td class="text-nowrap">
<a href="{{ path(list_path, parameters) }}">{{ month }}</a>
</td>
<td class="text-currency position-relative ps-4">
{{- _self.cell_value(item.count|round, last_count|default) -}}
{%- set last_count = item.count|round -%}
</td>
<td class="text-currency position-relative ps-4">
{{- _self.cell_value(item.items|round, last_items|default) -}}
{%- set last_items = item.items|round -%}
</td>
<td class="text-currency position-relative ps-4">
{{- _self.cell_value(item.margin_amount|round, last_amount|default) -}}
{%- set last_amount = item.margin_amount|round -%}
</td>
<td class="text-percent position-relative ps-4{{ _self.margin_below_class(item.margin_percent, min_margin) }}"{{ _self.margin_below_tooltip(item.margin_percent, min_margin) }}>
{{- _self.cell_value(item.margin_percent|round(2, 'floor'), last_percent|default, true) -}}
{%- set last_percent = item.margin_percent|round(2, 'floor') -%}
</td>
<td class="text-currency position-relative ps-4">
{{- _self.cell_value(item.total|round, last_sum|default) -}}
{%- set last_sum = item.total|round -%}
</td>
</tr>
{%- set month = item.date|locale_date('none', 'MMMM Y') -%}
{%- set parameters = {search: item.date|locale_date('none', 'MM.Y')} -%}
<tr title="{{ 'chart.month.row'|trans({'%name%': month}) }}">
<td class="text-nowrap">
<a class="d-flex" href="{{ path(list_path, parameters) }}">{{ month }}</a>
</td>
<td class="text-currency position-relative ps-4">
{{- _self.cell_value(item.count|round, last_count|default) -}}
</td>
<td class="text-currency position-relative ps-4">
{{- _self.cell_value(item.items|round, last_items|default) -}}
</td>
<td class="text-currency position-relative ps-4">
{{- _self.cell_value(item.margin_amount|round, last_amount|default) -}}
</td>
<td class="text-percent position-relative ps-4{{ _self.margin_below_class(item.margin_percent, min_margin) }}"
{{ _self.margin_below_tooltip(item.margin_percent, min_margin) }}>
{{- _self.cell_value(item.margin_percent|round(2, 'floor'), last_percent|default, true) -}}
</td>
<td class="text-currency position-relative ps-4">
{{- _self.cell_value(item.total|round, last_total|default) -}}
</td>
</tr>
{%- set last_count = item.count|round -%}
{%- set last_items = item.items|round -%}
{%- set last_amount = item.margin_amount|round -%}
{%- set last_percent = item.margin_percent|round(2, 'floor') -%}
{%- set last_total = item.total|round -%}
{% endfor -%}
<tr title="{{ 'chart.row_all'|trans }}">
<td class="fw-bold text-nowrap">
<tr title="{{ 'chart.row_all'|trans }}" class="fw-bold">
<td class="text-nowrap">
<a href="{{ path(list_path) }}">{{ 'calculation.fields.total'|trans }}</a>
</td>
<td class="fw-bold text-currency">{{ totals.count|integer }}</td>
<td class="fw-bold text-currency">{{ totals.items|integer }}</td>
<td class="fw-bold text-currency">{{ totals.margin_amount|integer }}</td>
<td class="fw-bold text-percent{{ _self.margin_below_class(totals.margin_percent, min_margin) }}"{{ _self.margin_below_tooltip(totals.margin_percent, min_margin) }}>{{ totals.margin_percent|percent }}</td>
<td class="fw-bold text-currency">{{ totals.total|integer }}</td>
<td class="text-currency">{{ totals.count|integer }}</td>
<td class="text-currency">{{ totals.items|integer }}</td>
<td class="text-currency">{{ totals.margin_amount|integer }}</td>
<td class="text-percent{{ _self.margin_below_class(totals.margin_percent, min_margin) }}"
{{- _self.margin_below_tooltip(totals.margin_percent, min_margin) }}>{{ totals.margin_percent|percent -}}
</td>
<td class="text-currency">{{ totals.total|integer }}</td>
</tr>
</tbody>
{% endblock %}
Expand Down
32 changes: 19 additions & 13 deletions templates/chart/chart_state.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,37 @@
{% for item in data -%}
<tr title="{{ 'chart.state.row'|trans({'%name%': item.code}) }}">
<td class="text-nowrap">
<div class="d-flex align-items-center">
<a class="d-flex align-items-center" href="{{ path(list_path, {stateId: item.id}) }}">
<span class="border me-1" style="width: 1.5rem; height: 1rem; background: {{ item.color }}"></span>
<a href="{{ path(list_path, {stateId: item.id}) }}">{{- item.code }}</a>
</div>
<span>{{ item.code }}</span>
</a>
</td>
<td class="text-currency">{{ item.count|integer }}</td>
<td class="text-percent">{{ item.percent_calculation|percent(true, 2, 5) }}</td>
<td class="text-currency">{{ item.items|amount }}</td>
<td class="text-currency">{{ item.margin_amount|amount }}</td>
<td class="text-percent{{ _self.margin_below_class(item.margin_percent, min_margin) }}"{{ _self.margin_below_tooltip(item.margin_percent, min_margin) }}>{{ item.margin_percent|percent }}</td>
<td class="text-percent{{ _self.margin_below_class(item.margin_percent, min_margin) }}"
{{ _self.margin_below_tooltip(item.margin_percent, min_margin) }}>
{{- item.margin_percent|percent -}}
</td>
<td class="text-currency">{{ item.total|amount }}</td>
<td class="text-percent">{{ item.percent_amount|percent(true, 2, 5) }}</td>
</tr>
{% endfor -%}
<tr title="{{ 'chart.row_all'|trans }}">
<td class="fw-bold text-nowrap">
<tr title="{{ 'chart.row_all'|trans }}" class="fw-bold">
<td class="text-nowrap">
<a href="{{ path(list_path) }}">{{ 'calculation.fields.total'|trans }}</a>
</td>
<td class="fw-bold text-currency">{{ totals.calculation_count|integer }}</td>
<td class="fw-bold text-percent">{{ totals.calculation_percent|percent(true, 2, 5) }}</td>
<td class="fw-bold text-currency">{{ totals.items_amount|amount }}</td>
<td class="fw-bold text-currency">{{ totals.margin_amount|amount }}</td>
<td class="fw-bold text-percent{{ _self.margin_below_class(totals.margin_percent, min_margin) }}"{{ _self.margin_below_tooltip(totals.margin_percent, min_margin) }}>{{- totals.margin_percent|percent -}}</td>
<td class="fw-bold text-currency">{{ totals.total_amount|amount }}</td>
<td class="fw-bold text-percent">{{ totals.total_percent|percent(true, 2, 5) }}</td>
<td class="text-currency">{{ totals.calculation_count|integer }}</td>
<td class="text-percent">{{ totals.calculation_percent|percent(true, 2, 5) }}</td>
<td class="text-currency">{{ totals.items_amount|amount }}</td>
<td class="text-currency">{{ totals.margin_amount|amount }}</td>
<td class="text-percent{{ _self.margin_below_class(totals.margin_percent, min_margin) }}"
{{ _self.margin_below_tooltip(totals.margin_percent, min_margin) }}>
{{- totals.margin_percent|percent -}}
</td>
<td class="text-currency">{{ totals.total_amount|amount }}</td>
<td class="text-percent">{{ totals.total_percent|percent(true, 2, 5) }}</td>
</tr>
</tbody>
{% endblock %}
Expand Down
62 changes: 34 additions & 28 deletions tests/Security/LoginFormAuthenticatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\Exception\CustomUserMessageAuthenticationException;
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\BadgeInterface;
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\CsrfTokenBadge;
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\PasswordUpgradeBadge;
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\RememberMeBadge;
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
use Symfony\Component\Security\Http\Authenticator\Passport\Credentials\PasswordCredentials;
use Symfony\Component\Security\Http\Authenticator\Passport\Passport;
use Symfony\Component\Security\Http\HttpUtils;

Expand Down Expand Up @@ -64,14 +64,10 @@ public function testAuthenticate(): void
SecurityAttributes::PASSWORD_FIELD => 'password',
SecurityAttributes::LOGIN_TOKEN => 'token',
];
$request = self::createRequest(values: $values);
$request->setSession(new Session(new MockArraySessionStorage()));
$request = self::createRequest(values: $values, session: $this->createSession());

$passport = $authenticator->authenticate($request);
self::assertHasBadge($passport, UserBadge::class);
self::assertHasBadge($passport, RememberMeBadge::class);
self::assertHasBadge($passport, PasswordUpgradeBadge::class);
self::assertHasBadge($passport, CsrfTokenBadge::class);
$this->validatePassport($passport);
}

/**
Expand Down Expand Up @@ -140,7 +136,7 @@ public function testAuthenticateEmptyUserName(): void
/**
* @throws Exception
*/
public function testAuthenticateWithUserProvider(): void
public function testAuthenticateWithSession(): void
{
$userProvider = $this->createMock(UserRepository::class);
$authenticator = $this->createAuthenticator(repository: $userProvider);
Expand All @@ -150,14 +146,10 @@ public function testAuthenticateWithUserProvider(): void
SecurityAttributes::PASSWORD_FIELD => 'password',
SecurityAttributes::LOGIN_TOKEN => 'token',
];
$request = self::createRequest(values: $values);
$request->setSession(new Session(new MockArraySessionStorage()));
$request = self::createRequest(values: $values, session: $this->createSession());

$passport = $authenticator->authenticate($request);
self::assertHasBadge($passport, UserBadge::class);
self::assertHasBadge($passport, RememberMeBadge::class);
self::assertHasBadge($passport, PasswordUpgradeBadge::class);
self::assertHasBadge($passport, CsrfTokenBadge::class);
$this->validatePassport($passport);
}

/**
Expand Down Expand Up @@ -198,11 +190,10 @@ public function testCaptchaNotDisplay(): void
SecurityAttributes::PASSWORD_FIELD => 'password',
SecurityAttributes::LOGIN_TOKEN => 'token',
];
$request = self::createRequest(values: $values);
$request->setSession(new Session(new MockArraySessionStorage()));
$request = self::createRequest(values: $values, session: $this->createSession());

$actual = $authenticator->authenticate($request);
self::assertInstanceOf(Passport::class, $actual);
$passport = $authenticator->authenticate($request);
$this->validatePassport($passport);
}

/**
Expand Down Expand Up @@ -284,15 +275,6 @@ public function testSupports(Request $request, bool $expected): void
self::assertSame($expected, $actual);
}

/**
* @param class-string<BadgeInterface> $badgeClass
*/
protected static function assertHasBadge(Passport $passport, string $badgeClass): void
{
$actual = $passport->getBadge($badgeClass);
self::assertInstanceOf($badgeClass, $actual);
}

/**
* @throws Exception
*/
Expand All @@ -318,12 +300,36 @@ private function createAuthenticator(
private static function createRequest(
array $values = [],
string $method = Request::METHOD_POST,
string $contentType = 'application/x-www-form-urlencoded'
string $contentType = 'application/x-www-form-urlencoded',
?Session $session = null
): Request {
$request = new Request(request: $values);
$request->setMethod($method);
$request->headers->set('Content-Type', $contentType);
if ($session instanceof Session) {
$request->setSession($session);
}

return $request;
}

private function createSession(): Session
{
return new Session(new MockArraySessionStorage());
}

private function validatePassport(Passport $passport): void
{
$classes = [
UserBadge::class,
PasswordCredentials::class,
RememberMeBadge::class,
PasswordUpgradeBadge::class,
CsrfTokenBadge::class,
];
foreach ($classes as $class) {
$actual = $passport->getBadge($class);
self::assertInstanceOf($class, $actual);
}
}
}
4 changes: 2 additions & 2 deletions vendor-bin/psalm/composer.lock

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

0 comments on commit 1dcbf70

Please sign in to comment.