- Load time entry activity names from Redmine enumeration. - Aggregate hours per issue and per activity in fetch_issues_with_spent_time. - Add --by-activity CLI flag and propagate it through report builder, summary, and all formatters (console, CSV, HTML, JSON, ODT). - Keep backward-compatible 2-tuple input in build_grouped_report. - Bump version to 1.8.0. Closes #41
50 lines
2.0 KiB
Python
50 lines
2.0 KiB
Python
from typing import List
|
|
|
|
from tabulate import tabulate
|
|
|
|
from ..types import ReportRow
|
|
from .base import Formatter
|
|
|
|
|
|
class TableFormatter(Formatter):
|
|
"""Форматтер для вывода красивой таблицы в консоль."""
|
|
|
|
def format(self, rows: List[ReportRow]) -> str:
|
|
table_rows = [["Проект", "Версия", "Задача", "Статус", "Затрачено"]]
|
|
for r in rows:
|
|
time_text = r["time_text"].replace("\n", " / ")
|
|
table_rows.append(
|
|
[
|
|
r["display_project"],
|
|
r["display_version"],
|
|
f"{r['issue_id']}. {r['subject']}",
|
|
r["status_ru"],
|
|
time_text,
|
|
]
|
|
)
|
|
return tabulate(table_rows, headers="firstrow", tablefmt="fancy_grid")
|
|
|
|
def save(self, rows: List[ReportRow], output_path: str) -> None:
|
|
# Консольные форматтеры не умеют сохранять в файл напрямую.
|
|
# Это делается в CLI.
|
|
raise NotImplementedError("TableFormatter не поддерживает сохранение в файл.")
|
|
|
|
|
|
class CompactFormatter(Formatter):
|
|
"""Форматтер для компактного вывода в консоль."""
|
|
|
|
def format(self, rows: List[ReportRow]) -> str:
|
|
lines = []
|
|
for r in rows:
|
|
time_text = r["time_text"].replace("\n", " / ")
|
|
lines.append(
|
|
f"{r['display_project']} | {r['display_version']} | "
|
|
f"{r['issue_id']}. {r['subject']} | {r['status_ru']} | {time_text}"
|
|
)
|
|
return "\n".join(lines)
|
|
|
|
def save(self, rows: List[ReportRow], output_path: str) -> None:
|
|
# Консольные форматтеры не умеют сохранять в файл напрямую.
|
|
# Это делается в CLI.
|
|
raise NotImplementedError("CompactFormatter не поддерживает сохранение в файл.")
|