Team Hoa, EPIC R08 (UI/Application Separation) - Team Hoa scope only
(R08-T11 -> T14; R08-T01->T10 belong to Team Duy/Team Nam).
- R08-T11: ui/schedule_task_tab.py (795 lines) -> presentation/scheduling/
{kanban_board_widget,calendar_view_widget,ai_task_creator_dialog,
ai_task_import_dialog,run_history_dialog}.py + schedule_task_tab.py
shell. Kanban CRUD/drag-drop now goes through
application/scheduling/task_application_service.py (R07-T04) instead of
~30 lines of inline if/elif per drag target.
- R08-T12: ui/folder_tab.py (1587 lines, the largest of the four) ->
presentation/folder/{workspace_file_tree,document_preview_manager,
code_editor,office_document_renderer,ai_file_editor_dialog,
ai_edit_model_resolver,ai_edit_pipeline}.py + folder_tab.py shell.
Closes the R06-T05 loop: FileWorkspaceService existed since R06 with
zero production call sites (confirmed by grep); every plain-text write
(save/create/write_content) now goes through it, gaining path
containment and a Python-syntax warning the original code never had.
Pure helpers (_read_text, _is_probably_text, _pptx_available,
_split_code_block, _parse_ai_output) moved to
application/workspaces/{file_preview_helpers,ai_edit_output}.py.
- R08-T13: ui/dashboard_tab.py (437 lines) -> presentation/dashboard/
{token_usage_card_widget,usage_chart_widget,habits_widget}.py +
dashboard_tab.py shell, backed by a new
application/monitoring/dashboard_query_service.py (pricing/period/
summary queries the three widgets used to each recompute separately).
Directory-ownership note left in the checklist for Team Nam.
- R08-T14: ui/structure_graph_view.py (1035 lines) ->
presentation/graph/{graph_scene_items,graph_renderer,
graph_messages_view,graph_qa_widget}.py + structure_graph_view.py
shell. Extraction helpers (_pdf_to_markdown, _extract_file_contents)
moved to application/workspaces/graph_index_service.py (pure Python).
Renderer and Q&A panel talk only through signals
(node_selected/graph_rendered/raw_json_ready/project_changed) - neither
imports the other.
- presentation/shared/web_engine_support.py: HAS_WEB_ENGINE, previously
duplicated (folder_tab imported it FROM structure_graph_view.py) - now
one shared flag instead of one screen importing another screen's module.
All four old ui/*.py files deleted; app.py and ui/workspace_tab.py updated
to the new import paths (each god-file only had 1-2 real construction
sites, so import sites were updated directly rather than kept as a
strangler-fig shim - unlike core/tools.py at R05, which had dozens).
pytest: 377 pass (+94 vs the R07 baseline of 328; same 4 pre-existing
failures as the R05/R06 baseline, unrelated to this work).
scripts/check_imports.py: PASS. python -c "import cowork_local.app": OK.
Every new file < 400 lines (largest: graph_renderer.py, 391).
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
149 lines
5.6 KiB
Python
149 lines
5.6 KiB
Python
"""Import-from-file tab content for AI Create Task (R08-T11, extracted from
|
|
``ui/schedule_task_tab.py``'s ``_AiCreateDialog`` — the Import tab + its
|
|
``_DropZone``, lines 551-576/643-665/674-720 of the original file).
|
|
|
|
:class:`ImportTaskPanel` is a plain ``QWidget`` (not its own dialog) so
|
|
``ai_task_creator_dialog.py`` can embed it as one tab of the single AI-create
|
|
dialog the user sees — the two files are a code split, not a UX split; there
|
|
is still one dialog with two tabs, exactly as before.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
from typing import List
|
|
|
|
from PySide6.QtCore import Signal
|
|
from PySide6.QtWidgets import (
|
|
QHBoxLayout, QLabel, QMessageBox, QPlainTextEdit, QPushButton,
|
|
QVBoxLayout, QWidget,
|
|
)
|
|
|
|
from cowork_local.application.scheduling.ai_task_planner_service import (
|
|
AiTaskPlannerService,
|
|
)
|
|
from cowork_local.i18n import tr
|
|
from cowork_local.theme import current_palette
|
|
from cowork_local.ui.icons import icon
|
|
from cowork_local.ui.osutil import open_path
|
|
|
|
|
|
class _DropZone(QLabel):
|
|
"""Drag-an-.xlsx-here area for the Import tab."""
|
|
|
|
file_dropped = Signal(str)
|
|
|
|
def __init__(self):
|
|
super().__init__()
|
|
from PySide6.QtCore import Qt
|
|
|
|
self.setAlignment(Qt.AlignCenter)
|
|
self.setMinimumHeight(70)
|
|
_p = current_palette()
|
|
self.setStyleSheet(
|
|
f"QLabel {{ border: 1px dashed {_p.border_strong};"
|
|
f" border-radius: {_p.radius_lg}px;"
|
|
f" color: {_p.text_muted}; padding: 10px; }}")
|
|
self.setAcceptDrops(True)
|
|
|
|
def dragEnterEvent(self, event): # noqa: N802
|
|
urls = event.mimeData().urls()
|
|
if urls and urls[0].toLocalFile().lower().endswith(
|
|
(".xlsx", ".xlsm", ".xls", ".csv", ".json")):
|
|
event.acceptProposedAction()
|
|
|
|
def dropEvent(self, event): # noqa: N802
|
|
urls = event.mimeData().urls()
|
|
if urls:
|
|
self.file_dropped.emit(urls[0].toLocalFile())
|
|
|
|
|
|
class ImportTaskPanel(QWidget):
|
|
"""Pick/drag an Excel/CSV/JSON file, preview the tasks it maps to, and
|
|
hold that NOT-yet-saved list — the dialog reads :attr:`planned` when the
|
|
user confirms.
|
|
|
|
Args:
|
|
planner: an ``AiTaskPlannerService`` — ``import_file`` is called
|
|
through it (R07-T05) rather than ``core.task_import`` directly.
|
|
"""
|
|
|
|
tasks_changed = Signal(bool) # True when the current preview has >=1 valid task
|
|
|
|
def __init__(self, planner: AiTaskPlannerService, parent=None):
|
|
super().__init__(parent)
|
|
self._planner = planner
|
|
self.planned: List[dict] = []
|
|
|
|
il = QVBoxLayout(self)
|
|
tpl_btn = QPushButton(tr("schedtask.export_template_btn"))
|
|
tpl_btn.setIcon(icon("upload"))
|
|
tpl_btn.clicked.connect(self._export_template)
|
|
il.addWidget(tpl_btn)
|
|
pick_row = QHBoxLayout()
|
|
pick_btn = QPushButton(tr("schedtask.import_pick_btn"))
|
|
pick_btn.setIcon(icon("folder"))
|
|
pick_btn.clicked.connect(self._pick_import_file)
|
|
pick_row.addWidget(pick_btn)
|
|
pick_row.addStretch(1)
|
|
il.addLayout(pick_row)
|
|
self.drop_zone = _DropZone()
|
|
self.drop_zone.setText(tr("schedtask.drop_hint"))
|
|
self.drop_zone.file_dropped.connect(self._load_import_file)
|
|
il.addWidget(self.drop_zone)
|
|
il.addWidget(QLabel(tr("schedtask.ai_preview_label")))
|
|
self.preview = QPlainTextEdit()
|
|
self.preview.setReadOnly(True)
|
|
il.addWidget(self.preview, 1)
|
|
|
|
def _export_template(self) -> None:
|
|
from PySide6.QtWidgets import QFileDialog
|
|
|
|
from cowork_local.core.task_excel import export_template
|
|
|
|
path, _ = QFileDialog.getSaveFileName(
|
|
self, tr("schedtask.export_template_btn"),
|
|
"cowork_tasks_template.xlsx", "Excel (*.xlsx)")
|
|
if not path:
|
|
return
|
|
try:
|
|
export_template(path)
|
|
open_path(str(Path(path).parent))
|
|
except Exception as exc: # noqa: BLE001
|
|
QMessageBox.warning(self, tr("schedtask.tab_import"), str(exc))
|
|
|
|
def _pick_import_file(self) -> None:
|
|
from PySide6.QtWidgets import QFileDialog
|
|
|
|
from cowork_local.core.task_import import IMPORT_FILTER
|
|
|
|
path, _ = QFileDialog.getOpenFileName(
|
|
self, tr("schedtask.import_pick_btn"), "", IMPORT_FILTER)
|
|
if path:
|
|
self._load_import_file(path)
|
|
|
|
def _load_import_file(self, path: str) -> None:
|
|
try:
|
|
self.planned = self._planner.import_file(path)
|
|
except ValueError as exc:
|
|
# Same as the original single-class dialog: a bad file leaves
|
|
# whatever was previously loaded in `planned` untouched (only the
|
|
# preview text and the Ok button reflect the failure) rather than
|
|
# discarding a prior successful load.
|
|
self.preview.setPlainText(str(exc))
|
|
self.tasks_changed.emit(False)
|
|
return
|
|
by_id = {t["task_id"]: t["title"] for t in self.planned}
|
|
lines = []
|
|
for i, t in enumerate(self.planned, 1):
|
|
sched = t.get("schedule", {})
|
|
when = sched.get("run_at") if sched.get("enabled") else tr("schedtask.no_schedule")
|
|
deps = t.get("dependency", {}).get("depends_on") or []
|
|
dep_note = (" ← depends: " + ", ".join(by_id.get(d, "?") for d in deps)) if deps else ""
|
|
lines.append(f"{i}. [{t.get('task_type')}] {t.get('title')}\n"
|
|
f" {when} repeat={sched.get('repeat_type', 'none')}{dep_note}")
|
|
self.preview.setPlainText("\n\n".join(lines))
|
|
self.tasks_changed.emit(bool(self.planned))
|
|
|
|
|
|
__all__ = ["ImportTaskPanel"]
|