Skip to content

Commit

Permalink
add filter tag
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Debrigode committed Jan 22, 2024
1 parent c4e397c commit 73e49e9
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 17 deletions.
2 changes: 2 additions & 0 deletions config/packages/twig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ twig:
decimals: 2
decimal_point: ','
thousands_separator: ' '
form_themes:
- 'core/form/_theme.html.twig'
5 changes: 5 additions & 0 deletions public/assets/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,8 @@
.sticky-top-legend {
top: 5px !important;
}

.form-check {
min-height: unset !important;
margin-bottom: unset !important;
}
25 changes: 22 additions & 3 deletions src/Controller/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,15 @@ public function index(
$form = $this->createForm(LegendForm::class);
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$data = $asDataRepository::get($this->base_data['top'], null, (array) $form->getData());
} else {
$data = $asDataRepository::get($this->base_data['top']);
}

return $this->render('pages/index.html.twig', [
'base_data' => $this->base_data,
'data' => $asDataRepository::get($this->base_data['top']),
'data' => $data,
'knownlinks' => KnowlinksRepository::get(),
'form' => [
'legend' => $form->createView(),
Expand All @@ -57,9 +63,10 @@ public function index(
#[Route(
path: '/{topinterval}',
name: 'index_topinterval',
methods: ['GET'],
methods: ['GET|POST'],
)]
public function indexTopInterval(
Request $request,
ConfigApplication $Config,
GetAsDataRepository $asDataRepository,
string $topinterval,
Expand All @@ -70,11 +77,23 @@ public function indexTopInterval(
$Config::getAsStatsConfigTopInterval()[$topinterval]['label']
);

$form = $this->createForm(LegendForm::class);
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$data = $asDataRepository::get($this->base_data['top'], $topinterval, (array) $form->getData());
} else {
$data = $asDataRepository::get($this->base_data['top'], $topinterval);
}

return $this->render('pages/index.html.twig', [
'base_data' => $this->base_data,
'data' => $asDataRepository::get($this->base_data['top'], $topinterval),
'data' => $data,
'hours' => $Config::getAsStatsConfigTopInterval()[$topinterval]['label'],
'knownlinks' => KnowlinksRepository::get(),
'form' => [
'legend' => $form->createView(),
],
]);
}
}
5 changes: 4 additions & 1 deletion src/Form/LegendForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
foreach (KnowlinksRepository::get() as $knowlink) {
$builder
->add(\sprintf('%s', $knowlink['tag']), CheckboxType::class, [
'label' => false,
'label' => $knowlink['descr'],
'translation_domain' => false,
'required' => false,
'label_attr' => [
'class' => 'small float-left',
],
])
;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Repository/GetAsDataRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class GetAsDataRepository
* @throws Exception
* @throws DbErrorException
*/
public static function get(int $top, ?string $topInterval = null): array
public static function get(int $top, ?string $topInterval = null, array $selectedLinks = []): array
{
if (0 === $top) {
return [];
Expand All @@ -33,7 +33,7 @@ public static function get(int $top, ?string $topInterval = null): array
$data = new DbAsStatsRepository($dbName);
$asInfoRepository = new DbAsInfoRepository();

foreach ($data->getASStatsTop($top, []) as $as => $nbytes) {
foreach ($data->getASStatsTop($top, KnowlinksRepository::select($selectedLinks)) as $as => $nbytes) {
$return['asinfo'][$as]['info'] = $asInfoRepository->getAsInfo($as);

$return['asinfo'][$as]['v4'] = [
Expand Down
12 changes: 12 additions & 0 deletions src/Repository/KnowlinksRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,16 @@ public static function get(): array

return $knownlinks;
}

public static function select(array $selectedLink): array
{
$selected_links = [];

foreach ($selectedLink as $tag => $check) {
if ($check) {
$selected_links[] = $tag;
}
}
return $selected_links;
}
}
11 changes: 11 additions & 0 deletions templates/core/form/_theme.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% use "bootstrap_5_layout.html.twig" %}

{# Checkbox #}

{% block checkbox_row -%}
<div{% with {attr: row_attr|merge({class: (row_attr.class|default(''))|trim})} %}{{ block('attributes') }}{% endwith %}>{#--#}
{{- form_widget(form) -}}
<em>{{- form_help(form) -}}</em>
{{- form_errors(form) -}}
</div>
{%- endblock checkbox_row %}
24 changes: 13 additions & 11 deletions templates/core/legend.html.twig
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
<div class="col-lg-2 col-sm-12">
<div class="sticky-top sticky-top-legend">
{{ form_start(form.legend) }}
<div class="card">
{{ form_start(form.legend) }}
<div class="card-body">
<h3 class="card-title">
<strong>Legend</strong>
</h3>
<div class="table-responsive">
<table class="table table-borderless table-vcenter table-sm">
<table class="table table-borderless table-sm">
<tbody>
{% if knownlinks is defined %}
{% for link in knownlinks %}
<tr>
<td class="align-middle">
{% for field in form.legend %}
{% if field.vars.name == link.tag %}
{{ form_row(field) }}
{% endif %}
{% endfor %}
</td>
<td>
<table class="table-legend">
<tr>
Expand All @@ -24,22 +31,17 @@
</tr>
</table>
</td>
<td class="small">{{ link.descr }}</td>
<td>
{% for field in form.legend %}
{% if field.vars.name == link.tag %}
{{ form_widget(field) }}
{% endif %}
{% endfor %}
</td>
</tr>
{% endfor %}
{% endif %}
</tbody>
</table>
</div>
</div>
{{ form_end(form.legend) }}
<div class="card-footer">
<button type="submit" class="btn btn-tabler btn-icon float-end">{{ icon('filter') }}</i></button>
</div>
</div>
{{ form_end(form.legend) }}
</div>
</div>

0 comments on commit 73e49e9

Please sign in to comment.