Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
28 changes: 20 additions & 8 deletions src/Controller/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use CodeRhapsodie\DataflowBundle\Entity\ScheduledDataflow;
use CodeRhapsodie\DataflowBundle\ExceptionsHandler\ExceptionHandlerInterface;
use CodeRhapsodie\DataflowBundle\ExceptionsHandler\NullExceptionHandler;
use CodeRhapsodie\DataflowBundle\Registry\DataflowTypeRegistryInterface;
use CodeRhapsodie\IbexaDataflowBundle\CodeRhapsodieIbexaDataflowBundle;
use CodeRhapsodie\IbexaDataflowBundle\Form\CreateOneshotType;
use CodeRhapsodie\IbexaDataflowBundle\Form\CreateScheduledType;
Expand All @@ -32,9 +33,9 @@ class DashboardController extends Controller
public function __construct(
private readonly JobGateway $jobGateway,
private readonly ScheduledDataflowGateway $scheduledDataflowGateway,
private readonly ExceptionHandlerInterface $exceptionHandler
)
{
private readonly ExceptionHandlerInterface $exceptionHandler,
private readonly DataflowTypeRegistryInterface $registry
) {
}

#[Route(path: '/', name: 'coderhapsodie.ibexa_dataflow.main')]
Expand All @@ -51,8 +52,8 @@ public function main(): Response

return $this->render('@ibexadesign/ibexa_dataflow/Dashboard/main.html.twig', [
'link' => 'https://www.code-rhapsodie.fr/product/redirect/'.str_replace('=', '',
base64_encode(json_encode($data))
),
base64_encode(json_encode($data))
),
]);
}

Expand Down Expand Up @@ -114,11 +115,22 @@ public function getOneshotPage(Request $request): Response
public function getHistoryPage(Request $request): Response
{
$this->denyAccessUnlessGranted(new Attribute('ibexa_dataflow', 'view'));
$filter = (int) $request->query->get('filter', JobGateway::FILTER_NONE);
$statusFilter = (int) $request->query->get('status', JobGateway::FILTER_NONE);
$typeFilter = $request->query->get('type');

$typeChoices = [['value' => '', 'label' => 'all']];
foreach ($this->registry->listDataflowTypes() as $type) {
$typeChoices[] = [
'value' => $type::class,
'label' => $type->getLabel(),
];
}

return $this->render('@ibexadesign/ibexa_dataflow/Dashboard/history.html.twig', [
'pager' => $this->getPager($this->jobGateway->getListQueryForAdmin($filter), $request, Job::class),
'filter' => $filter,
'pager' => $this->getPager($this->jobGateway->getListQueryForAdmin($statusFilter), $request, Job::class),
'status' => $statusFilter,
'type' => $typeFilter,
'typeChoices' => $typeChoices,
]);
}

Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ services:
$jobGateway: '@CodeRhapsodie\IbexaDataflowBundle\Gateway\JobGateway'
$scheduledDataflowGateway: '@CodeRhapsodie\IbexaDataflowBundle\Gateway\ScheduledDataflowGateway'
$exceptionHandler: '@CodeRhapsodie\DataflowBundle\ExceptionsHandler\ExceptionHandlerInterface'
$registry: '@CodeRhapsodie\DataflowBundle\Registry\DataflowTypeRegistryInterface'

CodeRhapsodie\IbexaDataflowBundle\Controller\ScheduledDataflowController:
public: true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{%- block content -%}
{% set choices = [
{% set statusChoices = [
{
'value': 0,
'label': 'coderhapsodie.ibexa_dataflow.history.filter.none'|trans,
Expand All @@ -10,9 +10,18 @@
},
] %}

{% set source %}
<select id="ibexa_dataflow_history_filter" class="form-control ibexa-input">
{% for choice in choices %}
{% set statusSource %}
<select id="ibexa_dataflow_history_filter_status" class="form-control ibexa-input">
{% for choice in statusChoices %}
<option value="{{ choice.value }}">
{{ choice.label }}
</option>
{% endfor %}
</select>
{% endset %}
{% set typeSource %}
<select id="ibexa_dataflow_history_filter_type" class="form-control ibexa-input">
{% for choice in typeChoices %}
<option value="{{ choice.value }}">
{{ choice.label }}
</option>
Expand All @@ -22,32 +31,40 @@

{% set actions %}
{{ include('@ibexadesign/ui/component/dropdown/dropdown.html.twig', {
source: source,
choices: choices,
value: filter,
source: typeSource,
choices: typeChoices,
value: type,
}) }}
{{ include('@ibexadesign/ui/component/dropdown/dropdown.html.twig', {
source: statusSource,
choices: statusChoices,
value: status,
}) }}
{% endset %}

{{ include('@ibexadesign/ibexa_dataflow/parts/tab/job_list.html.twig', {
identifier: 'ibexa_dataflow_history_results',
paginate_route: 'coderhapsodie.ibexa_dataflow.history',
paginate_params: {'filter': filter},
paginate_params: {'status': status, 'type': type},
headline: 'coderhapsodie.ibexa_dataflow.history.title'|trans,
actions: actions
}) }}

<script>
document.addEventListener('DOMContentLoaded', function () {
// Manage ajax pagination
document.getElementById('ibexa_dataflow_history_filter').addEventListener('change', function (e) {
const loading = document.getElementById('loading_ibexa_dataflow_history_results');
const results = document.getElementById('ibexa_dataflow_history_results').querySelector('.ibexa-table');
const pagination = document.getElementById('ibexa_dataflow_history_results').querySelector('.pag');

const statusSelect = document.getElementById('ibexa_dataflow_history_filter_status');
const typeSelect = document.getElementById('ibexa_dataflow_history_filter_type');

const refresh = (e) => {
e.preventDefault();
const loading = document.getElementById('loading_ibexa_dataflow_history_results');
const results = document.getElementById('ibexa_dataflow_history_results').querySelector('.ibexa-table');
const pagination = document.getElementById('ibexa_dataflow_history_results').querySelector('.pag');
loading.hidden = false;
results.innerHTML = '';
pagination.innerHTML = '';
fetch('{{ path('coderhapsodie.ibexa_dataflow.history') }}?filter=' + this.value)
fetch('{{ path('coderhapsodie.ibexa_dataflow.history') }}?status=' + encodeURIComponent(statusSelect.value) + '&type=' + encodeURIComponent(typeSelect.value))
.then((r) => r.text())
.then((content) => {
const node = document.createElement('div');
Expand All @@ -57,7 +74,11 @@
loading.hidden = true;
})
;
});
}

// Manage ajax pagination
statusSelect.addEventListener('change', refresh);
typeSelect.addEventListener('change', refresh);
})
</script>
{%- endblock -%}