feat: add common view module

This commit is contained in:
2024-08-13 20:54:12 +03:00
parent bf51ddabc0
commit 05161749e8
19 changed files with 155 additions and 88 deletions
@@ -6,16 +6,18 @@ from fastapi.responses import HTMLResponse, RedirectResponse
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
from gallery.easel.route.view.weather.util import TagType, TagUtil
from gallery.sketch.schedule.api import ScheduleApi
from gallery.version import __version__
from ..common.util import TagType, TagUtil
from .filters import timedelta_format
def mount(app: FastAPI):
base_dir = Path(__file__).parent
app.mount(
"/schedule/static", StaticFiles(directory=base_dir / "static"), name="static"
)
app.mount("/static/schedule", StaticFiles(directory=base_dir / "static"))
templates = Jinja2Templates(directory=base_dir / "templates")
templates.env.filters["timedelta_format"] = timedelta_format
@app.get("/schedule", response_class=HTMLResponse)
async def get_schedule_list(request: Request):
@@ -25,6 +27,7 @@ def mount(app: FastAPI):
request=request,
name="index.html",
context={
"version": __version__,
"channels": channels,
},
)
@@ -45,6 +48,7 @@ def mount(app: FastAPI):
request=request,
name="schedule.html",
context={
"version": __version__,
"tag_util": TagUtil,
"datetime": datetime,
"response": response,
@@ -0,0 +1,5 @@
import datetime
def timedelta_format(value: datetime.timedelta) -> str:
return ":".join(str(value).split(":")[:2])
Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

@@ -1,21 +1,7 @@
body {
font-size: 1.5rem;
}
.app-container {
display: flex;
flex-direction: column;
flex-wrap: nowrap;
align-items: center;
}
table,
th,
td {
/* border: 1px solid rgba(0, 0, 0, 0.2); */
text-align: left;
}
td {
padding: 0.1rem 0.4rem;
tr.live {
font-weight: bold;
}
@@ -9,14 +9,16 @@
content="ie=edge">
<title>ТВ</title>
<link rel="stylesheet"
href="/schedule/static/style.css?v=1">
href="/static/common/style.css?v={{version}}">
<link rel="stylesheet"
href="/static/schedule/style.css?v={{version}}">
<link rel="icon"
href="/schedule/static/favicon.ico"
href="/static/common/favicon.ico"
type="image/x-icon">
</head>
<body class="app-container">
<ul>
<ul class="app-list">
{% for channel in channels %}
<li><a href="schedule/{{channel}}">{{channel}}</a></li>
{% endfor %}
@@ -9,28 +9,38 @@
content="ie=edge">
<title>Программа | {{response.channel.name}} | {{response.date.strftime('%a, %d %B %Y')}}</title>
<link rel="stylesheet"
href="/schedule/static/style.css?v=1">
href="/static/common/style.css?v={{version}}">
<link rel="stylesheet"
href="/static/schedule/style.css?v={{version}}">
<link rel="icon"
href="/schedule/static/favicon.ico"
href="/static/common/favicon.ico"
type="image/x-icon">
</head>
<body class="app-container">
<h3>
{{response.channel.name}} | {{response.date.strftime('%a, %d %B %Y')}}
<a class="button {{'disabled' if response.date == datetime.date.today() else ''}}"
href="../tag/{{tag_util.create_tag('day', response.date, -1)}}">⬅️</a>
<a class="button"
href="../..">⬆️</a>
<span>{{response.channel.name}} | {{response.date.strftime('%a, %d %B %Y')}}</span>
<a class="button"
href="../tag/{{tag_util.create_tag('day', response.date, 1)}}">➡️</a>
</h3>
<table>
<thead>
<tr>
<td>TIME</td>
<td>NAME</td>
<td></td>
<td></td>
<td></td>
</tr>
</thead>
<tbody>
{% for value in response.values %}
<tr>
<tr class="{{'live' if value.live else ''}}">
<td>{{value.start.strftime('%H:%M')}}</td>
<td>{{(value.end - value.start) | timedelta_format}}</td>
<td>{{value.label}}</td>
</tr>
{% endfor %}