Skip to content

Commit

Permalink
feat: archived projects feature
Browse files Browse the repository at this point in the history
  • Loading branch information
lcfd committed Apr 16, 2024
1 parent 5e3f6af commit bc71c45
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 48 deletions.
10 changes: 9 additions & 1 deletion cli/trakcli/create/commands/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,18 @@ def create_session(
help="Check the session you are about to create, without save it.",
),
] = False,
archived: Annotated[
Optional[bool],
typer.Option(
"--archived",
"-a",
help="Show archived projects in lists.",
),
] = False,
):
#
# Project checking
projects_in_config = get_projects_from_config()
projects_in_config = get_projects_from_config(archived)

# Check if there are configured projects
if not len(projects_in_config):
Expand Down
12 changes: 10 additions & 2 deletions cli/trakcli/create/commands/work.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime
from typing import Annotated
from typing import Annotated, Optional

import typer
from rich import print as rprint
Expand Down Expand Up @@ -76,8 +76,16 @@ def create_work(
help="",
),
] = 1,
archived: Annotated[
Optional[bool],
typer.Option(
"--archived",
"-a",
help="Show archived projects in lists.",
),
] = False,
):
projects_in_config = get_projects_from_config()
projects_in_config = get_projects_from_config(archived)

if project_id in projects_in_config:
details = get_project_from_config(project_id)
Expand Down
40 changes: 13 additions & 27 deletions cli/trakcli/projects/commands.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pathlib
import shutil
from typing import Annotated, Optional

import typer
from rich import print as rprint
Expand All @@ -8,26 +9,30 @@

from trakcli.config.main import (
TRAK_FOLDER,
get_db_file_path,
)
from trakcli.projects.database import (
get_projects_from_config,
get_projects_from_db,
)
from trakcli.utils.print_with_padding import print_with_padding

app = typer.Typer()


@app.command(help="List your projects.")
def list():
def list(
archived: Annotated[
Optional[bool],
typer.Option(
"--archived",
"-a",
help="Show archived projects in lists.",
),
] = False,
):
"""List the projects."""

db_path = get_db_file_path()

projects_in_db = get_projects_from_db(db_path)
projects_in_config = get_projects_from_config()
combined = {*projects_in_db, *projects_in_config}
projects_in_config = get_projects_from_config(archived)
combined = {*projects_in_config}

number_of_projects = len(combined)

Expand All @@ -41,27 +46,8 @@ def list():
for project in projects_in_config:
table.add_row(project, "config")

projects_id_db_only = False
for project in projects_in_db:
if project not in projects_in_config:
projects_id_db_only = True
table.add_row(project, "database")

rprint("")
rprint(table)
rprint("")
if projects_id_db_only:
rprint(
Panel.fit(
title="Tip",
renderable=print_with_padding(
(
"You have projects that don't exist in configuration.\n"
"Plase, run the `trak create project <project-id>` command to configure your project."
)
),
)
)


@app.command(help="Delete a project.")
Expand Down
8 changes: 5 additions & 3 deletions cli/trakcli/projects/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


def get_projects_from_db(db_path: Path):
"""Get the projects in the database."""
"""Deprecated. Get the projects in the database."""

with open(db_path, "r") as db:
db_content = db.read()
Expand All @@ -16,7 +16,7 @@ def get_projects_from_db(db_path: Path):
return {record.get("project", "") for record in parsed_json}


def get_projects_from_config():
def get_projects_from_config(archived: bool | None = False):
"""Get the projects in the config."""

projects_path = pathlib.Path(TRAK_FOLDER / "projects")
Expand All @@ -28,7 +28,9 @@ def get_projects_from_config():
details_path = x / "details.json"
with open(details_path, "r") as f:
details = json.load(f)
projects.append(details.get("id", "ERROR: No id!"))

if not details.get("archived") or archived:
projects.append(details.get("id", "ERROR: No id!"))

return projects

Expand Down
12 changes: 10 additions & 2 deletions cli/trakcli/report/commands/report_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,23 @@ def report_project(
formats=["%Y-%m-%d"],
),
] = None,
archived: Annotated[
Optional[bool],
typer.Option(
"--archived",
"-a",
help="Show archived projects in lists.",
),
] = False,
):
"""
Get reports for your projects.
The projects will be get by the configuration in the .trak folder.
"""

projects_in_config = get_projects_from_config()
projects_in_config = get_projects_from_config(archived)

projects_in_config.append("all")
projects_in_config.append(ALL_PROJECTS)

# Check if there are configured projects
if not len(projects_in_config):
Expand Down
10 changes: 9 additions & 1 deletion cli/trakcli/tracker/commands/start_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,20 @@ def start_tracker(
help="Add a tag to the tracked time. Useful in the reporting phase.",
),
] = "",
archived: Annotated[
Optional[bool],
typer.Option(
"--archived",
"-a",
help="Show archived projects in lists.",
),
] = False,
):
"""
Start tracking a project by project_id.
"""

projects_in_config = get_projects_from_config()
projects_in_config = get_projects_from_config(archived)

if not project:
project = questionary.select(
Expand Down
19 changes: 13 additions & 6 deletions cli/trakcli/works/commands/delete.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from typing import Annotated
from rich.panel import Panel
from trakcli.projects.utils.print_missing_project import print_missing_project
from rich.prompt import Confirm

from typing import Annotated, Optional

import typer
from rich import print as rprint
from rich.panel import Panel
from rich.prompt import Confirm

from trakcli.projects.database import get_projects_from_config
from trakcli.projects.utils.print_missing_project import print_missing_project
from trakcli.works.database import (
get_project_works_from_config,
set_project_works_in_config,
Expand All @@ -22,10 +21,18 @@ def delete_work(
"--in", "--of", "-p", help="The project's id in which the work is located."
),
],
archived: Annotated[
Optional[bool],
typer.Option(
"--archived",
"-a",
help="Show archived projects in lists.",
),
] = False,
):
"""Delete a work from a project."""

projects = get_projects_from_config()
projects = get_projects_from_config(archived)

if project_id in projects:
delete = Confirm.ask(
Expand Down
12 changes: 10 additions & 2 deletions cli/trakcli/works/commands/done.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Annotated
from typing import Annotated, Optional

import typer
from rich import print as rprint
Expand All @@ -22,10 +22,18 @@ def done_work(
"--in", "--of", "-p", help="The project's id in which the work is located."
),
],
archived: Annotated[
Optional[bool],
typer.Option(
"--archived",
"-a",
help="Show archived projects in lists.",
),
] = False,
):
"""Mark as done a work of a project."""

projects = get_projects_from_config()
projects = get_projects_from_config(archived)

if project_id in projects:
confirm_done = Confirm.ask(
Expand Down
12 changes: 10 additions & 2 deletions cli/trakcli/works/commands/list.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime
from typing import Annotated
from typing import Annotated, Optional
from rich.panel import Panel
from trakcli.projects.utils.print_missing_project import print_with_padding

Expand Down Expand Up @@ -87,6 +87,14 @@ def list_works(
done: Annotated[
bool, typer.Option("--done", "-d", help="Show also done works.")
] = False,
archived: Annotated[
Optional[bool],
typer.Option(
"--archived",
"-a",
help="Show archived projects in lists.",
),
] = False,
):
"""List the works in a project or all of them."""

Expand All @@ -105,7 +113,7 @@ def list_works(
return
else:
# Show all current projects
projects = get_projects_from_config()
projects = get_projects_from_config(archived)

for project in projects:
works = get_project_works_from_config(project)
Expand Down
12 changes: 10 additions & 2 deletions cli/trakcli/works/commands/paid.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Annotated
from typing import Annotated, Optional

import typer
from rich import print as rprint
Expand All @@ -22,10 +22,18 @@ def paid_work(
"--in", "--of", "-p", help="The project's id in which the work is located."
),
],
archived: Annotated[
Optional[bool],
typer.Option(
"--archived",
"-a",
help="Show archived projects in lists.",
),
] = False,
):
"""Mark a work of a project as paid."""

projects = get_projects_from_config()
projects = get_projects_from_config(archived)

if project_id in projects:
confirm_done = Confirm.ask(
Expand Down

0 comments on commit bc71c45

Please sign in to comment.