Compare commits
10 commits
b2c1d5eaa4
...
1abb54372f
Author | SHA1 | Date | |
---|---|---|---|
1abb54372f | |||
016acf0ca0 | |||
a33495d27f | |||
a73c72fa93 | |||
dcbd030a48 | |||
a421ccfbb1 | |||
e580dc02dc | |||
4dde4f1596 | |||
8cf5ea3ec8 | |||
a077fb1206 |
9 changed files with 396 additions and 50 deletions
|
@ -4,4 +4,5 @@ version = "0.1.0"
|
|||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
serde = {version = "1.0.203", features = ["derive"]}
|
||||
serde_json = "1.0"
|
||||
|
|
4
build.sh
Executable file
4
build.sh
Executable file
|
@ -0,0 +1,4 @@
|
|||
# This script builds the application WITHOUT using dependencies on the system!
|
||||
# THE POWER OF DOCKER!
|
||||
clear
|
||||
docker run --rm -t -v "$PWD:/src:ro,z" -v "$PWD/build:/app:Z" tasky
|
|
@ -1,28 +1 @@
|
|||
[
|
||||
{
|
||||
"name": "Shipments",
|
||||
"cards": [
|
||||
{
|
||||
"name": "Dell Latitude 3410",
|
||||
"desc": "UPS"
|
||||
},
|
||||
{
|
||||
"name": "Microsoft Surface Laptop Studio",
|
||||
"desc": "USPS"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Projects",
|
||||
"cards": [
|
||||
{
|
||||
"name": "RustyPass",
|
||||
"desc": "Done"
|
||||
},
|
||||
{
|
||||
"name": "Tasky",
|
||||
"desc": "W.I.P"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
[{"cards":[{"desc":"UPS","name":"Dell Latitude 3410"},{"desc":"USPS","name":"Microsoft Surface Laptop Studio"},{"desc":"UPS","name":"MacBook Pro"}],"name":"Shipments"},{"cards":[{"desc":"Done","name":"RustyPass"},{"desc":"W.I.P","name":"Tasky"}],"name":"Projects"}]
|
|
@ -1,7 +1,9 @@
|
|||
// Libraries
|
||||
use serde::{Serialize, Deserialize};
|
||||
use crate::card;
|
||||
|
||||
// Structures
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct TaskBoard {
|
||||
pub name: String,
|
||||
pub cards: Vec<card::TaskCard>
|
||||
|
@ -14,10 +16,7 @@ impl TaskBoard {
|
|||
let name: String = name;
|
||||
|
||||
// Init default cards
|
||||
let mut cards: Vec<card::TaskCard> = Vec::new();
|
||||
|
||||
// Creating a new default card
|
||||
cards.push(card::TaskCard::init_empty());
|
||||
let cards: Vec<card::TaskCard> = Vec::new();
|
||||
|
||||
// Return the board!
|
||||
return TaskBoard {name: name, cards: cards};
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
// Library
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
// Structures
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct TaskCard {
|
||||
pub name: String,
|
||||
pub desc: String
|
||||
|
@ -8,10 +10,7 @@ pub struct TaskCard {
|
|||
|
||||
// Implementations
|
||||
impl TaskCard {
|
||||
pub fn init_val(name: String, desc: String) -> TaskCard {
|
||||
pub fn init(name: String, desc: String) -> TaskCard {
|
||||
return TaskCard{name: name, desc: desc};
|
||||
}
|
||||
pub fn init_empty() -> TaskCard {
|
||||
return TaskCard::init_val(String::from("New Card"), String::new());
|
||||
}
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
// Libraries
|
||||
use std::fs;
|
||||
use serde_json::*;
|
||||
|
||||
// Structures
|
||||
pub struct Data {
|
||||
|
@ -16,4 +15,7 @@ impl Data {
|
|||
// Returning the result
|
||||
return Data {content: content};
|
||||
}
|
||||
pub fn write(path: String, content: String){
|
||||
fs::write(path, content).expect("Failed to write file");
|
||||
}
|
||||
}
|
350
src/interface.rs
Normal file
350
src/interface.rs
Normal file
|
@ -0,0 +1,350 @@
|
|||
// Libraries
|
||||
use crate::{board, card, manager};
|
||||
use std::{io::{self, Write}, process::exit};
|
||||
|
||||
// Constants
|
||||
const COLOR_ERROR: &str = "\x1b[31m";
|
||||
const COLOR_CARD: &str = "\x1b[32m";
|
||||
const COLOR_TITLE: &str = "\x1b[33m";
|
||||
const COLOR_DESC: &str = "\x1b[35m";
|
||||
const COLOR_OPTION: &str = "\x1b[36m";
|
||||
const COLOR_RESET: &str = "\x1b[0m";
|
||||
|
||||
// Structures
|
||||
pub struct Interface<'a> {
|
||||
manager: &'a mut manager::Manager,
|
||||
|
||||
pub running: bool,
|
||||
page: u32,
|
||||
mode: u32,
|
||||
on: u32
|
||||
}
|
||||
|
||||
// Implementations
|
||||
impl<'a> Interface<'a> {
|
||||
pub fn init(manager: &'a mut manager::Manager) -> Interface<'a>{
|
||||
// Return result
|
||||
return Interface {manager: manager, running: true, page: 0, mode: 0, on: 0};
|
||||
}
|
||||
|
||||
fn p_0(&mut self) {
|
||||
// Showing options
|
||||
println!(" - {}Tasky{} - ", COLOR_TITLE, COLOR_RESET);
|
||||
println!("{}1{}) Open Board", COLOR_OPTION, COLOR_RESET);
|
||||
println!("{}2{}) Create Board", COLOR_OPTION, COLOR_RESET);
|
||||
println!("{}3{}) Exit", COLOR_OPTION, COLOR_RESET);
|
||||
println!("\nSelect option [{0}1{1}-{0}3{1}]: ", COLOR_OPTION, COLOR_RESET);
|
||||
|
||||
// Listening for option
|
||||
let mut user_input: String = String::new();
|
||||
io::stdin().read_line(&mut user_input).expect("Failed to read line");
|
||||
user_input = String::from(user_input.to_lowercase().trim());
|
||||
println!("");
|
||||
|
||||
// Deciding what to do
|
||||
if user_input == "1" {
|
||||
self.page = 1;
|
||||
} else if user_input == "2"{
|
||||
self.page = 6;
|
||||
} else if user_input == "3" {
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
fn p_1(&mut self) {
|
||||
// Showing options
|
||||
println!(" - {}Open Board{} - ", COLOR_TITLE, COLOR_RESET);
|
||||
for i in 0..self.manager.boards.len() {
|
||||
println!("{2}{0}{3}) {1}", i+1, self.manager.boards[i].name, COLOR_OPTION, COLOR_RESET);
|
||||
}
|
||||
println!("\nSelect board [{1}1{2}-{1}{0}{2}]: ", self.manager.boards.len(), COLOR_OPTION, COLOR_RESET);
|
||||
|
||||
|
||||
// Selecting option
|
||||
let mut user_input: String = String::new();
|
||||
io::stdin().read_line(&mut user_input).expect("Failed to read line");
|
||||
user_input = String::from(user_input.to_lowercase().trim());
|
||||
println!("");
|
||||
|
||||
// Parsing option
|
||||
self.on = user_input.parse::<u32>().unwrap() - 1;
|
||||
self.page = 2;
|
||||
}
|
||||
fn p_2(&mut self) {
|
||||
// Active board
|
||||
let board: &board::TaskBoard = &self.manager.boards[self.on as usize];
|
||||
|
||||
// Title
|
||||
println!(" - {1}{0}{2} - \n", board.name, COLOR_TITLE, COLOR_RESET);
|
||||
|
||||
// Going through cards
|
||||
for card in &board.cards {
|
||||
println!("- {2}{0}{4} ({3}{1}{4})", card.name, card.desc, COLOR_CARD, COLOR_DESC, COLOR_RESET);
|
||||
}
|
||||
|
||||
// Presenting options
|
||||
println!("\n{}1{}) Create Card", COLOR_OPTION, COLOR_RESET);
|
||||
println!("{}2{}) Edit Card", COLOR_OPTION, COLOR_RESET);
|
||||
println!("{}3{}) Delete Card", COLOR_OPTION, COLOR_RESET);
|
||||
println!("{}4{}) Delete Board", COLOR_OPTION, COLOR_RESET);
|
||||
println!("{}5{}) Exit", COLOR_OPTION, COLOR_RESET);
|
||||
println!("\nSelect Option [{0}1{1}-{0}5{1}]: ", COLOR_OPTION, COLOR_RESET);
|
||||
|
||||
// Selection option
|
||||
let mut user_input: String = String::new();
|
||||
io::stdin().read_line(&mut user_input).expect("Failed to read lines");
|
||||
user_input = String::from(user_input.to_lowercase().trim());
|
||||
println!("");
|
||||
|
||||
// What to do
|
||||
if user_input == "1" {
|
||||
self.page = 3;
|
||||
} else if user_input == "2"{
|
||||
self.page = 4;
|
||||
} else if user_input == "3"{
|
||||
self.mode = 0;
|
||||
self.page = 5;
|
||||
} else if user_input == "4"{
|
||||
self.mode = 1;
|
||||
self.page = 5;
|
||||
} else if user_input == "5"{
|
||||
self.page = 0;
|
||||
}
|
||||
}
|
||||
fn p_3(&mut self){
|
||||
// Title
|
||||
println!(" - {}Create Card{} - \n", COLOR_TITLE, COLOR_RESET);
|
||||
|
||||
// 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 [{}name{}]: ", COLOR_OPTION, COLOR_RESET);
|
||||
|
||||
// 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 [{}desc{}]: ", COLOR_OPTION, COLOR_RESET);
|
||||
|
||||
// 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(_name, _desc);
|
||||
|
||||
// Throw this into our manager
|
||||
self.manager.boards[self.on as usize].cards.push(_new_card);
|
||||
|
||||
// Finished!
|
||||
self.page = 2;
|
||||
}
|
||||
fn p_4(&mut self){
|
||||
// Title
|
||||
println!(" - {}Edit Card{} - \n", COLOR_TITLE, COLOR_RESET);
|
||||
|
||||
// Getting active board
|
||||
let _active: &mut board::TaskBoard = &mut self.manager.boards[self.on as usize];
|
||||
|
||||
// Showing all cards
|
||||
for i in 0.._active.cards.len() {
|
||||
println!("{2}{0}{3}) {1}", i+1, _active.cards[i].name, COLOR_OPTION, COLOR_RESET);
|
||||
}
|
||||
|
||||
// Asking for an option
|
||||
println!("\nSelect card[{1}1{2}-{1}{0}{2}]: ", _active.cards.len(), COLOR_OPTION, COLOR_RESET);
|
||||
|
||||
// Reading input
|
||||
let mut user_input: String = String::new();
|
||||
io::stdin().read_line(&mut user_input).expect("Failed to read line");
|
||||
user_input = String::from(user_input.to_lowercase().trim());
|
||||
println!("");
|
||||
|
||||
// Selecting the card
|
||||
let _card_index: usize = user_input.parse::<usize>().unwrap() - 1;
|
||||
let _card: &mut card::TaskCard = &mut _active.cards[_card_index];
|
||||
|
||||
// Printing options
|
||||
println!(" - {1}{0}{2} - ", _card.name, COLOR_CARD, COLOR_RESET);
|
||||
println!("{}1{}) Change Name", COLOR_OPTION, COLOR_RESET);
|
||||
println!("{}2{}) Change Description", COLOR_OPTION, COLOR_RESET);
|
||||
println!("{}3{}) Exit", COLOR_OPTION, COLOR_RESET);
|
||||
println!("\nSelect option [{0}1{1}-{0}3{1}]: ", COLOR_OPTION, COLOR_RESET);
|
||||
|
||||
// Reset input
|
||||
user_input = String::new();
|
||||
|
||||
// Reading input
|
||||
io::stdin().read_line(&mut user_input).expect("Failed to read line");
|
||||
user_input = String::from(user_input.to_lowercase().trim());
|
||||
|
||||
// Decide what to do
|
||||
if user_input == "1" {
|
||||
// Printing prompt
|
||||
println!("\nWhat should the new name be?");
|
||||
println!("Select name [{}name{}]:", COLOR_OPTION, COLOR_RESET);
|
||||
|
||||
// Reset input
|
||||
user_input = String::new();
|
||||
|
||||
// Reading input
|
||||
io::stdin().read_line(&mut user_input).expect("Failed to read line");
|
||||
user_input = String::from(user_input.trim());
|
||||
|
||||
// Setting the cards name
|
||||
_card.name = user_input;
|
||||
} else if user_input == "2" {
|
||||
// Printing prompt
|
||||
println!("\nWhat should the new description be?");
|
||||
println!("Select description [{}desc{}]:", COLOR_OPTION, COLOR_RESET);
|
||||
|
||||
// Reset input
|
||||
user_input = String::new();
|
||||
|
||||
// Reading input
|
||||
io::stdin().read_line(&mut user_input).expect("Failed to read line");
|
||||
user_input = String::from(user_input.trim());
|
||||
|
||||
// Setting the cards name
|
||||
_card.desc = user_input;
|
||||
}
|
||||
|
||||
// Changing page
|
||||
self.page = 2;
|
||||
}
|
||||
fn p_5(&mut self){
|
||||
// Which title do we use
|
||||
let title: String = String::from(match self.mode {
|
||||
0 => "Card",
|
||||
1 => "Board",
|
||||
_ => "INVALID MODE"
|
||||
});
|
||||
|
||||
// Printing out the title
|
||||
println!(" - {1}Delete {0}{2} - ", title, COLOR_TITLE, COLOR_RESET);
|
||||
|
||||
// Active board
|
||||
let _active: &board::TaskBoard = &self.manager.boards[self.on as usize];
|
||||
|
||||
// Branching
|
||||
if self.mode == 0 {
|
||||
// Presenting all cards
|
||||
for i in 0.._active.cards.len() {
|
||||
println!("{2}{0}{4}) {3}{1}{4}", i+1, _active.cards[i].name, COLOR_OPTION, COLOR_CARD, COLOR_RESET);
|
||||
}
|
||||
|
||||
// Displaying prompt
|
||||
println!("\nSelect option [{1}1{2}-{1}{0}{2}]: ", _active.cards.len(), COLOR_OPTION, COLOR_RESET);
|
||||
|
||||
// Getting user input
|
||||
let mut user_input: String = String::new();
|
||||
io::stdin().read_line(&mut user_input).expect("Failed to read line");
|
||||
user_input = String::from(user_input.to_lowercase().trim());
|
||||
|
||||
// Parse user input into a usize
|
||||
let card_index: usize = user_input.parse::<usize>().unwrap() - 1;
|
||||
|
||||
// Reset user input
|
||||
user_input = String::new();
|
||||
|
||||
// Confirming
|
||||
println!("\nAre you sure?\nSelect option [{0}y{1}/{0}n{1}]: ", COLOR_OPTION, COLOR_RESET);
|
||||
io::stdin().read_line(&mut user_input).expect("Failed to read line");
|
||||
user_input = String::from(user_input.to_lowercase().trim());
|
||||
println!("");
|
||||
|
||||
// If we don't want to do this:
|
||||
if user_input != "y" {
|
||||
self.page = 2;
|
||||
return;
|
||||
}
|
||||
|
||||
// Delete the card
|
||||
self.manager.boards[self.on as usize].cards.remove(card_index);
|
||||
|
||||
// Set page back to normal
|
||||
self.page = 2;
|
||||
} else if self.mode == 1 {
|
||||
// Confirming
|
||||
let mut user_input: String = String::new();
|
||||
println!("\nAre you sure?\nSelect option [{0}y{1}/{0}n{1}]: ", COLOR_OPTION, COLOR_RESET);
|
||||
io::stdin().read_line(&mut user_input).expect("Failed to read line");
|
||||
user_input = String::from(user_input.to_lowercase().trim());
|
||||
println!("");
|
||||
|
||||
// If the user says no
|
||||
if user_input != "y" {
|
||||
self.page = 2;
|
||||
return;
|
||||
}
|
||||
|
||||
// Deleting the board
|
||||
self.manager.boards.remove(self.on as usize);
|
||||
|
||||
// Resetting all of the stuff
|
||||
self.page = 0;
|
||||
self.on = 0;
|
||||
}
|
||||
}
|
||||
fn p_6(&mut self){
|
||||
// Title
|
||||
println!(" - {}Create Board{} - \n", COLOR_TITLE, COLOR_RESET);
|
||||
|
||||
// Variables
|
||||
let mut user_input: String = String::new();
|
||||
|
||||
// Asking the user what the name is
|
||||
println!("What is your boards's name?");
|
||||
println!("Select name [{}name{}]: ", COLOR_OPTION, COLOR_RESET);
|
||||
|
||||
// Reading input
|
||||
io::stdin().read_line(&mut user_input).expect("Failed to read line");
|
||||
let _name: String = String::from(user_input.trim());
|
||||
println!("");
|
||||
|
||||
// Creating the new board
|
||||
self.manager.boards.push(board::TaskBoard::init(_name));
|
||||
|
||||
// Open the board
|
||||
self.page = 2;
|
||||
self.on = (self.manager.boards.len()-1) as u32;
|
||||
}
|
||||
|
||||
fn clear(){
|
||||
println!("\x1B[2J\x1B[1;1H");
|
||||
io::stdout().flush().unwrap();
|
||||
}
|
||||
fn error(msg: &str){
|
||||
println!("INTERFACE ERROR: {}", msg);
|
||||
}
|
||||
|
||||
pub fn run(&mut self) {
|
||||
// Clearing the screen
|
||||
Interface::clear();
|
||||
|
||||
// Based on the page do something
|
||||
match self.page {
|
||||
0 => self.p_0(),
|
||||
1 => self.p_1(),
|
||||
2 => self.p_2(),
|
||||
3 => self.p_3(),
|
||||
4 => self.p_4(),
|
||||
5 => self.p_5(),
|
||||
6 => self.p_6(),
|
||||
_ => Interface::error("Invalid Page")
|
||||
}
|
||||
|
||||
// Save
|
||||
if !self.manager.save() {
|
||||
println!("{}ERROR{}: Failed to save", COLOR_ERROR, COLOR_RESET);
|
||||
}
|
||||
}
|
||||
}
|
16
src/main.rs
16
src/main.rs
|
@ -1,4 +1,5 @@
|
|||
// Libraries
|
||||
mod interface;
|
||||
mod manager;
|
||||
mod data;
|
||||
mod card;
|
||||
|
@ -12,14 +13,11 @@ fn main() {
|
|||
let mut managed: manager::Manager = manager::Manager::init();
|
||||
managed.parse(String::from("data/user.json"));
|
||||
|
||||
// Printing out the boards
|
||||
println!("-- PROJECT --");
|
||||
println!("You have {} boards.", managed.boards.len());
|
||||
|
||||
for board in managed.boards {
|
||||
println!("\n-- {} --", board.name);
|
||||
for card in board.cards {
|
||||
println!("\t- {} ({})", card.name, card.desc);
|
||||
}
|
||||
// Passing this through to the interface
|
||||
let mut int: interface::Interface = interface::Interface::init(&mut managed);
|
||||
|
||||
// Running the interface
|
||||
while int.running {
|
||||
int.run();
|
||||
}
|
||||
}
|
|
@ -1,20 +1,24 @@
|
|||
// Libraries
|
||||
use serde_json::{self, Value};
|
||||
use serde_json::{self, json, Value};
|
||||
use crate::board;
|
||||
use crate::card;
|
||||
use crate::data;
|
||||
|
||||
// Structures
|
||||
pub struct Manager{
|
||||
pub boards: Vec<board::TaskBoard>
|
||||
pub boards: Vec<board::TaskBoard>,
|
||||
path: String
|
||||
}
|
||||
|
||||
// Implementations
|
||||
impl Manager{
|
||||
pub fn init() -> Manager {
|
||||
return Manager {boards: vec![]};
|
||||
return Manager {boards: vec![], path: String::new()};
|
||||
}
|
||||
pub fn parse(&mut self, path: String){
|
||||
// Setting variables
|
||||
self.path = path.clone();
|
||||
|
||||
// Loading a data object from the path
|
||||
let loaded: data::Data = data::Data::init(path);
|
||||
|
||||
|
@ -31,11 +35,27 @@ impl Manager{
|
|||
let _name: String = String::from(task["name"].as_str().unwrap());
|
||||
let _desc: String = String::from(task["desc"].as_str().unwrap());
|
||||
|
||||
cards.push(card::TaskCard::init_val(_name, _desc));
|
||||
cards.push(card::TaskCard::init(_name, _desc));
|
||||
}
|
||||
|
||||
// Creating the boards inside the manager
|
||||
self.boards.push(board::TaskBoard {name: String::from(item["name"].as_str().expect("Failed to parse string")), cards: cards});
|
||||
}
|
||||
}
|
||||
pub fn save(&mut self) -> bool {
|
||||
// Did we even load from a file?
|
||||
if self.path.is_empty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Turning all of my data into a JSON file
|
||||
let boards = &self.boards;
|
||||
let json_out = json!(boards);
|
||||
|
||||
// Saving the file to our path
|
||||
data::Data::write(self.path.clone(), json_out.to_string());
|
||||
|
||||
// Worked!
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue