config
plantimager.webui.config Link
PlantDB Configuration Interface for Plant Imager Web UI.
This module provides components and callbacks for configuring the connection to the PlantDB REST API and managing datasets within the Plant Imager web interface.
Key Features
- REST API connection configuration and testing
- Dataset listing and management
- Dynamic UI components for database status visualization
- Bootstrap-styled modals and alerts for user interaction
check_server_availability Link
check_server_availability(_, host, port, prefix, stored_host, stored_port, stored_prefix)
Checks the availability of a server based on the provided host and port and updates the UI accordingly.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
_
|
int
|
The n_clicks property of the load-plantdb-button element, which triggers the callback (not used). |
required |
host
|
str
|
The IP address or hostname of the server to test. |
required |
port
|
int
|
The port number of the server to test. |
required |
stored_host
|
str
|
The previously stored server host value, used if the connection test fails. |
required |
stored_port
|
int
|
The previously stored server port value, used if the connection test fails. |
required |
Returns:
Type | Description |
---|---|
bool
|
A storer flag indicating whether the connection test was successful. |
bool
|
A boolean indicating whether the load button should be disabled. |
str
|
The updated server host value to store. |
int
|
The updated server port value to store. |
Source code in plantimager/webui/config.py
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 |
|
create_dataset_cfg_icon Link
create_dataset_cfg_icon(is_connected=False, dataset_list=None)
Create a navigation link with the database status icon and dataset counter badge.
Creates a Bootstrap NavLink component that displays a database status icon and a badge showing the number of datasets. The icon changes appearance based on connection status.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
is_connected
|
bool
|
Flag indicating whether the database connection is established, by default False |
False
|
dataset_list
|
list
|
List of datasets to count, by default empty list |
None
|
Returns:
Type | Description |
---|---|
NavLink
|
A navigation link component containing: - Database status icon - Badge showing dataset count The NavLink is styled and positioned according to the application's design. |
Source code in plantimager/webui/config.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
|
dataset_cfg_status Link
dataset_cfg_status(is_connected)
Generate a database status icon based on the connection state.
Creates a Bootstrap icon element representing the database connection status. Returns a check icon when connected and a gear icon when disconnected.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
is_connected
|
bool
|
Flag indicating whether the database connection is established. |
required |
Returns:
Type | Description |
---|---|
I
|
A Bootstrap icon component with the appropriate class based on connection status. |
Source code in plantimager/webui/config.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
|
show_api_address Link
show_api_address(modal_is_open, stored_host)
Callback updating the value of the 'api-address' field with stored data when opening the PlantDB configuration modal.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
modal_is_open
|
bool
|
Indicates whether the configuration modal is currently open. |
required |
stored_host
|
str or None
|
The stored value of the REST API host. Can be |
required |
Returns:
Type | Description |
---|---|
str
|
The IP address to be used, either the stored host value or the |
Source code in plantimager/webui/config.py
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
|
show_api_port Link
show_api_port(modal_is_open, stored_port)
Callback updating the value of the 'api-port' field with stored data when opening the PlantDB configuration modal.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
modal_is_open
|
bool
|
Boolean indicating whether the configuration modal is open or closed. |
required |
stored_port
|
str or None
|
Stored port value retrieved from the state. Can be |
required |
Returns:
Type | Description |
---|---|
str
|
Value to be set for the "api-port" input field, either the stored port value or the |
Source code in plantimager/webui/config.py
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
|
show_api_prefix Link
show_api_prefix(modal_is_open, stored_prefix)
Callback updating the value of the 'api-prefix' field with stored data when opening the PlantDB configuration modal.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
modal_is_open
|
bool
|
Boolean indicating whether the configuration modal is open or closed. |
required |
stored_prefix
|
str or None
|
Stored prefix value retrieved from the state. Can be |
required |
Returns:
Type | Description |
---|---|
str
|
Value to be set for the "api-prefix" input field. |
Source code in plantimager/webui/config.py
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 |
|
show_plantdb_status Link
show_plantdb_status(status, host, port, prefix)
Display the connection status of the PlantDB server in a Bootstrap alert component.
This callback function generates a styled alert component that shows whether the PlantDB server is available or not. The alert includes an icon and descriptive text with the server's host and port information when applicable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
status
|
bool or None
|
Connection status of the PlantDB server:
- |
required |
host
|
str
|
Hostname or IP address of the PlantDB server |
required |
port
|
int
|
Port number of the PlantDB server |
required |
prefix
|
str
|
URL prefix of the PlantDB server |
required |
Returns:
Type | Description |
---|---|
Alert
|
A Bootstrap alert component with the appropriate styling and message based on the connection status: - Info (blue): when status is unknown - Success (green): when server is available - Danger (red): when server is unavailable |
Source code in plantimager/webui/config.py
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 |
|
toggle_plantdb_cfg_modal Link
toggle_plantdb_cfg_modal(n_clicks, is_open)
Toggle the visibility state of the PlantDB configuration modal.
This callback function controls the opening and closing of the PlantDB configuration modal dialog. It is triggered by clicking on the configuration button and toggles the modal's visibility state.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_clicks
|
int
|
Number of times the plantdb-cfg-button has been clicked. Used to determine when to toggle the modal state. |
required |
is_open
|
bool
|
Current visibility state of the modal. |
required |
Returns:
Type | Description |
---|---|
bool or None
|
The new visibility state of the modal. Returns the opposite of the current state when n_clicks > 0, otherwise returns None. |
Source code in plantimager/webui/config.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
|
update_dataset_badge Link
update_dataset_badge(dataset_list)
Update the dataset count badge with the current number of datasets.
This callback function updates a badge element in the UI to display the total number of datasets currently available in the system. It converts the length of the dataset list to a string for display.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset_list
|
list
|
A list containing the dataset names stored in the dcc.Store component. |
required |
Returns:
Type | Description |
---|---|
str
|
String representation of the number of datasets in the list. |
Source code in plantimager/webui/config.py
513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 |
|
update_dataset_list Link
update_dataset_list(n_clicks, connected, host, port, prefix)
Callback updating the dataset list and displaying the load status when a user clicks the load button.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_clicks
|
int
|
The n_clicks property of the load-plantdb-button element, which triggers the callback (not used). |
required |
connected
|
bool
|
The connection status of the PlantDB REST API server. |
required |
host
|
str
|
The hostname or IP address of the PlantDB REST API server. |
required |
port
|
int
|
The port number of the PlantDB REST API server. |
required |
prefix
|
str
|
The prefix of the PlantDB REST API server. |
required |
Returns:
Type | Description |
---|---|
Alert
|
An alert component indicating success or failure of dataset retrieval. |
list of str
|
A list of dataset names retrieved from the server. |
Source code in plantimager/webui/config.py
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 |
|
update_plantdb_cfg_button Link
update_plantdb_cfg_button(status, dataset_list)
Update the PlantDB configuration button's appearance based on connection status.
This callback function updates the visual representation of the PlantDB configuration button in the navigation bar depending on the connection status and dataset list state. It uses the create_dataset_cfg_icon function to generate the appropriate icon.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
status
|
bool or None
|
The connection status to the PlantDB REST API.
|
required |
dataset_list
|
list or None
|
List of available datasets from the PlantDB.
|
required |
Returns:
Type | Description |
---|---|
Component
|
A Dash HTML component representing the configuration button icon with the appropriate styling based on the connection status. |
Source code in plantimager/webui/config.py
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 |
|