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 API and managing datasets within the Plant Imager web interface.
Key Features
- PlantDB 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, ssl, stored_host, stored_port, stored_prefix, stored_ssl)
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 |
prefix
|
str
|
The URL prefix of the server to test. |
required |
ssl
|
bool
|
Flag indicating whether SSL (HTTPS) is enabled. |
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 |
stored_prefix
|
str
|
The previously stored server prefix value, used if the connection test fails. |
required |
stored_ssl
|
bool
|
The previously stored server SSL flag, 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. |
str
|
The updated server prefix value to store. |
bool
|
The updated server SSL flag value to store. |
Source code in plantimager/webui/config.py
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 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 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 | |
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
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 111 112 113 | |
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
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
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 PlantDB 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
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | |
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
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | |
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
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 | |
show_api_ssl Link
show_api_ssl(modal_is_open, stored_ssl)
Callback updating the value of the 'api-ssl' checkbox 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_ssl
|
bool or None
|
Stored SSL flag retrieved from the state. Can be |
required |
Returns:
| Type | Description |
|---|---|
bool
|
Value to be set for the "api-ssl" checkbox. |
Source code in plantimager/webui/config.py
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 | |
show_plantdb_status Link
show_plantdb_status(status, host, port, prefix, ssl)
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 |
ssl
|
bool
|
Flag indicating whether SSL (HTTPS) is enabled |
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
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 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 | |
toggle_plantdb_cfg_modal Link
toggle_plantdb_cfg_modal(cfg_clicks, connect_clicks, host, port, prefix, ssl, 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 either: 1. The configuration button (opens modal) 2. The connect button (closes modal only if connection successful)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cfg_clicks
|
int
|
Number of times the plantdb-cfg-button has been clicked. |
required |
connect_clicks
|
int
|
Number of times the connect-plantdb-button has been clicked. |
required |
host
|
str or None
|
The host value from the form. |
required |
port
|
int or str or None
|
The port value from the form. |
required |
prefix
|
str or None
|
The prefix value from the form. |
required |
ssl
|
bool or None
|
The SSL flag from the form. |
required |
is_open
|
bool
|
Current visibility state of the modal. |
required |
Returns:
| Type | Description |
|---|---|
bool or None
|
The new visibility state of the modal. |
Source code in plantimager/webui/config.py
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | |
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
646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 | |
update_dataset_list Link
update_dataset_list(n_clicks, connected, host, port, prefix, ssl)
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 API server. |
required |
host
|
str
|
The hostname or IP address of the PlantDB API server. |
required |
port
|
int
|
The port number of the PlantDB API server. |
required |
prefix
|
str
|
The prefix of the PlantDB API server. |
required |
ssl
|
bool
|
Flag indicating whether SSL (HTTPS) is enabled. |
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
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 | |
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 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
550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 | |