Skip to content

Commit

Permalink
Show more info on user's self training notes page
Browse files Browse the repository at this point in the history
  • Loading branch information
Celeo committed Nov 21, 2024
1 parent 6d6c031 commit abc471f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
20 changes: 16 additions & 4 deletions vzdv-site/src/endpoints/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ use axum::{
use chrono::NaiveDateTime;
use log::{debug, warn};
use minijinja::context;
use std::{collections::HashMap, sync::Arc};
use std::{
collections::{HashMap, HashSet},
sync::Arc,
};
use tower_sessions::Session;
use vzdv::{
sql::{self, Controller},
vatusa::{self, TrainingRecord},
vatusa::{self, get_multiple_controller_names, TrainingRecord},
};

/// Retrieve and show the user their training records from VATUSA.
Expand All @@ -30,8 +33,9 @@ async fn page_training_notes(
Some(info) => info,
None => return Ok(Redirect::to("/").into_response()),
};
// let all_training_records = vatusa::get_training_records(user_info.cid, &state.config.vatsim.vatusa_api_key)
let all_training_records =
vatusa::get_training_records(user_info.cid, &state.config.vatsim.vatusa_api_key)
vatusa::get_training_records(1640903, &state.config.vatsim.vatusa_api_key)
.await
.map_err(|e| {
AppError::GenericFallback("getting VATUSA training records by controller", e)
Expand All @@ -56,9 +60,17 @@ async fn page_training_notes(
.unwrap_or_else(|_| NaiveDateTime::default());
date_b.cmp(&date_a) // sort newest first
});
let instructor_cids: Vec<u32> = training_records
.iter()
.map(|record| record.instructor_id)
.collect::<HashSet<u32>>()
.iter()
.copied()
.collect();
let instructors = get_multiple_controller_names(&instructor_cids).await;

let template = state.templates.get_template("user/training_notes.jinja")?;
let rendered = template.render(context! { user_info, training_records })?;
let rendered = template.render(context! { user_info, training_records, instructors })?;
Ok(Html(rendered).into_response())
}

Expand Down
1 change: 1 addition & 0 deletions vzdv-site/templates/changelog.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<ul>
<li>Styling improvements for modals on mobile</li>
<li>Improvements for Discord no-show notifications</li>
<li>Showing more info on user's own training notes page</li>
</ul>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion vzdv-site/templates/user/training_notes.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
aria-expanded="false"
aria-controls="record-{{ record.id }}"
>
#{{ record.id }} on {{ record.position }}
#{{ record.id }} on {{ record.position }} on {{ record.session_date }} for {{ record.duration }} with {{ instructors[record.instructor_id] }}
</button>
</h2>
<div id="record-{{ record.id }}" class="accordion-collapse collapse" data-bs-parent="#training_records_accordion">
Expand Down

0 comments on commit abc471f

Please sign in to comment.