Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

INTR-453 Navigation Prototyping (DO NOT MERGE) #840

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def filter_transactions(event, hint):
"peoplefinder.apps.PeoplefinderConfig",
"countries.apps.CountriesConfig",
"interactions.apps.InteractionsConfig",
"navigation_prototype",
]

THIRD_PARTY_APPS = [
Expand Down
8 changes: 6 additions & 2 deletions src/core/templates/includes/header.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load menu_tags waffle_tags %}
{% load menu_tags waffle_tags nav_proto %}
{% load render_bundle webpack_static from webpack_loader %}
{% load site_alert %}

Expand Down Expand Up @@ -29,7 +29,11 @@
hidden>Menu</button>
{% if USER_IS_AUTHENTICATED %}
<nav aria-label="Top Level Navigation" class="govuk-header__navigation">
{% main_menu max_levels=1 template="menus/main_menu.html" apply_active_classes=True %}
{% if FEATURE_FLAGS.navigation_prototype %}
{% nav_proto %}
{% else %}
{% main_menu max_levels=1 template="menus/main_menu.html" apply_active_classes=True %}
{% endif %}
</nav>
{% endif %}
</div>
Expand Down
Empty file.
77 changes: 77 additions & 0 deletions src/navigation_prototype/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Generated by Django 4.2.16 on 2024-12-10 16:44

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = []

operations = [
migrations.CreateModel(
name="Nav",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"sort_order",
models.IntegerField(blank=True, editable=False, null=True),
),
],
options={
"ordering": ["sort_order"],
"abstract": False,
},
),
migrations.CreateModel(
name="NavLink",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"sort_order",
models.IntegerField(blank=True, editable=False, null=True),
),
("label", models.CharField(max_length=255)),
("url", models.CharField(max_length=255)),
(
"navigation",
models.ForeignKey(
on_delete=django.db.models.deletion.PROTECT,
related_name="links",
to="navigation_prototype.nav",
),
),
(
"parent_link",
models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.PROTECT,
related_name="child_links",
to="navigation_prototype.navlink",
),
),
],
options={
"ordering": ["sort_order"],
"abstract": False,
},
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 4.2.16 on 2024-12-10 16:47

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("navigation_prototype", "0001_initial"),
]

operations = [
migrations.AlterModelOptions(
name="nav",
options={},
),
migrations.RemoveField(
model_name="nav",
name="sort_order",
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 4.2.16 on 2024-12-10 16:49

from django.db import migrations
import django.db.models.deletion
import modelcluster.fields


class Migration(migrations.Migration):

dependencies = [
("navigation_prototype", "0002_alter_nav_options_remove_nav_sort_order"),
]

operations = [
migrations.AlterField(
model_name="navlink",
name="navigation",
field=modelcluster.fields.ParentalKey(
on_delete=django.db.models.deletion.PROTECT,
related_name="links",
to="navigation_prototype.nav",
),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Generated by Django 4.2.16 on 2024-12-10 16:52

from django.db import migrations, models
import django.db.models.deletion
import modelcluster.fields


class Migration(migrations.Migration):

dependencies = [
("navigation_prototype", "0003_alter_navlink_navigation"),
]

operations = [
migrations.CreateModel(
name="PrimaryNavLink",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"sort_order",
models.IntegerField(blank=True, editable=False, null=True),
),
("label", models.CharField(max_length=255)),
("url", models.CharField(max_length=255)),
(
"navigation",
modelcluster.fields.ParentalKey(
on_delete=django.db.models.deletion.PROTECT,
related_name="links",
to="navigation_prototype.nav",
),
),
],
options={
"abstract": False,
},
),
migrations.CreateModel(
name="SecondaryNavLink",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"sort_order",
models.IntegerField(blank=True, editable=False, null=True),
),
("label", models.CharField(max_length=255)),
("url", models.CharField(max_length=255)),
(
"parent_link",
models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.PROTECT,
related_name="child_links",
to="navigation_prototype.primarynavlink",
),
),
],
options={
"abstract": False,
},
),
migrations.DeleteModel(
name="NavLink",
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 4.2.16 on 2024-12-10 16:53

from django.db import migrations
import django.db.models.deletion
import modelcluster.fields


class Migration(migrations.Migration):

dependencies = [
("navigation_prototype", "0004_primarynavlink_secondarynavlink_delete_navlink"),
]

operations = [
migrations.AlterField(
model_name="secondarynavlink",
name="parent_link",
field=modelcluster.fields.ParentalKey(
null=True,
on_delete=django.db.models.deletion.PROTECT,
related_name="child_links",
to="navigation_prototype.primarynavlink",
),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Generated by Django 4.2.16 on 2024-12-10 17:06

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
("wagtailcore", "0094_alter_page_locale"),
("navigation_prototype", "0005_alter_secondarynavlink_parent_link"),
]

operations = [
migrations.AddField(
model_name="primarynavlink",
name="page",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.PROTECT,
related_name="+",
to="wagtailcore.page",
),
),
migrations.AddField(
model_name="secondarynavlink",
name="page",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.PROTECT,
related_name="+",
to="wagtailcore.page",
),
),
migrations.AlterField(
model_name="primarynavlink",
name="url",
field=models.URLField(blank=True, null=True),
),
migrations.AlterField(
model_name="secondarynavlink",
name="url",
field=models.URLField(blank=True, null=True),
),
]
Empty file.
65 changes: 65 additions & 0 deletions src/navigation_prototype/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from django.db import models
from modelcluster.fields import ParentalKey
from modelcluster.models import ClusterableModel
from wagtail.admin.panels import PageChooserPanel
from wagtail.models import Orderable
from wagtail.snippets.models import register_snippet

from core.panels import FieldPanel, InlinePanel


@register_snippet
class Nav(ClusterableModel):
panels = [
InlinePanel("links", label="Links", min_num=1),
]


class NavLinkBase(Orderable):
label = models.CharField(max_length=255)
url = models.URLField(null=True, blank=True)
page = models.ForeignKey(
"wagtailcore.Page",
null=True,
blank=True,
on_delete=models.PROTECT,
related_name="+",
)

def get_url(self):
if self.page:
return self.page.get_full_url()
return self.url

def __str__(self):
return self.label

panels = [
FieldPanel("label"),
FieldPanel("url"),
PageChooserPanel("page"),
]

class Meta:
abstract = True


class PrimaryNavLink(ClusterableModel, NavLinkBase):
navigation = ParentalKey(
"Nav",
on_delete=models.PROTECT,
related_name="links",
)

panels = NavLinkBase.panels + [
InlinePanel("child_links", label="Sub links"),
]


class SecondaryNavLink(NavLinkBase):
parent_link = ParentalKey(
"PrimaryNavLink",
on_delete=models.PROTECT,
null=True,
related_name="child_links",
)
Loading
Loading