From 74314948d13cf7e67e47396b69bf7638de716e76 Mon Sep 17 00:00:00 2001 From: SvyatoslavArtymovych Date: Tue, 30 May 2023 16:30:14 +0300 Subject: [PATCH] breadcrumbs splitter --- app/models/section.py | 7 +++ app/schema/breadcrumbs.py | 1 + .../book/local_breadcrumbs_navigation.html | 49 +++++++++++-------- 3 files changed, 36 insertions(+), 21 deletions(-) diff --git a/app/models/section.py b/app/models/section.py index d108375..ac7cb9d 100644 --- a/app/models/section.py +++ b/app/models/section.py @@ -6,6 +6,7 @@ from app.controllers import create_breadcrumbs from .interpretation import Interpretation from .comment import Comment from .interpretation_vote import InterpretationVote +from app import schema as s class Section(BaseModel): @@ -49,6 +50,12 @@ class Section(BaseModel): breadcrumbs_path = create_breadcrumbs( book_id=self.book_id, collection_id=self.collection.id ) + if len(breadcrumbs_path) > 5: + breadcrumbs_path = ( + breadcrumbs_path[:3] + + [s.BreadCrumb(type=s.BreadCrumbType.Splitter, url="", label="...")] + + breadcrumbs_path[-2:] + ) return breadcrumbs_path @property diff --git a/app/schema/breadcrumbs.py b/app/schema/breadcrumbs.py index fb87758..11e4c1d 100644 --- a/app/schema/breadcrumbs.py +++ b/app/schema/breadcrumbs.py @@ -11,6 +11,7 @@ class BreadCrumbType(enum.StrEnum): Collection = "Collection" Section = "Section" Interpretation = "Interpretation" + Splitter = "Splitter" class BreadCrumb(BaseModel): diff --git a/app/templates/book/local_breadcrumbs_navigation.html b/app/templates/book/local_breadcrumbs_navigation.html index 963a078..6bb5de9 100644 --- a/app/templates/book/local_breadcrumbs_navigation.html +++ b/app/templates/book/local_breadcrumbs_navigation.html @@ -1,26 +1,33 @@
    {% for breadcrumb in local_breadcrumbs if breadcrumb.type != "MyBookList" and breadcrumb.type != "AuthorBookList" %} -
  1. - {% if not loop.index==local_breadcrumbs|length-1 %} - - {% else %} - - {% endif %} - - - {{ breadcrumb.label }} - {% if not loop.index==local_breadcrumbs|length %} - - {% else %} - - {% endif %} - {% if not loop.index==local_breadcrumbs|length-1 %} - - {% endif %} -
  2. +
  3. + {% if not loop.index==local_breadcrumbs|length-1 %} + + {% else %} + + {% endif %} + + {% if breadcrumb.type != "Splitter" %} + + {% endif %} + + + {{ breadcrumb.label }} + + {% if not loop.index==local_breadcrumbs|length %} + + {% else %} + + {% endif %} + + + {% if not loop.index==local_breadcrumbs|length-1 %} + + {% endif %} +
  4. {% endfor %}
\ No newline at end of file