pwix:app-pages
What is it ?
A package which let an application describe its pages, modals and so on, said display units.
The packages provides four client classes:
-
AppPages.DisplayUnitwhich manages each display unit, -
AppPages.DisplaySetwhich gathers all display units of the application -
AppPages.MenuItemwhich defines an interface a menu item may provide -
AppPages.RunContextwhich provides and manages runtime live informations and permissions about the currently displayed unit.
These classes are defined, and can be used, in common code.
Installation
This Meteor package is installable with the usual command:
meteor add pwix:app-pages meteor npm install lodash --save
Provides
AppPages
The exported AppPages global object provides following items:
Classes
AppPages.DisplaySet
The set of AppPages.DisplayUnit instances. There is at most one per application.
This class can be used as-is, or can be derived by the application.
Methods are:
-
new AppPages.DisplaySet( set<Object> ): AppPages.DisplaySetThe constructor.
it takes following arguments:
set:, an object where the keys are the (unique) name of the display units, and the values an object which describes the properties of the display unit.
We have chosen to not force a singleton implementation. Nonetheless, the last instance is stored as
AppPages.displaySetReactiveVar. -
async allowedInMenu( menu<String>, user<String> ): Array<AppPages.DisplayUnit>This method returns the list of
AppPages.DisplayUnits which are contained in the named menu, and are allowed to the specified user. -
byName( name<String> ): AppPages.DisplayUnit|nullThis method returns the named
AppPages.DisplayUnitif found, or null. -
async enumerate( cb<Function>, args<Any> )This method iterates through the
AppPages.DisplaySetset, and calls thecbcallback with theargsargument.The enumeration is stopped when the callback returns
false.The callback has following prototype:
async cb( name<String>, unit<AppPages.DisplayUnit>, args<Any> ): Boolean.
AppPages.DisplayUnit
A display unit, either a page or a modal or anything which can be addressed, from a menu, via a route, or anything.
This class can be used as-is, or can be derived by the application.
Methods are:
-
new AppPages.DisplayUnit( name<String>, properties<Object> ): AppPages.DisplayUnitThe constructor.
it takes following arguments:
-
name: the (unique) name of the display unit -
properties: the display unit properties:-
classesType: Array
The classes to be added.
Defaulting to the configured value.
-
inMenusDefinition type: String or Array of strings
Returned type: Array of strings
The menus names in which this page may appear as an item.
Defaulting to an empty array.
Starting with v1.4, this property is ignored when the application defines a
MenuSet. -
menuIconType: String
The name of the FontAwesome icon to be used in front of the menu label.
Defaulting to the configured value.
-
menuLabelType: String
The I18n translation key for the menu label.
Defaulting to the (untranslated) display unit name.
-
routethe route to the page
Defaulting to null.
-
templateType: String
The template to be loaded
Defaulting to null.
Please note that this option must be set to get any rendering.
-
templateParmsType: Object|Function
Parameters to be passed to the template, defaulting to an empty object.
-
wantPermissionType: String
A permission string to be passed as the action to an
isAllowed()function, defaulting to null (allowed)This permission is expected to determine the display/availability/visibility of the display unit for the current user.
Do not set anything here for public pages.
Contrarily, having a
wantPermissionnon-empty string means that the permissions of the current user must be validated by the application through the configuredallowFn()function.
-
-
-
async accessAllowed(): BooleanThis method determines if the current user is allowed to access the display unit.
It calls the
allowFn()configured function with thewantPermissionaction string of the display unit. -
get( key<String> ): AnyThis method returns the parameter value for the specified key.
-
name(): StringThis method returns the unique name of this
AppPages.DisplayUnit.
AppPages.MenuItem
This class defines an interface a menu item may provide.
This class can be used as-is, or can be derived by the application.
Methods are:
-
new AppPages.MenuItem({ icon<Any>, css<Any>, label<Any>, event<Any> }): AppPages.MenuItemThe constructor.
-
css(): AnyReturns the class.
-
event(): AnyReturns the event.
-
icon(): AnyReturns the icon.
-
label(): AnyReturns the label.
AppPages.MenuSet
This class defines a menu as an ordered list of DisplayUnits.
Methods are:
-
new AppPages.MenuSet({ name<String>, def<Array> }): AppPages.MenuSetThe constructor, where:
-
nameis the name of the menu, must be unique in the application -
defis an array where each item can be:-
an object with a single
unitkey, whose value must be an object with a singlenamekey identifying theDisplayUnit -
an object with a single
menukey, whose value must be an object with:-
an optional
iconkey providing the icon display as a HTML string -
a
labelkey providing the localized label to be displayed to open the sub-menu -
a
namekey identifying another menu as a sub-menu
-
-
an object with a single
dividerkey, which will be honored if its value is truethy.
-
-
-
static async getMenu( name<String> ): ArrayReturns the named menu as an array where each item can be:
-
an allowed
DisplayUnit -
the
AppPages.C.Dividerconstant -
a
{ label, menu }object.
-
-
static hasMenu( name<String): BooleanWhether the named menu has been defined.
Example:
1 new AppPages.MenuSet( 'app_menu_button', [ 2 { unit: { name: 'managers' }}, 3 { divider: true }, 4 { unit: { name: 'organization' }}, 5 { unit: { name: 'resources' }}, 6 { divider: true }, 7 { unit: { name: 'settings' }} 8 ]);
As the AppPages.MenuSet class keeps itself all definitions, there is no need for the application to keep the menuSet instance in a specific variable.
New in v1.4.
AppPages.RunContext
Let the application access or manages to live informations and permissions.
This class can be used as-is, or can be derived by the application.
Methods are:
-
new AppPages.RunContext(): AppPages.RunContextThe constructor.
We have chosen to not force a singleton implementation. Nonetheless, the last instance is stored as
AppPages.runContextReactiveVar. -
currentPage(): AppPages.DisplayUnitThis method returns the current display unit computed from the current route.
A reactive data source.
-
async getMenu( name<String> ): Array<AppPages.DisplayUnit>Returns the list of the display units available in the specified menu and allowed to the current user.
-
async wantFooter(): BooleanWhether we want display a page footer.
This method should most probably be overriden by the application.
Defaults to
true. -
async wantHeader(): BooleanWhether we want display a page header.
This method should most probably be overriden by the application.
Defaults to
true.
Functions
AppPages.configure()
See below.
A reactive data source.
Objects
displayUnitDefs
The pwix:app-pages package offers a AppPages.displayUnitDefs empty object as a placeholder where other packages are free to install the definitions of the display units they want exhibit.
Most often, the application may so:
-
install its own display unit definitions
-
instanciate its display set with:
1 new AppPages.DisplaySet( AppPages.displayUnitDefs );
Remind that the resulting display set will be available as a `AppPages.displaySet` ReactiveVar.
Permissions management
This package can take advantage of pwix:permissions package to manage the user permissions through the wantPermission DisplayUnit property. When present, the property is used as the action string identifier when calling the configured allowFn() function.
Configuration
The package's behavior can be configured through a call to the AppPages.configure() method, with just a single javascript object argument, which itself should only contains the options you want override.
Known configuration options are:
-
allowFnAn async function which will be called with an action string identifier, and must return whether the current user is allowed to do the specified action.
If the function is not provided, then the default is to deny all actions.
allowFnprototype is:async allowFn( permission<String>, user<String|Object>, page<DisplayUnit> ): Boolean -
classesA list of classes to be added to display units.
Default to
[ 't-page' ]. -
menuIconThe menu icon, defaulting to
fa-chevron-right. -
verbosityDefine the expected verbosity level.
The accepted value can be any or-ed combination of following:
-
AppPages.C.Verbose.NONEDo not display any trace log to the console
-
AppPages.C.Verbose.CONFIGURETrace
AppPages.configure()calls and their result -
AppPages.C.Verbose.CUURENT_PAGETrace the current page changes
-
AppPages.C.Verbose.DISPLAY_UNITTrace DisplayUnit's instanciations
-
AppPages.C.Verbose.FUNCTIONSTrace all functions calls
-
Please note that AppPages.configure() method should be called in the same terms both in client and server sides.
Remind too that Meteor packages are instanciated at application level. They are so only configurable once, or, in other words, only one instance has to be or can be configured. Addtionnal calls to AppPages.configure() will just override the previous one. You have been warned: only the application should configure a package.
NPM peer dependencies
Starting with v 0.1.0, and in accordance with advices from the Meteor Guide, we no more hardcode NPM dependencies in the Npm.depends clause of the package.js.
Instead we check npm versions of installed packages at runtime, on server startup, in development environment.
Dependencies as of v 1.4.0:
1 '@vestergaard-company/js-mixin': '^1.0.3', 2 'lodash': '^4.17.0'
Each of these dependencies should be installed at application level:
meteor npm install <package> --save
Translations
None at the moment.
Cookies and comparable technologies
None at the moment.
Issues & help
In case of support or error, please report your issue request to our Issues tracker.
P. Wieser
- Last updated on 2026, May. 31st