Compare commits
No commits in common. "18499631ea089f40d32db4f5502c59d84de5ba45" and "edd459e1afc91f6a598db8794ffcf518952e3921" have entirely different histories.
18499631ea
...
edd459e1af
|
|
@ -351,7 +351,6 @@ dependencies = [
|
||||||
"diesel_migrations",
|
"diesel_migrations",
|
||||||
"futures",
|
"futures",
|
||||||
"image",
|
"image",
|
||||||
"libsqlite3-sys",
|
|
||||||
"mime",
|
"mime",
|
||||||
"rand",
|
"rand",
|
||||||
"serde",
|
"serde",
|
||||||
|
|
@ -1089,7 +1088,6 @@ version = "0.30.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2e99fb7a497b1e3339bc746195567ed8d3e24945ecd636e3619d20b9de9e9149"
|
checksum = "2e99fb7a497b1e3339bc746195567ed8d3e24945ecd636e3619d20b9de9e9149"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cc",
|
|
||||||
"pkg-config",
|
"pkg-config",
|
||||||
"vcpkg",
|
"vcpkg",
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -15,12 +15,12 @@ chrono = { version = "0.4.39", features = ["serde"] }
|
||||||
clap = { version = "4.5.26", features = ["derive", "env"] }
|
clap = { version = "4.5.26", features = ["derive", "env"] }
|
||||||
diesel = { version = "2.2.6", features = ["sqlite", "returning_clauses_for_sqlite_3_35", "r2d2", "chrono"] }
|
diesel = { version = "2.2.6", features = ["sqlite", "returning_clauses_for_sqlite_3_35", "r2d2", "chrono"] }
|
||||||
diesel_migrations = { version = "2.2.0", features = ["sqlite"] }
|
diesel_migrations = { version = "2.2.0", features = ["sqlite"] }
|
||||||
# Forces diesel to include a bundled version of Sqlite
|
|
||||||
libsqlite3-sys = {version = ">=0.17.2, <0.31.0", features = ["bundled"]}
|
|
||||||
futures = "0.3.31"
|
futures = "0.3.31"
|
||||||
image = { version = "0.25.5", default-features = false, features = ["gif", "jpeg", "png"] }
|
image = { version = "0.25.5", default-features = false, features = ["gif", "jpeg", "png"] }
|
||||||
mime = "0.3.17"
|
mime = "0.3.17"
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
|
# this dependency is needed soly because the r2d2_sqlite crate doesn't export
|
||||||
|
# the 'chrono' feature flag
|
||||||
serde = { version = "1.0.217", features = ["derive"] }
|
serde = { version = "1.0.217", features = ["derive"] }
|
||||||
tera = "1.20.0"
|
tera = "1.20.0"
|
||||||
tokio = { version = "1.42.0", features = ["full"] }
|
tokio = { version = "1.42.0", features = ["full"] }
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ use chrono::NaiveDate;
|
||||||
use diesel::prelude::*;
|
use diesel::prelude::*;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::db::{schema::*, DbPool, DbResult, Pagination, Plant};
|
use crate::db::{schema::*, DbPool, DbResult, Pagination};
|
||||||
|
|
||||||
#[derive(Serialize, Queryable, Selectable)]
|
#[derive(Serialize, Queryable, Selectable)]
|
||||||
#[diesel(table_name = images)]
|
#[diesel(table_name = images)]
|
||||||
|
|
@ -62,15 +62,8 @@ impl Image {
|
||||||
.optional()?)
|
.optional()?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn page_with_plants(
|
pub fn page(pool: &DbPool, page: Pagination, filter: ImageFilter) -> DbResult<Vec<Self>> {
|
||||||
pool: &DbPool,
|
let mut query = images::table.select(Self::as_select()).into_boxed();
|
||||||
page: Pagination,
|
|
||||||
filter: ImageFilter,
|
|
||||||
) -> DbResult<Vec<(Self, Plant)>> {
|
|
||||||
let mut query = images::table
|
|
||||||
.inner_join(plants::table)
|
|
||||||
.select((Self::as_select(), Plant::as_select()))
|
|
||||||
.into_boxed();
|
|
||||||
|
|
||||||
if let Some(plant_id) = filter.plant_id {
|
if let Some(plant_id) = filter.plant_id {
|
||||||
query = query.filter(images::dsl::plant_id.eq(plant_id));
|
query = query.filter(images::dsl::plant_id.eq(plant_id));
|
||||||
|
|
|
||||||
|
|
@ -66,10 +66,9 @@ async fn get_images(
|
||||||
Query(filter): Query<db::ImageFilter>,
|
Query(filter): Query<db::ImageFilter>,
|
||||||
headers: HeaderMap,
|
headers: HeaderMap,
|
||||||
) -> super::Result<Html<String>> {
|
) -> super::Result<Html<String>> {
|
||||||
let images =
|
let images = tokio::task::spawn_blocking(move || db::Image::page(&ctx.pool, page, filter))
|
||||||
tokio::task::spawn_blocking(move || db::Image::page_with_plants(&ctx.pool, page, filter))
|
.await
|
||||||
.await
|
.unwrap()?;
|
||||||
.unwrap()?;
|
|
||||||
|
|
||||||
let mut context = Context::new();
|
let mut context = Context::new();
|
||||||
context.insert("images", &images);
|
context.insert("images", &images);
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,3 @@
|
||||||
<input type="submit">
|
<input type="submit">
|
||||||
</form>
|
</form>
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
{% macro name(plant) %}
|
|
||||||
<a hx-get="/plants/{{ plant.id }}" hx-target="#content" hx-push-url="true">{{ plant.name }} (<em>{{ plant.species }}</em>)</a>
|
|
||||||
{% endmacro %}
|
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,10 @@
|
||||||
{% import "components/plant.html" as comp_plant %}
|
|
||||||
|
|
||||||
<h1>Images</h1>
|
<h1>Images</h1>
|
||||||
{% for image in images %}
|
{% for image in images %}
|
||||||
<article>
|
<article>
|
||||||
<p>Date taken: {{ image.0.date_taken }}</p>
|
<p>Date taken: {{ image.date_taken }}</p>
|
||||||
<p>Note: {{ image.0.note }}</p>
|
<p>Note: {{ image.note }}</p>
|
||||||
<p>Plant: {{ comp_plant::name(plant=image.1) }}</p>
|
<a href="/images/{{ image.id }}/original" target="_blank">
|
||||||
<a href="/images/{{ image.0.id }}/original" target="_blank">
|
<img src="/images/{{ image.id }}/thumb">
|
||||||
<img src="/images/{{ image.0.id }}/thumb">
|
|
||||||
</a>
|
</a>
|
||||||
</article>
|
</article>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue