core/provider-configuration/provider-configuration.module.ts
Static config | ||||||
config(config: DynamicProviderConfig[])
|
||||||
Parameters :
Returns :
ModuleWithProviders<ProviderConfigurationModule>
|
When imported and configured properly this module will add one or more provider configuratin views to your application. Provider configuration views allow you to select a provider from a list of predefined providers and save credentials and other configuration data for that provider. The form where you enter your configiration and credentials is generated based on a JSON schema defined for the selected provider. Configuration can later be updated or deleted. Only one active provider configuration is currently supported, i.e. if you select a different provider from the list your old configuration will be overwritten by the new one. An exampple of a provider configuration view is the SMS provider:
The ProviderConfigurationModule
can be imported directly in your root module (usually called AppModule) or in any other module* within your application by calling its static config
method. You can import ProviderConfigurationModule
in more than one module as well as pass an array of DynamicProviderConfig
objects. Each object will create a separate provider configuration view.
In order for routing and navigation to work properly for your provider configuration views you must import
ProviderConfigurationModule
by calling its staticconfig
method within eagerly loaded modules. Should you use it in lazy loaded modules then you need to import the module directly without calling itsconfig
method. In this case you should take care of registering theProviderConfigurationComponent
on the route(s) you need and provide a configuration object withlayout
andendpoint
properties as route data.
You can define where and when your view will appear using the navigation
property of DynamicProviderConfig
. It will create a navigator node for your view allowing you to define its position via the parent
and priority
properties. Should your view appear in navigation only conditionally you can provide one or more guards that would check the necessary conditions.
ProviderConfigurationModule.config([
{
navigation: {
label: 'Your provider name',
path: 'path/to/configuration/view',
icon: 'envelope-o',
parent: 'Parent node',
priority: 1000,
canActivate: [YourFirstGuard, YourSecondGuard]
},
layout: { ... },
endpoint: { ... }
}
])
In the
canActivate
method of your guard you should not rely on theActivatedRouteSnapshot
andRouterStateSnapshot
as those will beundefined
.
You can customize all of the labels and messages in the provider configuration view. To do so provide the messages in the layout
object of your DynamicProviderConfig
. More details on the particular properties can be found in DynamicProviderLayoutConfig.
For every provider configuration view you need to define two endpoints. Your configured definitionsEndpoint
endpoint should return an array of ProviderDefinition objects. These will be the available providers to select from. Once a provider has been selected from the list a configuration form will be displayed based on its JSON schema defined in the schema
property. The configurationEndpoint
should support CRUD operations for your provider configuration types. It should support ProviderProperties objects where the provider
property should be used on both sides to identify the provider the configuration should be applied to.
ProviderConfigurationModule.config([
{
navigation: { ... },
layout: { ... },
endpoint: {
definitionsEndpoint: {
baseUrl: 'service/demo/providers',
listUrl: 'definitions'
},
configurationEndpoint: {
baseUrl: 'service/demo/providers',
listUrl: 'configuration'
}
}
}
])