2 Commits

Author SHA1 Message Date
jb cr
2c8c2112a1 add make by mention 2025-04-01 16:53:50 +02:00
AUDUL
4b8554c64a Add oneshot v5 (#3)
* Added possibility to create one shot job from scheduled job
2025-02-18 14:30:40 +01:00
10 changed files with 115 additions and 12 deletions

View File

@@ -1,3 +1,6 @@
# Version 5.1.0
* Added possibility to create one shot job from scheduled job
# Version 5.0.0
* Renamed bundle to IbexaDataflowBundle

View File

@@ -13,6 +13,9 @@ use Symfony\Component\HttpKernel\Bundle\Bundle;
class CodeRhapsodieIbexaDataflowBundle extends Bundle
{
public const VERSION = '5.1.0';
public const PRODUCT_NAME = 'ibexadataflow';
protected $name = 'CodeRhapsodieIbexaDataflowBundle';
public function getContainerExtension()

View File

@@ -6,6 +6,7 @@ namespace CodeRhapsodie\IbexaDataflowBundle\Controller;
use CodeRhapsodie\DataflowBundle\Entity\Job;
use CodeRhapsodie\DataflowBundle\Entity\ScheduledDataflow;
use CodeRhapsodie\IbexaDataflowBundle\CodeRhapsodieIbexaDataflowBundle;
use CodeRhapsodie\IbexaDataflowBundle\Form\CreateOneshotType;
use CodeRhapsodie\IbexaDataflowBundle\Form\CreateScheduledType;
use CodeRhapsodie\IbexaDataflowBundle\Form\UpdateScheduledType;
@@ -14,6 +15,7 @@ use CodeRhapsodie\IbexaDataflowBundle\Gateway\JobGateway;
use CodeRhapsodie\IbexaDataflowBundle\Gateway\ScheduledDataflowGateway;
use Doctrine\DBAL\Query\QueryBuilder;
use Ibexa\Contracts\AdminUi\Controller\Controller;
use Ibexa\Contracts\Core\Ibexa;
use Ibexa\Core\MVC\Symfony\Security\Authorization\Attribute;
use Pagerfanta\Doctrine\DBAL\QueryAdapter;
use Pagerfanta\Pagerfanta;
@@ -33,7 +35,18 @@ class DashboardController extends Controller
{
$this->denyAccessUnlessGranted(new Attribute('ibexa_dataflow', 'view'));
return $this->render('@ibexadesign/ibexa_dataflow/Dashboard/main.html.twig');
$data = [
'product' => CodeRhapsodieIbexaDataflowBundle::PRODUCT_NAME,
'version' => CodeRhapsodieIbexaDataflowBundle::VERSION,
'php' => PHP_VERSION,
'ibexa' => Ibexa::VERSION,
];
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))
),
]);
}
public function repeating(Request $request): Response
@@ -117,7 +130,7 @@ class DashboardController extends Controller
{
$pager = new Pagerfanta(
new ExceptionJSONDecoderAdapter(
new QueryAdapter($query, fn($queryBuilder) => $queryBuilder->select('COUNT(DISTINCT id) AS total_results')
new QueryAdapter($query, fn ($queryBuilder) => $queryBuilder->select('COUNT(DISTINCT id) AS total_results')
->resetQueryPart('orderBy')
->setMaxResults(1))
)

View File

@@ -7,12 +7,14 @@ namespace CodeRhapsodie\IbexaDataflowBundle\Controller;
use CodeRhapsodie\DataflowBundle\Entity\Job;
use CodeRhapsodie\IbexaDataflowBundle\Form\CreateOneshotType;
use CodeRhapsodie\IbexaDataflowBundle\Gateway\JobGateway;
use CodeRhapsodie\IbexaDataflowBundle\Gateway\ScheduledDataflowGateway;
use Ibexa\Contracts\AdminUi\Controller\Controller;
use Ibexa\Contracts\AdminUi\Notification\NotificationHandlerInterface;
use Ibexa\Core\MVC\Symfony\Security\Authorization\Attribute;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
@@ -20,7 +22,7 @@ use Symfony\Contracts\Translation\TranslatorInterface;
#[Route(path: '/ibexa_dataflow/job')]
class JobController extends Controller
{
public function __construct(private readonly JobGateway $jobGateway, private readonly NotificationHandlerInterface $notificationHandler, private readonly TranslatorInterface $translator)
public function __construct(private readonly JobGateway $jobGateway, private readonly NotificationHandlerInterface $notificationHandler, private readonly TranslatorInterface $translator, private readonly ScheduledDataflowGateway $scheduledDataflowGateway)
{
}
@@ -81,4 +83,35 @@ class JobController extends Controller
]),
]);
}
#[Route(path: '/run-oneshot/{id}', name: 'coderhapsodie.ibexa_dataflow.job.run-oneshot', methods: ['GET'])]
public function runOneShot(int $id): Response
{
$this->denyAccessUnlessGranted(new Attribute('ibexa_dataflow', 'view'));
$scheduledDataflow = $this->scheduledDataflowGateway->find($id);
if ($scheduledDataflow === null) {
throw new NotFoundHttpException();
}
$newOneshotJob = new Job();
$newOneshotJob->setOptions($scheduledDataflow->getOptions());
$newOneshotJob->setLabel("Manual " . $scheduledDataflow->getLabel());
$newOneshotJob->setScheduledDataflowId($scheduledDataflow->getId());
$newOneshotJob->setRequestedDate((new \DateTime())->add(new \DateInterval('PT1H')));
$newOneshotJob->setDataflowType($scheduledDataflow->getDataflowType());
$form = $this->createForm(CreateOneshotType::class, $newOneshotJob, [
'action' => $this->generateUrl('coderhapsodie.ibexa_dataflow.job.create'),
]);
return new JsonResponse([
'form' => $this->renderView('@ibexadesign/ibexa_dataflow/parts/form_modal.html.twig', [
'form' => $form->createView(),
'id' => 'modal-new-oneshot',
'mode' => 'oneshot',
]),
]);
}
}

View File

@@ -38,6 +38,7 @@ services:
$jobGateway: '@CodeRhapsodie\IbexaDataflowBundle\Gateway\JobGateway'
$notificationHandler: '@Ibexa\Contracts\AdminUi\Notification\NotificationHandlerInterface'
$translator: '@translator'
$scheduledDataflowGateway: '@CodeRhapsodie\IbexaDataflowBundle\Gateway\ScheduledDataflowGateway'
calls:
- [ 'setContainer', [ '@service_container' ] ]
- [ 'performAccessCheck', [ ] ]

View File

@@ -16,6 +16,7 @@ coderhapsodie.ibexa_dataflow.workflow.list.history: History
coderhapsodie.ibexa_dataflow.workflow.list.edit: Edit
coderhapsodie.ibexa_dataflow.workflow.list.disable: Disable
coderhapsodie.ibexa_dataflow.workflow.list.enable: Enable
coderhapsodie.ibexa_dataflow.workflow.list.runonce: Run now
coderhapsodie.ibexa_dataflow.history.title: History
coderhapsodie.ibexa_dataflow.history.list.title: 'Executions list'
coderhapsodie.ibexa_dataflow.history.list.name: Name
@@ -82,3 +83,5 @@ coderhapsodie.dataflow.update.next: 'Next execution'
coderhapsodie.ibexa_dataflow.workflow.edit.success: 'Dataflow schedule successfully updated.'
coderhapsodie.ibexa_dataflow.workflow.edit.error: 'An error occurred during the dataflow schedule update: "%message%".'
coderhapsodie.ibexa_dataflow.notfound: 'Requested data is not found'
coderhapsodie.ibexa_dataflow.powered_by: 'Powered by'
coderhapsodie.ibexa_dataflow.made_by: 'Made by'

View File

@@ -16,6 +16,7 @@ coderhapsodie.ibexa_dataflow.workflow.list.history: Historique
coderhapsodie.ibexa_dataflow.workflow.list.edit: Éditer
coderhapsodie.ibexa_dataflow.workflow.list.disable: Désactiver
coderhapsodie.ibexa_dataflow.workflow.list.enable: Activer
coderhapsodie.ibexa_dataflow.workflow.list.runonce: Lancer maintenant
coderhapsodie.ibexa_dataflow.history.title: Historique
coderhapsodie.ibexa_dataflow.history.list.title: 'Liste des exécutions'
coderhapsodie.ibexa_dataflow.history.list.name: Nom
@@ -80,3 +81,5 @@ coderhapsodie.dataflow.update.next: 'Prochaine exécution'
coderhapsodie.ibexa_dataflow.workflow.edit.success: 'La programmation du dataflow a été mise à jour avec succès.'
coderhapsodie.ibexa_dataflow.workflow.edit.error: 'Une erreur est survenue lors de la modification de la programmation du dataflow : "%message%".'
coderhapsodie.ibexa_dataflow.notfound: 'Les données demandées sont introuvables'
coderhapsodie.ibexa_dataflow.powered_by: 'Propulsé par'
coderhapsodie.ibexa_dataflow.made_by: 'Fabriqué par'

File diff suppressed because one or more lines are too long

View File

@@ -1,10 +1,11 @@
{%- block content -%}
{% set actions %}
<button
type="button"
class="btn ibexa-btn ibexa-btn--tertiary ibexa-btn--small"
data-bs-toggle="modal"
data-bs-target="#modal-new-oneshot"
id="create-oneshot-button"
type="button"
class="btn ibexa-btn ibexa-btn--tertiary ibexa-btn--small"
data-bs-toggle="modal"
data-bs-target="#modal-new-oneshot"
>
<svg class="ibexa-icon ibexa-icon--small ibexa-icon--create">
<use xlink:href="{{ ibexa_icon_path('create') }}"></use>
@@ -53,6 +54,16 @@
})
;
});
const createButton = document.getElementById('create-oneshot-button')
if (createButton) {
createButton.addEventListener('click', () => {
const oneShotModal = document.getElementById('modal-new-oneshot');
oneShotModal.querySelector('#create_oneshot_label').value = '';
oneShotModal.querySelector('#create_oneshot_options').value = '';
oneShotModal.querySelector('.flatpickr.flatpickr-input').parentNode.parentNode.ibexaInstance.flatpickrInstance.setDate(new Date(), true);
});
}
});
</script>
{%- endblock -%}

View File

@@ -40,6 +40,15 @@
<use xlink:href="{{ ibexa_icon_path('edit') }}"></use>
</svg>
</a>
<button
class="btn ibexa-btn ibexa-btn--ghost run-oneshot ibexa-btn--no-text"
data-url="{{ path('coderhapsodie.ibexa_dataflow.job.run-oneshot', {id: item.id}) }}"
title="{{ 'coderhapsodie.ibexa_dataflow.workflow.list.runonce'|trans }}"
>
<svg class="ibexa-icon ibexa-icon--small ibexa-icon--create">
<use xlink:href="{{ ibexa_icon_path('create') }}"></use>
</svg>
</button>
{% if item.enabled %}
<a href="{{ path('coderhapsodie.ibexa_dataflow.workflow.disable', {id: item.id}) }}"
class="btn ibexa-btn ibexa-btn--ghost ibexa-btn--no-text"
@@ -96,10 +105,10 @@
{% embed '@ibexadesign/ui/component/table/table_header.html.twig' %}
{% block actions %}
<button
type="button"
class="btn ibexa-btn ibexa-btn--tertiary ibexa-btn--small"
data-bs-toggle="modal"
data-bs-target="#modal-new-scheduled"
type="button"
class="btn ibexa-btn ibexa-btn--tertiary ibexa-btn--small"
data-bs-toggle="modal"
data-bs-target="#modal-new-scheduled"
>
<svg class="ibexa-icon ibexa-icon--small ibexa-icon--create">
<use xlink:href="{{ ibexa_icon_path('create') }}"></use>
@@ -125,3 +134,27 @@
{% endif %}
</div>
</div>
<script>
document.querySelectorAll(".run-oneshot").forEach((el) => {
el.addEventListener('click', () => {
const oneShotModal = document.getElementById('modal-new-oneshot');
fetch(el.getAttribute('data-url'))
.then(response => response.json())
.then(result => {
const node = document.createElement('div');
node.innerHTML = result.form;
oneShotModal.querySelector('#create_oneshot_label').value = node.querySelector('#create_oneshot_label').value;
oneShotModal.querySelector('#create_oneshot_options').value = node.querySelector('#create_oneshot_options').value;
oneShotModal.querySelector('.ibexa-dropdown').ibexaInstance.selectOption(node.querySelector('#create_oneshot_dataflowType').value)
oneShotModal.querySelector('.flatpickr.flatpickr-input').parentNode.parentNode.ibexaInstance.flatpickrInstance.setDate(new Date(), true);
})
.then(() => {
bootstrap.Tab.getOrCreateInstance(document.querySelector('#ibexa-tab-label-coderhapsodie-ibexa_dataflow-code-rhapsodie-ibexa_dataflow-oneshot')).show()
bootstrap.Modal.getOrCreateInstance(oneShotModal).show()
})
});
});
</script>