Add an interface to select an article illustration

This commit is contained in:
Baptiste Gelez 2018-10-30 21:04:59 +01:00
parent ab5edbc6a5
commit 485aac2e20
10 changed files with 112 additions and 17 deletions

View File

@ -32,6 +32,7 @@ use safe_string::SafeString;
use std::collections::HashSet; use std::collections::HashSet;
#[derive(Queryable, Identifiable, Serialize, Clone, AsChangeset)] #[derive(Queryable, Identifiable, Serialize, Clone, AsChangeset)]
#[changeset_options(treat_none_as_null = "true")]
pub struct Post { pub struct Post {
pub id: i32, pub id: i32,
pub blog_id: i32, pub blog_id: i32,

View File

@ -614,3 +614,9 @@ msgstr ""
msgid "There is currently no article with that tag" msgid "There is currently no article with that tag"
msgstr "" msgstr ""
msgid "Illustration"
msgstr ""
msgid "None"
msgstr ""

View File

@ -630,3 +630,10 @@ msgstr "Cet article nest pas encore publié."
msgid "There is currently no article with that tag" msgid "There is currently no article with that tag"
msgstr "Il n'y a pas encore d'article avec ce tag" msgstr "Il n'y a pas encore d'article avec ce tag"
#, fuzzy
msgid "Illustration"
msgstr "Administration"
msgid "None"
msgstr ""

View File

@ -617,3 +617,10 @@ msgstr "Esto é un borrador, non publicar por agora."
msgid "There is currently no article with that tag" msgid "There is currently no article with that tag"
msgstr "" msgstr ""
#, fuzzy
msgid "Illustration"
msgstr "Administración"
msgid "None"
msgstr ""

View File

@ -66,8 +66,10 @@ msgstr "Benvenuto su {{ instance_name | escape }}"
msgid "Notifications" msgid "Notifications"
msgstr "Notifiche" msgstr "Notifiche"
msgid "Written by {{ link_1 }}{{ url }}{{ link_2 }}{{ name | escape }}{{ link_3 }}" msgid ""
msgstr "Scritto da {{ link_1 }}{{ url }}{{ link_2 }}{{ name | escape }}{{ link_3 }}" "Written by {{ link_1 }}{{ url }}{{ link_2 }}{{ name | escape }}{{ link_3 }}"
msgstr ""
"Scritto da {{ link_1 }}{{ url }}{{ link_2 }}{{ name | escape }}{{ link_3 }}"
msgid "This article is under the {{ license }} license." msgid "This article is under the {{ license }} license."
msgstr "Questo articolo è rilasciato con licenza {{ license }} ." msgstr "Questo articolo è rilasciato con licenza {{ license }} ."
@ -131,7 +133,9 @@ msgid "Your Blogs"
msgstr "I Tuoi Blogs" msgstr "I Tuoi Blogs"
msgid "You don't have any blog yet. Create your own, or ask to join one." msgid "You don't have any blog yet. Create your own, or ask to join one."
msgstr "Non hai ancora nessun blog. Crea il tuo, oppure chiedi di unirti ad uno esistente." msgstr ""
"Non hai ancora nessun blog. Crea il tuo, oppure chiedi di unirti ad uno "
"esistente."
msgid "Start a new blog" msgid "Start a new blog"
msgstr "Inizia un nuovo blog" msgstr "Inizia un nuovo blog"
@ -250,7 +254,8 @@ msgid "You need to be logged in order to edit your profile"
msgstr "Devi effettuare l'accesso per modificare il tuo profilo" msgstr "Devi effettuare l'accesso per modificare il tuo profilo"
msgid "By {{ link_1 }}{{ link_2 }}{{ link_3 }}{{ name | escape }}{{ link_4 }}" msgid "By {{ link_1 }}{{ link_2 }}{{ link_3 }}{{ name | escape }}{{ link_4 }}"
msgstr "Per {{ link_1 }}{{ link_2 }}{{ link_3 }}{{ name | escape }}{{ link_4 }}" msgstr ""
"Per {{ link_1 }}{{ link_2 }}{{ link_3 }}{{ name | escape }}{{ link_4 }}"
msgid "{{ data }} boosted your article" msgid "{{ data }} boosted your article"
msgstr "{{ data }} ha boostato il tuo articolo" msgstr "{{ data }} ha boostato il tuo articolo"
@ -321,7 +326,9 @@ msgstr[0] "Un autore in questo blog: "
msgstr[1] "{{ count }} autori in questo blog: " msgstr[1] "{{ count }} autori in questo blog: "
msgid "Login or use your Fediverse account to interact with this article" msgid "Login or use your Fediverse account to interact with this article"
msgstr "Accedi o utilizza un tuo account del Fediverso per interagire con questo articolo" msgstr ""
"Accedi o utilizza un tuo account del Fediverso per interagire con questo "
"articolo"
msgid "Optional" msgid "Optional"
msgstr "Opzionale" msgstr "Opzionale"
@ -397,8 +404,12 @@ msgstr "Plume è un motore di blog decentralizzato."
msgid "Authors can manage various blogs from an unique website." msgid "Authors can manage various blogs from an unique website."
msgstr "Gli autori possono gestire vari blog da un unico sito." msgstr "Gli autori possono gestire vari blog da un unico sito."
msgid "Articles are also visible on other Plume websites, and you can interact with them directly from other platforms like Mastodon." msgid ""
msgstr "Gli articoli sono visibili anche da altri siti Plume, e puoi interagire con loro direttamente da altre piattaforme come Mastodon." "Articles are also visible on other Plume websites, and you can interact with "
"them directly from other platforms like Mastodon."
msgstr ""
"Gli articoli sono visibili anche da altri siti Plume, e puoi interagire con "
"loro direttamente da altre piattaforme come Mastodon."
msgid "Create your account" msgid "Create your account"
msgstr "Crea il tuo account" msgstr "Crea il tuo account"
@ -487,8 +498,11 @@ msgstr "File"
msgid "Send" msgid "Send"
msgstr "Invia" msgstr "Invia"
msgid "Sorry, but registrations are closed on this instance. Try to find another one" msgid ""
msgstr "Scusa, ma le registrazioni sono chiuse su questa istanza. Prova a cercarne un'altra" "Sorry, but registrations are closed on this instance. Try to find another one"
msgstr ""
"Scusa, ma le registrazioni sono chiuse su questa istanza. Prova a cercarne "
"un'altra"
msgid "Subtitle" msgid "Subtitle"
msgstr "Sottotitolo" msgstr "Sottotitolo"
@ -541,8 +555,14 @@ msgstr "Non riusciamo a trovare questa pagina."
msgid "Invalid CSRF token." msgid "Invalid CSRF token."
msgstr "Token CSRF non valido." msgstr "Token CSRF non valido."
msgid "Something is wrong with your CSRF token. Make sure cookies are enabled in you browser, and try reloading this page. If you continue to see this error message, please report it." msgid ""
msgstr "Qualcosa è andato storto con il tuo token CSRF. Assicurati di aver abilitato i cookies nel tuo browser, e prova a ricaricare questa pagina. Se l'errore si dovesse ripresentare, per favore segnalacelo." "Something is wrong with your CSRF token. Make sure cookies are enabled in "
"you browser, and try reloading this page. If you continue to see this error "
"message, please report it."
msgstr ""
"Qualcosa è andato storto con il tuo token CSRF. Assicurati di aver abilitato "
"i cookies nel tuo browser, e prova a ricaricare questa pagina. Se l'errore "
"si dovesse ripresentare, per favore segnalacelo."
msgid "Administration of {{ instance.name }}" msgid "Administration of {{ instance.name }}"
msgstr "Amministrazione di {{ instance.name }}" msgstr "Amministrazione di {{ instance.name }}"
@ -581,13 +601,15 @@ msgid "Danger zone"
msgstr "Zona pericolosa" msgstr "Zona pericolosa"
msgid "Be very careful, any action taken here can't be cancelled." msgid "Be very careful, any action taken here can't be cancelled."
msgstr "Fai molta attenzione, qualsiasi azione fatta qui non può essere annullata." msgstr ""
"Fai molta attenzione, qualsiasi azione fatta qui non può essere annullata."
msgid "Delete your account" msgid "Delete your account"
msgstr "Elimina il tuo account" msgstr "Elimina il tuo account"
msgid "Sorry, but as an admin, you can't leave your instance." msgid "Sorry, but as an admin, you can't leave your instance."
msgstr "Scusa, ma essendo tu un amministratore, non puoi abbandonare la tua istanza." msgstr ""
"Scusa, ma essendo tu un amministratore, non puoi abbandonare la tua istanza."
msgid "Users" msgid "Users"
msgstr "Utenti" msgstr "Utenti"
@ -597,3 +619,10 @@ msgstr "Questo post non è ancora stato pubblicato."
msgid "There is currently no article with that tag" msgid "There is currently no article with that tag"
msgstr "Attualmente non è ancora presente nessun articolo con quell'etichetta" msgstr "Attualmente non è ancora presente nessun articolo con quell'etichetta"
#, fuzzy
msgid "Illustration"
msgstr "Amministrazione"
msgid "None"
msgstr ""

View File

@ -639,6 +639,13 @@ msgstr ""
msgid "There is currently no article with that tag" msgid "There is currently no article with that tag"
msgstr "" msgstr ""
#, fuzzy
msgid "Illustration"
msgstr "Administrasjon"
msgid "None"
msgstr ""
#~ msgid "One reshare" #~ msgid "One reshare"
#~ msgid_plural "{{ count }} reshares" #~ msgid_plural "{{ count }} reshares"
#~ msgstr[0] "Én deling" #~ msgstr[0] "Én deling"

View File

@ -629,6 +629,13 @@ msgstr "Ten wpis nie został jeszcze opublikowany."
msgid "There is currently no article with that tag" msgid "There is currently no article with that tag"
msgstr "" msgstr ""
#, fuzzy
msgid "Illustration"
msgstr "Administracja"
msgid "None"
msgstr ""
#~ msgid "One reshare" #~ msgid "One reshare"
#~ msgid_plural "{{ count }} reshares" #~ msgid_plural "{{ count }} reshares"
#~ msgstr[0] "Jedno udostępnienie" #~ msgstr[0] "Jedno udostępnienie"

View File

@ -597,3 +597,9 @@ msgstr ""
msgid "There is currently no article with that tag" msgid "There is currently no article with that tag"
msgstr "" msgstr ""
msgid "Illustration"
msgstr ""
msgid "None"
msgstr ""

View File

@ -16,6 +16,7 @@ use plume_models::{
db_conn::DbConn, db_conn::DbConn,
comments::Comment, comments::Comment,
instance::Instance, instance::Instance,
medias::Media,
mentions::Mention, mentions::Mention,
post_authors::*, post_authors::*,
posts::*, posts::*,
@ -101,6 +102,7 @@ fn new(blog: String, user: User, conn: DbConn) -> Option<Template> {
"error_message": "You are not author in this blog." "error_message": "You are not author in this blog."
}))) })))
} else { } else {
let medias = Media::for_user(&*conn, user.id);
Some(Template::render("posts/new", json!({ Some(Template::render("posts/new", json!({
"account": user.to_json(&*conn), "account": user.to_json(&*conn),
"instance": Instance::get_local(&*conn), "instance": Instance::get_local(&*conn),
@ -108,6 +110,7 @@ fn new(blog: String, user: User, conn: DbConn) -> Option<Template> {
"errors": null, "errors": null,
"form": null, "form": null,
"is_draft": true, "is_draft": true,
"medias": medias.into_iter().map(|m| m.to_json(&*conn)).collect::<Vec<serde_json::Value>>(),
}))) })))
} }
} }
@ -128,6 +131,7 @@ fn edit(blog: String, slug: String, user: User, conn: DbConn) -> Option<Template
post.content.get().clone() // fallback to HTML if the markdown was not stored post.content.get().clone() // fallback to HTML if the markdown was not stored
}; };
let medias = Media::for_user(&*conn, user.id);
Some(Template::render("posts/new", json!({ Some(Template::render("posts/new", json!({
"account": user.to_json(&*conn), "account": user.to_json(&*conn),
"instance": Instance::get_local(&*conn), "instance": Instance::get_local(&*conn),
@ -144,8 +148,10 @@ fn edit(blog: String, slug: String, user: User, conn: DbConn) -> Option<Template
.join(", "), .join(", "),
license: post.license.clone(), license: post.license.clone(),
draft: true, draft: true,
cover: post.cover_id,
}, },
"is_draft": !post.published "is_draft": !post.published,
"medias": medias.into_iter().map(|m| m.to_json(&*conn)).collect::<Vec<serde_json::Value>>(),
}))) })))
} }
} }
@ -206,9 +212,13 @@ fn update(blog: String, slug: String, user: User, conn: DbConn, data: LenientFor
post.content = SafeString::new(&content); post.content = SafeString::new(&content);
post.source = form.content.clone(); post.source = form.content.clone();
post.license = license; post.license = license;
println!("Cover id from update: {:?}", form.cover);
post.cover_id = form.cover;
post.update(&*conn); post.update(&*conn);
println!("Cover id after update: {:?}", post.cover_id);
let post = post.update_ap_url(&*conn); let post = post.update_ap_url(&*conn);
println!("Cover id after after update: {:?}", post.cover_id);
if post.published { if post.published {
post.update_mentions(&conn, mentions.into_iter().map(|m| Mention::build_activity(&conn, m)).collect()); post.update_mentions(&conn, mentions.into_iter().map(|m| Mention::build_activity(&conn, m)).collect());
} }
@ -236,6 +246,7 @@ fn update(blog: String, slug: String, user: User, conn: DbConn, data: LenientFor
Ok(Redirect::to(uri!(details: blog = blog, slug = new_slug))) Ok(Redirect::to(uri!(details: blog = blog, slug = new_slug)))
} }
} else { } else {
let medias = Media::for_user(&*conn, user.id);
Err(Some(Template::render("posts/new", json!({ Err(Some(Template::render("posts/new", json!({
"account": user.to_json(&*conn), "account": user.to_json(&*conn),
"instance": Instance::get_local(&*conn), "instance": Instance::get_local(&*conn),
@ -243,6 +254,7 @@ fn update(blog: String, slug: String, user: User, conn: DbConn, data: LenientFor
"errors": errors.inner(), "errors": errors.inner(),
"form": form, "form": form,
"is_draft": form.draft, "is_draft": form.draft,
"medias": medias.into_iter().map(|m| m.to_json(&*conn)).collect::<Vec<serde_json::Value>>(),
})))) }))))
} }
} }
@ -256,6 +268,7 @@ struct NewPostForm {
pub tags: String, pub tags: String,
pub license: String, pub license: String,
pub draft: bool, pub draft: bool,
pub cover: Option<i32>,
} }
fn valid_slug(title: &str) -> Result<(), ValidationError> { fn valid_slug(title: &str) -> Result<(), ValidationError> {
@ -309,7 +322,7 @@ fn create(blog_name: String, data: LenientForm<NewPostForm>, user: User, conn: D
creation_date: None, creation_date: None,
subtitle: form.subtitle.clone(), subtitle: form.subtitle.clone(),
source: form.content.clone(), source: form.content.clone(),
cover_id: None, // TODO cover_id: form.cover,
}); });
let post = post.update_ap_url(&*conn); let post = post.update_ap_url(&*conn);
PostAuthor::insert(&*conn, NewPostAuthor { PostAuthor::insert(&*conn, NewPostAuthor {
@ -346,13 +359,15 @@ fn create(blog_name: String, data: LenientForm<NewPostForm>, user: User, conn: D
Ok(Redirect::to(uri!(details: blog = blog_name, slug = slug))) Ok(Redirect::to(uri!(details: blog = blog_name, slug = slug)))
} }
} else { } else {
let medias = Media::for_user(&*conn, user.id);
Err(Some(Template::render("posts/new", json!({ Err(Some(Template::render("posts/new", json!({
"account": user.to_json(&*conn), "account": user.to_json(&*conn),
"instance": Instance::get_local(&*conn), "instance": Instance::get_local(&*conn),
"editing": false, "editing": false,
"errors": errors.inner(), "errors": errors.inner(),
"form": form, "form": form,
"is_draft": form.draft "is_draft": form.draft,
"medias": medias.into_iter().map(|m| m.to_json(&*conn)).collect::<Vec<serde_json::Value>>()
})))) }))))
} }
} }

View File

@ -27,7 +27,7 @@
{% endfor %} {% endfor %}
{% endif %} {% endif %}
<label for="plume-editor">{{ "Content" | _ }}<small>{{ "Markdown is supported" | _ }}</small></label> <label for="plume-editor">{{ "Content" | _ }}<small>{{ "Markdown is supported" | _ }}</small></label>
<textarea id="plume-editor" name="content" rows="20">{{ form.content | default(value="") }}</textarea> <textarea id="plume-editor" name="content" rows="20">{{ form.content | default(value="") }}</textarea>
{{ macros::input(name="tags", label="Tags, separated by commas", errors=errors, form=form, optional=true) }} {{ macros::input(name="tags", label="Tags, separated by commas", errors=errors, form=form, optional=true) }}
@ -35,6 +35,16 @@
{% set license_infos = "Default license will be {{ instance.default_license }}" | _(instance=instance) %} {% set license_infos = "Default license will be {{ instance.default_license }}" | _(instance=instance) %}
{{ macros::input(name="license", label="License", errors=errors, form=form, optional=true, details=license_infos) }} {{ macros::input(name="license", label="License", errors=errors, form=form, optional=true, details=license_infos) }}
<label for="cover">{{ "Illustration" | _ }}<small>{{ "Optional" | _ }}</small>{{ form.cover }}</label>
<select id="cover" name="cover">
<option value="none" {% if not form.cover %}selected{% endif %}>{{ "None" | _ }}</option>
{% for media in medias %}
<option value="{{ media.id }}" {% if form.cover == media.id %}selected{% endif %}>
{{ media.alt_text | default(value=media.content_warning) }}
</option>
{% endfor %}
</select>
{% if is_draft %} {% if is_draft %}
<label for="draft"> <label for="draft">
<input type="checkbox" name="draft" id="draft" checked> <input type="checkbox" name="draft" id="draft" checked>