refactor for upcomming project management
This commit is contained in:
@@ -7,7 +7,7 @@ use std::process;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
use std::str::FromStr;
|
||||
use crate::project_controls;
|
||||
|
||||
use crate::Project;
|
||||
use crate::box_controls::make_box;
|
||||
|
||||
@@ -48,7 +48,7 @@ pub fn save_projects(projects: &Vec<Project>, config_path: &PathBuf){
|
||||
save_file_path.pop();
|
||||
save_file_path.push("projects.conf");
|
||||
let mut save_file = fs::File::create(save_file_path).expect("error creating save_file");
|
||||
save_file.write_all(b"customer:name:notes:files:active:time:box_name\n").expect("error writing first line to file");
|
||||
save_file.write_all(b"customer:name:notes:files:active:time:box_name:stage\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();
|
||||
@@ -66,13 +66,44 @@ pub fn save_projects(projects: &Vec<Project>, config_path: &PathBuf){
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_project(projects: &mut Vec<Project>, project_dir: &PathBuf, notes_dir: &PathBuf, tools_dir: &PathBuf, boxtemplate: &String, config_path: &PathBuf, new_id: i32){
|
||||
let mut new_project_dir = project_dir.clone();
|
||||
let mut new_note_dir = notes_dir.clone();
|
||||
pub fn new_project(projects: &mut Vec<Project>, project_dir: &PathBuf, notes_dir: &PathBuf, tools_dir: &PathBuf, boxtemplate: &String, config_path: &PathBuf, new_id: i32, upcoming_files: &PathBuf, upcoming_notes: &PathBuf){
|
||||
let mut new_project_dir = PathBuf::new();
|
||||
let mut new_note_dir = PathBuf::new();
|
||||
let mut existing_folders = String::new();
|
||||
let mut customer_name = String::new();
|
||||
let mut project_name = String::new();
|
||||
let mut project_stage = String::new();
|
||||
loop{
|
||||
let mut stage_response = String::new();
|
||||
println!("what stage is this project in?");
|
||||
print!("
|
||||
1.) current
|
||||
2.) upcoming
|
||||
");
|
||||
let stage_result = stdin().read_line(&mut stage_response);
|
||||
if stage_result.is_err(){
|
||||
println!("we need input here dummy, try again...");
|
||||
}
|
||||
else{
|
||||
match &stage_response.trim_end(){
|
||||
&"1" => {project_stage = "current".to_owned(); break;},
|
||||
&"2" => {project_stage = "upcoming".to_owned(); break;},
|
||||
_ => println!("unknown option, try again...")
|
||||
}
|
||||
}
|
||||
}
|
||||
if project_stage.contains("current"){
|
||||
new_project_dir = project_dir.clone();
|
||||
new_note_dir = notes_dir.clone();
|
||||
}
|
||||
else if project_stage.contains("upcoming"){
|
||||
new_project_dir = upcoming_files.clone();
|
||||
new_note_dir = upcoming_notes.clone();
|
||||
}
|
||||
else{
|
||||
println!("unknown stage!!")
|
||||
}
|
||||
println!("{}", new_project_dir.display());
|
||||
println!("do you have an existing notes and folder structure to copy over?\ny/n");
|
||||
std::io::stdin().read_line(&mut existing_folders).unwrap();
|
||||
if existing_folders.contains("y") || existing_folders.contains("Y"){
|
||||
@@ -184,25 +215,6 @@ pub fn new_project(projects: &mut Vec<Project>, project_dir: &PathBuf, notes_dir
|
||||
fs::create_dir_all(&new_project_dir).expect("error creating new files folder");
|
||||
fs::create_dir_all(&new_note_dir).expect("error creating new notes folder");
|
||||
}
|
||||
loop{
|
||||
let mut stage_response = String::new();
|
||||
println!("what stage is this project in?");
|
||||
print!("
|
||||
1.) current
|
||||
2.) upcoming
|
||||
");
|
||||
let stage_result = stdin().read_line(&mut stage_response);
|
||||
if stage_result.is_err(){
|
||||
println!("we need input here dummy, try again...");
|
||||
}
|
||||
else{
|
||||
match &stage_response.trim_end(){
|
||||
&"1" => {project_stage = "current".to_owned(); break;},
|
||||
&"2" => {project_stage = "upcoming".to_owned(); break;},
|
||||
_ => println!("unknown option, try again...")
|
||||
}
|
||||
}
|
||||
}
|
||||
thread::sleep(Duration::from_secs(2));
|
||||
let box_name = format!("atarchbox_{}", customer_name);
|
||||
let new_project = Project{customer: customer_name.trim_end().to_owned(),
|
||||
@@ -214,7 +226,9 @@ pub fn new_project(projects: &mut Vec<Project>, project_dir: &PathBuf, notes_dir
|
||||
boxname: box_name,
|
||||
stage: project_stage.to_owned()
|
||||
};
|
||||
make_box(&new_project, &tools_dir, &boxtemplate, true);
|
||||
if project_stage.contains("current"){
|
||||
make_box(&new_project, &tools_dir, &boxtemplate, true);
|
||||
}
|
||||
projects.push(new_project);
|
||||
save_projects(projects, config_path);
|
||||
|
||||
@@ -288,6 +302,12 @@ pub fn get_projects(config_path: &PathBuf) -> Vec<Project>{
|
||||
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();
|
||||
@@ -321,7 +341,7 @@ pub fn print_upcoming_projects(projects: &Vec<Project>){
|
||||
}
|
||||
}
|
||||
|
||||
pub fn promote_project(projects: &mut Vec<Project>, config_path: &PathBuf){
|
||||
pub fn promote_project(projects: &mut Vec<Project>, config_path: &PathBuf, project_dir: &PathBuf, notes_dir: &PathBuf, tools_dir: &PathBuf, boxtemplate: &String){
|
||||
let working_projects = projects.clone();
|
||||
for project in &working_projects{
|
||||
if project.stage.contains("upcoming"){
|
||||
@@ -335,12 +355,43 @@ pub fn promote_project(projects: &mut Vec<Project>, config_path: &PathBuf){
|
||||
println!("we need input here dummy try again....");
|
||||
}
|
||||
result.unwrap();
|
||||
println!("{}", project_dir.display());
|
||||
let promote_id: i32 = selection.trim_end().parse().unwrap();
|
||||
let mut projects_to_save = Vec::new();
|
||||
for project in &working_projects{
|
||||
if project.id == promote_id{
|
||||
let mut promoted_project = project.clone();
|
||||
let mut new_files_dir = project_dir.clone();
|
||||
let mut new_notes_dir = notes_dir.clone();
|
||||
new_files_dir.push(&promoted_project.customer);
|
||||
new_notes_dir.push(&promoted_project.customer);
|
||||
let folder_move_success = process::Command::new("mv")
|
||||
.arg("-i")
|
||||
.arg(&project.files_folder)
|
||||
.arg(&new_files_dir.display().to_string())
|
||||
.status().expect("unable to call the system mv command");
|
||||
let note_move_success = process::Command::new("mv")
|
||||
.arg("-i")
|
||||
.arg(&project.notes_folder)
|
||||
.arg(&new_notes_dir.display().to_string())
|
||||
.status().expect("unable to call the system mv command");
|
||||
if folder_move_success.success(){
|
||||
println!("we copied the project folder correctly!!");
|
||||
}
|
||||
else{
|
||||
println!("failed to copy the project folder, try to move it manually!");
|
||||
}
|
||||
if note_move_success.success(){
|
||||
println!("we copied the notes folder correctly!!");
|
||||
}
|
||||
else{
|
||||
println!("failed to copy the notes folder, try to move it manually!");
|
||||
}
|
||||
promoted_project.files_folder = new_files_dir;
|
||||
promoted_project.notes_folder = new_notes_dir;
|
||||
promoted_project.stage = "current".to_owned();
|
||||
thread::sleep(Duration::from_secs(3));
|
||||
make_box(&promoted_project, tools_dir, boxtemplate, true);
|
||||
projects_to_save.push(promoted_project);
|
||||
}
|
||||
else{
|
||||
|
||||
Reference in New Issue
Block a user