Compare commits

...

3 Commits

3 changed files with 65 additions and 26 deletions

View File

@ -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

View File

@ -3,30 +3,53 @@
<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>
<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_message }}</li>
<li class="list-group-item">Действие: {{ task.type }}</li>
<li class="list-group-item">Сессия: {{ task.session.name }}</li>
</ul>
</div> </div>
<ul class="list-group list-group-flush">
<li class="list-group-item">Статус: {{ task.status }}</li>
<li class="list-group-item">Сообщение: {{ task.status_message }}</li>
<li class="list-group-item">Действие: {{ task.type }}</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>
<div class="card-body"> <div class="card-body">
<button <div class="btn-group mx-2" role="group">
hx-delete="/api/tasks/{{task.id}}" <button
hx-swap="delete" hx-delete="/api/tasks/{{task.id}}"
hx-target='[data-task="{{ task.id }}"]' hx-swap="delete"
hx-confirm="Вы уверены, что хотите удалить эту задачу?" hx-target='[data-task="{{ task.id }}"]'
class="btn btn-outline-danger mt-2 mx-2" hx-confirm="Вы уверены, что хотите удалить эту задачу?"
> class="btn btn-outline-danger"
Удалить >
</button> Удалить
<button hx-put="/api/tasks/{{task.id}}/stop" hx-swap="none" class="btn btn-outline-secondary mt-2 mx-2"> </button>
Стоп <button hx-put="/api/tasks/{{task.id}}/stop" hx-swap="none" class="btn btn-outline-secondary">
</button> Стоп
<button hx-put="/api/tasks/{{task.id}}/start" hx-swap="none" class="btn btn-outline-success mt-2 mx-2"> </button>
Запустить <button hx-put="/api/tasks/{{task.id}}/start" hx-swap="none" class="btn btn-outline-success">
</button> Запустить
</button>
</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>
</div> </div>

View File

@ -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]