use orbit_orm::Database;
use crate::policy::ActingUser;
use crate::runtime_resource::RuntimeFuture;
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize)]
pub struct StatWidget {
pub label: &'static str,
pub value: i64,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct LatestRecords {
pub title: &'static str,
pub columns: &'static [&'static str],
pub limit: i64,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Stat {
label: String,
value: String,
description: Option<String>,
}
impl Stat {
pub fn make(label: impl Into<String>, value: impl ToString) -> Self {
Stat {
label: label.into(),
value: value.to_string(),
description: None,
}
}
pub fn description(mut self, description: impl Into<String>) -> Self {
self.description = Some(description.into());
self
}
pub fn get_label(&self) -> &str {
&self.label
}
pub fn get_value(&self) -> &str {
&self.value
}
pub fn get_description(&self) -> Option<&str> {
self.description.as_deref()
}
}
impl From<StatWidget> for Stat {
fn from(widget: StatWidget) -> Self {
Stat::make(widget.label, widget.value)
}
}
pub trait StatsOverviewWidget: Send + Sync + 'static {
fn stats<'a>(&'a self, db: &'a Database, user: &'a ActingUser) -> RuntimeFuture<'a, Vec<Stat>>;
fn can_view(&self, user: &ActingUser) -> bool {
let _ = user;
true
}
}