commit 4ccb6b62953e726dd01dd7f1ad17e775398e0804
Author: Pavel Fidransky <pavel.fidransky@yoso.fi>
Date:   Tue Oct 29 07:43:51 2019 +0100

    re #33: load frontend app configuration from config.json file

diff --git a/webapp/src/app/app.module.ts b/webapp/src/app/app.module.ts
index 5903849..42f812e 100644
--- a/webapp/src/app/app.module.ts
+++ b/webapp/src/app/app.module.ts
@@ -1,5 +1,5 @@
 import {BrowserModule} from '@angular/platform-browser';
-import {NgModule} from '@angular/core';
+import {NgModule, APP_INITIALIZER} from '@angular/core';
 
 import {AppRoutingModule} from './app-routing.module';
 import {AppComponent} from './app.component';
@@ -18,6 +18,9 @@ import {CommonModule} from '@angular/common';
 import {BasicAuthInterceptor} from "./auth/basic-auth.interceptor";
 import {LoginComponent} from "./login/login.component";
 
+import {loadConfig} from './loadConfig';
+import {Config} from './services/util/config.service';
+
 @NgModule({
   declarations: [
     AppComponent,
@@ -45,7 +48,20 @@ import {LoginComponent} from "./login/login.component";
     CommonModule
   ],
   providers: [
-    {provide: HTTP_INTERCEPTORS, useClass: BasicAuthInterceptor, multi: true}
+    {
+      provide: HTTP_INTERCEPTORS,
+      useClass: BasicAuthInterceptor,
+      multi: true,
+    },
+    {
+      provide: APP_INITIALIZER,
+      useFactory: loadConfig,
+      deps: [
+        HttpClient,
+        Config,
+      ],
+      multi: true
+    },
   ],
   bootstrap: [AppComponent]
 })
diff --git a/webapp/src/app/loadConfig.ts b/webapp/src/app/loadConfig.ts
new file mode 100644
index 0000000..2ee0471
--- /dev/null
+++ b/webapp/src/app/loadConfig.ts
@@ -0,0 +1,16 @@
+import { HttpClient } from '@angular/common/http';
+import { Config } from './services/util/config.service';
+
+export function loadConfig(http: HttpClient, config: Config) {
+  return (): Promise<void> => {
+    const configFile = 'assets/config/config.json';
+
+    return new Promise<void>((resolve, reject) => {
+      http.get(configFile).toPromise().then((response: any) => {
+        config.baseUrl = response.baseUrl;
+        config.redirectUrl = response.redirectUrl;
+        resolve();
+      });
+    });
+  };
+}
\ No newline at end of file
diff --git a/webapp/src/app/login/login.component.html b/webapp/src/app/login/login.component.html
index 8dbb28a..251ff22 100644
--- a/webapp/src/app/login/login.component.html
+++ b/webapp/src/app/login/login.component.html
@@ -3,7 +3,7 @@
     <h1>Sign-in</h1>
 
     <p>Please sign-in using one of the following methods: </p>
-    <a href="http://localhost:9080/api/signin/google?target=http://localhost">Login with Google</a>
+    <a href="{{loginUrl}}">Login with Google</a>
   </div>
 </div>
 
diff --git a/webapp/src/app/login/login.component.ts b/webapp/src/app/login/login.component.ts
index 52ce458..4b8a706 100644
--- a/webapp/src/app/login/login.component.ts
+++ b/webapp/src/app/login/login.component.ts
@@ -1,4 +1,5 @@
 import {Component, OnInit} from '@angular/core';
+import { Config } from '../services/util/config.service';
 
 @Component({
   selector: 'app-page-not-found',
@@ -6,8 +7,10 @@ import {Component, OnInit} from '@angular/core';
   styleUrls: ['./login.component.sass']
 })
 export class LoginComponent implements OnInit {
+  loginUrl: string;
 
-  constructor() {
+  constructor(private config: Config) {
+    this.loginUrl = config.loginUrl;
   }
 
   ngOnInit() {
diff --git a/webapp/src/app/services/api/basic.service.ts b/webapp/src/app/services/api/basic.service.ts
index e1fe2f3..2fe1dd8 100644
--- a/webapp/src/app/services/api/basic.service.ts
+++ b/webapp/src/app/services/api/basic.service.ts
@@ -1,16 +1,19 @@
 import {Injectable} from '@angular/core';
 import {HttpClient, HttpErrorResponse, HttpParams} from '@angular/common/http';
 import {throwError} from 'rxjs';
-import {environment} from '../../../environments/environment';
 import {MatSnackBar} from '@angular/material';
 import {TranslateService} from '@ngx-translate/core';
+import { Config } from '../util/config.service';
+
 @Injectable({
   providedIn: 'root'
 })
 export class BasicService {
-  protected baseUrl = environment.apiUrl;
+  protected baseUrl: string;
 
-  constructor(protected http: HttpClient, protected snackBar: MatSnackBar, protected translateService: TranslateService) { }
+  constructor(protected config: Config, protected http: HttpClient, protected snackBar: MatSnackBar, protected translateService: TranslateService) {
+    this.baseUrl = config.baseUrl;
+  }
 
   protected handleError(error: HttpErrorResponse) {
     let errMsg;
diff --git a/webapp/src/app/services/api/file.service.ts b/webapp/src/app/services/api/file.service.ts
index 7bb45cb..095e164 100644
--- a/webapp/src/app/services/api/file.service.ts
+++ b/webapp/src/app/services/api/file.service.ts
@@ -5,14 +5,15 @@ import {catchError} from 'rxjs/operators';
 import {Languages} from '../../enums/common.enum';
 import {MatSnackBar} from '@angular/material';
 import {TranslateService} from '@ngx-translate/core';
+import { Config } from '../util/config.service';
 
 @Injectable({
   providedIn: 'root'
 })
 export class FileService extends BasicService {
 
-  constructor(protected http: HttpClient, protected snackBar: MatSnackBar, protected translateService: TranslateService) {
-    super(http, snackBar, translateService);
+  constructor(protected config: Config, protected http: HttpClient, protected snackBar: MatSnackBar, protected translateService: TranslateService) {
+    super(config, http, snackBar, translateService);
   }
 
   /**
diff --git a/webapp/src/app/services/api/settings.service.ts b/webapp/src/app/services/api/settings.service.ts
index a2c6479..6881d48 100644
--- a/webapp/src/app/services/api/settings.service.ts
+++ b/webapp/src/app/services/api/settings.service.ts
@@ -7,6 +7,7 @@ import { Settings } from '../../models/settings.model';
 import {Languages} from '../../enums/common.enum';
 import {MatSnackBar} from '@angular/material';
 import {TranslateService} from '@ngx-translate/core';
+import { Config } from '../util/config.service';
 
 @Injectable({
   providedIn: 'root'
@@ -14,8 +15,8 @@ import {TranslateService} from '@ngx-translate/core';
 export class SettingsService extends BasicService {
   defaultSettingsUrl = this.baseUrl + '/api/settings';
 
-  constructor(protected http: HttpClient, protected snackBar: MatSnackBar, protected translateService: TranslateService) {
-    super(http, snackBar, translateService);
+  constructor(protected config: Config, protected http: HttpClient, protected snackBar: MatSnackBar, protected translateService: TranslateService) {
+    super(config, http, snackBar, translateService);
   }
 
   /**
diff --git a/webapp/src/app/services/api/user.service.ts b/webapp/src/app/services/api/user.service.ts
index 676240f..9245ac9 100644
--- a/webapp/src/app/services/api/user.service.ts
+++ b/webapp/src/app/services/api/user.service.ts
@@ -11,6 +11,7 @@ import {MatSnackBar} from '@angular/material';
 import {DateFormatterService} from '../util/date-formatter.service';
 import {TranslateService} from '@ngx-translate/core';
 import {ProfileService} from "../util/profile.service";
+import { Config } from '../util/config.service';
 
 @Injectable({
   providedIn: 'root'
@@ -18,8 +19,8 @@ import {ProfileService} from "../util/profile.service";
 export class UserService extends BasicService { // dost podobny k usersService, mozna zmenit v rest api
   private _userUrl = this.baseUrl + '/api/user/';
 
-  constructor(protected http: HttpClient, protected snackBar: MatSnackBar, protected translateService: TranslateService, protected profileService: ProfileService, private dateFormater: DateFormatterService) {
-    super(http, snackBar, translateService);
+  constructor(protected config: Config, protected http: HttpClient, protected snackBar: MatSnackBar, protected translateService: TranslateService, protected profileService: ProfileService, private dateFormater: DateFormatterService) {
+    super(config, http, snackBar, translateService);
   }
 
   /**
diff --git a/webapp/src/app/services/api/users.service.ts b/webapp/src/app/services/api/users.service.ts
index cb72294..1cd6488 100644
--- a/webapp/src/app/services/api/users.service.ts
+++ b/webapp/src/app/services/api/users.service.ts
@@ -9,6 +9,7 @@ import {Observable} from 'rxjs';
 import {UserBasicInformation, UserProfile} from '../../models/user.model';
 import {MatSnackBar} from '@angular/material';
 import {TranslateService} from '@ngx-translate/core';
+import { Config } from '../util/config.service';
 
 @Injectable({
   providedIn: 'root'
@@ -16,8 +17,8 @@ import {TranslateService} from '@ngx-translate/core';
 export class UsersService extends BasicService {
   private _usersUrl = this.baseUrl + '/api/users';
 
-  constructor(protected http: HttpClient, protected snackBar: MatSnackBar, protected translateService: TranslateService) {
-    super(http, snackBar, translateService);
+  constructor(protected config: Config, protected http: HttpClient, protected snackBar: MatSnackBar, protected translateService: TranslateService) {
+    super(config, http, snackBar, translateService);
   }
 
   /**
diff --git a/webapp/src/app/services/util/config.service.ts b/webapp/src/app/services/util/config.service.ts
new file mode 100644
index 0000000..81e2970
--- /dev/null
+++ b/webapp/src/app/services/util/config.service.ts
@@ -0,0 +1,13 @@
+import {Injectable} from '@angular/core';
+
+@Injectable({
+  providedIn: 'root'
+})
+export class Config {
+  baseUrl: string;
+  redirectUrl: string;
+
+  get loginUrl(): string {
+    return this.baseUrl + '/api/login/google?target=' + this.redirectUrl;
+  }
+}
\ No newline at end of file
diff --git a/webapp/src/assets/config/config.json b/webapp/src/assets/config/config.json
new file mode 100644
index 0000000..535beb6
--- /dev/null
+++ b/webapp/src/assets/config/config.json
@@ -0,0 +1,4 @@
+{
+	"baseUrl": "http://localhost:9080",
+	"redirectUrl": "http://localhost"
+}
\ No newline at end of file
diff --git a/webapp/src/environments/environment.prod.ts b/webapp/src/environments/environment.prod.ts
index f478df8..c966979 100644
--- a/webapp/src/environments/environment.prod.ts
+++ b/webapp/src/environments/environment.prod.ts
@@ -1,4 +1,3 @@
 export const environment = {
   production: true,
-  apiUrl: 'http://localhost:9080/' // TODO Change to production url
 };
diff --git a/webapp/src/environments/environment.ts b/webapp/src/environments/environment.ts
index 8b6de2f..a20cfe5 100644
--- a/webapp/src/environments/environment.ts
+++ b/webapp/src/environments/environment.ts
@@ -1,4 +1,3 @@
 export const environment = {
   production: false,
-  apiUrl: 'http://localhost:9080'
 };
