Skip to content
Extraits de code Groupes Projets
Vérifiée Valider fb36cda9 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

AMADEUS: Format the date and the filesize in the kara modal

parent 4ff1f81b
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!197Draft: Refactor the whole code.
......@@ -72,6 +72,7 @@ version = "3.0.1"
dependencies = [
"anyhow",
"async-trait",
"chrono",
"futures",
"hashbrown 0.14.2",
"iced",
......
......@@ -11,6 +11,7 @@ description = "Amadeus-RS, graphical interface for lektord"
serde.workspace = true
serde_json.workspace = true
chrono.workspace = true
anyhow.workspace = true
hashbrown.workspace = true
......
......@@ -24,6 +24,19 @@ pub fn loading_centered_shrink<'a, T: 'a>() -> iced::Element<'a, T> {
.into()
}
pub fn file_size<'a, T: 'a>(bytes: usize) -> iced::Element<'a, T> {
let kilos = bytes.div_euclid(1024);
let megas = kilos.div_euclid(1024);
iced::widget::text(if megas > 0 {
format!("File Size: {megas}MiB")
} else if kilos > 0 {
format!("File Size: {kilos}KiB")
} else {
format!("File Size: {bytes}B")
})
.into()
}
macro_rules! tip {
($inner: expr => $position: ident | $tip: expr) => {
iced::widget::tooltip($inner, $tip, iced::widget::tooltip::Position::$position)
......
use crate::style_sheet::{sizes::*, Color, RoundBadgeStyleSheet};
use crate::{
components::file_size,
style_sheet::{sizes::*, Color, RoundBadgeStyleSheet},
};
use chrono::TimeZone;
use iced::{
widget::{column, container, horizontal_rule, text},
Element,
......@@ -94,19 +98,26 @@ impl State {
..
} = self.0.as_ref();
let mut column = column![text(format!(
"Remote Name: {}",
self.0.remote.remote_name()
))];
if let Some(time) = chrono::Local.timestamp_opt(ts.created_at, 0).latest() {
let time = time.format("%Y-%m-%d %H:%M:%S");
column = column.push(text(format!("Created at: {time}")));
};
if let Some(time) = chrono::Local.timestamp_opt(ts.updated_at, 0).latest() {
let time = time.format("%Y-%m-%d %H:%M:%S");
column = column.push(text(format!("Last Modified at: {time}")));
};
let aux_infos = match self.0.kara_status {
lektor_payloads::KaraStatus::Virtual => column![
text(format!("Remote Name: {}", self.0.remote.remote_name())),
text(format!("Created at: {}", ts.created_at)),
text(format!("Last Modified at: {}", ts.updated_at)),
],
lektor_payloads::KaraStatus::Physical { filesize, hash } => column![
text(format!("Remote Name: {}", self.0.remote.remote_name())),
text(format!("Created at: {}", ts.created_at)),
text(format!("Last Modified at: {}", ts.updated_at)),
text(format!("File Size: {}B", filesize)),
text(format!("File Hash: {hash}")),
],
lektor_payloads::KaraStatus::Virtual => column,
lektor_payloads::KaraStatus::Physical { filesize, hash } => column
.push(file_size(filesize as usize))
.push(text(format!("File Hash: {hash}"))),
};
container(
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter