pub struct Presentation {
pub elements: Vec<ElementSpec>,
pub theme: Option<Theme>,
pub messages: BTreeMap<String, LocalizedText>,
}Expand description
How a profile presents itself on the dashboard: its custom elements and theme.
A Profile carries an optional presentation, so a deployment’s
dashboard offers exactly the sensor types its profiles introduce and renders them
the way the profile intends. The dashboard turns these declarations into the catalog
it serves to the page.
Fields§
§elements: Vec<ElementSpec>The custom sensors and node stats this profile contributes.
theme: Option<Theme>An optional theme that tints the dashboard.
messages: BTreeMap<String, LocalizedText>Localized text for the stable codes this profile introduces, keyed by the page’s
message key (a discrete state such as "state.flushing" or an event such as
"event.filter_clog"). The dashboard ships no translation for a code it never knew,
so a profile that emits a custom state or event supplies its wording here.
Implementations§
Source§impl Presentation
impl Presentation
Sourcepub fn from_json(text: &str) -> Result<Self>
pub fn from_json(text: &str) -> Result<Self>
Loads a presentation from its JSON text, the presentation object of a manifest.
§Arguments
text- the JSON object.
§Returns
The presentation.
§Errors
Returns Error::Codec if the text is not a
presentation.
Sourcepub fn to_json(&self) -> Result<String>
pub fn to_json(&self) -> Result<String>
Serializes this presentation to the JSON object a manifest carries.
§Returns
The pretty-printed JSON text.
§Errors
Returns Error::Codec if the presentation cannot be
serialized.
Sourcepub fn with_element(self, element: ElementSpec) -> Self
pub fn with_element(self, element: ElementSpec) -> Self
Sourcepub fn with_elements(
self,
elements: impl IntoIterator<Item = ElementSpec>,
) -> Self
pub fn with_elements( self, elements: impl IntoIterator<Item = ElementSpec>, ) -> Self
Declares several custom elements at once.
§Arguments
elements- the elements to declare, in the order they should be offered.
§Returns
The presentation, for chaining.
§Examples
use pamoja_profile::{ElementSpec, Presentation, Viz};
let presentation = Presentation::new().with_elements([
ElementSpec::new("ph", "ph", "Acidity", Viz::Dial).with_band(6.0, 8.0),
ElementSpec::new("water_turbidity", "ntu", "Turbidity", Viz::Gauge),
]);
assert_eq!(presentation.elements.len(), 2);Sourcepub fn with_theme(self, theme: Theme) -> Self
pub fn with_theme(self, theme: Theme) -> Self
Sourcepub fn with_message(
self,
key: impl Into<String>,
text: impl Into<LocalizedText>,
) -> Self
pub fn with_message( self, key: impl Into<String>, text: impl Into<LocalizedText>, ) -> Self
Supplies localized text for a stable code this profile introduces.
Use this for a custom discrete state or event the dashboard ships no wording for, so the page renders it as words rather than the raw code.
§Arguments
key- the page message key, such as"state.flushing"or"event.filter_clog".text- the text, one string for every locale or a per-locale map.
§Returns
The presentation, for chaining.
Sourcepub fn check(&self) -> Result<()>
pub fn check(&self) -> Result<()>
Checks the presentation for what the dashboard could not draw.
Profile::check runs this on the presentation a profile
carries.
§Returns
Nothing when every element, message, and theme color is usable.
§Errors
Returns Error::Codec naming the first problem: an
element with no key, unit, or label, a key declared twice, a band whose low end is
not below its high end, a starting value that is not a finite number, both a
starting value and a state, or a state that is not a state. code; a message whose
code is neither a state. nor an event. code, that is empty, or that gives no
en text; or a theme color that is empty.
§Examples
use pamoja_profile::{ElementSpec, Presentation, Viz};
let upside_down = Presentation::new().with_element(
ElementSpec::new("water_turbidity", "ntu", "Turbidity", Viz::Gauge).with_band(5.0, 0.0),
);
let refused = upside_down.check().unwrap_err().to_string();
assert!(refused.contains("the low end comes first"));Trait Implementations§
Source§impl Clone for Presentation
impl Clone for Presentation
Source§fn clone(&self) -> Presentation
fn clone(&self) -> Presentation
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more