Skip to content

Commit

Permalink
Add requests time range dropdown to admin
Browse files Browse the repository at this point in the history
  • Loading branch information
levkk committed Nov 26, 2024
1 parent 6ad400f commit 3010613
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
13 changes: 11 additions & 2 deletions rwf-admin/src/controllers/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ pub struct Requests;
#[async_trait]
impl Controller for Requests {
async fn handle(&self, request: &Request) -> Result<Response, Error> {
let minutes = request.query().get::<i64>("minutes").unwrap_or(60);
let requests = {
let mut conn = Pool::connection().await?;
RequestByCode::count(60).fetch_all(&mut conn).await?
RequestByCode::count(minutes).fetch_all(&mut conn).await?
};

let duration = {
let mut conn = Pool::connection().await?;
RequestsDuration::count(60).fetch_all(&mut conn).await?
RequestsDuration::count(minutes)
.fetch_all(&mut conn)
.await?
};

let requests = serde_json::to_string(&requests)?;
Expand All @@ -24,6 +27,12 @@ impl Controller for Requests {
"title" => "Requests | Rust Web Framework",
"requests" => requests,
"duration" => duration,
"interval" => match minutes {
60 => "Last hour".into(),
180 => "Last 3 hours".into(),
1440 => "Last 24 hours".into(),
m => format!("Last {} minutes", m)
}
)
}
}
4 changes: 4 additions & 0 deletions rwf-admin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ pub fn static_files() -> Result<Handler, Error> {
"/static/rwf_admin/js/bootstrap.min.js.map",
include_bytes!("../static/rwf_admin/js/bootstrap.min.js.map"),
)
.preload(
"/static/rwf_admin/js/popper.min.js",
include_bytes!("../static/rwf_admin/js/popper.min.js"),
)
.preload(
"/static/rwf_admin/css/bootstrap.min.css.map",
include_bytes!("../static/rwf_admin/css/bootstrap.min.css.map"),
Expand Down
Loading

0 comments on commit 3010613

Please sign in to comment.