Skip to content

Commit 11de860

Browse files
authored
Merge pull request #4 from cchalop1/feat-activity
Feat activity
2 parents d64fe2b + ec799b8 commit 11de860

File tree

2 files changed

+71
-4
lines changed

2 files changed

+71
-4
lines changed

src/data.rs

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize};
33
use serde_json::Value;
44
use std::collections::HashMap;
55

6-
#[derive(Deserialize,Serialize, Debug)]
6+
#[derive(Deserialize, Serialize, Debug)]
77
pub struct Pass {
88
pub autologin: String,
99
pub login: String,
@@ -34,6 +34,7 @@ pub struct Home {
3434
#[derive(Deserialize, Debug)]
3535
pub struct Board {
3636
projets: Vec<Projet>,
37+
activites: Vec<Activites>,
3738
}
3839

3940
#[derive(Deserialize, Debug)]
@@ -47,6 +48,21 @@ pub struct Projet {
4748
id_activite: String,
4849
}
4950

51+
#[derive(Deserialize, Debug)]
52+
pub struct Activites {
53+
title: String,
54+
module: String,
55+
module_link: String,
56+
module_code: String,
57+
title_link: String,
58+
timeline_start: String,
59+
timeline_end: String,
60+
timeline_barre: String,
61+
salle: String,
62+
token: Option<String>,
63+
token_link: String,
64+
}
65+
5066
#[derive(Deserialize, Debug)]
5167
pub struct Module {
5268
title: String,
@@ -175,6 +191,51 @@ impl Board {
175191
None => panic!("there is no project with this id"),
176192
}
177193
}
194+
195+
pub fn print_activity(&self) {
196+
let mut table = Table::new();
197+
table.set_format(format_display_table());
198+
table.add_row(row!["ID", "ACTIVITY_NAME", "TIMELINE_BARRE"]);
199+
table.add_row(row!["--", "-------------", "--------------"]);
200+
for (idx, activite) in self.activites.iter().enumerate() {
201+
let nbr: String = parce_json_float_to_string(&activite.timeline_barre);
202+
table.add_row(row![
203+
idx,
204+
activite.title,
205+
format!("|{}|{}%", parce_timeline(&nbr), &nbr)
206+
]);
207+
}
208+
print!("\n");
209+
table.printstd();
210+
}
211+
212+
pub fn print_activity_detail(&self, idx: i32, autologin_url: &String) {
213+
match self.activites.get(idx as usize) {
214+
Some(activite) => {
215+
let mut table = Table::new();
216+
let nbr: String = parce_json_float_to_string(&activite.timeline_barre);
217+
table.set_format(format_display());
218+
table.add_row(row!["Title: ", activite.title]);
219+
table.add_row(row![
220+
"Link: ",
221+
format!("{}{}project/", autologin_url, activite.title_link)
222+
]);
223+
table.add_row(row!["Start_Time: ", activite.timeline_start]);
224+
table.add_row(row!["End_Time: ", activite.timeline_end]);
225+
table.add_row(row![
226+
"Time_Barre: ",
227+
format!("|{}|{}%", parce_timeline(&nbr), &nbr)
228+
]);
229+
table.add_row(row!["Salle: ", activite.salle]);
230+
match &activite.token {
231+
Some(token) => table.add_row(row!["token: ", token]),
232+
None => table.add_row(row!["token: ", "null"]),
233+
};
234+
table.printstd();
235+
}
236+
None => panic!("there is no project with this id"),
237+
}
238+
}
178239
}
179240

180241
impl ModulesNotes {

src/main.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ enum Opt {
4040
user,
4141
/// Display all current project and for see detail put <id> after project
4242
project { idx: Option<i32> },
43+
/// Display all activites
44+
activity { idx: Option<i32> },
4345
/// Display all your notes
4446
notes,
4547
/// Display all your modules
@@ -61,9 +63,13 @@ fn start() {
6163
match matches {
6264
Opt::user => fetch_user(&pass.autologin).print(),
6365
Opt::project { idx } => match idx {
64-
Some(idx) => fetch_project(&pass.autologin).print_project_detail(idx, &pass.autologin),
65-
None => fetch_project(&pass.autologin).print_projects(),
66+
Some(idx) => fetch_home(&pass.autologin).print_project_detail(idx, &pass.autologin),
67+
None => fetch_home(&pass.autologin).print_projects(),
6668
},
69+
Opt::activity { idx } => match idx {
70+
Some(idx) => fetch_home(&pass.autologin).print_activity_detail(idx, &pass.autologin),
71+
None => fetch_home(&pass.autologin).print_activity(),
72+
},
6773
Opt::notes => fetch_note_modules(&pass.autologin).print_notes(),
6874
Opt::modules => fetch_note_modules(&pass.autologin).print_modules(),
6975
Opt::repo { repo_name } => match repo_name {
@@ -124,7 +130,7 @@ fn fetch_repos(pass: &Pass) -> Repos {
124130
.unwrap()
125131
}
126132

127-
fn fetch_project(autologin_url: &String) -> Board {
133+
fn fetch_home(autologin_url: &String) -> Board {
128134
let url: String = builder_url_autologin(&autologin_url, "");
129135
let home: Home = reqwest::get(&url[..]).unwrap().json().unwrap();
130136
home.board

0 commit comments

Comments
 (0)