Try implementing sidebar generation
This commit is contained in:
parent
5e1a4d8ea2
commit
916e8aa7d1
3 changed files with 57 additions and 74 deletions
|
@ -7,12 +7,31 @@ class NavSection:
|
|||
def add_item(self, item):
|
||||
self.items.append(item)
|
||||
|
||||
def get_html(self):
|
||||
pass
|
||||
def get_html(self, active=None):
|
||||
html = f"""
|
||||
<!-- Heading -->
|
||||
<div class="sidebar-heading">{self.name}</div>
|
||||
"""
|
||||
|
||||
self.items.sort(key=lambda x: x.order)
|
||||
|
||||
for item in self.items:
|
||||
html += f"""
|
||||
<!-- Nav Item -->
|
||||
<li class="nav-item """ + ("active" if item.name == active else "") + f""">
|
||||
<a class="nav-link" href="{item.url}">
|
||||
<i class="{item.icon}"></i>
|
||||
<span>{item.name}</span>
|
||||
</a>
|
||||
</li>
|
||||
"""
|
||||
|
||||
return html
|
||||
|
||||
class NavItem:
|
||||
def __init__(self, name, url, icon="fas fa-fw fa-smile", title=None):
|
||||
def __init__(self, name, url, icon="fas fa-fw fa-smile", title=None, order=100):
|
||||
self.name = name
|
||||
self.url = url
|
||||
self.icon = icon
|
||||
self.title = title or name
|
||||
self.title = title or name
|
||||
self.order = order
|
|
@ -0,0 +1,29 @@
|
|||
from frontend.classes import NavSection, NavItem
|
||||
|
||||
from django.urls import reverse_lazy
|
||||
|
||||
mood_section = NavSection("Mood")
|
||||
|
||||
mood_items = {
|
||||
"mood_status_list": NavItem("Status List", reverse_lazy("mood:status_list")),
|
||||
"mood_activity_list": NavItem("Activities", reverse_lazy("mood:activity_list")),
|
||||
"mood_mood_list": NavItem("Moods", reverse_lazy("mood:mood_list")),
|
||||
"mood_notification_list": NavItem("Notifications", reverse_lazy("mood:notification_list")),
|
||||
"mood_statistics": NavItem("Statistics", reverse_lazy("mood:statistics"))
|
||||
}
|
||||
|
||||
for _, item in mood_items.items():
|
||||
mood_section.add_item(item)
|
||||
|
||||
dreams_section = NavSection("Dreams")
|
||||
|
||||
dreams_items = {
|
||||
"dreams_dream_list": NavItem("Dream List", reverse_lazy("dreams:dream_list")),
|
||||
"dreams_theme_list": NavItem("Themes", reverse_lazy("dreams:theme_list")),
|
||||
"dreams_notification_list": NavItem("Notifications", reverse_lazy("dreams:notification_list"))
|
||||
}
|
||||
|
||||
for _, item in dreams_items.items():
|
||||
dreams_section.add_item(item)
|
||||
|
||||
NAV_SECTIONS = [mood_section, dreams_section]
|
|
@ -12,6 +12,10 @@ def sidebar_nav():
|
|||
for module in settings.CORE_MODULES + settings.ENABLED_MODULES:
|
||||
try:
|
||||
features = import_module(f"{module}.features")
|
||||
try:
|
||||
sections += features.NAV_SECTIONS
|
||||
except:
|
||||
pass
|
||||
except:
|
||||
pass
|
||||
|
||||
|
@ -24,73 +28,4 @@ def sidebar_nav():
|
|||
|
||||
<!-- Divider -->
|
||||
<hr class="sidebar-divider">
|
||||
|
||||
<!-- Heading -->
|
||||
<div class="sidebar-heading">
|
||||
Mood
|
||||
</div>
|
||||
|
||||
<!-- Nav Item - Status List -->
|
||||
<li class="nav-item {% if title == "Status List" %}active{% endif %}">
|
||||
<a class="nav-link" href="{% url "mood:status_list" %}">
|
||||
<i class="fas fa-fw fa-smile"></i>
|
||||
<span>Status List</span></a>
|
||||
</li>
|
||||
|
||||
<!-- Nav Item - Activity List -->
|
||||
<li class="nav-item {% if title == "Activities" %}active{% endif %}">
|
||||
<a class="nav-link" href="{% url "mood:activity_list" %}">
|
||||
<i class="fas fa-fw fa-smile"></i>
|
||||
<span>Activities</span></a>
|
||||
</li>
|
||||
|
||||
<!-- Nav Item - Mood List -->
|
||||
<li class="nav-item {% if title == "Moods" %}active{% endif %}">
|
||||
<a class="nav-link" href="{% url "mood:mood_list" %}">
|
||||
<i class="fas fa-fw fa-smile"></i>
|
||||
<span>Moods</span></a>
|
||||
</li>
|
||||
|
||||
<!-- Nav Item - Notification List -->
|
||||
<li class="nav-item {% if title == "Notifications" %}active{% endif %}">
|
||||
<a class="nav-link" href="{% url "mood:notification_list" %}">
|
||||
<i class="fas fa-fw fa-smile"></i>
|
||||
<span>Notifications</span></a>
|
||||
</li>
|
||||
|
||||
<!-- Nav Item - Notification List -->
|
||||
<li class="nav-item {% if title == "Statistics" %}active{% endif %}">
|
||||
<a class="nav-link" href="{% url "mood:statistics" %}">
|
||||
<i class="fas fa-fw fa-smile"></i>
|
||||
<span>Statistics</span></a>
|
||||
</li>
|
||||
|
||||
<!-- Divider -->
|
||||
<hr class="sidebar-divider">
|
||||
|
||||
<!-- Heading -->
|
||||
<div class="sidebar-heading">
|
||||
Dreams
|
||||
</div>
|
||||
|
||||
<!-- Nav Item - Dream List -->
|
||||
<li class="nav-item {% if title == "Dream List" %}active{% endif %}">
|
||||
<a class="nav-link" href="{% url "dreams:dream_list" %}">
|
||||
<i class="fas fa-fw fa-smile"></i>
|
||||
<span>Dream List</span></a>
|
||||
</li>
|
||||
|
||||
<!-- Nav Item - Theme List -->
|
||||
<li class="nav-item {% if title == "Themes" %}active{% endif %}">
|
||||
<a class="nav-link" href="{% url "dreams:theme_list" %}">
|
||||
<i class="fas fa-fw fa-smile"></i>
|
||||
<span>Themes</span></a>
|
||||
</li>
|
||||
|
||||
<!-- Nav Item - Notification List -->
|
||||
<li class="nav-item {% if title == "Notifications" %}active{% endif %}">
|
||||
<a class="nav-link" href="{% url "dreams:notification_list" %}">
|
||||
<i class="fas fa-fw fa-smile"></i>
|
||||
<span>Notifications</span></a>
|
||||
</li>
|
||||
"""
|
||||
""" + section.get_html() for section in sections
|
Loading…
Reference in a new issue