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