show answered question history on dashboard
This commit is contained in:
parent
411cf86632
commit
6ba4241a45
4 changed files with 67 additions and 3 deletions
|
|
@ -147,6 +147,8 @@ struct StateSnapshot {
|
|||
/// we mark the row answered and fire `HelperEvent::OperatorAnswered`
|
||||
/// into the manager's inbox.
|
||||
questions: Vec<crate::operator_questions::OpQuestion>,
|
||||
/// Last 20 answered questions, newest-first.
|
||||
question_history: Vec<crate::operator_questions::OpQuestion>,
|
||||
/// State dirs (config history + claude creds + /state/ notes) that
|
||||
/// survive after a destroy-without-purge. The operator can re-spawn
|
||||
/// with the same name to resume, or PURG3 to wipe them.
|
||||
|
|
@ -298,6 +300,8 @@ async fn api_state(headers: HeaderMap, State(state): State<AppState>) -> axum::J
|
|||
.recent_for(hive_sh4re::OPERATOR_RECIPIENT, 50),
|
||||
);
|
||||
let questions = log_default("questions.pending", state.coord.questions.pending());
|
||||
let question_history =
|
||||
log_default("questions.recent_answered", state.coord.questions.recent_answered(20));
|
||||
|
||||
axum::Json(StateSnapshot {
|
||||
hostname,
|
||||
|
|
@ -310,6 +314,7 @@ async fn api_state(headers: HeaderMap, State(state): State<AppState>) -> axum::J
|
|||
meta_inputs: read_meta_inputs(),
|
||||
operator_inbox,
|
||||
questions,
|
||||
question_history,
|
||||
tombstones,
|
||||
port_conflicts,
|
||||
})
|
||||
|
|
|
|||
|
|
@ -168,6 +168,21 @@ impl OperatorQuestions {
|
|||
rows.collect::<rusqlite::Result<Vec<_>>>()
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
/// Last `limit` answered questions, newest-first.
|
||||
pub fn recent_answered(&self, limit: u64) -> Result<Vec<OpQuestion>> {
|
||||
let conn = self.conn.lock().unwrap();
|
||||
let mut stmt = conn.prepare(
|
||||
"SELECT id, asker, question, options_json, multi, asked_at, answered_at, answer, deadline_at
|
||||
FROM operator_questions
|
||||
WHERE answered_at IS NOT NULL
|
||||
ORDER BY answered_at DESC
|
||||
LIMIT ?1",
|
||||
)?;
|
||||
let rows = stmt.query_map(params![limit as i64], row_to_question)?;
|
||||
rows.collect::<rusqlite::Result<Vec<_>>>()
|
||||
.map_err(Into::into)
|
||||
}
|
||||
}
|
||||
|
||||
fn row_to_question(row: &rusqlite::Row<'_>) -> rusqlite::Result<OpQuestion> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue