diff --git a/goofy-client/apps/goofy/src/app/app.component.html b/goofy-client/apps/goofy/src/app/app.component.html index 9d48b30975199d67f34a8b226891ffc7744a726d..a88d6c715f604116de4ab10440a97718912d5fbb 100644 --- a/goofy-client/apps/goofy/src/app/app.component.html +++ b/goofy-client/apps/goofy/src/app/app.component.html @@ -1,18 +1,23 @@ <ng-container *ngIf="apiRoot$ | async as apiRoot"> - <goofy-client-header - [darkMode]="darkMode$ | async" [navigationCollapse]="navigationCollapse$ | async" - (toggleMenuEvent)="toggleNavigation($event)" (darkModeEmitter)="changeColorMode($event)"> + <goofy-client-header + [darkMode]="darkMode$ | async" + [navigationCollapse]="navigationCollapse$ | async" + (toggleMenuEvent)="toggleNavigation($event)" + (darkModeEmitter)="changeColorMode($event)" + > </goofy-client-header> <div class="container"> - <goofy-client-navigation [isSmall]="navigationCollapse$ | async"></goofy-client-navigation> + <goofy-client-navigation [isSmall]="navigationCollapse$ | async"></goofy-client-navigation> <main><router-outlet></router-outlet></main> <section> <goofy-client-build-info [apiRoot]="apiRoot"></goofy-client-build-info> </section> </div> </ng-container> - +<!-- <ng-container *ngIf="apiRootStateless$ | async as apiRootStateless"> {{apiRootStateless | json}} -</ng-container> \ No newline at end of file +</ng-container> + +--> diff --git a/goofy-client/apps/goofy/src/app/app.module.ts b/goofy-client/apps/goofy/src/app/app.module.ts index 8c5d915cc3187af0d3ff8f355ffec45949dffe3e..74fca048c269e8432586ac64da8e02b1cfe6c74f 100644 --- a/goofy-client/apps/goofy/src/app/app.module.ts +++ b/goofy-client/apps/goofy/src/app/app.module.ts @@ -1,21 +1,21 @@ +import { registerLocaleData } from '@angular/common'; import { HttpClientModule } from '@angular/common/http'; -import { LOCALE_ID, NgModule } from '@angular/core'; import localeDe from '@angular/common/locales/de'; +import { LOCALE_ID, NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; -import { ApiRootSharedModule } from '@goofy-client/api-root-shared'; -import { EnvironmentSharedModule } from '@goofy-client/environment-shared'; -import { NgxsReduxDevtoolsPluginModule } from '@ngxs/devtools-plugin'; -import { NgxsLoggerPluginModule } from '@ngxs/logger-plugin'; -import { NgxsModule } from '@ngxs/store'; -import { AppComponent } from './app.component'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { RouterModule } from '@angular/router'; +import { ApiRootSharedModule } from '@goofy-client/api-root-shared'; +import { EnvironmentModule } from '@goofy-client/environment-shared'; +import { NavigationModule } from '@goofy-client/navigation'; import { UiModule } from '@goofy-client/ui'; import { VorgangModule } from '@goofy-client/vorgang'; -import { registerLocaleData } from '@angular/common'; -import { NgxsRouterPluginModule } from '@ngxs/router-plugin'; import { NgxsActionsExecutingModule } from '@ngxs-labs/actions-executing'; -import { NavigationModule } from '@goofy-client/navigation'; +import { NgxsReduxDevtoolsPluginModule } from '@ngxs/devtools-plugin'; +import { NgxsLoggerPluginModule } from '@ngxs/logger-plugin'; +import { NgxsRouterPluginModule } from '@ngxs/router-plugin'; +import { NgxsModule } from '@ngxs/store'; +import { AppComponent } from './app.component'; import { AppState } from './shared/app.state'; registerLocaleData(localeDe); @@ -32,7 +32,7 @@ registerLocaleData(localeDe); NgxsRouterPluginModule.forRoot(), NgxsActionsExecutingModule.forRoot(), HttpClientModule, - EnvironmentSharedModule, + EnvironmentModule, ApiRootSharedModule, BrowserAnimationsModule, RouterModule, @@ -45,4 +45,4 @@ registerLocaleData(localeDe); ], bootstrap: [AppComponent] }) -export class AppModule {} +export class AppModule { } diff --git a/goofy-client/libs/api-root-shared/src/lib/api-root-shared.actions.ts b/goofy-client/libs/api-root-shared/src/lib/api-root-shared.actions.ts index 9a48bf39c8447aa01f21152a43a778e4fca9677a..256e3150b484d0ad07c42f0066aaf5f699509763 100644 --- a/goofy-client/libs/api-root-shared/src/lib/api-root-shared.actions.ts +++ b/goofy-client/libs/api-root-shared/src/lib/api-root-shared.actions.ts @@ -1,7 +1,8 @@ import { ResourceUri } from '@ngxp/rest'; +import { Environment } from 'libs/environment-shared/src/lib/environment.model'; export class LoadApiRootAction { static readonly type = '[System ApiRoot] Load'; - - constructor(public remoteHost: ResourceUri){} + + constructor() { } } \ No newline at end of file diff --git a/goofy-client/libs/api-root-shared/src/lib/api-root-shared.state.ts b/goofy-client/libs/api-root-shared/src/lib/api-root-shared.state.ts index ce5584de64349a6f9defddc4baa1b39a9d523908..5ef79118b2ee78ceed201bd47f2206816bb8e467 100644 --- a/goofy-client/libs/api-root-shared/src/lib/api-root-shared.state.ts +++ b/goofy-client/libs/api-root-shared/src/lib/api-root-shared.state.ts @@ -1,11 +1,10 @@ import { Injectable } from '@angular/core'; import { Action, NgxsOnInit, Selector, State, StateContext } from '@ngxs/store'; -import { Environment } from 'libs/environment-shared/src/lib/environment-shared.model'; -import { getEnvironmentFactory } from 'libs/environment-shared/src/lib/environment-shared.util'; import { tap } from 'rxjs/operators'; import { LoadApiRootAction } from './api-root-shared.actions'; import { ApiRootResource } from './api-root-shared.model'; import { ApiRootService } from './api-root-shared.service'; +import { ApiRootRepository } from './api-root.repository'; const defaults: ApiRootStateModel = { apiRoot: null, @@ -17,21 +16,25 @@ interface ApiRootStateModel { @State<ApiRootStateModel>({ name: 'apiRoot', defaults }) @Injectable() -export class ApiRootState implements NgxsOnInit{ - +export class ApiRootState implements NgxsOnInit { + @Selector() static apiRootSelector(state: ApiRootStateModel): ApiRootResource { return state.apiRoot; } - constructor(private service: ApiRootService) {} + constructor(private service: ApiRootService, private repository: ApiRootRepository) { } ngxsOnInit(context: StateContext<any>): void { - getEnvironmentFactory().then((environment: Environment) => context.dispatch(new LoadApiRootAction(environment.remoteHost))); + // context.dispatch(new LoadApiRootAction(env)) + + // getEnvironmentFactory().then((environment: Environment) => context.dispatch(new LoadApiRootAction(environment.remoteHost))); + context.dispatch(new LoadApiRootAction()); } @Action(LoadApiRootAction) loadApiRoot(context: StateContext<ApiRootStateModel>, action: LoadApiRootAction) { - return this.service.get(action.remoteHost).pipe( + return this.repository.loadApiRoot().pipe( + // return this.service.get(action.remoteHost).pipe( tap((apiRoot) => { context.patchState({ apiRoot }); }) diff --git a/goofy-client/libs/api-root-shared/src/lib/api-root.repository.spec.ts b/goofy-client/libs/api-root-shared/src/lib/api-root.repository.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..6d01f78e8e407944b855ed6e845a4168787c7d69 --- /dev/null +++ b/goofy-client/libs/api-root-shared/src/lib/api-root.repository.spec.ts @@ -0,0 +1,25 @@ +import { Mock, mock, useFromMock } from '@goofy-client/test-utils'; +import { HttpService } from '@ngxp/rest'; +import { Environment } from 'libs/environment-shared/src/lib/environment.model'; +import { ApiRootRepository } from "./api-root.repository" +import { createEnvironment } from "../../../environment-shared/test/environment"; + +var repository: ApiRootRepository; +var httpService: Mock<HttpService>; + +const environment: Environment = createEnvironment(); + +beforeEach(() => { + httpService = mock(HttpService); + repository = new ApiRootRepository(useFromMock(httpService), environment); +}) + +describe('api root repository', () => { + describe('loadApiRoot', () => { + it('should call httpService', () => { + repository.loadApiRoot(); + + expect(httpService.get).toHaveBeenCalledWith(environment.remoteHost); + }) + }) +}) \ No newline at end of file diff --git a/goofy-client/libs/api-root-shared/src/lib/api-root.repository.ts b/goofy-client/libs/api-root-shared/src/lib/api-root.repository.ts index 07f41c8a6c4150d381d78623c178a59fd7b3deec..a5df6e6e7abdd3324a409b6f41fe7c5301cad23a 100644 --- a/goofy-client/libs/api-root-shared/src/lib/api-root.repository.ts +++ b/goofy-client/libs/api-root-shared/src/lib/api-root.repository.ts @@ -1,17 +1,19 @@ -import { Injectable } from '@angular/core'; +import { Inject, Injectable } from '@angular/core'; import { HttpService } from '@ngxp/rest'; import { Observable } from 'rxjs'; import { ApiRootResource } from './api-root-shared.model'; +import { ENVIRONMENT_CONFIG } from '@goofy-client/environment-shared'; +import { Environment } from 'libs/environment-shared/src/lib/environment.model'; @Injectable() export class ApiRootRepository { constructor( private httpService: HttpService, - //@Inject(ENVIRONMENT_CONFIG) private environmentConfig + @Inject(ENVIRONMENT_CONFIG) private environmentConfig: Environment ) { } public loadApiRoot(): Observable<ApiRootResource> { - return this.httpService.get('http://localhost:4300/api'); + return this.httpService.get(this.environmentConfig.remoteHost); } } \ No newline at end of file diff --git a/goofy-client/libs/environment-shared/src/index.ts b/goofy-client/libs/environment-shared/src/index.ts index 2c1eaac076108baf14223984218a3de4352f7939..5464f93f2e03cb60ddc9839a540eba9ed89daee5 100644 --- a/goofy-client/libs/environment-shared/src/index.ts +++ b/goofy-client/libs/environment-shared/src/index.ts @@ -1,2 +1,2 @@ -export * from './lib/environment-shared.module'; -export * from './lib/environment-shared.service'; +export * from './lib/environment.module'; +export * from './lib/environment.service'; diff --git a/goofy-client/libs/environment-shared/src/lib/environment-shared.state.ts b/goofy-client/libs/environment-shared/src/lib/environment-shared.state.ts index 7e88ab8f95956875e856c81d4e3e53c72616e399..5b4efcd6fe9d65d266e158f93f69af26f5791f46 100644 --- a/goofy-client/libs/environment-shared/src/lib/environment-shared.state.ts +++ b/goofy-client/libs/environment-shared/src/lib/environment-shared.state.ts @@ -1,8 +1,8 @@ import { Injectable } from '@angular/core'; import { Action, NgxsOnInit, State, StateContext } from '@ngxs/store'; import { SetEnvironmentAction } from './environment-shared.actions'; -import { Environment } from './environment-shared.model'; -import { getEnvironmentFactory } from './environment-shared.util'; +import { Environment } from './environment.model'; +import { getEnvironmentFactory } from './environment.service'; const defaults: EnvironmentStateModel = { environment: null @@ -16,7 +16,7 @@ interface EnvironmentStateModel { @Injectable() export class EnvironmentState implements NgxsOnInit { - constructor() {} + constructor() { } ngxsOnInit(context: StateContext<EnvironmentStateModel>) { context.dispatch(new SetEnvironmentAction()); @@ -24,8 +24,7 @@ export class EnvironmentState implements NgxsOnInit { @Action(SetEnvironmentAction) loadEnvironment(context: StateContext<EnvironmentStateModel>) { - return getEnvironmentFactory().then((environment: Environment) => { - context.patchState({environment }); - }) + const environment = getEnvironmentFactory(); + context.patchState({ environment }); } } \ No newline at end of file diff --git a/goofy-client/libs/environment-shared/src/lib/environment-shared.util.ts b/goofy-client/libs/environment-shared/src/lib/environment-shared.util.ts deleted file mode 100644 index 4425fb937056f8204a88db97a635a3fd99eac5b0..0000000000000000000000000000000000000000 --- a/goofy-client/libs/environment-shared/src/lib/environment-shared.util.ts +++ /dev/null @@ -1,3 +0,0 @@ -export function getEnvironmentFactory(): any { - return window['__env__']; -} \ No newline at end of file diff --git a/goofy-client/libs/environment-shared/src/lib/environment-shared.model.ts b/goofy-client/libs/environment-shared/src/lib/environment.model.ts similarity index 100% rename from goofy-client/libs/environment-shared/src/lib/environment-shared.model.ts rename to goofy-client/libs/environment-shared/src/lib/environment.model.ts diff --git a/goofy-client/libs/environment-shared/src/lib/environment-shared.module.ts b/goofy-client/libs/environment-shared/src/lib/environment.module.ts similarity index 53% rename from goofy-client/libs/environment-shared/src/lib/environment-shared.module.ts rename to goofy-client/libs/environment-shared/src/lib/environment.module.ts index ad119eed4455a3fdffbb1bf8f10fc45d744136c3..f6c2bab2621983270571dbe708393de640d47f04 100644 --- a/goofy-client/libs/environment-shared/src/lib/environment-shared.module.ts +++ b/goofy-client/libs/environment-shared/src/lib/environment.module.ts @@ -3,12 +3,19 @@ import { NgModule } from '@angular/core'; import { RestModule } from '@ngxp/rest'; import { NgxsModule } from '@ngxs/store'; import { EnvironmentState } from './environment-shared.state'; +import { ENVIRONMENT_CONFIG, getEnvironmentFactory } from './environment.service'; @NgModule({ imports: [ CommonModule, - NgxsModule.forFeature([EnvironmentState]), + NgxsModule.forFeature([EnvironmentState]), RestModule + ], + providers: [ + { + provide: ENVIRONMENT_CONFIG, + useFactory: getEnvironmentFactory + } ] }) -export class EnvironmentSharedModule {} +export class EnvironmentModule { } diff --git a/goofy-client/libs/environment-shared/src/lib/environment-shared.service.ts b/goofy-client/libs/environment-shared/src/lib/environment.service.ts similarity index 56% rename from goofy-client/libs/environment-shared/src/lib/environment-shared.service.ts rename to goofy-client/libs/environment-shared/src/lib/environment.service.ts index c378995551ded7e32be4e05c43b0b66bf8ec6c52..8c26461b779b5906bba1cc03d48681a5b75d2a7a 100644 --- a/goofy-client/libs/environment-shared/src/lib/environment-shared.service.ts +++ b/goofy-client/libs/environment-shared/src/lib/environment.service.ts @@ -1,15 +1,21 @@ import { InjectionToken } from '@angular/core'; import { getBaseUrl } from '@goofy-client/tech-shared'; +import { Environment } from './environment.model'; export const ENVIRONMENT_CONFIG = new InjectionToken('environmentConfig'); +export function getEnvironmentFactory(): Environment { + return window['__env__']; +} + export async function loadEnvironment(url?: string): Promise<any> { const envUrl = url ? url : `${getBaseUrl()}api/environment`; const headers = new Headers({ 'X-Client': 'web' }); - return window.fetch(envUrl, { headers }).then(response => { - const env = response.json(); - window['__env__'] = env; - return env; - }) + return window.fetch(envUrl, { headers }) + .then(response => response.json()) + .then(env => { + window['__env__'] = env; + return env; + }); } \ No newline at end of file diff --git a/goofy-client/libs/environment-shared/test/environment.ts b/goofy-client/libs/environment-shared/test/environment.ts new file mode 100644 index 0000000000000000000000000000000000000000..de6f7afa9c05d1b4b7577459f64c99f065cfd1f4 --- /dev/null +++ b/goofy-client/libs/environment-shared/test/environment.ts @@ -0,0 +1,14 @@ +import * as faker from 'faker'; +import { cloneDeep } from 'lodash-es'; +import { Environment } from '../src/lib/environment.model'; + +const baseUrl = faker.internet.url(); + +const environment: Environment = { + production: false, + remoteHost: baseUrl +}; + +export function createEnvironment(): Environment { + return cloneDeep(environment); +} diff --git a/goofy-client/package.json b/goofy-client/package.json index 90865edf802a768a0bee3047141f71e4d27a7e81..d81507afe2d6dfc41e092a8d7b14b618fa246ff0 100644 --- a/goofy-client/package.json +++ b/goofy-client/package.json @@ -7,6 +7,7 @@ "ng": "nx", "postinstall": "node ./decorate-angular-cli.js && ngcc --properties es2015 browser module main --first-only --create-ivy-entry-points", "start": "run-s \"nx -- serve --port 4300 --disable-host-check --proxy-config proxy.conf.json\" --", + "start:devbe": "run-s \"nx -- serve --port 4300 --disable-host-check --proxy-config proxy.dev.conf.json\" --", "build": "ng build", "test": "jest test a", "test:cov": "jest --coverage", diff --git a/goofy-client/proxy.dev.conf.json b/goofy-client/proxy.dev.conf.json new file mode 100644 index 0000000000000000000000000000000000000000..9c0b7901a2586801dc4cf245c90ccf88daf94852 --- /dev/null +++ b/goofy-client/proxy.dev.conf.json @@ -0,0 +1,12 @@ +{ + "/api": { + "target": { + "host": "kiel.dev.ozg-sh.de", + + "protocol": "https:" + }, + "secure": false, + "logLevel": "debug" + } + } + \ No newline at end of file