@@ -18,6 +18,12 @@ use rand::Rng;
18
18
use std:: fmt:: { Display , Formatter } ;
19
19
use std:: vec;
20
20
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
21
27
#[ derive( Debug , Clone ) ]
22
28
pub struct DetailPlant {
23
29
pub id : String ,
@@ -45,24 +51,52 @@ impl DetailPlant {
45
51
}
46
52
}
47
53
}
54
+ /// Contains all possible messages that can be sent to the detail page
48
55
#[ derive( Debug , Clone , PartialEq ) ]
49
56
pub enum DetailMessage {
57
+ /// Closes the modal and sends the changes of the plant or group to the server
50
58
OkButtonPressed ,
59
+ /// Sets the message to pending to display the overview
51
60
SwitchTime ( chrono:: Duration ) ,
61
+ /// Opens the modal to edit the plant
52
62
OpenModalPlant ,
63
+ /// Opens the modal to edit the group
53
64
OpenModalGroup ,
65
+ /// Closes the modal
54
66
CloseModal ,
67
+ /// Deletes the plant
55
68
Delete ,
69
+ /// The message is pending, the overview is displayed
56
70
Pending ,
71
+ /// Loads the data of the plant
57
72
Load ,
73
+ /// Gets the data of the plant
58
74
PlantData ( String ) ,
75
+ /// Indicates that the plant data was loaded
59
76
Loaded ,
77
+ /// Switches the graph to the given sensor
60
78
SwitchGraph ( Sensortypes ) ,
79
+ /// Handles the input of the plant id to search for a plant
61
80
Search ( String ) ,
81
+ /// Handles the input of the plant or group metadata
62
82
FieldUpdated ( u8 , String ) ,
83
+ /// Indicates that the plant was deleted
63
84
DeleteSuccess ,
64
85
}
65
86
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
66
100
pub ( crate ) struct DetailPage {
67
101
pub active_sensor : Sensortypes ,
68
102
pub timerange : ( String , String ) ,
@@ -75,14 +109,22 @@ pub(crate) struct DetailPage {
75
109
pub plant : DetailPlant ,
76
110
pub message : DetailMessage ,
77
111
}
112
+
113
+ /// Contains all available sensors, their names, and colors
78
114
#[ derive( Debug , Clone , Copy , PartialEq ) ]
79
115
pub enum Sensortypes {
116
+ /// Soil moisture sensor
80
117
Feuchtigkeit ,
118
+ /// Humidity sensor
81
119
Luftfeuchtigkeit ,
120
+ /// Temperature sensor
82
121
Temperatur ,
122
+ /// Light sensor
83
123
Licht ,
84
124
}
125
+
85
126
impl Display for Sensortypes {
127
+ /// Returns the sensor name as a string
86
128
fn fmt ( & self , f : & mut Formatter < ' _ > ) -> std:: fmt:: Result {
87
129
match self {
88
130
Sensortypes :: Feuchtigkeit => write ! ( f, "Feuchtigkeit" ) ,
@@ -92,7 +134,9 @@ impl Display for Sensortypes {
92
134
}
93
135
}
94
136
}
137
+
95
138
impl Sensortypes {
139
+ /// Returns the sensor name as a string in english
96
140
pub fn get_name ( & self ) -> String {
97
141
match self {
98
142
Sensortypes :: Feuchtigkeit => String :: from ( "soil-moisture" ) ,
@@ -101,6 +145,8 @@ impl Sensortypes {
101
145
Sensortypes :: Licht => String :: from ( "light" ) ,
102
146
}
103
147
}
148
+
149
+ /// Returns the color associated with the sensor
104
150
pub fn get_color ( & self ) -> RGBColor {
105
151
match self {
106
152
Sensortypes :: Feuchtigkeit => RGBColor ( 0 , 0 , 255 ) ,
@@ -109,6 +155,8 @@ impl Sensortypes {
109
155
Sensortypes :: Licht => RGBColor ( 255 , 255 , 0 ) ,
110
156
}
111
157
}
158
+
159
+ /// Returns a random offset color associated with the sensor
112
160
pub fn get_color_with_random_offset ( & self ) -> RGBColor {
113
161
let mut rng = rand:: thread_rng ( ) ;
114
162
let offset = rng. gen_range ( 0 ..=255 ) ;
@@ -121,6 +169,8 @@ impl Sensortypes {
121
169
Sensortypes :: Licht => RGBColor ( 255 - offset3, 255 - offset3. clone ( ) , offset) ,
122
170
}
123
171
}
172
+
173
+ /// Returns an iterator over all available sensors
124
174
pub fn iter ( ) -> impl Iterator < Item = Sensortypes > {
125
175
[
126
176
Sensortypes :: Feuchtigkeit ,
@@ -133,6 +183,7 @@ impl Sensortypes {
133
183
}
134
184
}
135
185
impl DetailPage {
186
+ /// Creates a new detail page
136
187
pub fn new ( ) -> DetailPage {
137
188
let plant = DetailPlant {
138
189
id : String :: new ( ) ,
@@ -157,6 +208,7 @@ impl DetailPage {
157
208
message : DetailMessage :: Pending ,
158
209
}
159
210
}
211
+ /// If the string is longer than 30 characters, a newline is inserted every 30 characters
160
212
pub fn insert_newline_to_string ( & self , string : String ) -> String {
161
213
let mut new_string = String :: new ( ) ;
162
214
let mut counter = 0 ;
@@ -172,6 +224,7 @@ impl DetailPage {
172
224
}
173
225
new_string
174
226
}
227
+ /// Adds the sensor border graph to the plant charts
175
228
pub fn min_max_graphs ( & self , sensor_types : Sensortypes ) -> Vec < PlantChart > {
176
229
let mut charts = vec ! [ ] ;
177
230
self . plant
@@ -203,6 +256,7 @@ impl DetailPage {
203
256
} ) ;
204
257
charts
205
258
}
259
+ /// Handles the messages for the detail page
206
260
pub fn update ( & mut self , message : DetailMessage ) -> Command < DetailMessage > {
207
261
match message {
208
262
DetailMessage :: SwitchTime ( value) => {
@@ -230,6 +284,7 @@ impl DetailPage {
230
284
|_| DetailMessage :: DeleteSuccess ,
231
285
) ;
232
286
}
287
+
233
288
DetailMessage :: Load => {
234
289
info ! ( "Refresh Id List" ) ;
235
290
//if empty self.id_names should be an empty vec
0 commit comments