Skip to content

Commit

Permalink
list total number of devices
Browse files Browse the repository at this point in the history
  • Loading branch information
bryangerlach committed Sep 28, 2023
1 parent 6c0db49 commit f399e4b
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/webs.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
extern crate time;
use std::{io::BufReader, fs::File};

use actix_web::{get, post, web, App, HttpResponse, HttpServer, Responder, cookie::Cookie, HttpRequest, HttpMessage};
use actix_web::{get, post, web, App, HttpResponse, HttpServer, Responder, cookie::Cookie, HttpRequest};
use chrono::NaiveDateTime;
use serde::Deserialize;
use sqlx::{sqlite::SqliteConnection, Connection};
use argon2::{self, Config};
//use time::{Duration, OffsetDateTime};
use actix_web::cookie::time::{Duration, OffsetDateTime};
use rustls::{Certificate, PrivateKey, ServerConfig};
use rustls_pemfile::{certs, pkcs8_private_keys};
Expand Down Expand Up @@ -36,6 +35,9 @@ async fn hello(req: HttpRequest) -> impl Responder {

let devices = sqlx::query_as!(Device, "SELECT id, user, info, status FROM peer WHERE status > 0").fetch_all(&mut conn).await;
let row_count = devices.as_ref().unwrap().len();
let devices2 = sqlx::query_as!(Device, "SELECT id, user, info, status FROM peer WHERE status = 0").fetch_all(&mut conn).await;
let row_count2 = devices2.as_ref().unwrap().len();
let tot_rows = row_count + row_count2;

// Render the data in a table.
let table = format!(
Expand All @@ -60,6 +62,7 @@ async fn hello(req: HttpRequest) -> impl Responder {
font-weight: bold;
}}
</style>
<h1>Total Devices ({})</h1>
<a href=/log>View Connection Log</a>
<h1>ONLINE ({})</h1>
<table>
Expand All @@ -77,6 +80,7 @@ async fn hello(req: HttpRequest) -> impl Responder {
</tbody>
</table>
"#,
tot_rows,
row_count,
if let Err(_err) = devices {
"Error".to_owned()
Expand Down Expand Up @@ -113,9 +117,6 @@ async fn hello(req: HttpRequest) -> impl Responder {
}
);

let devices2 = sqlx::query_as!(Device, "SELECT id, user, info, status FROM peer WHERE status = 0").fetch_all(&mut conn).await;
let row_count2 = devices2.as_ref().unwrap().len();

// Render the data in a table.
let table2 = format!(
r#"
Expand Down

0 comments on commit f399e4b

Please sign in to comment.