From be6670b02f535310c02d1f2c5c668cdd97fb8e23 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Mon, 2 Oct 2023 14:47:31 +0200 Subject: [PATCH] Changes - Rename type to category for courses - Add category to the exported calendar - Default to non-selected data when filtering TD/TP --- src/filter.rs | 12 ++++++------ src/ics.rs | 5 ++++- src/timetable.rs | 8 ++++---- src/timetable/models.rs | 10 ++++++++-- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/filter.rs b/src/filter.rs index 514f572..3fc4f0b 100644 --- a/src/filter.rs +++ b/src/filter.rs @@ -2,9 +2,9 @@ use std::collections::HashMap; use dialoguer::MultiSelect; +use crate::timetable::models::Category; use crate::timetable::models::Course; use crate::timetable::models::Timetable; -use crate::timetable::models::Type; use crate::utils::fill_hours; const DISCLAIMER: &str = "(selection avec ESPACE, ENTRER pour valider)"; @@ -59,7 +59,7 @@ fn courses(timetable: &mut Timetable) { /// Filter the multiples TD/TP fn tdtp(timetable: &mut Timetable) { // Entry's name used for finding duplicates - let get_entry = |course: &Course| format!("{} - {:?}", course.name, course.typee); + let get_entry = |course: &Course| format!("{} - {:?}", course.name, course.category); let mut hours = vec![]; fill_hours(&mut hours); @@ -86,8 +86,8 @@ fn tdtp(timetable: &mut Timetable) { timetable.1 .1.iter().for_each(|day| { day.courses.iter().for_each(|course_opt| { if let Some(course) = course_opt { - match course.typee { - Type::TD | Type::TP => { + match course.category { + Category::TD | Category::TP => { td_or_tp.push((course, day.name.to_owned())); let count = counts.entry(get_entry(course)).or_insert(0); *count += 1; @@ -104,7 +104,7 @@ fn tdtp(timetable: &mut Timetable) { let mut multiselected: Vec = td_or_tp.iter().map(|el| get_selection(el)).collect(); multiselected.sort(); - let defaults = vec![true; multiselected.len()]; + let defaults = vec![false; multiselected.len()]; let selections = MultiSelect::new() .with_prompt(format!("Choisis tes horaires de TD/TP {}", DISCLAIMER)) .items(&multiselected[..]) @@ -117,7 +117,7 @@ fn tdtp(timetable: &mut Timetable) { day.courses.retain(|course_opt| { if let Some(course) = course_opt { // Keep if it's a course - if course.typee == Type::Cours { + if course.category == Category::Cours { return true; } diff --git a/src/ics.rs b/src/ics.rs index f180d81..22e8f39 100644 --- a/src/ics.rs +++ b/src/ics.rs @@ -1,7 +1,7 @@ use chrono::TimeZone; use ics::{ parameters, - properties::{Class, Description, DtEnd, DtStart, Location, Summary, Transp}, + properties::{Categories, Class, Description, DtEnd, DtStart, Location, Summary, Transp}, Event, ICalendar, Standard, }; @@ -57,6 +57,9 @@ pub fn export(courses: Vec, filename: &mut Str course_name.append(parameters!("LANGUAGE" => "fr")); event.push(course_name); + // Course's type + event.push(Categories::new(course.category.to_string())); + // Add the course to the calendar calendar.add_event(event); } diff --git a/src/timetable.rs b/src/timetable.rs index 32bd650..0a022b1 100644 --- a/src/timetable.rs +++ b/src/timetable.rs @@ -67,13 +67,13 @@ pub async fn timetable( let binding = i.select(&sel_b).last().unwrap().inner_html(); let course = models::Course{ - typee: match matches + category: match matches .name("type") .unwrap() .as_str() { - "COURS" => models::Type::Cours, - "TP" => models::Type::TP, - "TD" => models::Type::TD, + "COURS" => models::Category::Cours, + "TP" => models::Category::TP, + "TD" => models::Category::TD, _ => panic!("Unknown type of course") }, name: matches diff --git a/src/timetable/models.rs b/src/timetable/models.rs index 77c2d71..b3c567d 100644 --- a/src/timetable/models.rs +++ b/src/timetable/models.rs @@ -1,14 +1,20 @@ #[derive(Clone, Debug, PartialEq)] -pub enum Type { +pub enum Category { Cours, TP, TD, } +impl std::fmt::Display for Category { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + std::fmt::Debug::fmt(self, f) + } +} + #[derive(Clone, Debug, PartialEq)] pub struct Course { /// Type du cours - pub typee: Type, + pub category: Category, /// Course's name pub name: String,