added some functions to switch between managing
personal projects and managing work projects as well as the ability to separate your current project list into work and personal.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::fs::read_to_string;
|
||||
use std::io::stdin;
|
||||
use std::io::Write;
|
||||
use std::path::PathBuf;
|
||||
@@ -11,12 +12,12 @@ use std::str::FromStr;
|
||||
use colored::Colorize;
|
||||
|
||||
use crate::get_user_input;
|
||||
use crate::open_overwrite;
|
||||
use crate::tableize;
|
||||
use crate::Project;
|
||||
use crate::box_controls::make_box;
|
||||
use crate::print_success;
|
||||
use crate::print_error;
|
||||
use crate::print_informational;
|
||||
|
||||
pub fn
|
||||
switch_project(projects: &mut Vec<Project>){
|
||||
@@ -62,7 +63,7 @@ pub fn save_projects(projects: &Vec<Project>, config_path: &PathBuf){
|
||||
return;
|
||||
}
|
||||
let mut save_file = save_file_res.unwrap();
|
||||
save_file.write_all(b"customer:name:notes:files:active:time:box_name:stage\n").expect("error writing first line to file");
|
||||
save_file.write_all(b"Current Loaded Projects Config File\n").expect("error writing first line to file");
|
||||
for project in projects{
|
||||
let default = format!{"{}:{}:{}:{}:", project.customer, project.project_name, project.notes_folder.display(), project.files_folder.display()};
|
||||
let mut _outline = String::new();
|
||||
@@ -335,37 +336,40 @@ pub fn get_projects(config_path: &PathBuf, show: bool) -> Option<Vec<Project>>{
|
||||
let mut first = 0;
|
||||
let mut already_active = false;
|
||||
for line in project_lines{
|
||||
//println!("{}", line);
|
||||
first = first + 1;
|
||||
if first != 1{
|
||||
if line.len() > 1{
|
||||
let settings: Vec<&str> = line.split(":").collect();
|
||||
//debug config file...
|
||||
/*let mut count = 0;
|
||||
for settin in &settings{
|
||||
println!("{}: {}", count, settin);
|
||||
count = count + 1;
|
||||
}*/
|
||||
let customer = settings[0].to_owned();
|
||||
let project = settings[1].to_owned();
|
||||
let notes_string = settings[2].to_owned();
|
||||
let folder_string = settings[3].to_owned();
|
||||
let notes_folder = PathBuf::from_str(¬es_string.trim_end()).expect("error reading notes string");
|
||||
let project_folder = PathBuf::from_str(&folder_string.trim_end()).expect("error reading folding sering");
|
||||
let mut active = false;
|
||||
let boxname = settings[5].to_owned();
|
||||
if settings[4] == "yes"{
|
||||
if already_active == false{
|
||||
env::set_var("CURRENT_PROJECT_BOX", boxname.clone());
|
||||
already_active = true;
|
||||
active = true;
|
||||
if settings.len() > 5{
|
||||
// debug config file...
|
||||
/*let mut count = 0;
|
||||
for settin in &settings{
|
||||
println!("{}: {}", count, settin);
|
||||
count = count + 1;
|
||||
}*/
|
||||
let customer = settings[0].to_owned();
|
||||
let project = settings[1].to_owned();
|
||||
let notes_string = settings[2].to_owned();
|
||||
let folder_string = settings[3].to_owned();
|
||||
let notes_folder = PathBuf::from_str(¬es_string.trim_end()).expect("error reading notes string");
|
||||
let project_folder = PathBuf::from_str(&folder_string.trim_end()).expect("error reading folding sering");
|
||||
let mut active = false;
|
||||
let boxname = settings[5].to_owned();
|
||||
if settings[4] == "yes"{
|
||||
if already_active == false{
|
||||
env::set_var("CURRENT_PROJECT_BOX", boxname.clone());
|
||||
already_active = true;
|
||||
active = true;
|
||||
}
|
||||
}
|
||||
let project_stage = settings[6].to_owned();
|
||||
let new_project = Project{customer: customer, project_name: project, files_folder: project_folder, notes_folder: notes_folder, active: active, id: first, boxname: boxname, stage: project_stage};
|
||||
if show{
|
||||
println!("{} {} {}", &new_project.customer, &new_project.project_name, "LOADED!".green());
|
||||
}
|
||||
projects.push(new_project);
|
||||
}
|
||||
let project_stage = settings[6].to_owned();
|
||||
let new_project = Project{customer: customer, project_name: project, files_folder: project_folder, notes_folder: notes_folder, active: active, id: first, boxname: boxname, stage: project_stage};
|
||||
if show{
|
||||
println!("{} {} {}", &new_project.customer, &new_project.project_name, "LOADED!".green());
|
||||
}
|
||||
projects.push(new_project);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -496,3 +500,132 @@ pub fn list_projects(projects: &Vec<Project>){
|
||||
tableize(lines);
|
||||
}
|
||||
|
||||
|
||||
pub fn separate_personal_work_projects(config_path: &PathBuf){
|
||||
let mut projects_conf_path = config_path.clone();
|
||||
projects_conf_path.pop();
|
||||
projects_conf_path.push("projects.conf");
|
||||
let mut working_conf_path = config_path.clone();
|
||||
working_conf_path.pop();
|
||||
working_conf_path.push("projects.work");
|
||||
let mut personal_conf_path = config_path.clone();
|
||||
personal_conf_path.pop();
|
||||
personal_conf_path.push("projects.personal");
|
||||
println!("{}", projects_conf_path.display());
|
||||
let project_read_res = read_to_string(&projects_conf_path);
|
||||
if project_read_res.is_err(){
|
||||
print_error("error reading current projects config file!", project_read_res.err().unwrap().to_string());
|
||||
return;
|
||||
}
|
||||
let project_string = project_read_res.unwrap();
|
||||
let project_lines: Vec<&str> = project_string.split("\n").collect();
|
||||
let mut personal_projects = Vec::new();
|
||||
let mut work_projects = Vec::new();
|
||||
let mut default = String::new();
|
||||
for line in project_lines{
|
||||
let words: Vec<&str> = line.split(":").collect();
|
||||
if words.len() > 3{
|
||||
if words[0].contains("default"){
|
||||
default = line.to_owned();
|
||||
}
|
||||
else{
|
||||
println!("{} {}", words[0], words[1]);
|
||||
if get_user_input("should this project be added to your personal projects config files?").to_lowercase().contains("y"){
|
||||
personal_projects.push(line.to_owned());
|
||||
print_success(format!("{}:{} {}",words[0], words[1], "successfully added to personal config!"));
|
||||
if get_user_input("Do you also want to keep it in your work projects config?").to_lowercase().contains("y"){
|
||||
work_projects.push(line.to_owned());
|
||||
}
|
||||
}
|
||||
else{
|
||||
work_projects.push(line.to_owned());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let work_config_open_res = fs::OpenOptions::new().create(true).write(true).open(working_conf_path);
|
||||
if work_config_open_res.is_err(){
|
||||
print_error("error opening work projects config file!", work_config_open_res.err().unwrap().to_string());
|
||||
return;
|
||||
}
|
||||
let person_config_open_res = fs::OpenOptions::new().create(true).write(true).open(personal_conf_path);
|
||||
if person_config_open_res.is_err(){
|
||||
print_error("error opening personal config file!", person_config_open_res.err().unwrap().to_string());
|
||||
return;
|
||||
}
|
||||
let mut work_config_file = work_config_open_res.unwrap();
|
||||
let mut personal_config_file = person_config_open_res.unwrap();
|
||||
let work_write_success = write!(work_config_file, "Work Config File\n");
|
||||
let personal_write_success = write!(personal_config_file, "Personal Config File\n");
|
||||
if work_write_success.is_err(){
|
||||
print_error("error writing to work config file!", work_write_success.err().unwrap().to_string());
|
||||
return;
|
||||
}
|
||||
else{
|
||||
work_write_success.unwrap();
|
||||
}
|
||||
if personal_write_success.is_err(){
|
||||
print_error("error writing personal config file!", personal_write_success.err().unwrap().to_string());
|
||||
return;
|
||||
}
|
||||
else{
|
||||
personal_write_success.unwrap();
|
||||
}
|
||||
write!(personal_config_file, "{}\n", default).unwrap();
|
||||
write!(work_config_file, "{}\n", default).unwrap();
|
||||
for project in work_projects{
|
||||
write!(work_config_file, "{}\n", project).unwrap();
|
||||
}
|
||||
for project in personal_projects{
|
||||
write!(personal_config_file, "{}\n", project).unwrap();
|
||||
}
|
||||
print_success("projects separated successfully!");
|
||||
}
|
||||
|
||||
pub fn swith_to_personal(config: &PathBuf) -> Option<Vec<Project>>{
|
||||
let mut projects_path = config.clone();
|
||||
projects_path.pop();
|
||||
let mut personal_projects = config.clone();
|
||||
personal_projects.pop();
|
||||
projects_path.push("projects.conf");
|
||||
personal_projects.push("projects.personal");
|
||||
let personal_projects_read_res = read_to_string(&personal_projects);
|
||||
if personal_projects_read_res.is_err(){
|
||||
print_error("error reading personal projects!", personal_projects_read_res.err().unwrap().to_string());
|
||||
return None;
|
||||
}
|
||||
let person_projects_string = personal_projects_read_res.unwrap();
|
||||
let open_res = open_overwrite(&projects_path);
|
||||
if open_res.is_none(){
|
||||
print_error("error opening projects.conf file!", "".to_string());
|
||||
return None;
|
||||
}
|
||||
let mut project_conf = open_res.unwrap();
|
||||
write!(project_conf, "{}", person_projects_string).unwrap();
|
||||
let new_projects = get_projects(config, true);
|
||||
return new_projects;
|
||||
}
|
||||
|
||||
pub fn swith_to_work(config: &PathBuf) -> Option<Vec<Project>>{
|
||||
let mut projects_path = config.clone();
|
||||
projects_path.pop();
|
||||
let mut work_projects = config.clone();
|
||||
work_projects.pop();
|
||||
projects_path.push("projects.conf");
|
||||
work_projects.push("projects.work");
|
||||
let work_projects_read_res = read_to_string(work_projects);
|
||||
if work_projects_read_res.is_err(){
|
||||
print_error("error reading personal projects!", work_projects_read_res.err().unwrap().to_string());
|
||||
return None;
|
||||
}
|
||||
let work_projects_string = work_projects_read_res.unwrap();
|
||||
let open_res = open_overwrite(&projects_path);
|
||||
if open_res.is_none(){
|
||||
print_error("", "error opening projects.conf file!".to_string());
|
||||
return None;
|
||||
}
|
||||
let mut project_conf = open_res.unwrap();
|
||||
write!(project_conf, "{}", work_projects_string).unwrap();
|
||||
let new_projects = get_projects(config, true);
|
||||
return new_projects;
|
||||
}
|
||||
Reference in New Issue
Block a user