@companieshouse/ch-node-utils 1.3.2 → 1.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -0
- package/package.json +1 -1
- package/templates/navbar.njk +74 -0
package/README.md
CHANGED
|
@@ -76,3 +76,27 @@ Available as a normal npm dependency([here on npmjs](https://www.npmjs.com/packa
|
|
|
76
76
|
| ------- | ----------- |
|
|
77
77
|
|`CH_NODE_UTILS_DROP_LANG_QUERY_PARAM`| It could be set to [drop the lang="xx" query param](https://github.com/companieshouse/ch-node-utils/blob/f9e5c47a86206f0b12e4e536c4c459db16747631/src/middleware/manageLocales.middleware.ts#L25) from the current URL ([see Example](https://github.com/companieshouse/docker-chs-development/blob/842c61245adcbba02a6316847fc4f9d94c52410d/services/modules/dissolution/dissolution-web.docker-compose.yaml#L50)) |
|
|
78
78
|
|`CH_NODE_UTILS_LOG_LVL`| It could be set to ["TRACE" or "DEBUG" (case insensitive)](https://github.com/companieshouse/ch-node-utils/blob/24bc717477d21082439d1b460108cb0d60465f0f/src/utils/log.ts#L2) to dump internal info while inside ch-node-utils ([see Example](https://github.com/companieshouse/docker-chs-development/blob/842c61245adcbba02a6316847fc4f9d94c52410d/services/modules/dissolution/dissolution-web.docker-compose.yaml#L49))|
|
|
79
|
+
|
|
80
|
+
### Menu navigation bar
|
|
81
|
+
A menu navigation bar component has been added to make it easier to add links pointing to new services when needed. There are two Nunjucks macros: one that adds a menu navigation bar with the provided items and another that adds a menu navigation bar with predefined items. The latter internally uses the former and at the moment contains links to the following service:
|
|
82
|
+
|
|
83
|
+
- Authorised agent
|
|
84
|
+
- Your companies
|
|
85
|
+
- Your filings
|
|
86
|
+
- Companies you follow
|
|
87
|
+
- Basket
|
|
88
|
+
- Manage account
|
|
89
|
+
- Sign out
|
|
90
|
+
|
|
91
|
+
The "Authorised agent" menu item appears conditionally if the logged user has ACSP membership.
|
|
92
|
+
|
|
93
|
+
The navbar requires importing language files from the `locales` folder in ch-node-utils and making them available to all Nunjuck templates using the [`addGlobal()` function](https://mozilla.github.io/nunjucks/api.html#addglobal) in `app.ts`. At the moment only English and Welsh language versions are supported. It also requires a flag `displayAuthorisedAgent` set the same way for displaying the "Authorised agent" menu item. If the logged user has ACSP membership, this flag should be set to `'yes'`.
|
|
94
|
+
|
|
95
|
+
The navbar also requires the use of styles provided in the [ch.gov.uk.css](https://github.com/companieshouse/cdn.ch.gov.uk/blob/master/app/assets/stylesheets/ch.gov.uk.css) stylesheet (you can either add the provided link to the head section or include specific styles in your own stylesheet)
|
|
96
|
+
|
|
97
|
+
`<link href="{{ cdnHost }}/stylesheets/ch.gov.uk.css" rel="stylesheet"/>`
|
|
98
|
+
|
|
99
|
+
It also requires the [navbar.js](https://github.com/companieshouse/cdn.ch.gov.uk/blob/master/app/assets/javascripts/lib/navbar.js) script to be added to the footer to make the navbar work in mobile mode
|
|
100
|
+
|
|
101
|
+
`<script src="{{ cdnHost }}/javascripts/lib/navbar.js"></script>`
|
|
102
|
+
|
package/package.json
CHANGED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
{#
|
|
2
|
+
GENERAL NOTES:
|
|
3
|
+
The navbar requires importing language files from the locales folder in ch-node-utils
|
|
4
|
+
and making them available to all Nunjuck templates using the addGlobal() function in app.ts.
|
|
5
|
+
It also requires a flag displayAuthorisedAgent set the same way for displaying the 'Authorised agent'
|
|
6
|
+
menu item. If the logged user has ACSP membership, this flag should be set to 'yes'.
|
|
7
|
+
|
|
8
|
+
It also requires the use of styles provided in the following stylesheet
|
|
9
|
+
(you can either add the provided link to the head section or include specific
|
|
10
|
+
styles in your own stylesheet)
|
|
11
|
+
|
|
12
|
+
<link href="{{ cdnHost }}/stylesheets/ch.gov.uk.css" rel="stylesheet"/>
|
|
13
|
+
|
|
14
|
+
It also requires the following script to be added to the footer
|
|
15
|
+
|
|
16
|
+
<script src="{{ cdnHost }}/javascripts/lib/navbar.js"></script>
|
|
17
|
+
#}
|
|
18
|
+
|
|
19
|
+
{#
|
|
20
|
+
A macro that adds a menu navigation bar with the provided items.
|
|
21
|
+
It receives:
|
|
22
|
+
- signInHref: the URL of the sign in / register page
|
|
23
|
+
- menuItems: a collection of objects representing individual menu items.
|
|
24
|
+
Each object must contain properties with the following keys to build an anchor:
|
|
25
|
+
- id: it's the anchor element id
|
|
26
|
+
- href: the URL of the page the menu item will point to
|
|
27
|
+
- displayText: the text to display in the anchor
|
|
28
|
+
- userDisplayText: a text identifying the logged user, e.g. email address or name
|
|
29
|
+
#}
|
|
30
|
+
{% macro addNavbar(signInHref, menuItems, userDisplayText) %}
|
|
31
|
+
<div class="js-toggle-nav" id="global-nav">
|
|
32
|
+
<nav role="navigation" class="content" aria-label="{{ lang.mainNavbar or 'The main navigation bar' }}">
|
|
33
|
+
{% if userDisplayText %}
|
|
34
|
+
<a href="#navigation" class="js-header-toggle menu">{{ userDisplayText }}
|
|
35
|
+
<span class="govuk-visually-hidden">{{ lang.clickToExpandOrCollapse or 'Click to expand or collapse' }}</span>
|
|
36
|
+
</a>
|
|
37
|
+
{% else %}
|
|
38
|
+
<a id="user-signin-mobile" href="{{ signInHref }}" class="sign-in govuk-link">{{ lang.signInOrRegister or 'Sign in / Register' }}</a>
|
|
39
|
+
{% endif %}
|
|
40
|
+
|
|
41
|
+
<ul id="navigation">
|
|
42
|
+
<li id="signed-in-user" class="user">
|
|
43
|
+
{{ userDisplayText }}
|
|
44
|
+
</li>
|
|
45
|
+
{% for item in menuItems %}
|
|
46
|
+
<li>
|
|
47
|
+
<a class="govuk-link" id="{{ item.id }}" href="{{ item.href }}">{{ item.displayText }}</a>
|
|
48
|
+
</li>
|
|
49
|
+
{% endfor %}
|
|
50
|
+
</ul>
|
|
51
|
+
</nav>
|
|
52
|
+
</div>
|
|
53
|
+
{% endmacro %}
|
|
54
|
+
|
|
55
|
+
{#
|
|
56
|
+
A macro that adds a menu navigation bar with predefined items.
|
|
57
|
+
It receives:
|
|
58
|
+
- userDisplayText: a text identifying the logged user, e.g. email address or name
|
|
59
|
+
- chsMonitorGuiUrl: the URL for the 'Companies you follow' link
|
|
60
|
+
#}
|
|
61
|
+
{% macro addPredefinedNavbar(userDisplayText, chsMonitorGuiUrl) %}
|
|
62
|
+
{% set menuItems = [
|
|
63
|
+
{ id: "authorised-agent", href: "/authorised-agent", displayText: lang.authorisedAgent or "Authorised agent" } if displayAuthorisedAgent === "yes",
|
|
64
|
+
{ id: "your-companies", href: "/your-companies", displayText: lang.yourCompanies or "Your companies" },
|
|
65
|
+
{ id: "your-filings", href: "/user/transactions", displayText: lang.yourFilings or "Your filings" },
|
|
66
|
+
{ id: "companies-you-follow", href: chsMonitorGuiUrl, displayText: lang.companiesYouFollow or "Companies you follow" },
|
|
67
|
+
{ id: "basket", href: "/basket", displayText: lang.basket or "Basket" },
|
|
68
|
+
{ id: "your-details", href: "/user/account", displayText: lang.manageAccount or "Manage account" },
|
|
69
|
+
{ id: "user-signout", href: "/signout", displayText: lang.signOut or "Sign out" }
|
|
70
|
+
] | reject("falsy") %}
|
|
71
|
+
|
|
72
|
+
{{ addNavbar("/signin", menuItems, userDisplayText) }}
|
|
73
|
+
|
|
74
|
+
{% endmacro %}
|