Display current inputs for flakes
This commit is contained in:
parent
56a331555e
commit
8ab45c982a
@ -125,6 +125,7 @@ async fn route_flake(
|
||||
Ok(render_template(&FlakeTemplate {
|
||||
uri: uri.clone(),
|
||||
revisions: state.storage.revisions_from_flake(&uri).await?,
|
||||
current_inputs: state.storage.current_inputs_for_flake(&uri).await?,
|
||||
})?)
|
||||
}
|
||||
|
||||
|
@ -105,6 +105,31 @@ impl Storage {
|
||||
.await
|
||||
.context("Failed to fetch data from database")
|
||||
}
|
||||
|
||||
pub async fn current_inputs_for_flake(&self, flake_uri: &str) -> Result<Vec<InputForFlakeRow>> {
|
||||
sqlx::query_as("
|
||||
|
||||
SELECT
|
||||
flake_revisions.revision_uri,
|
||||
MAX(flake_revisions.last_modified) AS last_modified,
|
||||
flake_revisions_inputs.input_name,
|
||||
flake_revisions_inputs.uri
|
||||
FROM
|
||||
flake_revisions
|
||||
LEFT JOIN
|
||||
flake_revisions_inputs
|
||||
ON
|
||||
flake_revisions.revision_uri = flake_revisions_inputs.flake_revision_uri
|
||||
WHERE
|
||||
flake_revisions.uri = ?
|
||||
GROUP BY
|
||||
flake_revisions_inputs.input_name
|
||||
")
|
||||
.bind(&flake_uri)
|
||||
.fetch_all(&self.db)
|
||||
.await
|
||||
.context("Failed to fetch data from database")
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(FromRow)]
|
||||
@ -117,6 +142,24 @@ pub struct FlakeRevisionRow {
|
||||
pub last_modified: Option<i64>,
|
||||
}
|
||||
|
||||
#[derive(FromRow)]
|
||||
pub struct InputForFlakeRow {
|
||||
pub revision_uri: String,
|
||||
pub last_modified: Option<i64>,
|
||||
pub input_name: String,
|
||||
pub uri: Option<String>,
|
||||
}
|
||||
|
||||
impl InputForFlakeRow {
|
||||
pub fn flake_link(&self ) -> String {
|
||||
match &self.uri {
|
||||
Some(uri) => format!("/f/{}", urlencode(&uri)),
|
||||
None => String::from("#"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[derive(FromRow)]
|
||||
pub struct RevisionListModel {
|
||||
pub revision_uri: String,
|
||||
|
@ -5,6 +5,7 @@ use crate::{
|
||||
storage::{
|
||||
FlakeUri,
|
||||
InputModel,
|
||||
InputForFlakeRow,
|
||||
RevisionListModel,
|
||||
},
|
||||
};
|
||||
@ -25,6 +26,7 @@ pub struct FlakesTemplate {
|
||||
pub struct FlakeTemplate {
|
||||
pub uri: String,
|
||||
pub revisions: Vec<RevisionListModel>,
|
||||
pub current_inputs: Vec<InputForFlakeRow>,
|
||||
}
|
||||
|
||||
#[derive(Template)]
|
||||
|
@ -14,5 +14,23 @@
|
||||
<li><a href="{{ revision.link() }}">{{ revision.revision_uri }}</a> ({{ revision.last_modified }})</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
<h2>Current Inputs</h2>
|
||||
|
||||
<ul>
|
||||
{% for input in current_inputs %}
|
||||
<li>
|
||||
{{ input.input_name }}
|
||||
<ul>
|
||||
{% match input.uri %}
|
||||
{% when Some with (uri) %}
|
||||
<li>Flake: <a href="{{ input.flake_link() }}">{{ uri }}</a></li>
|
||||
{% when None %}
|
||||
{% endmatch %}
|
||||
</ul>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user