Compare commits
	
		
			2 Commits 
		
	
	
		
			edd459e1af
			...
			18499631ea
		
	
	| Author | SHA1 | Date | 
|---|---|---|
| 
							
							
								
									
								
								 | 
						18499631ea | |
| 
							
							
								
									
								
								 | 
						15b2ef3477 | 
| 
						 | 
				
			
			@ -351,6 +351,7 @@ dependencies = [
 | 
			
		|||
 "diesel_migrations",
 | 
			
		||||
 "futures",
 | 
			
		||||
 "image",
 | 
			
		||||
 "libsqlite3-sys",
 | 
			
		||||
 "mime",
 | 
			
		||||
 "rand",
 | 
			
		||||
 "serde",
 | 
			
		||||
| 
						 | 
				
			
			@ -1088,6 +1089,7 @@ version = "0.30.1"
 | 
			
		|||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "2e99fb7a497b1e3339bc746195567ed8d3e24945ecd636e3619d20b9de9e9149"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "cc",
 | 
			
		||||
 "pkg-config",
 | 
			
		||||
 "vcpkg",
 | 
			
		||||
]
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -15,12 +15,12 @@ chrono = { version = "0.4.39", features = ["serde"] }
 | 
			
		|||
clap = { version = "4.5.26", features = ["derive", "env"] }
 | 
			
		||||
diesel = { version = "2.2.6", features = ["sqlite", "returning_clauses_for_sqlite_3_35", "r2d2", "chrono"] }
 | 
			
		||||
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"
 | 
			
		||||
image = { version = "0.25.5", default-features = false, features = ["gif", "jpeg", "png"] }
 | 
			
		||||
mime = "0.3.17"
 | 
			
		||||
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"] }
 | 
			
		||||
tera = "1.20.0"
 | 
			
		||||
tokio = { version = "1.42.0", features = ["full"] }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,7 +2,7 @@ use chrono::NaiveDate;
 | 
			
		|||
use diesel::prelude::*;
 | 
			
		||||
use serde::{Deserialize, Serialize};
 | 
			
		||||
 | 
			
		||||
use crate::db::{schema::*, DbPool, DbResult, Pagination};
 | 
			
		||||
use crate::db::{schema::*, DbPool, DbResult, Pagination, Plant};
 | 
			
		||||
 | 
			
		||||
#[derive(Serialize, Queryable, Selectable)]
 | 
			
		||||
#[diesel(table_name = images)]
 | 
			
		||||
| 
						 | 
				
			
			@ -62,8 +62,15 @@ impl Image {
 | 
			
		|||
            .optional()?)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn page(pool: &DbPool, page: Pagination, filter: ImageFilter) -> DbResult<Vec<Self>> {
 | 
			
		||||
        let mut query = images::table.select(Self::as_select()).into_boxed();
 | 
			
		||||
    pub fn page_with_plants(
 | 
			
		||||
        pool: &DbPool,
 | 
			
		||||
        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 {
 | 
			
		||||
            query = query.filter(images::dsl::plant_id.eq(plant_id));
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -66,9 +66,10 @@ async fn get_images(
 | 
			
		|||
    Query(filter): Query<db::ImageFilter>,
 | 
			
		||||
    headers: HeaderMap,
 | 
			
		||||
) -> super::Result<Html<String>> {
 | 
			
		||||
    let images = tokio::task::spawn_blocking(move || db::Image::page(&ctx.pool, page, filter))
 | 
			
		||||
        .await
 | 
			
		||||
        .unwrap()?;
 | 
			
		||||
    let images =
 | 
			
		||||
        tokio::task::spawn_blocking(move || db::Image::page_with_plants(&ctx.pool, page, filter))
 | 
			
		||||
            .await
 | 
			
		||||
            .unwrap()?;
 | 
			
		||||
 | 
			
		||||
    let mut context = Context::new();
 | 
			
		||||
    context.insert("images", &images);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -35,3 +35,7 @@
 | 
			
		|||
    <input type="submit">
 | 
			
		||||
</form>
 | 
			
		||||
{% 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,10 +1,13 @@
 | 
			
		|||
{% import "components/plant.html" as comp_plant %}
 | 
			
		||||
 | 
			
		||||
<h1>Images</h1>
 | 
			
		||||
{% for image in images %}
 | 
			
		||||
<article>
 | 
			
		||||
    <p>Date taken: {{ image.date_taken }}</p>
 | 
			
		||||
    <p>Note: {{ image.note }}</p>
 | 
			
		||||
    <a href="/images/{{ image.id }}/original" target="_blank">
 | 
			
		||||
        <img src="/images/{{ image.id }}/thumb">
 | 
			
		||||
    <p>Date taken: {{ image.0.date_taken }}</p>
 | 
			
		||||
    <p>Note: {{ image.0.note }}</p>
 | 
			
		||||
    <p>Plant: {{ comp_plant::name(plant=image.1) }}</p>
 | 
			
		||||
    <a href="/images/{{ image.0.id }}/original" target="_blank">
 | 
			
		||||
        <img src="/images/{{ image.0.id }}/thumb">
 | 
			
		||||
    </a>
 | 
			
		||||
</article>
 | 
			
		||||
{% endfor %}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue