fix: adds action button to manually run monitors
This commit is contained in:
46
assets/controllers/action_button_controller.js
Normal file
46
assets/controllers/action_button_controller.js
Normal file
@@ -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')
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -54,10 +54,12 @@ class ApiController extends AbstractController
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[Route('/api/monitor/dispatch', name: 'api_monitor_dispatch', methods: ['GET'])]
|
#[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();
|
$dispatcher();
|
||||||
|
|
||||||
|
$broadcaster->alert('Success', 'The monitor job has been dispatched.');
|
||||||
|
|
||||||
return $this->json([
|
return $this->json([
|
||||||
'status' => 200,
|
'status' => 200,
|
||||||
'message' => 'Manually dispatched MonitorDispatcher'
|
'message' => 'Manually dispatched MonitorDispatcher'
|
||||||
|
|||||||
10
src/Twig/Components/ActionButton.php
Normal file
10
src/Twig/Components/ActionButton.php
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Twig\Components;
|
||||||
|
|
||||||
|
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
|
||||||
|
|
||||||
|
#[AsTwigComponent]
|
||||||
|
final class ActionButton
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -20,7 +20,12 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="col-span-6 md:col-span-5 h-screen overflow-y-scroll">
|
<div class="col-span-6 md:col-span-5 h-screen overflow-y-scroll">
|
||||||
<twig:Header />
|
<twig:Header />
|
||||||
<h2 class="px-4 mt-4 mb-2 text-3xl font-bold text-gray-50">{% block h2 %}{% endblock %}</h2>
|
<div class="flex justify-between items-center">
|
||||||
|
<h2 class="px-4 mt-4 mb-2 text-3xl font-bold text-gray-50">{% block h2 %}{% endblock %}</h2>
|
||||||
|
<div class="flex mt-4 gap-2 items-center grow-0 md:px-4">
|
||||||
|
{% block action_buttons %}{% endblock %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{% block body %}{% endblock %}
|
{% block body %}{% endblock %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
7
templates/components/ActionButton.html.twig
Normal file
7
templates/components/ActionButton.html.twig
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<button
|
||||||
|
class="h-8 bg-{{ color|default('orange') }}-500/80 hover:bg-{{ color|default('orange') }}-600/80 px-2 text-{{ text_color|default('white') }} rounded text-sm font-semibold"
|
||||||
|
{{ attributes.defaults(stimulus_controller('action_button')) }}
|
||||||
|
{{ stimulus_action('action_button', action|default('default')) }}
|
||||||
|
>
|
||||||
|
{{ text|default('button') }}
|
||||||
|
</button>
|
||||||
@@ -3,6 +3,10 @@
|
|||||||
{% block title %}Monitors — Torsearch{% endblock %}
|
{% block title %}Monitors — Torsearch{% endblock %}
|
||||||
{% block h2 %}Monitors{% endblock %}
|
{% block h2 %}Monitors{% endblock %}
|
||||||
|
|
||||||
|
{% block action_buttons %}
|
||||||
|
<twig:ActionButton action="monitorDispatch" text="Run Monitors" />
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<div class="px-4 py-2">
|
<div class="px-4 py-2">
|
||||||
<twig:Card title="Active Monitors">
|
<twig:Card title="Active Monitors">
|
||||||
|
|||||||
Reference in New Issue
Block a user