diff --git a/web/.angular-cli.json b/web/.angular-cli.json index 886ad2b27..debf28c4c 100644 --- a/web/.angular-cli.json +++ b/web/.angular-cli.json @@ -9,7 +9,8 @@ "outDir": "dist", "assets": [ "assets", - "taskana.ico" + "taskana.ico", + "environments/data-sources" ], "index": "index.html", "main": "main.ts", diff --git a/web/src/app/app-routing.module.ts b/web/src/app/app-routing.module.ts index 4edda3429..39683b68c 100644 --- a/web/src/app/app-routing.module.ts +++ b/web/src/app/app-routing.module.ts @@ -8,11 +8,13 @@ import { MasterAndDetailComponent } from './shared/master-and-detail/master-and- import { NoAccessComponent } from './administration/workbasket/details/noAccess/no-access.component'; import { ClassificationListComponent } from './administration/classification/master/list/classification-list.component'; import { ClassificationDetailsComponent } from 'app/administration/classification/details/classification-details.component'; +import { EnvironmentUrlGuard } from 'app/guards/environment-url-guard'; const appRoutes: Routes = [ { path: 'administration/workbaskets', component: MasterAndDetailComponent, + canActivate: [EnvironmentUrlGuard], children: [ { path: '', @@ -39,6 +41,7 @@ const appRoutes: Routes = [ { path: 'administration/classifications', component: MasterAndDetailComponent, + canActivate: [EnvironmentUrlGuard], children: [ { path: '', diff --git a/web/src/app/app.module.ts b/web/src/app/app.module.ts index c4a1420aa..e913c5b9b 100644 --- a/web/src/app/app.module.ts +++ b/web/src/app/app.module.ts @@ -59,6 +59,7 @@ import { TreeService } from './services/tree/tree.service'; import { ClassificationTypesService } from './services/classification-types/classification-types.service'; import { ClassificationCategoriesService } from 'app/services/classification-categories-service/classification-categories.service'; + /** * Pipes */ @@ -68,6 +69,11 @@ import { SelectWorkBasketPipe } from './pipes/selectedWorkbasket/seleted-workbas import { SpreadNumberPipe } from './pipes/spreadNumber/spread-number'; import { DomainService } from './services/domain/domain.service'; +/** + * Guards + */ +import { EnvironmentUrlGuard } from './guards/environment-url-guard'; + const MODULES = [ BrowserModule, FormsModule, @@ -135,7 +141,8 @@ const DECLARATIONS = [ ClassificationsService, TreeService, ClassificationTypesService, - ClassificationCategoriesService + ClassificationCategoriesService, + EnvironmentUrlGuard ], bootstrap: [AppComponent] }) diff --git a/web/src/app/guards/environment-url-guard.ts b/web/src/app/guards/environment-url-guard.ts new file mode 100644 index 000000000..92074c15b --- /dev/null +++ b/web/src/app/guards/environment-url-guard.ts @@ -0,0 +1,28 @@ +import { Observable } from 'rxjs/Observable'; +import { HttpClient } from '@angular/common/http'; +import { CanActivate } from '@angular/router'; +import { environment } from 'app/../environments/environment'; +import { Injectable } from '@angular/core'; + +@Injectable() +export class EnvironmentUrlGuard implements CanActivate { + constructor(private httpClient: HttpClient) { } + + canActivate() { + return this.httpClient.get('environments/data-sources/environment-information.json').map(jsonFile => { + if (jsonFile) { + environment.taskanaWorkplaceUrl = jsonFile.taskanaWorkplaceUrl === '' ? + environment.taskanaWorkplaceUrl : jsonFile.taskanaWorkplaceUrl; + environment.taskanaAdminUrl = jsonFile.taskanaAdminUrl === '' ? + environment.taskanaAdminUrl : jsonFile.taskanaAdminUrl; + environment.taskanaMonitorUrl = jsonFile.taskanaMonitorUrl === '' ? + environment.taskanaMonitorUrl : jsonFile.taskanaMonitorUrl; + environment.taskanaRestUrl = jsonFile.taskanaRestUrl === '' ? + environment.taskanaRestUrl : jsonFile.taskanaRestUrl; + } + return true; + }).catch(() => { + return Observable.of(true) + }); + } +} diff --git a/web/src/app/services/httpClientInterceptor/http-client-interceptor.service.ts b/web/src/app/services/httpClientInterceptor/http-client-interceptor.service.ts index e9d94b419..910b51f2b 100644 --- a/web/src/app/services/httpClientInterceptor/http-client-interceptor.service.ts +++ b/web/src/app/services/httpClientInterceptor/http-client-interceptor.service.ts @@ -29,6 +29,8 @@ export class HttpClientInterceptor implements HttpInterceptor { this.requestInProgressService.setRequestInProgress(false); if (err instanceof HttpErrorResponse && (err.status === 401 || err.status === 403)) { this.permissionService.setPermission(false) + } else if (err instanceof HttpErrorResponse && (err.status === 404) && err.url.indexOf('environment-information.json')) { + // ignore this error message } else { this.errorModalService.triggerError( new ErrorModel('There was error, please contact with your administrator ', err)) diff --git a/web/src/environments/data-sources/environment-information.json b/web/src/environments/data-sources/environment-information.json new file mode 100644 index 000000000..8ef643f83 --- /dev/null +++ b/web/src/environments/data-sources/environment-information.json @@ -0,0 +1,6 @@ +{ + "taskanaAdminUrl": "", + "taskanaWorkplaceUrl": "", + "taskanaMonitorUrl": "", + "taskanaRestUrl": "" +} \ No newline at end of file