MvplusDynamicConfigurationLibApp
This project was generated with Angular CLI version 6.2.5.
Support
- Angular version >=5.0.0
- Rxjs@ version >=5.0.0
Upgrade version of npm plugin
Change manually the version in projects/mvplus-dynamic-configuration-lib/package.json
Build package
npm run package
Publish on npm
npm login
npm publish dist/mvplus-dynamic-configuration-lib/mvplus-dynamic-configuration-lib-
${your-version}.tgz
Usage
Import MvplusDynamicConfigurationLibModule
in your app (or core if you have) module, calling forRoot method :
Example core.module.ts
@NgModule({
imports: [
BrowserModule,
CommonModule,
LeafletModule.forRoot(),
HttpClientModule,
MvplusDynamicConfigurationLibModule.forRoot({
endpoints: [
{ name: 'dev', value: 'http://dev.virt.moviplus.ch:8083/tpc_app_clients' },
{ name: 'demo', value: 'http://demo.virt.moviplus.ch:8085/tpc_app_clients' }
],
activeEndpoint: { name: 'dev', value: 'http://demo.virt.moviplus.ch:8083/tpc_app_clients' }
})
],
providers: [],
exports: [MvplusDynamicConfigurationLibModule]
})
You can see class definitions below.
Then use the component in the view :
<mvplus-configuration-selector [buttonText]="'Open'" [customBtnClass]="['btn']"></mvplus-configuration-selector>
Input properties
buttonText
type string
, default value : 'Ouvrir'
customBtnClass
type string[]
, default value : []
forRoot
options
endpoints
This is an array of EndpointConfiguration
(see impl. below), which appear to the dropdown of backend endpoint choice.
activeEndpoint
This is a representation of EndpointConfiguration
(see impl. below), which is the default backend endpoint.
Usage of dynamic backend in code
You must inject BackendConfigService
to have access to current active endpoint.
Example
@Injectable()
export class SigninService {
constructor(
private http: HttpClient,
private authenticationService: AuthenticationService,
private backendConfigurationService: BackendConfigService) {
}
public $signin(login: string, password: string): Observable<UserResponse> {
const params: SigninParams = {
login: login,
password: password
};
const body: HttpParams = new HttpParams({ fromObject: params });
return this.http
.post<UserResponse>(`${this.backendConfigurationService.getBackend().value}/signin.cms.json`, body);
}
}
Implementation of the configuration
BackendConfig
class BackendConfig {
constructor(public endpoints: EndpointConfiguration[] = [], public activeEndpoint: EndpointConfiguration = null) {
}
}
EndpointConfiguration
interface EndpointConfiguration {
value: string;
name: string;
version: string;
}
Changelog
v1.6.1 (11.12.18)
- New method in
BackendConfigurationService
to build the URL directly,
with optional parameters to include version
of api in the url.
v1.6.0 (11.12.18)
- Add API version in `EndpointConfiguration
v1.5.9 (29.10.18)
- Remove "Close" button
- Update readme
v1.5.8 (29.10.18)
- You can change the label of the button by input
[buttonText]
of string
type - You can change the css style of the button by input
[customBtnClass]
of string[]
type