use rocket::serde; use handlebars::Handlebars; // use rocket::serde::__private::de::TagContentOtherField::Content; use urlencoding::encode; mod installation; mod vrm_account; struct InstallationToHtmlInterface<'a> { Name: &'a str, Ip: i64, Vrm: &'a str, Identifier: &'a str, Serial: &'a str, EscapedName: &'a str, Online: &'a str, LastSeen: &'a str, NumBatteries: &'a str, BatteryVersion: &'a str, ServerIp : &'a str, FirmwareVersion: &'a str, } // impl Default for InstallationToHtmlInterface{ // fn default() -> Self { // Self{ // Name: "", // Ip: 0, // Vrm: "", // Identifier: "", // Serial: "", // EscapedName: "", // Online: "", // LastSeen: "", // NumBatteries: "", // BatteryVersion: "", // ServerIp : "10.2.0.1", // FirmwareVersion: "AF09", // } // } // } #[macro_use] extern crate rocket; #[get("/")] async fn index() -> String{ let res = vrm_account::all_installations_request().await; let json = rocket::serde::Deserialize(res.unwrap().text().await.unwrap()); let source = "
{{#inst}} {{> installations}} {{/inst}}
Name Gui VRM Grafana Identifier Last Seen Serial #Batteries Firmware-Version Update
"; let partialSource= "{{Name}} {{online}} {{Ip}} VRM Grafana {{Identifier}} {{LastSeen}} {{Serial}} {{NumBatteries}} {{BatteryVersion}} ⬆️{{FirmwareVersion}} "; let mut handlebars = Handlebars::new(); handlebars.register_template_string("installations", partialSource); let mut installsForHtml = Vec::::new(); for inst in json["records"] { let mut installation = InstallationToHtmlInterface { Name: inst["name"], Ip: 0, // TODO Vrm: inst["idSite"].parse::(), Identifier: inst["identifier"], Serial: "", //Todo Grab and parse Details EscapedName: &encode(inst["name"]).to_string(), Online: "", LastSeen: "", NumBatteries: "", BatteryVersion: "", ServerIp : "10.2.0.1", FirmwareVersion: "AF09", }; installsForHtml.push(installation) } let mut data = installsForHtml; let result = handlebars.render(source, &data); return result.unwrap(); } #[launch] fn rocket() -> _ { rocket::build().mount("/", routes![index]) }