feat: got timeline for beacons working

This commit is contained in:
Andrew Rioux
2025-02-24 15:10:51 -05:00
parent a57a95a98a
commit 5eb66c8d5d
11 changed files with 653 additions and 53 deletions

View File

@@ -29,6 +29,34 @@ macro_rules! define_actions_enum {
$($act($mod::$act)),+,
}
impl Actions {
#[cfg(feature = "server")]
fn render_internal(&self, data: String) -> AnyView {
match self {
$(
Actions::$act(action) => {
let Ok(data) = serde_json::from_str(&data) else {
return view! {
<p>"The command results in the database are corrupted"</p>
}.into_any();
};
action.render_data(data).into_any()
},
)*
}
}
fn render_empty_internal(&self) -> AnyView {
match self {
$(
Actions::$act(action) => {
action.render_empty().into_any()
},
)*
}
}
}
$(
impl From<$mod::$act> for Actions {
fn from(act: $mod::$act) -> Self {
@@ -60,14 +88,31 @@ define_actions_enum! {
}
#[async_trait::async_trait]
#[cfg(feature = "beacon")]
impl Action for Actions {
const REQ_VERSION: Version = Version::new(2, 0);
const REQ_OS: Option< &'static str> = None;
const REQ_FIELDS: &'static[(&'static str, &'static str,Option< &'static str>)] = &[];
type ActionData = String;
#[cfg(feature = "server-ssr")]
type BuilderData = Self;
#[cfg(feature = "server-ssr")]
async fn build_action(data: Self::BuilderData, _db: &sqlx::SqlitePool) -> Result<Self, BuildActionError> {
Ok(data)
}
#[cfg(feature = "server")]
fn render_data(&self, data: String) -> AnyView {
self.render_internal(data)
}
#[cfg(feature = "server")]
fn render_empty(&self) -> AnyView {
self.render_empty_internal()
}
#[cfg(feature = "beacon")]
async fn execute<'a, T, S>(
&self,
parameters: &Parameters,
@@ -117,7 +162,10 @@ pub trait Action: Serialize + for<'a> Deserialize<'a> {
async fn build_action(data: Self::BuilderData, db: &sqlx::SqlitePool) -> Result<Self, BuildActionError>;
#[cfg(feature = "server")]
fn render_data(&self, data: Self::ActionData) -> impl IntoView;
fn render_data(&self, data: String) -> AnyView;
#[cfg(feature = "server")]
fn render_empty(&self) -> AnyView;
#[cfg(feature = "beacon")]
async fn execute<'a, T, S>(

View File

@@ -1,5 +1,5 @@
#[cfg(feature = "server")]
use leptos::prelude::*;
use leptos::{either::Either, prelude::*};
use serde::{Deserialize, Serialize};
#[cfg(feature = "beacon")]
@@ -45,9 +45,38 @@ impl super::Action for Exec {
}
#[cfg(feature = "server")]
fn render_data(&self, _data: Self::ActionData) -> impl IntoView {
fn render_data(&self, data: String) -> AnyView {
view! {
"execute command"
<div>
"execute command: " {self.exec_cmd.clone()}
</div>
<details>
{if data.len() > 0 {
Either::Left(view! {
<summary>
"results:"
</summary>
<pre>
{data.clone()}
</pre>
})
} else {
Either::Right(view! {
<div>"results: (empty)"</div>
})
}}
</details>
}
.into_any()
}
#[cfg(feature = "server")]
fn render_empty(&self) -> AnyView {
view! {
<div>
"execute command: " {self.exec_cmd.clone()}
</div>
}
.into_any()
}
}