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,
} => match web_command {
WebSubcommands::Build { output } => {
let user_count_group =
let (groups, user_count_group) =
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 {
None
(vec![], None)
};
create_dir_all(&output).await?;
HomeTemplate::new(
groups,
user_count_group.as_ref().map(|group| group.subscribers),
)
.render_to_file(&output)

View File

@ -24,13 +24,41 @@
.page-main {
h2,
img,
p {
p,
table {
margin-bottom: var(--medium-spacing);
&:last-child {
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 {

View File

@ -19,6 +19,32 @@
</p>
<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>
<footer class="page-footer">

View File

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