2021-05-12 20:13:06 +02:00
|
|
|
use chrono::{Local, TimeZone};
|
2021-04-01 19:12:23 +02:00
|
|
|
use jm_client_core::api::{Category, Meme, User};
|
2021-05-12 20:13:06 +02:00
|
|
|
use term_table::{row::Row, table_cell::TableCell, Table, TableBuilder, TableStyle};
|
|
|
|
|
|
|
|
/// returns an empty table with the correct format settings for lists
|
|
|
|
pub fn list_table<'a>() -> Table<'a> {
|
|
|
|
TableBuilder::new()
|
|
|
|
.style(TableStyle::simple())
|
|
|
|
.separate_rows(false)
|
|
|
|
.has_top_boarder(false)
|
|
|
|
.has_bottom_boarder(false)
|
|
|
|
.build()
|
|
|
|
}
|
|
|
|
|
2021-05-27 18:01:30 +02:00
|
|
|
pub trait AsTableRow {
|
|
|
|
fn as_table_row(&self) -> term_table::row::Row;
|
2021-05-12 20:13:06 +02:00
|
|
|
}
|
2020-12-05 12:08:24 +01:00
|
|
|
|
2021-05-27 18:01:30 +02:00
|
|
|
impl AsTableRow for Category {
|
|
|
|
fn as_table_row(&self) -> Row<'_> {
|
2021-01-05 15:13:19 +01:00
|
|
|
Row::new(vec![TableCell::new(&self.id), TableCell::new(&self.name)])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-27 18:01:30 +02:00
|
|
|
impl AsTableRow for Meme {
|
|
|
|
fn as_table_row(&self) -> Row<'_> {
|
2020-12-05 22:20:08 +01:00
|
|
|
Row::new(vec![
|
|
|
|
TableCell::new(&self.link),
|
|
|
|
TableCell::new(&self.category),
|
|
|
|
TableCell::new(&self.user),
|
2021-05-12 20:13:06 +02:00
|
|
|
TableCell::new(Local.timestamp(self.timestamp, 0).format("%F %R")),
|
2020-12-05 22:20:08 +01:00
|
|
|
])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-27 18:01:30 +02:00
|
|
|
impl AsTableRow for User {
|
|
|
|
fn as_table_row(&self) -> Row<'_> {
|
2020-12-19 19:43:23 +01:00
|
|
|
Row::new(vec![
|
|
|
|
TableCell::new(&self.name),
|
|
|
|
TableCell::new(&self.get_id().map(String::as_ref).unwrap_or("[No ID]")),
|
|
|
|
TableCell::new(&self.dayuploads),
|
|
|
|
])
|
|
|
|
}
|
|
|
|
}
|