feat: Enhances asset management for dashboard sections
Introduces methods to manage styles and scripts in dashboard sections, promoting modularity and reusability. Updates templates to dynamically render styles and scripts directly from context, ensuring better integration with existing features system. Migrates related static assets to 'mood' section to streamline the module structure. These changes enable smoother customization and extendability of the dashboard's look and feel. Relates to improved frontend architecture.
This commit is contained in:
parent
bc8da6b1cc
commit
725f566d97
10 changed files with 56 additions and 9 deletions
|
@ -98,6 +98,14 @@ class DashboardSection:
|
|||
self.name = name
|
||||
self.template = template
|
||||
self.context = context or {}
|
||||
self.styles = []
|
||||
self.scripts = []
|
||||
|
||||
def get_html(self, request):
|
||||
return render_to_string(self.template, self.context, request)
|
||||
|
||||
def add_style(self, style):
|
||||
self.styles.append(style)
|
||||
|
||||
def add_script(self, script):
|
||||
self.scripts.append(script)
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
<!-- Page level custom scripts -->
|
||||
{% for script in scripts %}
|
||||
<script src="{% static script %}"></script>
|
||||
<script src="{{ script }}"></script>
|
||||
{% endfor %}
|
||||
|
||||
</body>
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
<!-- Custom fonts for this template -->
|
||||
<link href="https://fa.kumi.systems/css/all.min.css" rel="stylesheet" type="text/css">
|
||||
<link
|
||||
href="https://fontproxy.kumi.systems/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i"
|
||||
href="https://googledonts.private.coffee/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i"
|
||||
rel="stylesheet">
|
||||
|
||||
<!-- Custom styles for this template -->
|
||||
|
@ -24,7 +24,7 @@
|
|||
|
||||
<!-- Custom styles for this page -->
|
||||
{% for style in styles %}
|
||||
<link href="{% static style %}" rel="stylesheet">
|
||||
<link href="{{ style }}" rel="stylesheet">
|
||||
{% endfor %}
|
||||
|
||||
</head>
|
||||
|
|
|
@ -31,3 +31,35 @@ def dashboard(context):
|
|||
dashboard_html += '<hr class="dashboard-divider">'
|
||||
|
||||
return dashboard_html
|
||||
|
||||
|
||||
@register.simple_tag
|
||||
def dashboard_styles():
|
||||
styles = []
|
||||
|
||||
for module in settings.CORE_MODULES + settings.ENABLED_MODULES:
|
||||
try:
|
||||
features = import_module(f"{module}.features")
|
||||
for section in features.DASHBOARD_SECTIONS:
|
||||
for style in section.styles:
|
||||
styles.append(style)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return styles
|
||||
|
||||
|
||||
@register.simple_tag
|
||||
def dashboard_scripts():
|
||||
scripts = []
|
||||
|
||||
for module in settings.CORE_MODULES + settings.ENABLED_MODULES:
|
||||
try:
|
||||
features = import_module(f"{module}.features")
|
||||
for section in features.DASHBOARD_SECTIONS:
|
||||
for script in section.scripts:
|
||||
scripts.append(script)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return scripts
|
||||
|
|
|
@ -4,6 +4,8 @@ from django.contrib.auth.forms import UserCreationForm
|
|||
from django.contrib.auth import get_user_model, login
|
||||
from django.urls import reverse_lazy
|
||||
|
||||
from .templatetags.dashboard import dashboard_styles, dashboard_scripts
|
||||
|
||||
|
||||
class DashboardView(LoginRequiredMixin, TemplateView):
|
||||
template_name = "frontend/dashboard.html"
|
||||
|
@ -14,12 +16,8 @@ class DashboardView(LoginRequiredMixin, TemplateView):
|
|||
context["subtitle"] = (
|
||||
"An overview of everything going on in your Kumify account."
|
||||
)
|
||||
context["scripts"] = [
|
||||
"frontend/dist/js/d3.v7.min.js",
|
||||
"frontend/dist/js/cal-heatmap.min.js",
|
||||
"frontend/js/dashboard.js",
|
||||
]
|
||||
context["styles"] = ["frontend/dist/css/cal-heatmap.css"]
|
||||
context["scripts"] = dashboard_scripts()
|
||||
context["styles"] = dashboard_styles()
|
||||
return context
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
from frontend.classes import NavSection, NavItem, NavCollapse, DashboardSection
|
||||
|
||||
from django.urls import reverse_lazy
|
||||
from django.templatetags.static import static
|
||||
|
||||
# Sidebar navigation items
|
||||
|
||||
|
@ -31,4 +32,12 @@ NAV_SECTIONS = [mood_section]
|
|||
|
||||
mood_section = DashboardSection("Moods", "mood/dashboard_section.html")
|
||||
|
||||
mood_section.add_script(static("mood/dist/js/d3.v7.min.js"))
|
||||
mood_section.add_script(static("mood/dist/js/cal-heatmap.min.js"))
|
||||
|
||||
mood_section.add_script(static("mood/dashboard.js"))
|
||||
|
||||
mood_section.add_style(static("mood/dist/css/cal-heatmap.css"))
|
||||
|
||||
|
||||
DASHBOARD_SECTIONS = [mood_section]
|
||||
|
|
Loading…
Reference in a new issue