Display the list of pending devices in the UI

This commit is contained in:
2024-07-03 19:17:47 +02:00
parent 01ffe085d7
commit 716af6219a
14 changed files with 301 additions and 17 deletions

View File

@ -81,7 +81,7 @@ impl DevicesList {
let dev = self
.0
.get(id)
.ok_or_else(|| DevicesListError::PersistFailedDeviceNotFound)?;
.ok_or(DevicesListError::PersistFailedDeviceNotFound)?;
std::fs::write(
AppConfig::get().device_config_path(id),
@ -90,4 +90,9 @@ impl DevicesList {
Ok(())
}
/// Get a copy of the full list of devices
pub fn full_list(&self) -> Vec<Device> {
self.0.clone().into_values().collect()
}
}

View File

@ -1,5 +1,5 @@
use crate::constants;
use crate::devices::device::{DeviceId, DeviceInfo};
use crate::devices::device::{Device, DeviceId, DeviceInfo};
use crate::devices::devices_list::DevicesList;
use crate::energy::consumption;
use crate::energy::consumption::EnergyConsumption;
@ -93,3 +93,16 @@ impl Handler<EnrollDevice> for EnergyActor {
self.devices.enroll(&msg.0, &msg.1, &msg.2)
}
}
/// Get the list of devices
#[derive(Message)]
#[rtype(result = "Vec<Device>")]
pub struct GetDeviceLists;
impl Handler<GetDeviceLists> for EnergyActor {
type Result = Vec<Device>;
fn handle(&mut self, _msg: GetDeviceLists, _ctx: &mut Context<Self>) -> Self::Result {
self.devices.full_list()
}
}

View File

@ -131,6 +131,14 @@ pub async fn secure_server(energy_actor: EnergyActorAddr) -> anyhow::Result<()>
"/web_api/energy/cached_consumption",
web::get().to(energy_controller::cached_consumption),
)
.route(
"/web_api/devices/list_pending",
web::get().to(devices_controller::list_pending),
)
.route(
"/web_api/devices/list_validated",
web::get().to(devices_controller::list_validated),
)
// Devices API
.route(
"/devices_api/utils/time",

View File

@ -0,0 +1,28 @@
use crate::energy::energy_actor;
use crate::server::custom_error::HttpResult;
use crate::server::WebEnergyActor;
use actix_web::HttpResponse;
/// Get the list of pending (not accepted yet) devices
pub async fn list_pending(actor: WebEnergyActor) -> HttpResult {
let list = actor
.send(energy_actor::GetDeviceLists)
.await?
.into_iter()
.filter(|d| !d.validated)
.collect::<Vec<_>>();
Ok(HttpResponse::Ok().json(list))
}
/// Get the list of validated (not accepted yet) devices
pub async fn list_validated(actor: WebEnergyActor) -> HttpResult {
let list = actor
.send(energy_actor::GetDeviceLists)
.await?
.into_iter()
.filter(|d| d.validated)
.collect::<Vec<_>>();
Ok(HttpResponse::Ok().json(list))
}

View File

@ -1,3 +1,4 @@
pub mod auth_controller;
pub mod devices_controller;
pub mod energy_controller;
pub mod server_controller;