generated from ministryofjustice/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Install MOJ frontend Update the sass and Makefile commands. Created header include to try the MOJ header. * Use MOJ frontend header and navigation components Use includes and context processors to build the header and nav * Move MOJ header svg to an include * Use gov uk header class * Update make static commands * Add .htmlhintrc to disable some incompatible flags * More htmllint config * Disable attr-no-duplication htmlhint as incompatible with DTL syntax * Move header and nav context to base view * Add unit tests for BaseView * Remove context processors * Add test for get_header_context * Revert "Remove context processors" This reverts commit 5f92cf0. * Revert to using context_processors in header Decided to use context_processors rather than adding a view mixin, as using a mixin means remembering to use it for every view that you add. Also reduces the chance that it is overwritten accidentally for a view. Using context processors means it is defined once, in one place, and will always be used. * Remove BaseView
- Loading branch information
1 parent
f34c865
commit 5c04e1f
Showing
17 changed files
with
269 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"tagname-lowercase": true, | ||
"attr-lowercase": true, | ||
"attr-value-double-quotes": true, | ||
"attr-value-not-empty": false, | ||
"attr-no-duplication": false, | ||
"doctype-first": false, | ||
"tag-pair": true, | ||
"tag-self-close": false, | ||
"spec-char-escape": true, | ||
"id-unique": true, | ||
"src-not-empty": true, | ||
"title-require": true, | ||
"alt-require": true, | ||
"doctype-html5": false, | ||
"id-class-value": false, | ||
"style-disabled": false, | ||
"inline-style-disabled": false, | ||
"inline-script-disabled": false, | ||
"space-tab-mixed-disabled": "space", | ||
"id-class-ad-disabled": false, | ||
"href-abs-or-rel": false, | ||
"attr-unsafe-chars": true, | ||
"head-script-disabled": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from django.urls import reverse | ||
|
||
|
||
def nav_items(request): | ||
data_products_url = reverse("data-products") | ||
return { | ||
"nav_items": [ | ||
{"name": "Home", "url": "/", "active": request.get_full_path() == "/"}, | ||
{ | ||
"name": "Data Products", | ||
"url": data_products_url, | ||
"active": request.get_full_path() == data_products_url, | ||
}, | ||
] | ||
} | ||
|
||
|
||
def header_context(request): | ||
is_logged_in = request.user.is_authenticated | ||
return { | ||
"header_nav_items": [ | ||
{ | ||
"name": request.user.name, | ||
"url": "", | ||
}, | ||
{ | ||
"name": "Sign out" if is_logged_in else "Sign in", | ||
"url": reverse("logout") if is_logged_in else reverse("login"), | ||
}, | ||
], | ||
"header_organisation_url": "https://www.gov.uk/government/organisations/ministry-of-justice", # noqa | ||
"header_service_url": "https://github.com/ministryofjustice/data-platform", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
$govuk-assets-path: "/static/assets/"; | ||
|
||
/* stylelint-disable import-notation */ | ||
@import "govuk-frontend/govuk/all"; | ||
@import "node_modules/govuk-frontend/govuk/all"; | ||
@import "node_modules/@ministryofjustice/frontend/moj/all"; | ||
|
||
/* stylelint-enable */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
controlpanel/interfaces/web/templates/includes/header.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<header class="moj-header" role="banner"> | ||
|
||
<div class="moj-header__container"> | ||
|
||
<div class="moj-header__logo"> | ||
|
||
{% include "includes/moj_header.svg" %} | ||
<a class="moj-header__link moj-header__link--organisation-name" href="{{ header_organisation_url }}">Ministry of Justice</a> | ||
|
||
<a class="moj-header__link moj-header__link--service-name" href="{{ header_service_url}}">Data Platform</a> | ||
</div> | ||
<div class="moj-header__content"> | ||
|
||
<nav class="moj-header__navigation" aria-label="Account navigation"> | ||
|
||
<ul class="moj-header__navigation-list"> | ||
{% for item in header_nav_items %} | ||
{% include "includes/nav_item.html" with item=item level="moj-header__navigation-" %} | ||
{% endfor %} | ||
</ul> | ||
|
||
</nav> | ||
|
||
</div> | ||
</div> | ||
|
||
</header> | ||
|
||
{% include "includes/navigation.html" %} |
7 changes: 7 additions & 0 deletions
7
controlpanel/interfaces/web/templates/includes/moj_header.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<li class="{{ level }}item"> | ||
<a class="{{ level }}link" {% if item.active %}aria-current="page" {% endif %}href="{{ item.url }}">{{ item.name }}</a> | ||
</li> |
20 changes: 20 additions & 0 deletions
20
controlpanel/interfaces/web/templates/includes/navigation.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<div class="moj-primary-navigation"> | ||
|
||
<div class="moj-primary-navigation__container"> | ||
|
||
<div class="moj-primary-navigation__nav"> | ||
|
||
<nav class="moj-primary-navigation" aria-label="Primary navigation"> | ||
|
||
<ul class="moj-primary-navigation__list"> | ||
{% for item in nav_items %} | ||
{% include "includes/nav_item.html" with level="moj-primary-navigation__" %} | ||
{% endfor %} | ||
</ul> | ||
|
||
</nav> | ||
|
||
</div> | ||
</div> | ||
|
||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
from django.shortcuts import render | ||
from django.views.generic import View | ||
from typing import Any | ||
|
||
from django.views.generic import TemplateView | ||
|
||
from controlpanel.core.models import User | ||
from controlpanel.interfaces.web.auth.mixins import OIDCLoginRequiredMixin | ||
|
||
|
||
class IndexView(OIDCLoginRequiredMixin, View): | ||
class IndexView(OIDCLoginRequiredMixin, TemplateView): | ||
template_name = "home.html" | ||
|
||
def get(self, request): | ||
users = User.objects.all() | ||
context = { | ||
"user": request.user, | ||
"users": users, | ||
} | ||
return render(request, "home.html", context=context) | ||
def get_context_data(self, **kwargs: Any) -> dict[str, Any]: | ||
context = super().get_context_data(**kwargs) | ||
context.update( | ||
{ | ||
"users": User.objects.all(), | ||
} | ||
) | ||
return context |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.