forked from Anri/cal8tor
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 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<String> = 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<crate::timetable::models::Course>, 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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue