mirror of
https://github.com/logos-co/open-law.git
synced 2025-02-12 23:06:30 +00:00
section.next_section
This commit is contained in:
parent
841c5ac294
commit
4fd687e26c
28
app/controllers/next_prev_section.py
Normal file
28
app/controllers/next_prev_section.py
Normal file
@ -0,0 +1,28 @@
|
||||
from app import models as m
|
||||
|
||||
|
||||
def get_next_section(collection: m.Collection):
|
||||
if collection.active_sections:
|
||||
return collection.active_sections[0]
|
||||
|
||||
# find on current level in next by order collections
|
||||
for child in collection.active_children:
|
||||
if section := get_next_section(child):
|
||||
return section
|
||||
|
||||
|
||||
def recursive_move_down(collection: m.Collection):
|
||||
parent: m.Collection = collection.parent
|
||||
current: m.Collection = collection
|
||||
while True:
|
||||
if len(parent.active_children) > current.position + 1:
|
||||
index = parent.active_children.index(current) + 1
|
||||
for child in parent.active_children[index:]:
|
||||
if section := get_next_section(child):
|
||||
return section
|
||||
|
||||
if current.is_root:
|
||||
return None
|
||||
|
||||
current = parent
|
||||
parent = parent.parent
|
@ -7,6 +7,7 @@ from app.controllers import create_breadcrumbs
|
||||
from .interpretation import Interpretation
|
||||
from .comment import Comment
|
||||
from .interpretation_vote import InterpretationVote
|
||||
from app.controllers.next_prev_section import recursive_move_down
|
||||
|
||||
|
||||
class Section(BaseModel):
|
||||
@ -129,18 +130,15 @@ class Section(BaseModel):
|
||||
|
||||
@property
|
||||
def next_section(self):
|
||||
next_section = Section.query.filter(
|
||||
section = Section.query.filter(
|
||||
Section.collection_id == self.collection_id,
|
||||
Section.position > self.position,
|
||||
).first()
|
||||
if not next_section:
|
||||
next_collections = Collection.query.filter(
|
||||
Collection.version_id == self.collection.version_id,
|
||||
Collection.position > self.collection.position,
|
||||
Collection.parent_id == self.collection.parent_id,
|
||||
).order_by(Collection.position)
|
||||
# Move on parent -> childern
|
||||
return next_section
|
||||
if section:
|
||||
return section
|
||||
|
||||
section = recursive_move_down(self.collection)
|
||||
return section
|
||||
|
||||
@property
|
||||
def previous_section(self):
|
||||
|
File diff suppressed because one or more lines are too long
@ -220,26 +220,29 @@
|
||||
</div>
|
||||
</button>
|
||||
<!-- prettier-ignore -->
|
||||
<button
|
||||
type="button"
|
||||
class="{% if not section.previous_section %}cursor-not-allowed{% endif %} 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"
|
||||
{% if not section.next_section %}disabled{% endif %}>
|
||||
<div class="flex flex-col items-start mr-5">
|
||||
<p class="p-3">Book label</p>
|
||||
<p class="p-3">Next section</p>
|
||||
</div>
|
||||
<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>
|
||||
</button>
|
||||
{% set next_section = section.next_section %}
|
||||
{% if next_section %}
|
||||
<button
|
||||
type="button"
|
||||
class="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"
|
||||
>
|
||||
<div class="flex flex-col items-start mr-5">
|
||||
<p class="p-3">Book label</p>
|
||||
<p class="p-3">{{ next_section.label }}</p>
|
||||
</div>
|
||||
<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>
|
||||
</button>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<!-- prettier-ignore -->
|
||||
|
Loading…
x
Reference in New Issue
Block a user