display shift id in list
This commit is contained in:
parent
7736a70eb9
commit
9a14ae4a62
1 changed files with 18 additions and 5 deletions
23
src/grist.rs
23
src/grist.rs
|
|
@ -139,13 +139,20 @@ pub enum CustomOrDefined {
|
|||
// {"Autres_infos": Null, "Heure_de_debut": Number(1782144000), "Inscriptions": Array [String("L"), Number(1)], "Type_de_shift": Number(23)}
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Shift {
|
||||
pub id: Option<u64>,
|
||||
pub shift_type: CustomOrDefined,
|
||||
pub start_time: DateTime<FixedOffset>,
|
||||
pub inscriptions: Vec<String>,
|
||||
}
|
||||
impl Shift {
|
||||
pub fn new(shift_type: CustomOrDefined, start_time: u64, inscriptions: Vec<String>) -> Self {
|
||||
pub fn new(
|
||||
id: u64,
|
||||
shift_type: CustomOrDefined,
|
||||
start_time: u64,
|
||||
inscriptions: Vec<String>,
|
||||
) -> Self {
|
||||
Self {
|
||||
id: Some(id),
|
||||
shift_type: shift_type,
|
||||
start_time: DateTime::from_timestamp(start_time as i64, 0)
|
||||
.expect("failed to parse timestamp")
|
||||
|
|
@ -165,6 +172,7 @@ impl Shift {
|
|||
guide: impl Into<String>,
|
||||
) -> Self {
|
||||
Self {
|
||||
id: None,
|
||||
shift_type: CustomOrDefined::Custom(CustomShiftValues::new(
|
||||
name, priority, persons, duration, guide,
|
||||
)),
|
||||
|
|
@ -250,6 +258,10 @@ impl Shift {
|
|||
|
||||
impl Display for Shift {
|
||||
fn fmt(&self, f: &mut Fmt<'_>) -> FmtRes {
|
||||
let id = match self.id {
|
||||
Some(id) => format!("{} - ", id),
|
||||
None => "".to_string(),
|
||||
};
|
||||
let start_time = self.start_time.format("le %d à %H:%M");
|
||||
let inscriptions = if self.inscriptions.len() < self.persons() as usize {
|
||||
format!("<b>{}/{}</b>", self.inscriptions.len(), self.persons())
|
||||
|
|
@ -258,7 +270,8 @@ impl Display for Shift {
|
|||
};
|
||||
write!(
|
||||
f,
|
||||
"<i>{}</i> ({}): {}, durée {} h, inscrit·es : {}",
|
||||
"{}<i>{}</i> ({}): {}, durée {} h, inscrit·es : {}",
|
||||
id,
|
||||
self.name(),
|
||||
self.priority(),
|
||||
start_time,
|
||||
|
|
@ -297,7 +310,7 @@ pub fn get_priority(record: &RecordsListRecordsInner, column: &str) -> Res<Prior
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_number_array(record: RecordsListRecordsInner, column: &str) -> Res<Vec<u64>> {
|
||||
pub fn get_number_array(record: &RecordsListRecordsInner, column: &str) -> Res<Vec<u64>> {
|
||||
let val_col = record
|
||||
.fields
|
||||
.get(column)
|
||||
|
|
@ -389,7 +402,7 @@ pub async fn list_shifts() -> Res<Vec<Shift>> {
|
|||
};
|
||||
let start_time = get_number(&record, "Heure_de_debut")?;
|
||||
let inscriptions_refs =
|
||||
get_number_array(record, "Inscriptions").context("getting inscriptions refs")?;
|
||||
get_number_array(&record, "Inscriptions").context("getting inscriptions refs")?;
|
||||
// let inscriptions = inscriptions_refs
|
||||
// .iter()
|
||||
// .filter_map(async |i| get_inscription(i).await.ok())
|
||||
|
|
@ -398,7 +411,7 @@ pub async fn list_shifts() -> Res<Vec<Shift>> {
|
|||
for inscription_ref in inscriptions_refs {
|
||||
inscriptions.push(get_inscription(inscription_ref).await?);
|
||||
}
|
||||
let shift = Shift::new(shift_type, start_time, inscriptions);
|
||||
let shift = Shift::new(record.id, shift_type, start_time, inscriptions);
|
||||
shifts.push(shift);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue