mirror of https://github.com/logos-co/open-law.git
Merge pull request #14 from Simple2B/svyat/feat/sections_view
Fix displaying sections on different levels
This commit is contained in:
commit
727b793e48
|
@ -9,7 +9,7 @@
|
|||
{{ book.owner.username }}/{{ book.label }}
|
||||
</h1>
|
||||
<h1 class="text-2xl font-extrabold dark:text-white ml-4">
|
||||
{{collection.label}}/{{sub_collection.label}}/{{section.label}}
|
||||
{{collection.label}} {% if sub_collection %}/ {{sub_collection.label}} {% endif %} /{{section.label}}
|
||||
</h1>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -32,7 +32,11 @@
|
|||
<dl class="w-md md:w-full text-gray-900 divide-y divide-gray-200 dark:text-white dark:divide-gray-700">
|
||||
<!-- prettier-ignore -->
|
||||
{% for interpretation in section.interpretations %}
|
||||
<a href="{{url_for('book.interpretation_view',book_id=book.id,collection_id=collection.id,sub_collection_id=sub_collection.id, section_id=section.id)}}" >
|
||||
{% if sub_collection %}
|
||||
<a href="{{url_for('book.interpretation_view', book_id=book.id, collection_id=collection.id, sub_collection_id=sub_collection.id, section_id=section.id)}}" >
|
||||
{% else %}
|
||||
<a href="{{url_for('book.interpretation_view', book_id=book.id, collection_id=collection.id, section_id=section.id)}}" >
|
||||
{% endif %}
|
||||
<dl class="bg-white dark:bg-gray-900 max-w-full p-3 text-gray-900 divide-y divide-gray-200 dark:text-white dark:divide-gray-700 m-3 border-2 border-gray-200 border-solid rounded-lg dark:border-gray-700">
|
||||
<div class="flex flex-col pb-3 p-3 w-full">
|
||||
<!-- prettier-ignore -->
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
<div class="flex p-2">
|
||||
<div>
|
||||
<h1 class="text-l font-extrabold dark:text-white ml-4"> {{ book.owner.username }}/{{ book.label }} </h1>
|
||||
<h1 class="text-2xl font-extrabold dark:text-white ml-4">{{collection.label}}/{{sub_collection.label}}</h1>
|
||||
<h1 class="text-2xl font-extrabold dark:text-white ml-4">{{collection.label}}{% if sub_collection %}/ {{sub_collection.label}} {% endif %} </h1>
|
||||
</div>
|
||||
</div>
|
||||
<!-- prettier-ignore -->
|
||||
|
@ -54,10 +54,14 @@
|
|||
<dl
|
||||
class="w-md md:w-full text-gray-900 divide-y divide-gray-200 dark:text-white dark:divide-gray-700">
|
||||
<!-- prettier-ignore -->
|
||||
{% for section in sub_collection.sections %}
|
||||
{% for section in sections %}
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
<a href="{{url_for('book.interpretation_view',book_id=book.id,collection_id=collection.id,sub_collection_id=sub_collection.id, section_id=section.id)}}">
|
||||
{% if sub_collection %}
|
||||
<a href="{{url_for('book.interpretation_view', book_id=book.id, collection_id=collection.id, sub_collection_id=sub_collection.id, section_id=section.id)}}">
|
||||
{% else %}
|
||||
<a href="{{url_for('book.interpretation_view', book_id=book.id, collection_id=collection.id, section_id=section.id)}}">
|
||||
{% endif %}
|
||||
<dl class="bg-white dark:bg-gray-900 max-w-full p-3 text-gray-900 divide-y divide-gray-200 dark:text-white dark:divide-gray-700 m-3 border-2 border-gray-200 border-solid rounded-lg dark:border-gray-700">
|
||||
<div class="flex flex-col pb-3 p-3 w-full">
|
||||
<dt class="flex w-full mb-1 text-gray-500 md:text-lg dark:text-gray-400 flex-col">
|
||||
|
@ -87,9 +91,7 @@
|
|||
id="about"
|
||||
role="tabpanel"
|
||||
aria-labelledby="about-tab">
|
||||
<p class="text-sm text-gray-500 dark:text-gray-400">
|
||||
This is about of {{sub_collection.label}}
|
||||
</p>
|
||||
<p class="text-sm text-gray-500 dark:text-gray-400">This is about</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -65,11 +65,11 @@
|
|||
</div>
|
||||
<!-- prettier-ignore -->
|
||||
<div class="hidden p-4 rounded-lg bg-gray-50 dark:bg-gray-800" id="all-sections" role="tabpanel" aria-labelledby="all-sections-tab">
|
||||
{% for section in sections %}
|
||||
<!-- prettier-ignore -->
|
||||
<h1 class="text-l font-extrabold dark:text-white my-2">{{section.path}}</h1>
|
||||
{% for section in sections %}
|
||||
<!-- prettier-ignore -->
|
||||
<h1 class="text-l font-extrabold dark:text-white my-2">{{section.path}}</h1>
|
||||
{% endfor %}
|
||||
<a type="button" href="{{ url_for('section.get_all') }}" class="mt-4 text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center inline-flex items-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800"> Explore all sections... <svg aria-hidden="true" class="w-5 h-5 ml-2 -mr-1" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" d="M10.293 3.293a1 1 0 011.414 0l6 6a1 1 0 010 1.414l-6 6a1 1 0 01-1.414-1.414L14.586 11H3a1 1 0 110-2h11.586l-4.293-4.293a1 1 0 010-1.414z" clip-rule="evenodd"></path></svg> </a>
|
||||
<a type="button" href="{{ url_for('book.get_all') }}" class="mt-4 text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center inline-flex items-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800"> Explore all sections... <svg aria-hidden="true" class="w-5 h-5 ml-2 -mr-1" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" d="M10.293 3.293a1 1 0 011.414 0l6 6a1 1 0 010 1.414l-6 6a1 1 0 01-1.414-1.414L14.586 11H3a1 1 0 110-2h11.586l-4.293-4.293a1 1 0 010-1.414z" clip-rule="evenodd"></path></svg> </a>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
|
@ -76,7 +76,7 @@ def create():
|
|||
return redirect(url_for("book.my_books"))
|
||||
|
||||
|
||||
@bp.route("/<int:book_id>", methods=["GET"])
|
||||
@bp.route("/<int:book_id>/collections", methods=["GET"])
|
||||
def collection_view(book_id: int):
|
||||
book = db.session.get(m.Book, book_id)
|
||||
if not book or book.is_deleted:
|
||||
|
@ -87,7 +87,7 @@ def collection_view(book_id: int):
|
|||
return render_template("book/collection_view.html", book=book)
|
||||
|
||||
|
||||
@bp.route("/<int:book_id>/<int:collection_id>", methods=["GET"])
|
||||
@bp.route("/<int:book_id>/<int:collection_id>/subcollections", methods=["GET"])
|
||||
def sub_collection_view(book_id: int, collection_id: int):
|
||||
book: m.Book = db.session.get(m.Book, book_id)
|
||||
if not book or book.is_deleted:
|
||||
|
@ -101,11 +101,8 @@ def sub_collection_view(book_id: int, collection_id: int):
|
|||
flash("Collection not found", "danger")
|
||||
return redirect(url_for("book.collection_view", book_id=book_id))
|
||||
if collection.is_leaf:
|
||||
return render_template(
|
||||
"book/section_view.html",
|
||||
book=book,
|
||||
collection=collection,
|
||||
sub_collection=collection,
|
||||
return redirect(
|
||||
url_for("book.section_view", book_id=book.id, collection_id=collection.id)
|
||||
)
|
||||
else:
|
||||
return render_template(
|
||||
|
@ -113,44 +110,13 @@ def sub_collection_view(book_id: int, collection_id: int):
|
|||
)
|
||||
|
||||
|
||||
@bp.route("/<int:book_id>/<int:collection_id>/<int:sub_collection_id>", methods=["GET"])
|
||||
def section_view(book_id: int, collection_id: int, sub_collection_id: int):
|
||||
book: m.Book = db.session.get(m.Book, book_id)
|
||||
if not book or book.is_deleted:
|
||||
log(log.WARNING, "Book with id [%s] not found", book_id)
|
||||
flash("Book not found", "danger")
|
||||
return redirect(url_for("book.my_books"))
|
||||
|
||||
collection: m.Collection = db.session.get(m.Collection, collection_id)
|
||||
if not collection or collection.is_deleted:
|
||||
log(log.WARNING, "Collection with id [%s] not found", collection_id)
|
||||
flash("Collection not found", "danger")
|
||||
return redirect(url_for("book.collection_view", book_id=book_id))
|
||||
|
||||
sub_collection: m.Collection = db.session.get(m.Collection, sub_collection_id)
|
||||
if not sub_collection or sub_collection.is_deleted:
|
||||
log(log.WARNING, "Sub_collection with id [%s] not found", sub_collection_id)
|
||||
flash("Sub_collection not found", "danger")
|
||||
return redirect(
|
||||
url_for(
|
||||
"book.sub_collection_view", book_id=book_id, collection_id=collection_id
|
||||
)
|
||||
)
|
||||
else:
|
||||
return render_template(
|
||||
"book/section_view.html",
|
||||
book=book,
|
||||
collection=collection,
|
||||
sub_collection=sub_collection,
|
||||
)
|
||||
|
||||
|
||||
@bp.route("/<int:book_id>/<int:collection_id>/sections", methods=["GET"])
|
||||
@bp.route(
|
||||
"/<int:book_id>/<int:collection_id>/<int:sub_collection_id>/<int:section_id>",
|
||||
"/<int:book_id>/<int:collection_id>/<int:sub_collection_id>/sections",
|
||||
methods=["GET"],
|
||||
)
|
||||
def interpretation_view(
|
||||
book_id: int, collection_id: int, sub_collection_id: int, section_id: int
|
||||
def section_view(
|
||||
book_id: int, collection_id: int, sub_collection_id: int | None = None
|
||||
):
|
||||
book: m.Book = db.session.get(m.Book, book_id)
|
||||
if not book or book.is_deleted:
|
||||
|
@ -164,15 +130,72 @@ def interpretation_view(
|
|||
flash("Collection not found", "danger")
|
||||
return redirect(url_for("book.collection_view", book_id=book_id))
|
||||
|
||||
sub_collection: m.Collection = db.session.get(m.Collection, sub_collection_id)
|
||||
if not sub_collection or sub_collection.is_deleted:
|
||||
log(log.WARNING, "Sub_collection with id [%s] not found", sub_collection_id)
|
||||
flash("Sub_collection not found", "danger")
|
||||
return redirect(
|
||||
url_for(
|
||||
"book.sub_collection_view", book_id=book_id, collection_id=collection_id
|
||||
sub_collection = None
|
||||
if sub_collection_id:
|
||||
sub_collection: m.Collection = db.session.get(m.Collection, sub_collection_id)
|
||||
if not sub_collection or sub_collection.is_deleted:
|
||||
log(log.WARNING, "Sub_collection with id [%s] not found", sub_collection_id)
|
||||
flash("Sub_collection not found", "danger")
|
||||
return redirect(
|
||||
url_for(
|
||||
"book.sub_collection_view",
|
||||
book_id=book_id,
|
||||
collection_id=collection_id,
|
||||
)
|
||||
)
|
||||
|
||||
if sub_collection:
|
||||
sections = sub_collection.sections
|
||||
else:
|
||||
sections = collection.sections
|
||||
|
||||
return render_template(
|
||||
"book/section_view.html",
|
||||
book=book,
|
||||
collection=collection,
|
||||
sections=sections,
|
||||
sub_collection=sub_collection,
|
||||
)
|
||||
|
||||
|
||||
@bp.route(
|
||||
"/<int:book_id>/<int:collection_id>/<int:section_id>/interpretations",
|
||||
methods=["GET"],
|
||||
)
|
||||
@bp.route(
|
||||
"/<int:book_id>/<int:collection_id>/<int:sub_collection_id>/<int:section_id>/interpretations",
|
||||
methods=["GET"],
|
||||
)
|
||||
def interpretation_view(
|
||||
book_id: int,
|
||||
collection_id: int,
|
||||
section_id: int,
|
||||
sub_collection_id: int | None = None,
|
||||
):
|
||||
book: m.Book = db.session.get(m.Book, book_id)
|
||||
if not book or book.is_deleted:
|
||||
log(log.WARNING, "Book with id [%s] not found", book_id)
|
||||
flash("Book not found", "danger")
|
||||
return redirect(url_for("book.my_books"))
|
||||
|
||||
collection: m.Collection = db.session.get(m.Collection, collection_id)
|
||||
if not collection or collection.is_deleted:
|
||||
log(log.WARNING, "Collection with id [%s] not found", collection_id)
|
||||
flash("Collection not found", "danger")
|
||||
return redirect(url_for("book.collection_view", book_id=book_id))
|
||||
|
||||
if sub_collection_id:
|
||||
sub_collection: m.Collection = db.session.get(m.Collection, sub_collection_id)
|
||||
if not sub_collection or sub_collection.is_deleted:
|
||||
log(log.WARNING, "Sub_collection with id [%s] not found", sub_collection_id)
|
||||
flash("Sub_collection not found", "danger")
|
||||
return redirect(
|
||||
url_for(
|
||||
"book.sub_collection_view",
|
||||
book_id=book_id,
|
||||
collection_id=collection_id,
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
section: m.Section = db.session.get(m.Section, section_id)
|
||||
if not section:
|
||||
|
@ -191,7 +214,7 @@ def interpretation_view(
|
|||
"book/interpretation_view.html",
|
||||
book=book,
|
||||
collection=collection,
|
||||
sub_collection=sub_collection,
|
||||
sub_collection=sub_collection if sub_collection_id else None,
|
||||
section=section,
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue