-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from lcfd/works
Works
- Loading branch information
Showing
15 changed files
with
504 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,147 @@ | ||
from datetime import datetime | ||
from typing import Annotated | ||
|
||
import typer | ||
from rich import print as rprint | ||
from rich.panel import Panel | ||
|
||
from trakcli.projects.database import get_project_from_config, get_projects_from_config | ||
from trakcli.projects.utils.print_missing_project import print_missing_project | ||
from trakcli.utils.print_with_padding import print_with_padding | ||
from trakcli.works.database import ( | ||
get_project_works_from_config, | ||
set_project_works_in_config, | ||
) | ||
from trakcli.works.models import Work | ||
|
||
|
||
def create_work( | ||
id: Annotated[ | ||
str, | ||
typer.Argument(help="The id for the new work."), | ||
], | ||
project_id: Annotated[ | ||
str, | ||
typer.Option( | ||
"--project-id", | ||
"-p", | ||
help="The id of the project where the new work will be placed.", | ||
), | ||
], | ||
name: Annotated[ | ||
str, | ||
typer.Option( | ||
"--name", | ||
"-n", | ||
help="A readable name for the new work.", | ||
), | ||
], | ||
time: Annotated[ | ||
int, | ||
typer.Option( | ||
"--time", | ||
"-t", | ||
help="", | ||
), | ||
], | ||
from_date: Annotated[ | ||
datetime, | ||
typer.Option( | ||
"--from", | ||
help="", | ||
formats=["%Y-%m-%d"], | ||
), | ||
], | ||
to_date: Annotated[ | ||
datetime, | ||
typer.Option( | ||
"--to", | ||
help="", | ||
formats=["%Y-%m-%d"], | ||
), | ||
], | ||
description: Annotated[ | ||
str, | ||
typer.Option( | ||
"--description", | ||
"-d", | ||
help="", | ||
), | ||
] = "", | ||
rate: Annotated[ | ||
int, | ||
typer.Option( | ||
"--rate", | ||
"-r", | ||
help="", | ||
), | ||
] = 1, | ||
): | ||
projects_in_config = get_projects_from_config() | ||
|
||
if project_id in projects_in_config: | ||
details = get_project_from_config(project_id) | ||
|
||
# Check if project esists | ||
if details: | ||
works = get_project_works_from_config(project_id) | ||
|
||
# Check if id already exists | ||
if works is not None: | ||
work_ids = [w["id"] for w in works] | ||
if id in work_ids: | ||
rprint("") | ||
rprint( | ||
Panel.fit( | ||
title="[yellow]This work id already exists[/yellow]", | ||
renderable=print_with_padding( | ||
"You should change the id parameter or you can just use the work already in the configuration." | ||
), | ||
) | ||
) | ||
|
||
return | ||
|
||
new_work = Work( | ||
id=id, | ||
name=name, | ||
time=time, | ||
rate=rate, | ||
from_date=from_date.strftime("%Y-%d-%m"), | ||
to_date=to_date.strftime("%Y-%d-%m"), | ||
description=description, | ||
done=False, | ||
) | ||
|
||
if works is not None: | ||
works.append(new_work._asdict()) | ||
else: | ||
works = [new_work._asdict()] | ||
|
||
set_project_works_in_config(project_id, works) | ||
|
||
rprint("") | ||
rprint( | ||
Panel.fit( | ||
title="[green]Work created[/green]", | ||
renderable=print_with_padding(f"Work {id} created."), | ||
) | ||
) | ||
|
||
return | ||
else: | ||
rprint("") | ||
rprint( | ||
Panel.fit( | ||
title="[red]Error in config[/red]", | ||
renderable=print_with_padding( | ||
"Error in/with details file in project's configuration." | ||
), | ||
) | ||
) | ||
|
||
return | ||
else: | ||
print_missing_project(projects_in_config) | ||
|
||
def create_work(): | ||
rprint("Create a work") | ||
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from rich import print as rprint | ||
from rich.panel import Panel | ||
from trakcli.utils.print_with_padding import print_with_padding | ||
|
||
|
||
def print_missing_project(projects_in_config): | ||
renderable_projects_list = "\n • ".join(projects_in_config) | ||
rprint("") | ||
rprint( | ||
Panel.fit( | ||
title="[red]Missing project[/red]", | ||
renderable=print_with_padding( | ||
"This project doesn't exists.\n\n" | ||
f"Awailable projects: \n\n • {renderable_projects_list}\n\n\n\n" | ||
"Try to run the `trak create project <project name>` command if you want to create a new project." | ||
), | ||
) | ||
) | ||
|
||
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import typer | ||
|
||
from trakcli.works.commands.delete import delete_work | ||
from trakcli.works.commands.done import done_work | ||
from trakcli.works.commands.list import list_works | ||
|
||
app = typer.Typer() | ||
|
||
|
||
app.command("list")(list_works) | ||
app.command("delete")(delete_work) | ||
app.command("done")(done_work) |
Empty file.
Oops, something went wrong.