Skip to content

Commit

Permalink
Add LOA form for Sr Staff
Browse files Browse the repository at this point in the history
  • Loading branch information
Celeo committed Jan 10, 2025
1 parent 902c35d commit 3c632ec
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 2 deletions.
7 changes: 7 additions & 0 deletions static/controller_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ document
document.getElementById("modalRemoveController").close();
});

document
.getElementById("btn-modal-loa-close")
.addEventListener("click", (e) => {
e.preventDefault();
document.getElementById("modalUpdateLOA").close();
});

document
.getElementById("btn-modal-training-record-close")
.addEventListener("click", (e) => {
Expand Down
65 changes: 65 additions & 0 deletions vzdv-site/src/endpoints/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,9 @@ struct RemoveControllerForm {
reason: String,
}

/// Form submission to remove a controller from the roster.
///
/// For admin staff members.
async fn post_remove_controller(
State(state): State<Arc<AppState>>,
session: Session,
Expand Down Expand Up @@ -954,12 +957,74 @@ async fn post_remove_controller(
Ok(Redirect::to(&format!("/controller/{cid}")))
}

#[derive(Debug, Deserialize)]
struct LoaUpdateForm {
loa: String,
}

/// Form submission to set controller LOA.
///
/// For admin staff members.
async fn post_loa(
State(state): State<Arc<AppState>>,
session: Session,
Path(cid): Path<u32>,
Form(loa_form): Form<LoaUpdateForm>,
) -> Result<Redirect, AppError> {
let user_info: Option<UserInfo> = session.get(SESSION_USER_INFO_KEY).await?;
if let Some(redirect) = reject_if_not_in(&state, &user_info, PermissionsGroup::Admin).await {
return Ok(redirect);
}
let user_info = user_info.unwrap();

let controller: Option<Controller> = sqlx::query_as(sql::GET_CONTROLLER_BY_CID)
.bind(cid)
.fetch_optional(&state.db)
.await?;
if controller.is_none() {
warn!(
"{} tried to update LOA for unknown controller {cid}",
user_info.cid
);
flashed_messages::push_flashed_message(session, MessageLevel::Error, "Unknown controller")
.await?;
return Ok(Redirect::to(&format!("/controller/{cid}")));
}

if loa_form.loa.is_empty() {
let dt: Option<String> = None;
sqlx::query(sql::CONTROLLER_UPDATE_LOA)
.bind(cid)
.bind(dt)
.execute(&state.db)
.await?;
} else {
let dt = js_timestamp_to_utc(&loa_form.loa, "UTC")?;
sqlx::query(sql::CONTROLLER_UPDATE_LOA)
.bind(cid)
.bind(dt)
.execute(&state.db)
.await?;
}
record_log(
format!(
"{} updated LOA for {cid} to {}",
user_info.cid, loa_form.loa
),
&state.db,
true,
)
.await?;
Ok(Redirect::to(&format!("/controller/{cid}")))
}

pub fn router() -> Router<Arc<AppState>> {
Router::new()
.route("/controller/{cid}", get(page_controller))
.route("/controller/{cid}/discord/unlink", post(api_unlink_discord))
.route("/controller/{cid}/ois", post(post_change_ois))
.route("/controller/{cid}/certs", post(post_change_certs))
.route("/controller/{cid}/loa", post(post_loa))
.route("/controller/{cid}/certs/solo", post(post_new_solo_cert))
.route(
"/controller/{cid}/certs/solo/{cert_id}",
Expand Down
11 changes: 11 additions & 0 deletions vzdv-site/templates/changelog.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@

<hr>

<div class="card shadow mb-3">
<div class="card-body">
<h5 class="card-title">2025-01-09</h5>
<div class="card-text">
<ul>
<li>Added LOA form for Sr Staff to use for controllers</li>
</ul>
</div>
</div>
</div>

<div class="card shadow mb-3">
<div class="card-body">
<h5 class="card-title">2025-01-03</h5>
Expand Down
29 changes: 29 additions & 0 deletions vzdv-site/templates/controller/controller.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
Edit OIs
</button>
{% if controller.is_on_roster %}
<button class="ms-2 btn btn-sm btn-warning" onclick="modalUpdateLOA.showModal()">
<i class="bi bi-person-raised-hand"></i>
LOA
</button>
<button class="ms-2 btn btn-sm btn-danger" onclick="modalRemoveController.showModal()">
<i class="bi bi-x-circle"></i>
Remove
Expand All @@ -38,6 +42,10 @@
<strong>Type:</strong> {% if not controller.is_on_roster %}Guest{% elif not controller.home_facility == 'ZDV' %}Visiting{% else %}Home{% endif %}
<br>
<strong>Joined:</strong> {{ controller.join_date }}
{% if controller.loa_until %}
<br>
<strong>LOA until</strong>: {{ controller.loa_until }}
{% endif %}
{% if user_info and user_info.is_some_staff %}
<br>
<strong>Discord user ID:</strong> {{ controller.discord_id }}
Expand Down Expand Up @@ -466,6 +474,27 @@
</form>
</dialog>

<dialog id="modalUpdateLOA">
<h2 class="pb-3">Update LOA</h2>
<p>Leave empty and save to remove a LOA.</p>
<form action="/controller/{{ controller.cid }}/loa" method="POST">
<div class="row">
<div class="col">
<div class="mb-3">
<label for="date" class="form-label">LOA until</label>
<input type="datetime-local" name="loa" id="loa" class="form-control">
</div>
</div>
</div>
<div class="row">
<div class="d-flex justify-content-between">
<button class="btn btn-warning" role="button" id="btn-modal-loa-close">Close</button>
<button class="btn btn-primary" role="button" type="submit">Save</button>
</div>
</div>
</form>
</dialog>

<dialog id="modalRemoveController">
<h2 class="pb-3">Remove controller from roster</h2>
<p>
Expand Down
2 changes: 1 addition & 1 deletion vzdv-site/templates/facility/activity.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<span title="Potential activity violation"><i class="bi bi-calendar-x" style="color: yellow"></i></span>
{% endif %}
{{ row.name }} {% if row.ois %}({{ row.ois }}){% endif %}
{% if row.loa_until %}<span class="text-info" title="{{ row.loa_until }}">(LOA)</span>{% endif %}
{% if row.loa_until %}<span class="text-info" title="Until {{ row.loa_until }}">(LOA)</span>{% endif %}
<a href="/controller/{{ row.cid }}" class="icon-link icon-link-hover text-decoration-none">
<i class="bi bi-arrow-right-short"></i>
</a>
Expand Down
2 changes: 1 addition & 1 deletion vzdv-site/templates/facility/roster.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<tr class="d-flex">
<td class="col-1">
{{ controller.operating_initials }}
{% if controller.loa_until %}<span class="text-info" title="{{ controller.loa_until }}">(LOA)</span>{% endif %}
{% if controller.loa_until %}<span class="text-info" title="Until {{ controller.loa_until }}">(LOA)</span>{% endif %}
</td>
<td class="col-3">{{ controller.first_name }} {{ controller.last_name }}</td>
<td class="col-3">
Expand Down
1 change: 1 addition & 0 deletions vzdv/src/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ pub const SET_CONTROLLER_ROLES: &str = "UPDATE controller SET roles=$2 WHERE cid
pub const SET_CONTROLLER_ON_ROSTER: &str = "UPDATE controller SET is_on_roster=$2 WHERE cid=$1";
pub const GET_CONTROLLERS_WITH_ROLES: &str =
"SELECT * FROM controller WHERE roles IS NOT NULL AND roles <> ''";
pub const CONTROLLER_UPDATE_LOA: &str = "UPDATE controller SET loa_until=$2 WHERE cid=$1";

pub const GET_ALL_CERTIFICATIONS: &str = "SELECT * FROM certification";
pub const GET_ALL_CERTIFICATIONS_FOR: &str = "SELECT * FROM certification WHERE cid=$1";
Expand Down

0 comments on commit 3c632ec

Please sign in to comment.