diff --git a/assets/controllers/action_button_controller.js b/assets/controllers/action_button_controller.js new file mode 100644 index 0000000..a2e0733 --- /dev/null +++ b/assets/controllers/action_button_controller.js @@ -0,0 +1,46 @@ +import { Controller } from '@hotwired/stimulus'; + +/* +* The following line makes this controller "lazy": it won't be downloaded until needed +* See https://symfony.com/bundles/StimulusBundle/current/index.html#lazy-stimulus-controllers +*/ + +/* stimulusFetch: 'lazy' */ +export default class extends Controller { + + initialize() { + // Called once when the controller is first instantiated (per element) + + // Here you can initialize variables, create scoped callables for event + // listeners, instantiate external libraries, etc. + // this._fooBar = this.fooBar.bind(this) + } + + connect() { + // Called every time the controller is connected to the DOM + // (on page load, when it's added to the DOM, moved in the DOM, etc.) + + // Here you can add event listeners on the element or target elements, + // add or remove classes, attributes, dispatch custom events, etc. + // this.fooTarget.addEventListener('click', this._fooBar) + } + + // Add custom controller actions here + // fooBar() { this.fooTarget.classList.toggle(this.bazClass) } + + disconnect() { + // Called anytime its element is disconnected from the DOM + // (on page change, when it's removed from or moved in the DOM, etc.) + + // Here you should remove all event listeners added in "connect()" + // this.fooTarget.removeEventListener('click', this._fooBar) + } + + default() { + console.log('Looks like you need to add an action to your action button...') + } + + monitorDispatch() { + fetch('/api/monitor/dispatch') + } +} diff --git a/src/Monitor/Framework/Controller/ApiController.php b/src/Monitor/Framework/Controller/ApiController.php index 4332c27..5b51469 100644 --- a/src/Monitor/Framework/Controller/ApiController.php +++ b/src/Monitor/Framework/Controller/ApiController.php @@ -54,10 +54,12 @@ class ApiController extends AbstractController } #[Route('/api/monitor/dispatch', name: 'api_monitor_dispatch', methods: ['GET'])] - public function dispatch(MonitorDispatcher $dispatcher): Response + public function dispatch(MonitorDispatcher $dispatcher, Broadcaster $broadcaster): Response { $dispatcher(); + $broadcaster->alert('Success', 'The monitor job has been dispatched.'); + return $this->json([ 'status' => 200, 'message' => 'Manually dispatched MonitorDispatcher' diff --git a/src/Twig/Components/ActionButton.php b/src/Twig/Components/ActionButton.php new file mode 100644 index 0000000..1ba050c --- /dev/null +++ b/src/Twig/Components/ActionButton.php @@ -0,0 +1,10 @@ +
-

{% block h2 %}{% endblock %}

+
+

{% block h2 %}{% endblock %}

+
+ {% block action_buttons %}{% endblock %} +
+
{% block body %}{% endblock %}
diff --git a/templates/components/ActionButton.html.twig b/templates/components/ActionButton.html.twig new file mode 100644 index 0000000..3e6afa6 --- /dev/null +++ b/templates/components/ActionButton.html.twig @@ -0,0 +1,7 @@ + diff --git a/templates/monitor/index.html.twig b/templates/monitor/index.html.twig index cc82233..fc9bea8 100644 --- a/templates/monitor/index.html.twig +++ b/templates/monitor/index.html.twig @@ -3,6 +3,10 @@ {% block title %}Monitors — Torsearch{% endblock %} {% block h2 %}Monitors{% endblock %} +{% block action_buttons %} + +{% endblock %} + {% block body %}