Skip to content

Commit

Permalink
Show count of finished unpublished articles
Browse files Browse the repository at this point in the history
  • Loading branch information
furo321 committed Nov 15, 2024
1 parent ce54cf2 commit 7540eb1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
6 changes: 6 additions & 0 deletions sql/articles/get_all_done_unpublished-count.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SELECT
COUNT(*) AS "count!: i64"
FROM
articles
WHERE
marked_as_done = true AND is_published = false
3 changes: 2 additions & 1 deletion src/app/control_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ async fn control_panel(
let published_texts = Text::get_by_author(db, &claims.data.username, true).await?;
let unpublished_texts = Text::get_by_author(db, &claims.data.username, false).await?;
let about_us = data_dir::get_about_us();
let done_unpublished_texts_count = Text::get_all_done_unpublished_count(db).await?;

let all_creator_usernames = Creator::get_all(db)
.await?
Expand All @@ -31,7 +32,7 @@ async fn control_panel(

Ok(Template::render(
"control_panel/main",
context! { creator, published_texts, unpublished_texts, all_creator_usernames, about_us, flash, is_admin: claims.data.is_publisher() },
context! { creator, published_texts, unpublished_texts, all_creator_usernames, done_unpublished_texts_count, about_us, flash, is_admin: claims.data.is_publisher() },
))
}

Expand Down
10 changes: 9 additions & 1 deletion src/database/models/article.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,22 @@ impl Text {
.map_err(Error::from)
}

/// Gets all done, but unpublished, articles.
/// Gets all done, but unpublished articles.
pub async fn get_all_done_unpublished(db: &DatabaseHandler) -> Result<Vec<Self>, Error> {
sqlx::query_file_as!(Self, "sql/articles/get_all_done_unpublished.sql")
.fetch_all(&db.pool)
.await
.map_err(Error::from)
}

/// Gets the count of unpublished articles.
pub async fn get_all_done_unpublished_count(db: &DatabaseHandler) -> Result<i64, Error> {
sqlx::query_file_scalar!("sql/articles/get_all_done_unpublished-count.sql")
.fetch_one(&db.pool)
.await
.map_err(Error::from)
}

/// Gets ONE `Text` from the database by its id.
/// * `must_be_published` if `true`, returns only if published.
/// If false, returns article so long it exists.
Expand Down
2 changes: 1 addition & 1 deletion templates/control_panel/main.html.tera
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<div class="sep"></div>
{% endif %}
<a href="/control-panel/image-gallery" class="btn" icon="gallery_thumbnail">Bildgalleriet</a>
<a href="/control-panel/preview-done-unpublished" class="btn" icon="preview">Granska och godkänn nya texter</a>
<a href="/control-panel/preview-done-unpublished" class="btn" icon="preview">Granska och godkänn nya texter ({{ done_unpublished_texts_count}})</a>
</div>
</div>

Expand Down

0 comments on commit 7540eb1

Please sign in to comment.