Navigation System Reference

Table of Contents


Introduction

The MVCS page navigation system consists of three parts: a nav object, a nav controller page, and a Nav Component. The nav object provides methods and properties to control page navigation, the nav page provides state variables and Model computations in support of page navigation, and the Nav Component provides the navigation "chrome" and an area to display the selected page.

Page types

The navigation system manages a page stack, representing a stack of pages from the bottommost to the topmost. All the pages on the stack remain open, but only the topmost one is active. See Page Overview for a description of page open and active states. There are three types of pages:

It is possible for the same page to appear more than once in the stack as one or more popup pages or as a base page and popup pages. Overlay pages typically appear only at the top of the stack.

The navigation system supports two styles of base page navigation:

Navigation style is controlled by setting the value of the nav_style state variable. The position of the tab is controlled by setting the value of the nav_tabFooter state variable.

Dark mode

The normal presentation style is a dark font color on a light background. If the nav_darkMode state variable value is true, then the presentation is a light font color on a dark background.

Initialization

When the application starts up, it specifies the navigation layout by calling ctl.startApp(info). The info.template property includes the Nav component. The Nav component's attributes set the menu layout and initial starting page. Note that it's possible for the application to not use the Nav component, in which case it must provide its own navigation. For example:

ctl.startApp({
	deviceType: deviceType(),
	title: 'Example 1',
	id: 'Example1',
	template: tml`<Nav layout=${['adder', 'set']} startPage=adder />`
});

The nav page provides several state variables that other pages can use to control nav page characteristics or to trigger Model or View actions:

Page histogram

The nav page maintains a special state variable, nav_pageHistogram, that contains a histogram of pages opened per session. The value is a Map. Each key is a page ID, and its value is the number of sessions in which that page has been opened; a page is counted at most once per session. The special key sessionCount holds the number of sessions. A new session starts when more than one hour passes between page openings, and when the app starts. The state variable is saved globally so that the histogram persists across sessions and app instantiations. Its saved state is an array of [key, count] entries (Array.from(map)), which is validated on restore (it must include a numeric sessionCount); an invalid saved state starts a new histogram. The state variable is never reset to a default.

Exported identifiers

Syntax

import {nav} from 'common/mvcs/export.js';

The nav object provides methods and properties to control page navigation. It is also assigned to the global/window object as window.nav for use in debugging.


The nav object contains both methods and data properties to control navigation. The methods are:

basePage()

Syntax

nav.basePage(pageId, arg)

Open pageId as a base page that replaces the current base page. The arg parameter is passed to the page's open() method. This must only be called when there are no popup or overlay pages: if any are present, the request is ignored and a message is logged. If the navigation is locked to a different page by lockPage(), the request is also silently ignored.

Parameters


currentPageId()

Syntax

nav.currentPageId()`

Returns the page ID of the currently active page on top of the page stack. This includes popup and overlay pages, so it is not necessarily the base page. It returns the value of the nav_selectedPage state variable.

Return value

A page ID string.


basePageIds()

Syntax

nav.basePageIds()

Returns the IDs of the base pages: every page that the Nav component's layout can select, in layout order, with the pages in groups flattened. These are the pages that open without an argument.

Return value

An array of page ID strings.


help()

Syntax

nav.help(pageId)
nav.help()

Opens the Help page as a popup page with pageId as the help topic. If the help page does not have a topic of that name, the topic selection is left unchanged.

Parameters


lockPage()

Syntax

nav.lockPage(pageId)

The lockPage() method opens pageId as a base page and locks the navigation so that the base page can't change. This is used to lock the Terms of Use page until it is acknowledged. The lock is released by the the unlockPage() method

Parameters


isPopup()

Syntax

nav.isPopup()

nav.isPopup() returns true if the current top page is a popup or overlay page. It returns false if the current page is a base page. It is possible for the same page to be on the page stack more than once and this method can help distinguish pages invoked as a popup page versus as a base page.

Return value

A boolean value.


popupDone()

Syntax

nav.popupDone()

Closes the current top popup or overlay page. This must only be called whent here is a popup page on the page stack. On normal popup pages popupDone() is called automatically when the user clicks the "Done" button. On overlay pages, the page must call popupDone() when the the page is dismissed.


popupPage()

Syntax

nav.popupPage(pageId, arg)

Open pageId as a popup page. The arg parameter is passed to the page's open() method.

Parameters


overlayPage()

Syntax

nav.overlayPage(pageId, arg)

Open pageId as an overlay page. The arg parameter is passed to the page's open() method.

Parameters


parseRef()

Syntax

nav.parseRef(ref)

Splits a <Ref> reference string, "pageId" or "pageId.arg", at its first . into a page ID and an argument. The argument is everything after the first ., so it may itself contain . characters.

Parameters

Return value

An array [pageId, arg], where arg is undefined if there is none. If ref is empty, an empty array.


refProblem()

Syntax

nav.refProblem(ref)

Returns a description of why a <Ref> reference can't be opened, or an empty string if it can. It checks that the page exists, that the page takes an argument if one is given, and, for the help page, that the help topic exists. Other arguments (such as a procedure or breaker) depend on the aircraft, so the application must check them. It is used to validate help and other text.

Parameters

Return value

A string: the problem description, or '' if there is no problem.


templateRefs()

Syntax

nav.templateRefs(template)

Returns the page references contained in a template: the ref of each <Ref> or <ClRef> element and the pageId of each <NavPopupButton> element. Only literal string values are found; content that is rendered by a function isn't built until the template is rendered. Templates in the props of elements (such as a Card title) are searched as well.

Parameters

Return value

An array of reference strings, "pageId" or "pageId.arg", suitable for refProblem().


unlockPage()

Syntax

nav.unlockPage()

The unlockPage() method clears the page lock initiated by the lockPage() method. It releases the lock and resets the base page to the previous value or the starting page. This is used to unlock the Terms of Use page when it is acknowledged.


Syntax

tml`
	<Nav startPage=myStartPageId layout=myPageLayout />
`

The Nav component provides the View infrastructure for standard MVCS page navigation. It displays the "chrome" that provides navigation elements and an area to display selected pages.

The layout attribute is an array that contains the page ID strings of the menu. The array can also contain an object that contains a group title and another sub-array of page IDs in the group. The layout is used to set the tab or slide-in menus. The startPage attribute sets the initially selected page.

If the application does not use the Nav component, it must provide its own navigation using the nav object methods. The Nav component calls nav.basePage() when it renders, to open the locked page, if any, or else the startPage.

Attributes


Header and button components

The navigation system also provides several small components that pages can use in their own layouts. They are available as tags in templates: