condash 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- condash/__init__.py +3 -0
- condash/__main__.py +4 -0
- condash/app.py +189 -0
- condash/assets/dashboard.html +1264 -0
- condash/assets/favicon.ico +0 -0
- condash/assets/favicon.svg +6 -0
- condash/cli.py +223 -0
- condash/config.py +130 -0
- condash/legacy.py +1300 -0
- condash-0.1.0.dist-info/METADATA +96 -0
- condash-0.1.0.dist-info/RECORD +14 -0
- condash-0.1.0.dist-info/WHEEL +4 -0
- condash-0.1.0.dist-info/entry_points.txt +2 -0
- condash-0.1.0.dist-info/licenses/LICENSE +21 -0
condash/__init__.py
ADDED
condash/__main__.py
ADDED
condash/app.py
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"""NiceGUI-backed native window for condash.
|
|
2
|
+
|
|
3
|
+
The existing ``dashboard.html`` is served verbatim at ``/``; all the AJAX
|
|
4
|
+
endpoints the JS calls (``/toggle``, ``/add-step``, ``/tidy``, …) are
|
|
5
|
+
re-implemented here as FastAPI routes on top of NiceGUI's underlying
|
|
6
|
+
FastAPI instance.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
from fastapi import Request
|
|
12
|
+
from fastapi.responses import HTMLResponse, JSONResponse, Response
|
|
13
|
+
from nicegui import app as _ng_app
|
|
14
|
+
from nicegui import ui
|
|
15
|
+
|
|
16
|
+
from . import legacy
|
|
17
|
+
from .config import CondashConfig
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _error(status: int, message: str) -> JSONResponse:
|
|
21
|
+
return JSONResponse(status_code=status, content={"error": message})
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _register_routes() -> None:
|
|
25
|
+
"""Attach all API routes to NiceGUI's FastAPI instance."""
|
|
26
|
+
|
|
27
|
+
@_ng_app.get("/", response_class=HTMLResponse)
|
|
28
|
+
def index():
|
|
29
|
+
items = legacy.collect_items()
|
|
30
|
+
return HTMLResponse(content=legacy.render_page(items))
|
|
31
|
+
|
|
32
|
+
@_ng_app.get("/favicon.svg")
|
|
33
|
+
def favicon_svg():
|
|
34
|
+
data = legacy._favicon_bytes()
|
|
35
|
+
if data is None:
|
|
36
|
+
return Response(status_code=404)
|
|
37
|
+
return Response(
|
|
38
|
+
content=data,
|
|
39
|
+
media_type="image/svg+xml",
|
|
40
|
+
headers={"Cache-Control": "public, max-age=86400"},
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
@_ng_app.get("/favicon.ico")
|
|
44
|
+
def favicon_ico():
|
|
45
|
+
data = legacy._favicon_bytes()
|
|
46
|
+
if data is None:
|
|
47
|
+
return Response(status_code=404)
|
|
48
|
+
return Response(content=data, media_type="image/svg+xml")
|
|
49
|
+
|
|
50
|
+
@_ng_app.get("/check-updates")
|
|
51
|
+
def check_updates():
|
|
52
|
+
items = legacy.collect_items()
|
|
53
|
+
return {
|
|
54
|
+
"fingerprint": legacy._compute_fingerprint(items),
|
|
55
|
+
"tidy_needed": legacy._tidy_needed(items),
|
|
56
|
+
"git_fingerprint": legacy._git_fingerprint(),
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@_ng_app.get("/note")
|
|
60
|
+
def get_note(path: str = ""):
|
|
61
|
+
full = legacy.validate_note_path(path)
|
|
62
|
+
if full is None:
|
|
63
|
+
return Response(status_code=403)
|
|
64
|
+
return HTMLResponse(content=legacy._render_note(full))
|
|
65
|
+
|
|
66
|
+
@_ng_app.get("/download/{rel_path:path}")
|
|
67
|
+
def download(rel_path: str):
|
|
68
|
+
full = legacy.validate_download_path(rel_path)
|
|
69
|
+
if full is None:
|
|
70
|
+
return Response(status_code=403)
|
|
71
|
+
return Response(
|
|
72
|
+
content=full.read_bytes(),
|
|
73
|
+
media_type="application/pdf",
|
|
74
|
+
headers={"Content-Disposition": f'inline; filename="{full.name}"'},
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
@_ng_app.get("/asset/{rel_path:path}")
|
|
78
|
+
def asset(rel_path: str):
|
|
79
|
+
result = legacy.validate_asset_path(rel_path)
|
|
80
|
+
if result is None:
|
|
81
|
+
return Response(status_code=403)
|
|
82
|
+
full, ctype = result
|
|
83
|
+
return Response(
|
|
84
|
+
content=full.read_bytes(),
|
|
85
|
+
media_type=ctype,
|
|
86
|
+
headers={"Cache-Control": "public, max-age=300"},
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
@_ng_app.post("/toggle")
|
|
90
|
+
async def toggle(req: Request):
|
|
91
|
+
data = await req.json()
|
|
92
|
+
full = legacy._validate_path(data.get("file", ""))
|
|
93
|
+
if not full:
|
|
94
|
+
return _error(400, "invalid path")
|
|
95
|
+
status = legacy._toggle_checkbox(full, data.get("line", -1))
|
|
96
|
+
if status is None:
|
|
97
|
+
return _error(400, "not a checkbox line")
|
|
98
|
+
return {"ok": True, "status": status}
|
|
99
|
+
|
|
100
|
+
@_ng_app.post("/remove-step")
|
|
101
|
+
async def remove_step(req: Request):
|
|
102
|
+
data = await req.json()
|
|
103
|
+
full = legacy._validate_path(data.get("file", ""))
|
|
104
|
+
if not full:
|
|
105
|
+
return _error(400, "invalid path")
|
|
106
|
+
if legacy._remove_step(full, data.get("line", -1)):
|
|
107
|
+
return {"ok": True}
|
|
108
|
+
return _error(400, "cannot remove")
|
|
109
|
+
|
|
110
|
+
@_ng_app.post("/edit-step")
|
|
111
|
+
async def edit_step(req: Request):
|
|
112
|
+
data = await req.json()
|
|
113
|
+
text = (data.get("text") or "").strip()
|
|
114
|
+
if not text:
|
|
115
|
+
return _error(400, "empty text")
|
|
116
|
+
full = legacy._validate_path(data.get("file", ""))
|
|
117
|
+
if not full:
|
|
118
|
+
return _error(400, "invalid path")
|
|
119
|
+
if legacy._edit_step(full, data.get("line", -1), text):
|
|
120
|
+
return {"ok": True}
|
|
121
|
+
return _error(400, "cannot edit")
|
|
122
|
+
|
|
123
|
+
@_ng_app.post("/add-step")
|
|
124
|
+
async def add_step(req: Request):
|
|
125
|
+
data = await req.json()
|
|
126
|
+
text = (data.get("text") or "").strip()
|
|
127
|
+
if not text:
|
|
128
|
+
return _error(400, "empty text")
|
|
129
|
+
full = legacy._validate_path(data.get("file", ""))
|
|
130
|
+
if not full:
|
|
131
|
+
return _error(400, "invalid path")
|
|
132
|
+
line = legacy._add_step(full, text, data.get("section"))
|
|
133
|
+
return {"ok": True, "line": line}
|
|
134
|
+
|
|
135
|
+
@_ng_app.post("/set-priority")
|
|
136
|
+
async def set_priority(req: Request):
|
|
137
|
+
data = await req.json()
|
|
138
|
+
full = legacy._validate_path(data.get("file", ""))
|
|
139
|
+
if not full:
|
|
140
|
+
return _error(400, "invalid path")
|
|
141
|
+
priority = data.get("priority", "")
|
|
142
|
+
if legacy._set_priority(full, priority):
|
|
143
|
+
moves = legacy._tidy()
|
|
144
|
+
return {"ok": True, "priority": priority, "moved": bool(moves)}
|
|
145
|
+
return _error(400, "invalid priority")
|
|
146
|
+
|
|
147
|
+
@_ng_app.post("/reorder-all")
|
|
148
|
+
async def reorder_all(req: Request):
|
|
149
|
+
data = await req.json()
|
|
150
|
+
full = legacy._validate_path(data.get("file", ""))
|
|
151
|
+
if not full:
|
|
152
|
+
return _error(400, "invalid path")
|
|
153
|
+
order = data.get("order") or []
|
|
154
|
+
if legacy._reorder_all(full, order):
|
|
155
|
+
return {"ok": True}
|
|
156
|
+
return _error(400, "cannot reorder")
|
|
157
|
+
|
|
158
|
+
@_ng_app.post("/open")
|
|
159
|
+
async def open_path(req: Request):
|
|
160
|
+
data = await req.json()
|
|
161
|
+
resolved = legacy._validate_open_path(data.get("path", ""))
|
|
162
|
+
if not resolved:
|
|
163
|
+
return _error(400, "invalid path")
|
|
164
|
+
tool = data.get("tool", "")
|
|
165
|
+
if legacy._open_path(tool, resolved):
|
|
166
|
+
return {"ok": True}
|
|
167
|
+
return _error(500, f"could not launch {tool}")
|
|
168
|
+
|
|
169
|
+
@_ng_app.post("/tidy")
|
|
170
|
+
async def tidy(_req: Request):
|
|
171
|
+
moves = legacy._tidy()
|
|
172
|
+
return {
|
|
173
|
+
"ok": True,
|
|
174
|
+
"moves": [{"from": f, "to": t} for f, t in moves],
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def run(cfg: CondashConfig) -> None:
|
|
179
|
+
"""Launch the native condash window."""
|
|
180
|
+
legacy.init(cfg)
|
|
181
|
+
_register_routes()
|
|
182
|
+
ui.run(
|
|
183
|
+
native=True,
|
|
184
|
+
title="condash",
|
|
185
|
+
window_size=(1400, 900),
|
|
186
|
+
reload=False,
|
|
187
|
+
show=False,
|
|
188
|
+
port=0,
|
|
189
|
+
)
|