Skip to content

Commit 3533147

Browse files
authoredApr 25, 2024
Merge pull request #668 from hms-dbmi/HYP-302
HYP-302 - Added top-level navigation functionality
2 parents 2f4a980 + 9e4703a commit 3533147

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed
 

‎app/hypatio/views.py

+8
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,15 @@ def group_context():
3838
# Check for group
3939
active_group = next((g for g in groups if project in g.dataproject_set.all()), None)
4040

41+
# Pull out top-level groups
42+
parent_groups_keys = groups.filter(parent__isnull=False).values_list('parent', flat=True)
43+
parent_groups = Group.objects.filter(id__in=parent_groups_keys)
44+
45+
# Remove groups that will be placed under a parent group
46+
groups = groups.filter(parent__isnull=True)
47+
4148
return {
49+
"parent_groups": parent_groups,
4250
"groups": groups,
4351
"active_group": active_group,
4452
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Generated by Django 4.2.11 on 2024-04-25 13:33
2+
3+
from django.db import migrations, models
4+
import django.db.models.deletion
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('projects', '0103_dataproject_commercial_only'),
11+
]
12+
13+
operations = [
14+
migrations.AddField(
15+
model_name='group',
16+
name='parent',
17+
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='projects.group'),
18+
),
19+
]

‎app/projects/models.py

+1
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@ class Group(models.Model):
694694
title = models.CharField(max_length=255, blank=False, null=False)
695695
description = models.TextField(blank=True)
696696
navigation_title = models.CharField(max_length=20, blank=True, null=True)
697+
parent = models.ForeignKey("Group", on_delete=models.PROTECT, blank=True, null=True)
697698

698699
# Meta
699700
created = models.DateTimeField(auto_now_add=True)

‎app/templates/base.html

+13
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,19 @@
209209
{% url 'index' as index_url %}
210210
<li class="nav-item{% if request.path == index_url %} active{% endif %}"><a class="nav-link" href="{{ index_url }}">Home</a></li>
211211

212+
{% for group in navigation.parent_groups %}
213+
{% url 'group' group.key as group_url %}
214+
<li class="dropdown">
215+
<a class="dropdown-toggle" data-toggle="dropdown" href="#">{{ group.navigation_title|default:group.title }} <span class="caret"></span></a>
216+
<ul class="dropdown-menu" aria-labelledby="{{ group.navigation_title|default:group.title }}">
217+
{% for child in group.group_set.all %}
218+
{% url 'group' child.key as group_url %}
219+
<li class="nav-item{% if request.path == group_url or child.key == navigation.active_group.key %} active{% endif %}"><a class="nav-link" href="{{ group_url }}">{{ child.navigation_title|default:child.title }}</a></li>
220+
{% endfor %}
221+
</ul>
222+
</li>
223+
{% endfor %}
224+
212225
{% for group in navigation.groups %}
213226
{% url 'group' group.key as group_url %}
214227
<li class="nav-item{% if request.path == group_url or group.key == navigation.active_group.key %} active{% endif %}"><a class="nav-link" href="{{ group_url }}">{{ group.navigation_title|default:group.title }}</a></li>

0 commit comments

Comments
 (0)