Commit cbf5c5b9 authored by Israel Ramos's avatar Israel Ramos Committed by Geovanni Perez

fetch settings before bootstrap the app to set language (#194)

* fetch settings before bootstrap the app to set language

* get the app config with fetch before the bootstrap

* polyfill for ie to use fetch
parent e3032a9d
......@@ -11,7 +11,7 @@ import { MatDialogModule } from '@angular/material/dialog';
import { MaterialModule } from './app.material-module';
import { MatSnackBarModule } from '@angular/material/snack-bar';
import { NgModule } from '@angular/core';
import { RecaptchaModule } from 'ng-recaptcha';
import { RecaptchaModule, RECAPTCHA_LANGUAGE } from 'ng-recaptcha';
import { RecaptchaFormsModule } from 'ng-recaptcha/forms';
import { RouterModule } from '@angular/router';
......@@ -38,7 +38,9 @@ import { RouterModule } from '@angular/router';
ReactiveFormsModule,
RouterModule
],
exports: [
]
exports: [ ],
providers: [
{ provide: RECAPTCHA_LANGUAGE, useFactory: () => window['config'].recaptcha.languageCode },
]
})
export class AppModule { }
\ No newline at end of file
......@@ -42,12 +42,12 @@ export class ChangePasswordComponent implements OnInit {
ViewOptions: ViewOptions;
// Form Controls
FormGroup = new FormGroup({
username: new FormControl('', [Validators.required]),
currentPassword: new FormControl('', [Validators.required]),
newPassword: new FormControl('', [Validators.required]),
newPasswordVerify: new FormControl('', [Validators.required])
}, PasswordMatch);
FormGroup = new FormGroup({
username: new FormControl('', [Validators.required]),
currentPassword: new FormControl('', [Validators.required]),
newPassword: new FormControl('', [Validators.required]),
newPasswordVerify: new FormControl('', [Validators.required])
}, PasswordMatch);
// Angular "OnInit": happens only on first page load
ngOnInit() {
......@@ -120,24 +120,21 @@ export class ChangePasswordComponent implements OnInit {
// Get data from the form
GetData(queryParam: string) {
this.FormData.Username = queryParam;
this.http.get<ViewOptions>('api/password')
.subscribe(data => {
this.ViewOptions = data;
this.titleService.setTitle(this.ViewOptions.changePasswordTitle + ' - ' + this.ViewOptions.applicationTitle);
if (this.ViewOptions.recaptcha.isEnabled) {
this.FormGroup.addControl('reCaptcha', new FormControl('', [Validators.required]));
const sp = document.createElement('script');
sp.type = 'text/javascript';
sp.async = true;
sp.defer = true;
sp.src = 'https://www.google.com/recaptcha/api.js?onload=vcRecaptchaApiLoaded&render=explicit&hl=' + this.ViewOptions.recaptcha.languageCode;
}
if (this.ViewOptions.defaultDomain) {
this.FormGroup.get('username').setValidators(Validators.pattern(this.ViewOptions.validationRegex.usernameRegex));
} else {
this.FormGroup.get('username').setValidators(Validators.pattern(this.ViewOptions.validationRegex.emailRegex));
}
});
this.ViewOptions = window['config'];
this.titleService.setTitle(this.ViewOptions.changePasswordTitle + ' - ' + this.ViewOptions.applicationTitle);
if (this.ViewOptions.recaptcha.isEnabled) {
this.FormGroup.addControl('reCaptcha', new FormControl('', [Validators.required]));
const sp = document.createElement('script');
sp.type = 'text/javascript';
sp.async = true;
sp.defer = true;
sp.src = 'https://www.google.com/recaptcha/api.js?onload=vcRecaptchaApiLoaded&render=explicit&hl=' + this.ViewOptions.recaptcha.languageCode;
}
if (this.ViewOptions.defaultDomain) {
this.FormGroup.get('username').setValidators(Validators.pattern(this.ViewOptions.validationRegex.usernameRegex));
} else {
this.FormGroup.get('username').setValidators(Validators.pattern(this.ViewOptions.validationRegex.emailRegex));
}
}
// Uses RecaptchaModule / RecaptchaFormsModule
......
......@@ -3,5 +3,8 @@ import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => console.log(err));
\ No newline at end of file
fetch('api/password').then(response => response.json()).then(config => {
window['config'] = config;
platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => console.log(err));
});
......@@ -2,3 +2,4 @@
import 'core-js';
import 'zone.js/dist/zone';
import 'promise-polyfill/src/polyfill';
......@@ -41,8 +41,10 @@
"@angular/router": "^6.0.0",
"core-js": "^2.5.5",
"ng-recaptcha": "^4.0.0-beta.1",
"promise-polyfill": "8.0.0",
"reflect-metadata": "^0.1.12",
"rxjs": "^6.1.0",
"whatwg-fetch": "^2.0.4",
"zone.js": "^0.8.26"
}
}
......@@ -16,7 +16,7 @@ module.exports = {
extensions: ['.ts', '.js']
},
entry: {
'main': './ClientApp/main.ts',
'main': [ 'whatwg-fetch', './ClientApp/main.ts'],
'vendor': './ClientApp/vendor.ts',
'polyfills': './ClientApp/polyfills.ts'
},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment