Include revisions of inputs in flake overview
This commit is contained in:
parent
4a2f16d6ff
commit
aa2ac96288
@ -24,7 +24,7 @@ use flake_tracker::{
|
||||
Storage,
|
||||
},
|
||||
templates::{
|
||||
FlakeInfoTemplate,
|
||||
FlakeTemplate,
|
||||
FlakesTemplate,
|
||||
IndexTemplate,
|
||||
RevisionTemplate,
|
||||
@ -91,7 +91,7 @@ async fn main() -> anyhow::Result<()> {
|
||||
let app = Router::new()
|
||||
.route("/", get(route_index))
|
||||
.route("/flakes", get(route_flakes))
|
||||
.route("/f/{uri}", get(route_flake_info))
|
||||
.route("/f/{uri}", get(route_flake))
|
||||
.route("/r/{revision_uri}", get(route_revision))
|
||||
.with_state(state);
|
||||
|
||||
@ -118,13 +118,13 @@ async fn route_flakes(
|
||||
})?)
|
||||
}
|
||||
|
||||
async fn route_flake_info(
|
||||
async fn route_flake(
|
||||
State(state): State<AppState>,
|
||||
Path(uri): Path<String>,
|
||||
) -> Result<impl IntoResponse, AppError> {
|
||||
Ok(render_template(&FlakeInfoTemplate {
|
||||
Ok(render_template(&FlakeTemplate {
|
||||
uri: uri.clone(),
|
||||
flake_revisions: state.storage.revisions_from_flake(&uri).await?,
|
||||
revisions: state.storage.revisions_from_flake(&uri).await?,
|
||||
})?)
|
||||
}
|
||||
|
||||
|
@ -46,17 +46,23 @@ impl Storage {
|
||||
.context("Failed to fetch data from database")
|
||||
}
|
||||
|
||||
pub async fn revisions_from_flake(&self, uri: &str) -> Result<Vec<FlakeRevision>> {
|
||||
pub async fn revisions_from_flake(&self, uri: &str) -> Result<Vec<RevisionListModel>> {
|
||||
sqlx::query_as("
|
||||
SELECT
|
||||
revision_uri,
|
||||
revision,
|
||||
last_modified
|
||||
FROM flake_revisions
|
||||
WHERE uri = ?
|
||||
UNION
|
||||
SELECT
|
||||
revision_uri,
|
||||
last_modified
|
||||
FROM flake_revisions_inputs
|
||||
WHERE uri = ?
|
||||
ORDER BY last_modified
|
||||
")
|
||||
.bind(&uri)
|
||||
.bind(&uri)
|
||||
.fetch_all(&self.db)
|
||||
.await
|
||||
.context("Failed to fetch data from database")
|
||||
@ -93,13 +99,12 @@ pub struct FlakeRevisionRow {
|
||||
}
|
||||
|
||||
#[derive(FromRow)]
|
||||
pub struct FlakeRevision {
|
||||
pub struct RevisionListModel {
|
||||
pub revision_uri: String,
|
||||
pub revision: String,
|
||||
pub last_modified: i64,
|
||||
}
|
||||
|
||||
impl FlakeRevision {
|
||||
impl RevisionListModel {
|
||||
pub fn link(&self ) -> String {
|
||||
format!("/r/{}", urlencode(&self.revision_uri))
|
||||
}
|
||||
|
@ -3,9 +3,9 @@ use askama::{
|
||||
};
|
||||
use crate::{
|
||||
storage::{
|
||||
FlakeRevision,
|
||||
FlakeUri,
|
||||
InputModel,
|
||||
RevisionListModel,
|
||||
},
|
||||
};
|
||||
|
||||
@ -21,10 +21,10 @@ pub struct FlakesTemplate {
|
||||
}
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "flake-info.html")]
|
||||
pub struct FlakeInfoTemplate {
|
||||
#[template(path = "flake.html")]
|
||||
pub struct FlakeTemplate {
|
||||
pub uri: String,
|
||||
pub flake_revisions: Vec<FlakeRevision>,
|
||||
pub revisions: Vec<RevisionListModel>,
|
||||
}
|
||||
|
||||
#[derive(Template)]
|
||||
|
@ -10,8 +10,8 @@
|
||||
<h2>Revisions</h2>
|
||||
|
||||
<ul>
|
||||
{% for flake_revision in flake_revisions %}
|
||||
<li><a href="{{ flake_revision.link() }}">{{ flake_revision.revision }}</a> ({{ flake_revision.last_modified }})</li>
|
||||
{% for revision in revisions %}
|
||||
<li><a href="{{ revision.link() }}">{{ revision.revision_uri }}</a> ({{ revision.last_modified }})</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endblock %}
|
Loading…
x
Reference in New Issue
Block a user