- academic: POST /api/v1/content/reorder applies a full tree arrangement in one request — chapter order, section order and section->chapter moves, article order and article->section moves (positions and parent ids updated) - web: POST /admin/content/reorder accepts the tree from JS (CSRF via query param), calls the gateway with the admin token - /learn admin view: draggable handles (⠿) for chapters, sections and articles; drop before/after to reorder, drop into a chapter/section to move; visual indicators; structure is collected from DOM and saved, then page reloads - docs: class diagram method + new sequence diagram for drag & drop
264 lines
19 KiB
HTML
264 lines
19 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="ru" xmlns:th="http://www.thymeleaf.org" th:replace="~{fragments/base :: layout(~{::title}, ~{::#content})}">
|
||
<head><title>Материалы — LMS</title></head>
|
||
<body>
|
||
<div id="content" th:attr="data-csrf=${csrfToken}">
|
||
<div class="flex items-center justify-between gap-4 mb-6">
|
||
<h1 class="page-title">Учебные материалы</h1>
|
||
<div th:if="${currentUser != null and currentUser.admin}" class="flex gap-2">
|
||
<button class="btn btn-primary" type="button" onclick="openModal('modal-new-article')">+ Статья</button>
|
||
<button class="btn btn-secondary" type="button" onclick="openModal('modal-import')">Импорт zip</button>
|
||
<button class="btn btn-secondary" type="button" onclick="openModal('modal-new-chapter')">+ Глава</button>
|
||
</div>
|
||
</div>
|
||
<div th:if="${currentUser != null and currentUser.admin}" class="card card-body text-sm text-muted mb-4">
|
||
Режим администратора: скрытые главы, разделы и статьи помечены значком «скрыто»
|
||
и видны только вам. Кнопка-значок публикует материал для студентов или снова скрывает его.
|
||
Перетаскивайте за значок ⠿, чтобы менять порядок глав, разделов и статей, а также
|
||
переносить разделы в другую главу и статьи — в другой раздел.
|
||
</div>
|
||
<div th:if="${notice}" class="alert alert-success" th:text="${notice}"></div>
|
||
<div th:if="${error}" class="alert alert-error" th:text="${error}"></div>
|
||
|
||
<div th:if="${tree == null || #lists.isEmpty(tree.chapters)}" class="card card-body text-muted">
|
||
Материалы ещё не добавлены.
|
||
</div>
|
||
|
||
<details th:each="chapter, chStat : ${tree?.chapters}" class="card mb-4 accordion"
|
||
th:attr="open=${chStat.last},data-chapter-id=${chapter.id}">
|
||
<summary class="card-body acc-head">
|
||
<h2 class="section-title acc-title" th:text="${chapter.title}">Глава</h2>
|
||
<span class="acc-arrow" aria-hidden="true"></span>
|
||
</summary>
|
||
<div class="card-body acc-body">
|
||
<div class="flex flex-wrap items-center justify-between gap-4 mb-4">
|
||
<h2 class="section-title m-0">
|
||
<span th:text="${chapter.title}">Глава</span>
|
||
<span th:if="${!chapter.published}" class="badge badge-warn ml-2">скрыто</span>
|
||
</h2>
|
||
<div th:if="${currentUser != null and currentUser.admin}" class="flex flex-wrap items-center gap-2">
|
||
<span class="drag-handle" draggable="true"
|
||
th:attr="data-drag-kind='chapter',data-drag-id=${chapter.id}"
|
||
title="Перетащите мышью: изменить порядок или перенести главу">⠿</span>
|
||
<form class="inline-form" th:action="@{/admin/content/chapters/toggle-published}" method="post">
|
||
<input type="hidden" name="_csrf" th:value="${csrfToken}">
|
||
<input type="hidden" name="id" th:value="${chapter.id}">
|
||
<input type="hidden" name="published" th:value="${!chapter.published}">
|
||
<button class="btn btn-sm" type="submit"
|
||
th:classappend="${chapter.published} ? 'btn-secondary' : 'btn-primary'"
|
||
th:text="${chapter.published} ? 'Скрыть главу' : 'Опубликовать главу'">Скрыть главу</button>
|
||
</form>
|
||
<button class="btn btn-secondary btn-sm" type="button"
|
||
th:data-modal="|modal-rename-chapter-${chapter.id}|" onclick="openModalData(this)">Переименовать</button>
|
||
<form th:action="@{/admin/content/chapters/{id}/delete(id=${chapter.id})}" method="post"
|
||
onsubmit="return confirm('Удалить главу со всеми разделами и статьями?')">
|
||
<input type="hidden" name="_csrf" th:value="${csrfToken}">
|
||
<button class="btn btn-danger btn-sm" type="submit">Удалить главу</button>
|
||
</form>
|
||
</div>
|
||
</div>
|
||
|
||
<p th:if="${#lists.isEmpty(chapter.sections)}" class="text-sm text-muted">Разделов пока нет</p>
|
||
|
||
<details th:each="section : ${chapter.sections}" class="mt-4 sub-acc"
|
||
th:attr="data-section-id=${section.id}">
|
||
<summary class="sub-head">
|
||
<h3 class="group-title m-0">
|
||
<span class="sub-arrow" aria-hidden="true"></span>
|
||
<a th:href="@{/learn/{c}/{s}(c=${chapter.slug}, s=${section.slug})}" th:text="${section.title}">Раздел</a>
|
||
<span th:if="${!section.published}" class="badge badge-warn ml-2">скрыто</span>
|
||
</h3>
|
||
</summary>
|
||
<div class="flex flex-wrap items-center justify-between gap-4 sub-actions">
|
||
<div class="spacer"></div>
|
||
<div th:if="${currentUser != null and currentUser.admin}" class="flex flex-wrap items-center gap-2">
|
||
<span class="drag-handle" draggable="true"
|
||
th:attr="data-drag-kind='section',data-drag-id=${section.id}"
|
||
title="Перетащите мышью: изменить порядок или перенести раздел">⠿</span>
|
||
<form class="inline-form" th:action="@{/admin/content/sections/toggle-published}" method="post">
|
||
<input type="hidden" name="_csrf" th:value="${csrfToken}">
|
||
<input type="hidden" name="id" th:value="${section.id}">
|
||
<input type="hidden" name="published" th:value="${!section.published}">
|
||
<button class="btn btn-sm" type="submit"
|
||
th:classappend="${section.published} ? 'btn-secondary' : 'btn-primary'"
|
||
th:text="${section.published} ? 'Скрыть раздел' : 'Опубликовать раздел'">Скрыть раздел</button>
|
||
</form>
|
||
<button class="btn btn-secondary btn-sm" type="button"
|
||
th:data-modal="|modal-rename-section-${section.id}|" onclick="openModalData(this)">Переименовать</button>
|
||
<button class="btn btn-secondary btn-sm" type="button"
|
||
th:data-modal="|modal-move-${section.id}|" onclick="openModalData(this)">Перенести статьи</button>
|
||
<form class="inline-form" th:action="@{/admin/content/sections/{id}/delete(id=${section.id})}" method="post"
|
||
onsubmit="return confirm('Удалить раздел со всеми статьями?')">
|
||
<input type="hidden" name="_csrf" th:value="${csrfToken}">
|
||
<button class="btn btn-danger btn-sm" type="submit">Удалить раздел</button>
|
||
</form>
|
||
</div>
|
||
</div>
|
||
<ul class="list-pad text-sm" data-article-list>
|
||
<li th:each="article : ${section.articles}" class="flex items-center gap-2"
|
||
th:attr="data-article-id=${article.id}">
|
||
<a th:href="@{/learn/{c}/{s}/{a}(c=${chapter.slug}, s=${section.slug}, a=${article.slug})}"
|
||
th:text="${article.title}">Статья</a>
|
||
<span th:if="${!article.published}" class="badge badge-warn">скрыто</span>
|
||
<th:block th:if="${currentUser != null and currentUser.admin}">
|
||
<span class="drag-handle" draggable="true"
|
||
th:attr="data-drag-kind='article',data-drag-id=${article.id}"
|
||
title="Перетащите мышью: изменить порядок или перенести статью">⠿</span>
|
||
<form class="inline-form" th:action="@{/admin/content/articles/toggle-published}" method="post">
|
||
<input type="hidden" name="_csrf" th:value="${csrfToken}">
|
||
<input type="hidden" name="id" th:value="${article.id}">
|
||
<input type="hidden" name="published" th:value="${!article.published}">
|
||
<button class="btn btn-sm" type="submit"
|
||
th:classappend="${article.published} ? 'btn-secondary' : 'btn-primary'"
|
||
th:text="${article.published} ? 'Скрыть' : 'Опубликовать'">Скрыть</button>
|
||
</form>
|
||
<button class="btn btn-secondary btn-sm" type="button"
|
||
th:data-modal="|modal-edit-article-${article.id}|" onclick="openModalData(this)">Править</button>
|
||
<form class="inline-form" th:action="@{/admin/content/articles/{id}/delete(id=${article.id})}" method="post"
|
||
onsubmit="return confirm('Удалить статью?')">
|
||
<input type="hidden" name="_csrf" th:value="${csrfToken}">
|
||
<button class="btn btn-danger btn-sm" type="submit">✕</button>
|
||
</form>
|
||
</th:block>
|
||
</li>
|
||
<li th:if="${#lists.isEmpty(section.articles)}" class="text-muted">Статей пока нет</li>
|
||
</ul>
|
||
|
||
<th:block th:if="${currentUser != null and currentUser.admin}">
|
||
<dialog th:id="|modal-rename-section-${section.id}|" class="modal">
|
||
<div class="modal-header">
|
||
<h2 class="modal-title">Переименовать раздел</h2>
|
||
<button class="modal-close" type="button"
|
||
th:data-modal="|modal-rename-section-${section.id}|" onclick="closeModalData(this)">✕</button>
|
||
</div>
|
||
<div class="modal-body">
|
||
<form class="form-stack" th:action="@{/admin/content/sections/{id}/rename(id=${section.id})}" method="post">
|
||
<input type="hidden" name="_csrf" th:value="${csrfToken}">
|
||
<div><label class="label">Название</label>
|
||
<input class="input" name="title" th:value="${section.title}" required></div>
|
||
<button class="btn btn-primary" type="submit">Сохранить</button>
|
||
</form>
|
||
</div>
|
||
</dialog>
|
||
<dialog th:id="|modal-move-${section.id}|" class="modal">
|
||
<div class="modal-header">
|
||
<h2 class="modal-title">Перенести статьи из раздела</h2>
|
||
<button class="modal-close" type="button"
|
||
th:data-modal="|modal-move-${section.id}|" onclick="closeModalData(this)">✕</button>
|
||
</div>
|
||
<div class="modal-body">
|
||
<form class="form-stack" th:action="@{/admin/content/sections/{id}/delete(id=${section.id})}" method="post">
|
||
<input type="hidden" name="_csrf" th:value="${csrfToken}">
|
||
<p class="text-sm text-muted">Выберите раздел-приёмник: статьи перенесутся туда, а текущий раздел будет удалён.</p>
|
||
<div><label class="label">Перенести в раздел</label>
|
||
<select class="input" name="moveTo">
|
||
<option th:each="pair : ${sectionChoices}"
|
||
th:value="${pair['id']}" th:text="${pair['label']}">—</option>
|
||
</select></div>
|
||
<button class="btn btn-primary" type="submit">Перенести и удалить раздел</button>
|
||
</form>
|
||
</div>
|
||
</dialog>
|
||
</th:block>
|
||
</details>
|
||
<th:block th:if="${currentUser != null and currentUser.admin}">
|
||
<dialog th:id="|modal-rename-chapter-${chapter.id}|" class="modal">
|
||
<div class="modal-header">
|
||
<h2 class="modal-title">Переименовать главу</h2>
|
||
<button class="modal-close" type="button"
|
||
th:data-modal="|modal-rename-chapter-${chapter.id}|" onclick="closeModalData(this)">✕</button>
|
||
</div>
|
||
<div class="modal-body">
|
||
<form class="form-stack" th:action="@{/admin/content/chapters/{id}/rename(id=${chapter.id})}" method="post">
|
||
<input type="hidden" name="_csrf" th:value="${csrfToken}">
|
||
<div><label class="label">Название</label>
|
||
<input class="input" name="title" th:value="${chapter.title}" required></div>
|
||
<button class="btn btn-primary" type="submit">Сохранить</button>
|
||
</form>
|
||
</div>
|
||
</dialog>
|
||
</th:block>
|
||
</div>
|
||
</details>
|
||
|
||
<dialog id="modal-import" class="modal">
|
||
<div class="modal-header">
|
||
<h2 class="modal-title">Импорт материалов (zip)</h2>
|
||
<button class="modal-close" type="button" onclick="closeModal('modal-import')">✕</button>
|
||
</div>
|
||
<div class="modal-body">
|
||
<form class="form-stack" th:action="@{/admin/content/import}" method="post" enctype="multipart/form-data">
|
||
<input type="hidden" name="_csrf" th:value="${csrfToken}">
|
||
<p class="text-sm text-muted">
|
||
Структура: <code class="code">chapters/01-глава/01-раздел/01-статья.md</code>, картинки в <code class="code">assets/</code>.
|
||
</p>
|
||
<div><label class="label" for="file">Архив</label>
|
||
<input class="input" id="file" name="file" type="file" accept=".zip" required></div>
|
||
<button class="btn btn-primary" type="submit">Импортировать</button>
|
||
</form>
|
||
</div>
|
||
</dialog>
|
||
|
||
<dialog id="modal-new-chapter" class="modal">
|
||
<div class="modal-header">
|
||
<h2 class="modal-title">Новая глава</h2>
|
||
<button class="modal-close" type="button" onclick="closeModal('modal-new-chapter')">✕</button>
|
||
</div>
|
||
<div class="modal-body">
|
||
<form class="form-stack" th:action="@{/admin/content/chapters/create}" method="post">
|
||
<input type="hidden" name="_csrf" th:value="${csrfToken}">
|
||
<div><label class="label" for="chTitle">Название</label>
|
||
<input class="input" id="chTitle" name="title" required></div>
|
||
<button class="btn btn-primary" type="submit">Создать</button>
|
||
</form>
|
||
</div>
|
||
</dialog>
|
||
|
||
<dialog id="modal-new-article" class="modal">
|
||
<div class="modal-header">
|
||
<h2 class="modal-title">Новая статья</h2>
|
||
<button class="modal-close" type="button" onclick="closeModal('modal-new-article')">✕</button>
|
||
</div>
|
||
<div class="modal-body">
|
||
<form class="form-stack" th:action="@{/admin/content/articles/create}" method="post">
|
||
<input type="hidden" name="_csrf" th:value="${csrfToken}">
|
||
<div><label class="label" for="naChapter">Существующая глава и раздел</label>
|
||
<select class="input" id="naChapter" name="sectionId">
|
||
<option th:each="pair : ${sectionChoices}"
|
||
th:value="${pair['id']}" th:text="${pair['label']}">—</option>
|
||
</select></div>
|
||
<div><label class="label" for="naNewSection">…или новый раздел в выбранной главе</label>
|
||
<input class="input" id="naNewSection" name="newSectionTitle" placeholder="Новый раздел"></div>
|
||
<div><label class="label" for="naTitle">Заголовок статьи</label>
|
||
<input class="input" id="naTitle" name="title" required></div>
|
||
<div><label class="label" for="naBody">Текст (markdown)</label>
|
||
<textarea class="input" id="naBody" name="bodyMd" rows="10"></textarea></div>
|
||
<button class="btn btn-primary" type="submit">Создать</button>
|
||
</form>
|
||
</div>
|
||
</dialog>
|
||
|
||
<th:block th:if="${currentUser != null and currentUser.admin}" th:each="a : ${articles}">
|
||
<dialog th:id="|modal-edit-article-${a.id}|" class="modal">
|
||
<div class="modal-header">
|
||
<h2 class="modal-title">Правка статьи</h2>
|
||
<button class="modal-close" type="button"
|
||
th:data-modal="|modal-edit-article-${a.id}|" onclick="closeModalData(this)">✕</button>
|
||
</div>
|
||
<div class="modal-body">
|
||
<form class="form-stack" th:action="@{/admin/content/articles/{id}/save(id=${a.id})}" method="post">
|
||
<input type="hidden" name="_csrf" th:value="${csrfToken}">
|
||
<div><label class="label">Заголовок</label>
|
||
<input class="input" name="title" th:value="${a.title}" required></div>
|
||
<div><label class="label">Текст (markdown)</label>
|
||
<textarea class="input" name="bodyMd" rows="14" th:text="${a.bodyMd}"></textarea></div>
|
||
<button class="btn btn-primary" type="submit">Сохранить</button>
|
||
</form>
|
||
</div>
|
||
</dialog>
|
||
</th:block>
|
||
<script src="/js/content-sort.js" defer></script>
|
||
</div>
|
||
</body>
|
||
</html>
|