Compare commits
3 Commits
5e1f0c1f56
...
f83a2ae152
Author | SHA1 | Date |
---|---|---|
Анатолий Богомолов | f83a2ae152 | |
Анатолий Богомолов | 8ce11f337a | |
Анатолий Богомолов | 495812a2a6 |
|
@ -12,8 +12,9 @@ tasks = Blueprint("tasks", __name__, url_prefix="/tasks", template_folder="templ
|
||||||
@tasks.route("/", methods=["GET"])
|
@tasks.route("/", methods=["GET"])
|
||||||
def get_tasks():
|
def get_tasks():
|
||||||
tasks = Task.query.all()
|
tasks = Task.query.all()
|
||||||
|
sessions = Session.query.all()
|
||||||
|
|
||||||
return render_template("tasks_cards.j2", tasks=tasks)
|
return render_template("tasks_cards.j2", tasks=tasks, sessions=sessions)
|
||||||
|
|
||||||
@tasks.route("/<int:task_id>", methods=["GET"])
|
@tasks.route("/<int:task_id>", methods=["GET"])
|
||||||
def get_task(task_id: int):
|
def get_task(task_id: int):
|
||||||
|
@ -62,7 +63,7 @@ def stop_task(task_id: int):
|
||||||
case 'add':
|
case 'add':
|
||||||
fn = add_to_group_task
|
fn = add_to_group_task
|
||||||
|
|
||||||
if task.task_id:
|
if task.task_id and fn:
|
||||||
task_fn = fn.AsyncResult(task.task_id)
|
task_fn = fn.AsyncResult(task.task_id)
|
||||||
task_fn.abort()
|
task_fn.abort()
|
||||||
|
|
||||||
|
@ -86,3 +87,18 @@ def start_task(task_id: int):
|
||||||
add_to_group_task.delay(task_id=task_id)
|
add_to_group_task.delay(task_id=task_id)
|
||||||
|
|
||||||
return 'Started', 200
|
return 'Started', 200
|
||||||
|
|
||||||
|
@tasks.route("/<int:task_id>/change", methods=["PUT"])
|
||||||
|
def change_settings(task_id: int):
|
||||||
|
task: Task = Task.query.get_or_404(task_id)
|
||||||
|
data = request.form
|
||||||
|
|
||||||
|
if data.get("session"):
|
||||||
|
task.session = Session.query.get(data.get("session"))
|
||||||
|
|
||||||
|
if data.get("name"):
|
||||||
|
task.name = data.get("name")
|
||||||
|
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
return 'Changed', 200
|
|
@ -3,32 +3,55 @@
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<h3 class="card-title">{{ task.name }}</h3>
|
<h3 class="card-title">{{ task.name }}</h3>
|
||||||
|
</div>
|
||||||
<ul class="list-group list-group-flush">
|
<ul class="list-group list-group-flush">
|
||||||
<li class="list-group-item">Дата и время: {{ task.datetime }}</li>
|
|
||||||
<li class="list-group-item">Статус: {{ task.status }}</li>
|
<li class="list-group-item">Статус: {{ task.status }}</li>
|
||||||
<li class="list-group-item">Сообщение: {{ task.status_message }}</li>
|
<li class="list-group-item">Сообщение: {{ task.status_message }}</li>
|
||||||
<li class="list-group-item">Действие: {{ task.type }}</li>
|
<li class="list-group-item">Действие: {{ task.type }}</li>
|
||||||
<li class="list-group-item">Сессия: {{ task.session.name }}</li>
|
|
||||||
|
<li class="list-group-item">
|
||||||
|
<label class="form-label">Сессия:</label>
|
||||||
|
<select
|
||||||
|
name="session"
|
||||||
|
hx-put="/api/tasks/{{task.id}}/change"
|
||||||
|
hx-trigger="change"
|
||||||
|
hx-confirm="Вы уверены, что хотите поменять сессию?"
|
||||||
|
hx-swap="none"
|
||||||
|
class="form-select form-select-lg mb-3"
|
||||||
|
>
|
||||||
|
{% for session in sessions %}
|
||||||
|
{% if task.session.name == session.name %}
|
||||||
|
<option selected value="{{ session.id }}">{{ session.name }}</option>
|
||||||
|
{% else %}
|
||||||
|
<option value="{{ session.id }}">{{ session.name }}</option>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
|
<div class="btn-group mx-2" role="group">
|
||||||
<button
|
<button
|
||||||
hx-delete="/api/tasks/{{task.id}}"
|
hx-delete="/api/tasks/{{task.id}}"
|
||||||
hx-swap="delete"
|
hx-swap="delete"
|
||||||
hx-target='[data-task="{{ task.id }}"]'
|
hx-target='[data-task="{{ task.id }}"]'
|
||||||
hx-confirm="Вы уверены, что хотите удалить эту задачу?"
|
hx-confirm="Вы уверены, что хотите удалить эту задачу?"
|
||||||
class="btn btn-outline-danger mt-2 mx-2"
|
class="btn btn-outline-danger"
|
||||||
>
|
>
|
||||||
Удалить
|
Удалить
|
||||||
</button>
|
</button>
|
||||||
<button hx-put="/api/tasks/{{task.id}}/stop" hx-swap="none" class="btn btn-outline-secondary mt-2 mx-2">
|
<button hx-put="/api/tasks/{{task.id}}/stop" hx-swap="none" class="btn btn-outline-secondary">
|
||||||
Стоп
|
Стоп
|
||||||
</button>
|
</button>
|
||||||
<button hx-put="/api/tasks/{{task.id}}/start" hx-swap="none" class="btn btn-outline-success mt-2 mx-2">
|
<button hx-put="/api/tasks/{{task.id}}/start" hx-swap="none" class="btn btn-outline-success">
|
||||||
Запустить
|
Запустить
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="card-footer">
|
||||||
|
<small class="text-body-secondary">Создано {{ task.datetime.strftime("%d.%m.%y") }} в {{ task.datetime.strftime("%H:%M") }}</small>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% else %}
|
{% else %}
|
||||||
<small id="helpId" class="form-text">Здесь ничего нет.</small>
|
<small id="helpId" class="form-text">Здесь ничего нет.</small>
|
||||||
|
|
|
@ -13,7 +13,7 @@ class Task(db.Model):
|
||||||
|
|
||||||
session_id = Column(Integer, ForeignKey("session.id"))
|
session_id = Column(Integer, ForeignKey("session.id"))
|
||||||
session: Mapped['Session'] = relationship("Session", back_populates="tasks")
|
session: Mapped['Session'] = relationship("Session", back_populates="tasks")
|
||||||
datetime: Mapped[DateTime] = Column(DateTime, default=datetime.datetime.utcnow().strftime("%d.%m.%y %H:%M"))
|
datetime: Mapped[DateTime] = Column(DateTime, default=datetime.datetime.utcnow())
|
||||||
status: Mapped[str]
|
status: Mapped[str]
|
||||||
status_message: Mapped[str]
|
status_message: Mapped[str]
|
||||||
type: Mapped[str]
|
type: Mapped[str]
|
||||||
|
|
Loading…
Reference in New Issue