Changes
- Rename type to category for courses - Add category to the exported calendar - Default to non-selected data when filtering TD/TP
This commit is contained in:
parent
e65534d8f9
commit
be6670b02f
4 changed files with 22 additions and 13 deletions
|
@ -2,9 +2,9 @@ use std::collections::HashMap;
|
||||||
|
|
||||||
use dialoguer::MultiSelect;
|
use dialoguer::MultiSelect;
|
||||||
|
|
||||||
|
use crate::timetable::models::Category;
|
||||||
use crate::timetable::models::Course;
|
use crate::timetable::models::Course;
|
||||||
use crate::timetable::models::Timetable;
|
use crate::timetable::models::Timetable;
|
||||||
use crate::timetable::models::Type;
|
|
||||||
use crate::utils::fill_hours;
|
use crate::utils::fill_hours;
|
||||||
|
|
||||||
const DISCLAIMER: &str = "(selection avec ESPACE, ENTRER pour valider)";
|
const DISCLAIMER: &str = "(selection avec ESPACE, ENTRER pour valider)";
|
||||||
|
@ -59,7 +59,7 @@ fn courses(timetable: &mut Timetable) {
|
||||||
/// Filter the multiples TD/TP
|
/// Filter the multiples TD/TP
|
||||||
fn tdtp(timetable: &mut Timetable) {
|
fn tdtp(timetable: &mut Timetable) {
|
||||||
// Entry's name used for finding duplicates
|
// 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![];
|
let mut hours = vec![];
|
||||||
fill_hours(&mut hours);
|
fill_hours(&mut hours);
|
||||||
|
@ -86,8 +86,8 @@ fn tdtp(timetable: &mut Timetable) {
|
||||||
timetable.1 .1.iter().for_each(|day| {
|
timetable.1 .1.iter().for_each(|day| {
|
||||||
day.courses.iter().for_each(|course_opt| {
|
day.courses.iter().for_each(|course_opt| {
|
||||||
if let Some(course) = course_opt {
|
if let Some(course) = course_opt {
|
||||||
match course.typee {
|
match course.category {
|
||||||
Type::TD | Type::TP => {
|
Category::TD | Category::TP => {
|
||||||
td_or_tp.push((course, day.name.to_owned()));
|
td_or_tp.push((course, day.name.to_owned()));
|
||||||
let count = counts.entry(get_entry(course)).or_insert(0);
|
let count = counts.entry(get_entry(course)).or_insert(0);
|
||||||
*count += 1;
|
*count += 1;
|
||||||
|
@ -104,7 +104,7 @@ fn tdtp(timetable: &mut Timetable) {
|
||||||
let mut multiselected: Vec<String> = td_or_tp.iter().map(|el| get_selection(el)).collect();
|
let mut multiselected: Vec<String> = td_or_tp.iter().map(|el| get_selection(el)).collect();
|
||||||
multiselected.sort();
|
multiselected.sort();
|
||||||
|
|
||||||
let defaults = vec![true; multiselected.len()];
|
let defaults = vec![false; multiselected.len()];
|
||||||
let selections = MultiSelect::new()
|
let selections = MultiSelect::new()
|
||||||
.with_prompt(format!("Choisis tes horaires de TD/TP {}", DISCLAIMER))
|
.with_prompt(format!("Choisis tes horaires de TD/TP {}", DISCLAIMER))
|
||||||
.items(&multiselected[..])
|
.items(&multiselected[..])
|
||||||
|
@ -117,7 +117,7 @@ fn tdtp(timetable: &mut Timetable) {
|
||||||
day.courses.retain(|course_opt| {
|
day.courses.retain(|course_opt| {
|
||||||
if let Some(course) = course_opt {
|
if let Some(course) = course_opt {
|
||||||
// Keep if it's a course
|
// Keep if it's a course
|
||||||
if course.typee == Type::Cours {
|
if course.category == Category::Cours {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use chrono::TimeZone;
|
use chrono::TimeZone;
|
||||||
use ics::{
|
use ics::{
|
||||||
parameters,
|
parameters,
|
||||||
properties::{Class, Description, DtEnd, DtStart, Location, Summary, Transp},
|
properties::{Categories, Class, Description, DtEnd, DtStart, Location, Summary, Transp},
|
||||||
Event, ICalendar, Standard,
|
Event, ICalendar, Standard,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -57,6 +57,9 @@ pub fn export(courses: Vec<crate::timetable::models::Course>, filename: &mut Str
|
||||||
course_name.append(parameters!("LANGUAGE" => "fr"));
|
course_name.append(parameters!("LANGUAGE" => "fr"));
|
||||||
event.push(course_name);
|
event.push(course_name);
|
||||||
|
|
||||||
|
// Course's type
|
||||||
|
event.push(Categories::new(course.category.to_string()));
|
||||||
|
|
||||||
// Add the course to the calendar
|
// Add the course to the calendar
|
||||||
calendar.add_event(event);
|
calendar.add_event(event);
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,13 +67,13 @@ pub async fn timetable(
|
||||||
|
|
||||||
let binding = i.select(&sel_b).last().unwrap().inner_html();
|
let binding = i.select(&sel_b).last().unwrap().inner_html();
|
||||||
let course = models::Course{
|
let course = models::Course{
|
||||||
typee: match matches
|
category: match matches
|
||||||
.name("type")
|
.name("type")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.as_str() {
|
.as_str() {
|
||||||
"COURS" => models::Type::Cours,
|
"COURS" => models::Category::Cours,
|
||||||
"TP" => models::Type::TP,
|
"TP" => models::Category::TP,
|
||||||
"TD" => models::Type::TD,
|
"TD" => models::Category::TD,
|
||||||
_ => panic!("Unknown type of course")
|
_ => panic!("Unknown type of course")
|
||||||
},
|
},
|
||||||
name: matches
|
name: matches
|
||||||
|
|
|
@ -1,14 +1,20 @@
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub enum Type {
|
pub enum Category {
|
||||||
Cours,
|
Cours,
|
||||||
TP,
|
TP,
|
||||||
TD,
|
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)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub struct Course {
|
pub struct Course {
|
||||||
/// Type du cours
|
/// Type du cours
|
||||||
pub typee: Type,
|
pub category: Category,
|
||||||
|
|
||||||
/// Course's name
|
/// Course's name
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
|
Reference in a new issue