Skip to content

Commit 67d4d13

Browse files
committed
added documentation AGAIN
1 parent 72d296e commit 67d4d13

File tree

5 files changed

+125
-1
lines changed

5 files changed

+125
-1
lines changed

src/detail.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ use rand::Rng;
1818
use std::fmt::{Display, Formatter};
1919
use std::vec;
2020

21+
/// Stores all information about a plant that is displayed on the detail page
22+
///
23+
/// Arguments:
24+
/// * `id` - The id of the plant that is displayed
25+
/// * `data` - The metadata of the plant, containing f.e. the name
26+
/// * `charts` - The charts of the plant, containing the coordinates and the message
2127
#[derive(Debug, Clone)]
2228
pub struct DetailPlant {
2329
pub id: String,
@@ -45,24 +51,52 @@ impl DetailPlant {
4551
}
4652
}
4753
}
54+
/// Contains all possible messages that can be sent to the detail page
4855
#[derive(Debug, Clone, PartialEq)]
4956
pub enum DetailMessage {
57+
/// Closes the modal and sends the changes of the plant or group to the server
5058
OkButtonPressed,
59+
/// Sets the message to pending to display the overview
5160
SwitchTime(chrono::Duration),
61+
/// Opens the modal to edit the plant
5262
OpenModalPlant,
63+
/// Opens the modal to edit the group
5364
OpenModalGroup,
65+
/// Closes the modal
5466
CloseModal,
67+
/// Deletes the plant
5568
Delete,
69+
/// The message is pending, the overview is displayed
5670
Pending,
71+
/// Loads the data of the plant
5772
Load,
73+
/// Gets the data of the plant
5874
PlantData(String),
75+
/// Indicates that the plant data was loaded
5976
Loaded,
77+
/// Switches the graph to the given sensor
6078
SwitchGraph(Sensortypes),
79+
/// Handles the input of the plant id to search for a plant
6180
Search(String),
81+
/// Handles the input of the plant or group metadata
6282
FieldUpdated(u8, String),
83+
/// Indicates that the plant was deleted
6384
DeleteSuccess,
6485
}
6586

87+
/// Contains all information about the detail page
88+
///
89+
/// Fields:
90+
/// * `active_sensor` - The sensor that is currently displayed
91+
/// * `timerange` - The timerange that is currently displayed
92+
/// * `modal` - Indicates if the modal is open
93+
/// * `modal_is_plant` - Indicates if the modal is open for a plant or a group
94+
/// * `additionalCareTips` - The additional care tips of the plant only for this plant
95+
/// * `careTips` - The care tips of the plant for all plants of this group
96+
/// * `sensor_border` - The min max values of the sensor
97+
/// * `id_names` - The id and name of the plant
98+
/// * `plant` - The plant that is displayed
99+
/// * `message` - The message that is currently displayed
66100
pub(crate) struct DetailPage {
67101
pub active_sensor: Sensortypes,
68102
pub timerange: (String, String),
@@ -75,14 +109,22 @@ pub(crate) struct DetailPage {
75109
pub plant: DetailPlant,
76110
pub message: DetailMessage,
77111
}
112+
113+
/// Contains all available sensors, their names, and colors
78114
#[derive(Debug, Clone, Copy, PartialEq)]
79115
pub enum Sensortypes {
116+
/// Soil moisture sensor
80117
Feuchtigkeit,
118+
/// Humidity sensor
81119
Luftfeuchtigkeit,
120+
/// Temperature sensor
82121
Temperatur,
122+
/// Light sensor
83123
Licht,
84124
}
125+
85126
impl Display for Sensortypes {
127+
/// Returns the sensor name as a string
86128
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
87129
match self {
88130
Sensortypes::Feuchtigkeit => write!(f, "Feuchtigkeit"),
@@ -92,7 +134,9 @@ impl Display for Sensortypes {
92134
}
93135
}
94136
}
137+
95138
impl Sensortypes {
139+
/// Returns the sensor name as a string in english
96140
pub fn get_name(&self) -> String {
97141
match self {
98142
Sensortypes::Feuchtigkeit => String::from("soil-moisture"),
@@ -101,6 +145,8 @@ impl Sensortypes {
101145
Sensortypes::Licht => String::from("light"),
102146
}
103147
}
148+
149+
/// Returns the color associated with the sensor
104150
pub fn get_color(&self) -> RGBColor {
105151
match self {
106152
Sensortypes::Feuchtigkeit => RGBColor(0, 0, 255),
@@ -109,6 +155,8 @@ impl Sensortypes {
109155
Sensortypes::Licht => RGBColor(255, 255, 0),
110156
}
111157
}
158+
159+
/// Returns a random offset color associated with the sensor
112160
pub fn get_color_with_random_offset(&self) -> RGBColor {
113161
let mut rng = rand::thread_rng();
114162
let offset = rng.gen_range(0..=255);
@@ -121,6 +169,8 @@ impl Sensortypes {
121169
Sensortypes::Licht => RGBColor(255 - offset3, 255 - offset3.clone(), offset),
122170
}
123171
}
172+
173+
/// Returns an iterator over all available sensors
124174
pub fn iter() -> impl Iterator<Item = Sensortypes> {
125175
[
126176
Sensortypes::Feuchtigkeit,
@@ -133,6 +183,7 @@ impl Sensortypes {
133183
}
134184
}
135185
impl DetailPage {
186+
/// Creates a new detail page
136187
pub fn new() -> DetailPage {
137188
let plant = DetailPlant {
138189
id: String::new(),
@@ -157,6 +208,7 @@ impl DetailPage {
157208
message: DetailMessage::Pending,
158209
}
159210
}
211+
/// If the string is longer than 30 characters, a newline is inserted every 30 characters
160212
pub fn insert_newline_to_string(&self, string: String) -> String {
161213
let mut new_string = String::new();
162214
let mut counter = 0;
@@ -172,6 +224,7 @@ impl DetailPage {
172224
}
173225
new_string
174226
}
227+
/// Adds the sensor border graph to the plant charts
175228
pub fn min_max_graphs(&self, sensor_types: Sensortypes) -> Vec<PlantChart> {
176229
let mut charts = vec![];
177230
self.plant
@@ -203,6 +256,7 @@ impl DetailPage {
203256
});
204257
charts
205258
}
259+
/// Handles the messages for the detail page
206260
pub fn update(&mut self, message: DetailMessage) -> Command<DetailMessage> {
207261
match message {
208262
DetailMessage::SwitchTime(value) => {
@@ -230,6 +284,7 @@ impl DetailPage {
230284
|_| DetailMessage::DeleteSuccess,
231285
);
232286
}
287+
233288
DetailMessage::Load => {
234289
info!("Refresh Id List");
235290
//if empty self.id_names should be an empty vec

src/graphs.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,25 @@ use plotters::style::{Color, IntoFont, BLACK, BLUE, WHITE};
1111
use plotters_iced::{Chart, ChartBuilder, ChartWidget, DrawingBackend};
1212

1313
#[derive(Debug, Clone, PartialEq)]
14+
/// A chart that can be drawn
15+
///
16+
/// Fields:
17+
/// - `name`: The name of the chart
18+
/// - `x`: The x values of the chart
19+
/// - `y`: The y values of the chart
20+
/// - `color`: The color of the chart
1421
pub struct PlantChart {
1522
pub name: String,
1623
pub x: Vec<i32>,
1724
pub y: Vec<i32>,
1825
color: RGBColor,
1926
}
2027
impl PlantChart {
28+
/// Create a new PlantChart
2129
pub fn new(name: String, x: Vec<i32>, y: Vec<i32>, color: RGBColor) -> PlantChart {
2230
PlantChart { name, x, y, color }
2331
}
32+
/// Create a test PlantChart
2433
pub fn test() -> PlantChart {
2534
PlantChart {
2635
name: String::from("Test"),
@@ -29,11 +38,13 @@ impl PlantChart {
2938
color: BLUE,
3039
}
3140
}
41+
/// Get the color of the chart
3242
pub fn get_color(&self) -> RGBColor {
3343
self.color
3444
}
3545
}
3646
impl Default for PlantChart {
47+
/// Create a default PlantChart
3748
fn default() -> Self {
3849
Self {
3950
name: String::new(),
@@ -44,21 +55,29 @@ impl Default for PlantChart {
4455
}
4556
}
4657
#[derive(Debug, Clone, PartialEq)]
58+
/// A collection of PlantCharts
59+
///
60+
/// Fields:
61+
/// - `charts`: The charts
62+
/// - `message`: The message that is passed to the charts, depending on the page it is used in
4763
pub struct PlantCharts<M> {
4864
pub charts: Vec<PlantChart>,
4965
pub message: M,
5066
}
5167

5268
impl<M: 'static> PlantCharts<M> {
69+
/// Create a new PlantCharts object
5370
pub fn new(charts: Vec<PlantChart>, message: M) -> PlantCharts<M> {
5471
PlantCharts { charts, message }
5572
}
73+
/// Create a test PlantCharts object
5674
pub fn test(message: M) -> PlantCharts<M> {
5775
PlantCharts {
5876
charts: vec![PlantChart::test()],
5977
message,
6078
}
6179
}
80+
/// Get the largest x and y values of the charts
6281
pub fn largest_x_y(&self) -> (i32, i32) {
6382
let mut x = 0;
6483
let mut y = 0;
@@ -74,6 +93,7 @@ impl<M: 'static> PlantCharts<M> {
7493
}
7594
(x, y)
7695
}
96+
/// Create the charts from the data
7797
pub fn create_charts(
7898
message: M,
7999
graph_data: Vec<GraphData>,
@@ -92,6 +112,7 @@ impl<M: 'static> PlantCharts<M> {
92112
}
93113
PlantCharts::new(charts, message)
94114
}
115+
/// Update the charts with new data
95116
pub fn update_charts(
96117
&self,
97118
message: M,
@@ -105,6 +126,7 @@ impl<M: 'static> PlantCharts<M> {
105126

106127
impl<M: 'static + Clone> Chart<M> for PlantCharts<M> {
107128
type State = ();
129+
/// Build the chart
108130
fn build_chart<DB: DrawingBackend>(&self, _state: &Self::State, mut builder: ChartBuilder<DB>) {
109131
//Change background color
110132
let mut chart = builder
@@ -153,6 +175,7 @@ impl<M: 'static + Clone> Chart<M> for PlantCharts<M> {
153175
}
154176

155177
impl<M: 'static + Clone> PlantCharts<M> {
178+
/// Shows the chart
156179
fn view(&self) -> Element<'_, M> {
157180
ChartWidget::new(self)
158181
.width(Length::Fill)

src/home.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,50 @@ use plotters_iced::ChartWidget;
1616
use std::collections::HashMap;
1717

1818
#[derive(Debug, Clone)]
19+
/// The message of the home page
1920
pub enum HomeMessage {
21+
/// Open the modal to add a new plant
2022
OpenModalPlant,
23+
/// Open the modal to add a new group
2124
OpenModalGroup,
25+
/// Close the modal
2226
CloseModal,
27+
/// The cancel button was pressed
2328
CancelButtonPressed,
29+
/// The ok button was pressed, the data is sent to the server
2430
OkButtonPressed,
31+
/// An empty message to do nothing
2532
Plant,
33+
/// Deletes the selected group
2634
DeleteGroup,
35+
/// Refresh the page
2736
Refresh,
37+
/// Change the graphs to the selected sensor
2838
SwitchGraph(Sensortypes),
39+
/// Updates the variable to match the input
2940
FieldUpdated(u8, String),
3041
}
3142

43+
/// The home page
44+
///
45+
/// Fields:
46+
/// - `timerange`: The timerange of the graphs
47+
/// - `selected_group`: The selected group
48+
/// - `group_name_id`: The names and ids of the groups
49+
/// - `show_modal`: If the modal is shown
50+
/// - `modal_is_plant`: If the modal is for a plant
51+
/// - `new_plant`: The data of the new plant
52+
/// - `new_group`: The data of the new group
53+
/// - `additionalCareTips`: The additional care tips of the new plant only for the plant
54+
/// - `sensor_border`: The border of the sensor
55+
/// - `careTips`: The care tips of the new plant for the plant and the group
56+
/// - `group`: The group of the new plant
57+
/// - `charts`: The charts of all groups for the selected sensor
58+
/// - `active_sensor`: The active sensor
59+
/// - `group_ids`: The ids of the groups
60+
/// - `id_names`: The ids and names of the plants
61+
/// - `group_names`: The names of the groups
62+
/// - `sensor_data`: The graph data of the sensors if the sensor was already selected
3263
pub(crate) struct HomePage {
3364
timerange: (String, String),
3465
selected_group: String,
@@ -50,6 +81,7 @@ pub(crate) struct HomePage {
5081
}
5182

5283
impl HomePage {
84+
/// Creates a new home page
5385
pub fn new() -> Self {
5486
let vec_chart = Vec::new();
5587
let charts = PlantCharts::new(vec_chart, HomeMessage::Plant);
@@ -84,6 +116,7 @@ impl HomePage {
84116
}
85117
}
86118

119+
/// Handles the messages of the home page
87120
pub fn update(&mut self, message: HomeMessage) -> Command<HomeMessage> {
88121
match message {
89122
HomeMessage::DeleteGroup => {
@@ -271,13 +304,16 @@ impl HomePage {
271304
impl Tab for HomePage {
272305
type Message = Message;
273306

307+
/// Sets the title of the page
274308
fn title(&self) -> String {
275309
String::from("Dashboard")
276310
}
277311

312+
/// Sets the label of the tab
278313
fn tab_label(&self) -> TabLabel {
279314
TabLabel::IconText(Icon::Homescreen.into(), self.title())
280315
}
316+
/// Sets the content of the page
281317
fn content(&self) -> Element<'_, Self::Message> {
282318
if self.show_modal {
283319
if self.modal_is_plant {

src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ const EXTERNAL_ICON_FONT: Font = iced::Font::External {
4545
name: "External Icons",
4646
bytes: include_bytes!("../fonts/MaterialIcons-Regular.ttf"),
4747
};
48+
49+
/// Default text size for the application.
4850
const TEXT_SIZE: u16 = 30;
4951
/// The Icons used in the application.
5052
enum Icon {

0 commit comments

Comments
 (0)