Add the groups table.

This commit is contained in:
Bauke 2022-10-08 22:11:52 +02:00
parent a25ae7adda
commit 7cc2d7518f
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
4 changed files with 68 additions and 6 deletions

View File

@ -85,15 +85,19 @@ pub async fn run() -> Result<()> {
command: web_command, command: web_command,
} => match web_command { } => match web_command {
WebSubcommands::Build { output } => { WebSubcommands::Build { output } => {
let user_count_group = let (groups, user_count_group) =
if let Some(snapshot) = SnapshotModel::get_most_recent(&db).await? { if let Some(snapshot) = SnapshotModel::get_most_recent(&db).await? {
GroupDataModel::get_highest_subscribers(&db, &snapshot).await? (
GroupDataModel::get_all_by_snapshot(&db, &snapshot).await?,
GroupDataModel::get_highest_subscribers(&db, &snapshot).await?,
)
} else { } else {
None (vec![], None)
}; };
create_dir_all(&output).await?; create_dir_all(&output).await?;
HomeTemplate::new( HomeTemplate::new(
groups,
user_count_group.as_ref().map(|group| group.subscribers), user_count_group.as_ref().map(|group| group.subscribers),
) )
.render_to_file(&output) .render_to_file(&output)

View File

@ -24,13 +24,41 @@
.page-main { .page-main {
h2, h2,
img, img,
p { p,
table {
margin-bottom: var(--medium-spacing); margin-bottom: var(--medium-spacing);
&:last-child { &:last-child {
margin-bottom: 0; margin-bottom: 0;
} }
} }
table {
border: 2px solid var(--background-2);
border-collapse: collapse;
width: 100%;
}
thead {
background-color: var(--background-2);
border-bottom: 2px solid var(--background-2);
text-align: left;
}
tr {
border: 2px solid var(--background-2);
}
td,
th {
padding: var(--medium-spacing);
}
tbody {
> tr:nth-of-type(2n) {
background-color: var(--background-2);
}
}
} }
.page-footer { .page-footer {

View File

@ -19,6 +19,32 @@
</p> </p>
<img src="/charts/user-count.svg" alt="User Count Chart"> <img src="/charts/user-count.svg" alt="User Count Chart">
<table>
<thead>
<tr>
<th>Group</th>
<th>Subscribers</th>
<th>Description</th>
</tr>
</thead>
<tbody>
{% for group in groups %}
<tr>
<td>
<a href="https://tildes.net/{{ group.name }}">{{ group.name }}</a>
</td>
<td>{{ group.subscribers }}</td>
<td>
{% if let Some(description) = group.description %}
{{ description }}
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</main> </main>
<footer class="page-footer"> <footer class="page-footer">

View File

@ -7,12 +7,15 @@ use {
color_eyre::Result, color_eyre::Result,
}; };
use crate::utilities::today; use crate::{group_data::GroupDataModel, utilities::today};
/// The template for the home page. /// The template for the home page.
#[derive(Template)] #[derive(Template)]
#[template(path = "index.html")] #[template(path = "index.html")]
pub struct HomeTemplate { pub struct HomeTemplate {
/// The groups to create the table with.
pub groups: Vec<GroupDataModel>,
/// The string for the `<title>` element. /// The string for the `<title>` element.
pub page_title: String, pub page_title: String,
@ -25,8 +28,9 @@ pub struct HomeTemplate {
impl HomeTemplate { impl HomeTemplate {
/// Create a new [`HomeTemplate`]. /// Create a new [`HomeTemplate`].
pub fn new(user_count: Option<i64>) -> Self { pub fn new(groups: Vec<GroupDataModel>, user_count: Option<i64>) -> Self {
Self { Self {
groups,
page_title: "Tildes Statistics".to_string(), page_title: "Tildes Statistics".to_string(),
today: today(), today: today(),
user_count: user_count user_count: user_count