Added card creation

This commit is contained in:
Maddox Werts 2024-06-23 14:31:36 -04:00
parent e580dc02dc
commit a421ccfbb1

View file

@ -1,5 +1,5 @@
// Libraries // Libraries
use crate::{board, manager}; use crate::{board, card, manager};
use std::{io, process::exit}; use std::{io, process::exit};
// Structures // Structures
@ -71,11 +71,12 @@ impl<'a> Interface<'a> {
} }
// Presenting options // Presenting options
println!("\n1) Edit Card"); println!("\n1) Create Card");
println!("2) Delete Card"); println!("2) Edit Card");
println!("3) Delete Board"); println!("3) Delete Card");
println!("4) Exit"); println!("4) Delete Board");
println!("\nSelect Option [1-4]: "); println!("5) Exit");
println!("\nSelect Option [1-5]: ");
// Selection option // Selection option
let mut user_input: String = String::new(); let mut user_input: String = String::new();
@ -84,20 +85,58 @@ impl<'a> Interface<'a> {
println!(""); println!("");
// What to do // What to do
if user_input == "1"{ if user_input == "1" {
self.page = 3;
} else if user_input == "2"{ } else if user_input == "2"{
self.mode = 0;
self.page = 4;
} else if user_input == "3"{ } else if user_input == "3"{
self.mode = 1; self.mode = 0;
self.page = 4; self.page = 5;
} else if user_input == "4"{ } else if user_input == "4"{
self.mode = 1;
self.page = 5;
} else if user_input == "5"{
self.page = 0; self.page = 0;
} }
} }
fn p_3(&mut self){
// Title
println!(" - Create Card - \n");
fn p_4(&mut self){ // Variables
let mut user_input: String = String::new();
// Asking the user what the name is
println!("What is your card's name?");
println!("Select name: ");
// Reading input
io::stdin().read_line(&mut user_input).expect("Failed to read line");
let _name: String = String::from(user_input.trim());
println!("");
// Reset user input
user_input = String::new();
// Asking the user what the description is
println!("Give your card a description!");
println!("Select description: ");
// Reading input
io::stdin().read_line(&mut user_input).expect("Failed to read line");
let _desc: String = String::from(user_input.trim());
println!("");
// Creating a card
let _new_card: card::TaskCard = card::TaskCard::init_val(_name, _desc);
// Throw this into our manager
self.manager.boards[self.on as usize].cards.push(_new_card);
// Finished!
self.page = 2;
}
fn p_5(&mut self){
// Which title do we use // Which title do we use
let title: String = String::from(match self.mode { let title: String = String::from(match self.mode {
0 => "Card", 0 => "Card",
@ -127,7 +166,7 @@ impl<'a> Interface<'a> {
user_input = String::from(user_input.to_lowercase().trim()); user_input = String::from(user_input.to_lowercase().trim());
// Parse user input into a usize // Parse user input into a usize
let card_index: usize = user_input.parse().unwrap(); let card_index: usize = user_input.parse::<usize>().unwrap() - 1;
// Reset user input // Reset user input
user_input = String::new(); user_input = String::new();
@ -182,7 +221,8 @@ impl<'a> Interface<'a> {
0 => self.p_0(), 0 => self.p_0(),
1 => self.p_1(), 1 => self.p_1(),
2 => self.p_2(), 2 => self.p_2(),
4 => self.p_4(), 3 => self.p_3(),
5 => self.p_5(),
_ => Interface::error("Invalid Page") _ => Interface::error("Invalid Page")
} }
} }