Compare commits
No commits in common. "1abb54372fb4b8799e232bca633a4c3d3d69898c" and "b2c1d5eaa465106e4a2804a9ac401eb871e59db5" have entirely different histories.
1abb54372f
...
b2c1d5eaa4
9 changed files with 50 additions and 396 deletions
|
@ -4,5 +4,4 @@ version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = {version = "1.0.203", features = ["derive"]}
|
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
|
|
4
build.sh
4
build.sh
|
@ -1,4 +0,0 @@
|
||||||
# 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 +1,28 @@
|
||||||
[{"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"}]
|
[
|
||||||
|
{
|
||||||
|
"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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
|
@ -1,9 +1,7 @@
|
||||||
// Libraries
|
// Libraries
|
||||||
use serde::{Serialize, Deserialize};
|
|
||||||
use crate::card;
|
use crate::card;
|
||||||
|
|
||||||
// Structures
|
// Structures
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct TaskBoard {
|
pub struct TaskBoard {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub cards: Vec<card::TaskCard>
|
pub cards: Vec<card::TaskCard>
|
||||||
|
@ -16,7 +14,10 @@ impl TaskBoard {
|
||||||
let name: String = name;
|
let name: String = name;
|
||||||
|
|
||||||
// Init default cards
|
// Init default cards
|
||||||
let cards: Vec<card::TaskCard> = Vec::new();
|
let mut cards: Vec<card::TaskCard> = Vec::new();
|
||||||
|
|
||||||
|
// Creating a new default card
|
||||||
|
cards.push(card::TaskCard::init_empty());
|
||||||
|
|
||||||
// Return the board!
|
// Return the board!
|
||||||
return TaskBoard {name: name, cards: cards};
|
return TaskBoard {name: name, cards: cards};
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
// Library
|
// Library
|
||||||
use serde::{Serialize, Deserialize};
|
|
||||||
|
|
||||||
// Structures
|
// Structures
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct TaskCard {
|
pub struct TaskCard {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub desc: String
|
pub desc: String
|
||||||
|
@ -10,7 +8,10 @@ pub struct TaskCard {
|
||||||
|
|
||||||
// Implementations
|
// Implementations
|
||||||
impl TaskCard {
|
impl TaskCard {
|
||||||
pub fn init(name: String, desc: String) -> TaskCard {
|
pub fn init_val(name: String, desc: String) -> TaskCard {
|
||||||
return TaskCard{name: name, desc: desc};
|
return TaskCard{name: name, desc: desc};
|
||||||
}
|
}
|
||||||
|
pub fn init_empty() -> TaskCard {
|
||||||
|
return TaskCard::init_val(String::from("New Card"), String::new());
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
// Libraries
|
// Libraries
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
use serde_json::*;
|
||||||
|
|
||||||
// Structures
|
// Structures
|
||||||
pub struct Data {
|
pub struct Data {
|
||||||
|
@ -15,7 +16,4 @@ impl Data {
|
||||||
// Returning the result
|
// Returning the result
|
||||||
return Data {content: content};
|
return Data {content: content};
|
||||||
}
|
}
|
||||||
pub fn write(path: String, content: String){
|
|
||||||
fs::write(path, content).expect("Failed to write file");
|
|
||||||
}
|
|
||||||
}
|
}
|
350
src/interface.rs
350
src/interface.rs
|
@ -1,350 +0,0 @@
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
14
src/main.rs
14
src/main.rs
|
@ -1,5 +1,4 @@
|
||||||
// Libraries
|
// Libraries
|
||||||
mod interface;
|
|
||||||
mod manager;
|
mod manager;
|
||||||
mod data;
|
mod data;
|
||||||
mod card;
|
mod card;
|
||||||
|
@ -13,11 +12,14 @@ fn main() {
|
||||||
let mut managed: manager::Manager = manager::Manager::init();
|
let mut managed: manager::Manager = manager::Manager::init();
|
||||||
managed.parse(String::from("data/user.json"));
|
managed.parse(String::from("data/user.json"));
|
||||||
|
|
||||||
// Passing this through to the interface
|
// Printing out the boards
|
||||||
let mut int: interface::Interface = interface::Interface::init(&mut managed);
|
println!("-- PROJECT --");
|
||||||
|
println!("You have {} boards.", managed.boards.len());
|
||||||
|
|
||||||
// Running the interface
|
for board in managed.boards {
|
||||||
while int.running {
|
println!("\n-- {} --", board.name);
|
||||||
int.run();
|
for card in board.cards {
|
||||||
|
println!("\t- {} ({})", card.name, card.desc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,24 +1,20 @@
|
||||||
// Libraries
|
// Libraries
|
||||||
use serde_json::{self, json, Value};
|
use serde_json::{self, Value};
|
||||||
use crate::board;
|
use crate::board;
|
||||||
use crate::card;
|
use crate::card;
|
||||||
use crate::data;
|
use crate::data;
|
||||||
|
|
||||||
// Structures
|
// Structures
|
||||||
pub struct Manager{
|
pub struct Manager{
|
||||||
pub boards: Vec<board::TaskBoard>,
|
pub boards: Vec<board::TaskBoard>
|
||||||
path: String
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implementations
|
// Implementations
|
||||||
impl Manager{
|
impl Manager{
|
||||||
pub fn init() -> Manager {
|
pub fn init() -> Manager {
|
||||||
return Manager {boards: vec![], path: String::new()};
|
return Manager {boards: vec![]};
|
||||||
}
|
}
|
||||||
pub fn parse(&mut self, path: String){
|
pub fn parse(&mut self, path: String){
|
||||||
// Setting variables
|
|
||||||
self.path = path.clone();
|
|
||||||
|
|
||||||
// Loading a data object from the path
|
// Loading a data object from the path
|
||||||
let loaded: data::Data = data::Data::init(path);
|
let loaded: data::Data = data::Data::init(path);
|
||||||
|
|
||||||
|
@ -35,27 +31,11 @@ impl Manager{
|
||||||
let _name: String = String::from(task["name"].as_str().unwrap());
|
let _name: String = String::from(task["name"].as_str().unwrap());
|
||||||
let _desc: String = String::from(task["desc"].as_str().unwrap());
|
let _desc: String = String::from(task["desc"].as_str().unwrap());
|
||||||
|
|
||||||
cards.push(card::TaskCard::init(_name, _desc));
|
cards.push(card::TaskCard::init_val(_name, _desc));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creating the boards inside the manager
|
// 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});
|
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