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)}
|
// {"Autres_infos": Null, "Heure_de_debut": Number(1782144000), "Inscriptions": Array [String("L"), Number(1)], "Type_de_shift": Number(23)}
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Shift {
|
pub struct Shift {
|
||||||
|
pub id: Option<u64>,
|
||||||
pub shift_type: CustomOrDefined,
|
pub shift_type: CustomOrDefined,
|
||||||
pub start_time: DateTime<FixedOffset>,
|
pub start_time: DateTime<FixedOffset>,
|
||||||
pub inscriptions: Vec<String>,
|
pub inscriptions: Vec<String>,
|
||||||
}
|
}
|
||||||
impl Shift {
|
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 {
|
Self {
|
||||||
|
id: Some(id),
|
||||||
shift_type: shift_type,
|
shift_type: shift_type,
|
||||||
start_time: DateTime::from_timestamp(start_time as i64, 0)
|
start_time: DateTime::from_timestamp(start_time as i64, 0)
|
||||||
.expect("failed to parse timestamp")
|
.expect("failed to parse timestamp")
|
||||||
|
|
@ -165,6 +172,7 @@ impl Shift {
|
||||||
guide: impl Into<String>,
|
guide: impl Into<String>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
id: None,
|
||||||
shift_type: CustomOrDefined::Custom(CustomShiftValues::new(
|
shift_type: CustomOrDefined::Custom(CustomShiftValues::new(
|
||||||
name, priority, persons, duration, guide,
|
name, priority, persons, duration, guide,
|
||||||
)),
|
)),
|
||||||
|
|
@ -250,6 +258,10 @@ impl Shift {
|
||||||
|
|
||||||
impl Display for Shift {
|
impl Display for Shift {
|
||||||
fn fmt(&self, f: &mut Fmt<'_>) -> FmtRes {
|
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 start_time = self.start_time.format("le %d à %H:%M");
|
||||||
let inscriptions = if self.inscriptions.len() < self.persons() as usize {
|
let inscriptions = if self.inscriptions.len() < self.persons() as usize {
|
||||||
format!("<b>{}/{}</b>", self.inscriptions.len(), self.persons())
|
format!("<b>{}/{}</b>", self.inscriptions.len(), self.persons())
|
||||||
|
|
@ -258,7 +270,8 @@ impl Display for Shift {
|
||||||
};
|
};
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
"<i>{}</i> ({}): {}, durée {} h, inscrit·es : {}",
|
"{}<i>{}</i> ({}): {}, durée {} h, inscrit·es : {}",
|
||||||
|
id,
|
||||||
self.name(),
|
self.name(),
|
||||||
self.priority(),
|
self.priority(),
|
||||||
start_time,
|
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
|
let val_col = record
|
||||||
.fields
|
.fields
|
||||||
.get(column)
|
.get(column)
|
||||||
|
|
@ -389,7 +402,7 @@ pub async fn list_shifts() -> Res<Vec<Shift>> {
|
||||||
};
|
};
|
||||||
let start_time = get_number(&record, "Heure_de_debut")?;
|
let start_time = get_number(&record, "Heure_de_debut")?;
|
||||||
let inscriptions_refs =
|
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
|
// let inscriptions = inscriptions_refs
|
||||||
// .iter()
|
// .iter()
|
||||||
// .filter_map(async |i| get_inscription(i).await.ok())
|
// .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 {
|
for inscription_ref in inscriptions_refs {
|
||||||
inscriptions.push(get_inscription(inscription_ref).await?);
|
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);
|
shifts.push(shift);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue