Add the possibility to save an article as draft
This commit is contained in:
parent
fcdd3d4c1a
commit
8879935925
|
@ -1451,6 +1451,7 @@ version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"activitypub 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"activitypub 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"atom_syndication 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"atom_syndication 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"colored 1.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"colored 1.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"diesel 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"diesel 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"dotenv 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"dotenv 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|
|
@ -22,6 +22,10 @@ validator_derive = "0.7"
|
||||||
webfinger = "0.3"
|
webfinger = "0.3"
|
||||||
workerpool = "1.1"
|
workerpool = "1.1"
|
||||||
|
|
||||||
|
[dependencies.chrono]
|
||||||
|
features = ["serde"]
|
||||||
|
version = "0.4"
|
||||||
|
|
||||||
[dependencies.diesel]
|
[dependencies.diesel]
|
||||||
features = ["postgres", "r2d2", "chrono"]
|
features = ["postgres", "r2d2", "chrono"]
|
||||||
version = "*"
|
version = "*"
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
extern crate activitypub;
|
extern crate activitypub;
|
||||||
extern crate atom_syndication;
|
extern crate atom_syndication;
|
||||||
|
extern crate chrono;
|
||||||
extern crate colored;
|
extern crate colored;
|
||||||
extern crate diesel;
|
extern crate diesel;
|
||||||
extern crate dotenv;
|
extern crate dotenv;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use activitypub::object::Article;
|
use activitypub::object::Article;
|
||||||
|
use chrono::Utc;
|
||||||
use heck::{CamelCase, KebabCase};
|
use heck::{CamelCase, KebabCase};
|
||||||
use rocket::{State, request::LenientForm};
|
use rocket::{State, request::LenientForm};
|
||||||
use rocket::response::{Redirect, Flash};
|
use rocket::response::{Redirect, Flash};
|
||||||
|
@ -95,7 +96,8 @@ fn new(blog: String, user: User, conn: DbConn) -> Template {
|
||||||
"instance": Instance::get_local(&*conn),
|
"instance": Instance::get_local(&*conn),
|
||||||
"editing": false,
|
"editing": false,
|
||||||
"errors": null,
|
"errors": null,
|
||||||
"form": null
|
"form": null,
|
||||||
|
"is_draft": true,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -131,7 +133,9 @@ fn edit(blog: String, slug: String, user: User, conn: DbConn) -> Template {
|
||||||
.collect::<Vec<String>>()
|
.collect::<Vec<String>>()
|
||||||
.join(", "),
|
.join(", "),
|
||||||
license: post.license.clone(),
|
license: post.license.clone(),
|
||||||
}
|
draft: true,
|
||||||
|
},
|
||||||
|
"is_draft": !post.published
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -172,6 +176,12 @@ fn update(blog: String, slug: String, user: User, conn: DbConn, data: LenientFor
|
||||||
Instance::get_local(&*conn).map(|i| i.default_license).unwrap_or(String::from("CC-0"))
|
Instance::get_local(&*conn).map(|i| i.default_license).unwrap_or(String::from("CC-0"))
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// update publication date if when this article is no longer a draft
|
||||||
|
if !post.published && !form.draft {
|
||||||
|
post.published = true;
|
||||||
|
post.creation_date = Utc::now().naive_utc();
|
||||||
|
}
|
||||||
|
|
||||||
post.slug = new_slug.clone();
|
post.slug = new_slug.clone();
|
||||||
post.title = form.title.clone();
|
post.title = form.title.clone();
|
||||||
post.subtitle = form.subtitle.clone();
|
post.subtitle = form.subtitle.clone();
|
||||||
|
@ -195,9 +205,11 @@ fn update(blog: String, slug: String, user: User, conn: DbConn, data: LenientFor
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let act = post.update_activity(&*conn);
|
if post.published {
|
||||||
let dest = User::one_by_instance(&*conn);
|
let act = post.update_activity(&*conn);
|
||||||
worker.execute(Thunk::of(move || broadcast(&user, act, dest)));
|
let dest = User::one_by_instance(&*conn);
|
||||||
|
worker.execute(Thunk::of(move || broadcast(&user, act, dest)));
|
||||||
|
}
|
||||||
|
|
||||||
Ok(Redirect::to(uri!(details: blog = blog, slug = new_slug)))
|
Ok(Redirect::to(uri!(details: blog = blog, slug = new_slug)))
|
||||||
}
|
}
|
||||||
|
@ -207,7 +219,8 @@ fn update(blog: String, slug: String, user: User, conn: DbConn, data: LenientFor
|
||||||
"instance": Instance::get_local(&*conn),
|
"instance": Instance::get_local(&*conn),
|
||||||
"editing": true,
|
"editing": true,
|
||||||
"errors": errors.inner(),
|
"errors": errors.inner(),
|
||||||
"form": form
|
"form": form,
|
||||||
|
"is_draft": form.draft,
|
||||||
})))
|
})))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -219,7 +232,8 @@ struct NewPostForm {
|
||||||
pub subtitle: String,
|
pub subtitle: String,
|
||||||
pub content: String,
|
pub content: String,
|
||||||
pub tags: String,
|
pub tags: String,
|
||||||
pub license: String
|
pub license: String,
|
||||||
|
pub draft: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn valid_slug(title: &str) -> Result<(), ValidationError> {
|
fn valid_slug(title: &str) -> Result<(), ValidationError> {
|
||||||
|
@ -263,7 +277,7 @@ fn create(blog_name: String, data: LenientForm<NewPostForm>, user: User, conn: D
|
||||||
slug: slug.to_string(),
|
slug: slug.to_string(),
|
||||||
title: form.title.to_string(),
|
title: form.title.to_string(),
|
||||||
content: SafeString::new(&content),
|
content: SafeString::new(&content),
|
||||||
published: true,
|
published: !form.draft,
|
||||||
license: if form.license.len() > 0 {
|
license: if form.license.len() > 0 {
|
||||||
form.license.to_string()
|
form.license.to_string()
|
||||||
} else {
|
} else {
|
||||||
|
@ -280,10 +294,6 @@ fn create(blog_name: String, data: LenientForm<NewPostForm>, user: User, conn: D
|
||||||
author_id: user.id
|
author_id: user.id
|
||||||
});
|
});
|
||||||
|
|
||||||
for m in mentions.into_iter() {
|
|
||||||
Mention::from_activity(&*conn, Mention::build_activity(&*conn, m), post.id, true, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
let tags = form.tags.split(",").map(|t| t.trim().to_camel_case()).filter(|t| t.len() > 0);
|
let tags = form.tags.split(",").map(|t| t.trim().to_camel_case()).filter(|t| t.len() > 0);
|
||||||
for tag in tags {
|
for tag in tags {
|
||||||
Tag::insert(&*conn, NewTag {
|
Tag::insert(&*conn, NewTag {
|
||||||
|
@ -293,9 +303,15 @@ fn create(blog_name: String, data: LenientForm<NewPostForm>, user: User, conn: D
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let act = post.create_activity(&*conn);
|
if post.published {
|
||||||
let dest = User::one_by_instance(&*conn);
|
for m in mentions.into_iter() {
|
||||||
worker.execute(Thunk::of(move || broadcast(&user, act, dest)));
|
Mention::from_activity(&*conn, Mention::build_activity(&*conn, m), post.id, true, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
let act = post.create_activity(&*conn);
|
||||||
|
let dest = User::one_by_instance(&*conn);
|
||||||
|
worker.execute(Thunk::of(move || broadcast(&user, act, dest)));
|
||||||
|
}
|
||||||
|
|
||||||
Ok(Redirect::to(uri!(details: blog = blog_name, slug = slug)))
|
Ok(Redirect::to(uri!(details: blog = blog_name, slug = slug)))
|
||||||
}
|
}
|
||||||
|
@ -305,7 +321,8 @@ fn create(blog_name: String, data: LenientForm<NewPostForm>, user: User, conn: D
|
||||||
"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
|
||||||
})))
|
})))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,9 @@
|
||||||
name=article.author.name,
|
name=article.author.name,
|
||||||
link_4="</a>")
|
link_4="</a>")
|
||||||
}}
|
}}
|
||||||
⋅ {{ article.date | date(format="%B %e") }}
|
{% if article.post.published %}⋅ {{ article.date | date(format="%B %e") }}{% endif %}
|
||||||
⋅ <a href="/~/{{ article.blog.fqn }}/">{{ article.blog.title }}</a>
|
⋅ <a href="/~/{{ article.blog.fqn }}/">{{ article.blog.title }}</a>
|
||||||
|
{% if not article.post.published %}⋅ {{ "Draft" | _ }}{% endif %}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
{% endmacro post_card %}
|
{% endmacro post_card %}
|
||||||
|
|
|
@ -29,6 +29,9 @@
|
||||||
—
|
—
|
||||||
<a href="{{ article.url}}delete" onclick="return confirm('Are you sure you?')">{{ "Delete this article" | _ }}</a>
|
<a href="{{ article.url}}delete" onclick="return confirm('Are you sure you?')">{{ "Delete this article" | _ }}</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if not article.post.published %}
|
||||||
|
<span class="badge">{{ "Draft" }}</span>
|
||||||
|
{% endif %}
|
||||||
</p>
|
</p>
|
||||||
<article>
|
<article>
|
||||||
{{ article.post.content | safe }}
|
{{ article.post.content | safe }}
|
||||||
|
|
|
@ -35,10 +35,21 @@
|
||||||
{% 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) }}
|
||||||
|
|
||||||
|
{% if is_draft %}
|
||||||
|
<label for="draft">
|
||||||
|
<input type="checkbox" name="draft" id="draft" checked>
|
||||||
|
{{ "This is a draft, don't publish it yet." | _ }}
|
||||||
|
</label>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% if editing %}
|
{% if editing %}
|
||||||
<input type="submit" value="{{ "Update" | _ }}" />
|
<input type="submit" value="{{ "Update" | _ }}" />
|
||||||
{% else %}
|
{% else %}
|
||||||
<input type="submit" value="{{ "Publish" | _ }}" />
|
{% if is_draft %}
|
||||||
|
<input type="submit" value="{{ "Update or publish" | _ }}" />
|
||||||
|
{% else %}
|
||||||
|
<input type="submit" value="{{ "Publish" | _ }}" />
|
||||||
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</form>
|
</form>
|
||||||
<script src="/static/js/autoExpand.js"></script>
|
<script src="/static/js/autoExpand.js"></script>
|
||||||
|
|
Loading…
Reference in New Issue