diff --git a/ngapp/src/app/connections/connections.module.ts b/ngapp/src/app/connections/connections.module.ts index 771334ab..6d850ee0 100644 --- a/ngapp/src/app/connections/connections.module.ts +++ b/ngapp/src/app/connections/connections.module.ts @@ -34,6 +34,10 @@ import { SharedModule } from "@shared/shared.module"; import { PatternFlyNgModule } from "patternfly-ng"; import { ConnectionTypeCardComponent } from "./connection-type-cards/connection-type-card/connection-type-card.component"; import { ConnectionTypeCardsComponent } from "./connection-type-cards/connection-type-cards.component"; +import { AppSettingsService } from "@core/app-settings.service"; +import { Http } from "@angular/http"; +import { environment } from "@environments/environment"; +import { MockConnectionService } from "@connections/shared/mock-connection.service"; @NgModule({ imports: [ @@ -59,10 +63,30 @@ import { ConnectionTypeCardsComponent } from "./connection-type-cards/connection ConnectionTypeCardComponent ], providers: [ - ConnectionService, + { + provide: ConnectionService, + useFactory: connectionServiceFactory, + deps: [ Http, AppSettingsService, LoggerService ], + multi: false + }, LoggerService ], exports: [ ] }) export class ConnectionsModule { } + +/** + * A factory that produces the appropriate instande of the service based on current environment settings. + * + * @param {Http} http the HTTP service + * @param {AppSettingsService} appSettings the app settings service + * @param {LoggerService} logger the logger + * @returns {ConnectionService} the requested service + */ +export function connectionServiceFactory( http: Http, + appSettings: AppSettingsService, + logger: LoggerService ): ConnectionService { + return environment.production || !environment.uiDevMode ? new ConnectionService( http, appSettings, logger ) + : new MockConnectionService( http, appSettings, logger ); +} diff --git a/ngapp/src/app/core/core.module.ts b/ngapp/src/app/core/core.module.ts index 7ab84f9e..3399eae1 100644 --- a/ngapp/src/app/core/core.module.ts +++ b/ngapp/src/app/core/core.module.ts @@ -17,7 +17,7 @@ import { CommonModule } from "@angular/common"; import { NgModule, Optional, SkipSelf } from "@angular/core"; -import { HttpModule } from "@angular/http"; +import { Http, HttpModule } from "@angular/http"; import { RouterModule } from "@angular/router"; import { AboutDialogComponent } from "@core/about-dialog/about-dialog.component"; import { AboutService } from "@core/about-dialog/about.service"; @@ -25,7 +25,9 @@ import { AppSettingsService } from "@core/app-settings.service"; import { BreadcrumbComponent } from "@core/breadcrumbs/breadcrumb/breadcrumb.component"; import { BreadcrumbsComponent } from "@core/breadcrumbs/breadcrumbs.component"; import { LoggerService } from "@core/logger.service"; +import { MockAppSettingsService } from "@core/mock-app-settings.service"; import { VerticalNavComponent } from "@core/vertical-nav/vertical-nav.component"; +import { environment } from "@environments/environment"; import { ModalModule } from "ngx-bootstrap/modal"; import { BsModalService } from "ngx-bootstrap/modal"; import { PatternFlyNgModule } from "patternfly-ng"; @@ -51,7 +53,12 @@ import { PatternFlyNgModule } from "patternfly-ng"; ], providers: [ AboutService, - AppSettingsService, + { + provide: AppSettingsService, + useFactory: appSettingsServiceFactory, + deps: [ Http, LoggerService ], + multi: false + }, LoggerService, BsModalService ] @@ -65,3 +72,16 @@ export class CoreModule { } } + +/** + * A factory that produces the appropriate instande of the service based on current environment settings. + * + * @param {Http} http the HTTP service + * @param {LoggerService} logger the logger + * @returns {AppSettingsService} the requested service + */ +export function appSettingsServiceFactory( http: Http, + logger: LoggerService ): AppSettingsService { + return environment.production || !environment.uiDevMode ? new AppSettingsService( http, logger ) + : new MockAppSettingsService( http, logger ); +} diff --git a/ngapp/src/app/dataservices/dataservices.module.ts b/ngapp/src/app/dataservices/dataservices.module.ts index 975f3430..ad71ea21 100644 --- a/ngapp/src/app/dataservices/dataservices.module.ts +++ b/ngapp/src/app/dataservices/dataservices.module.ts @@ -18,7 +18,9 @@ import { CommonModule } from "@angular/common"; import { NgModule } from "@angular/core"; import { FormsModule, ReactiveFormsModule } from "@angular/forms"; +import { Http } from "@angular/http"; import { RouterModule } from "@angular/router"; +import { AppSettingsService } from "@core/app-settings.service"; import { CoreModule } from "@core/core.module"; import { LoggerService } from "@core/logger.service"; import { DataservicesCardsComponent } from "@dataservices/dataservices-cards/dataservices-cards.component"; @@ -28,9 +30,13 @@ import { ViewsContentComponent } from "@dataservices/dataservices-list/views-con import { DataservicesRoutingModule } from "@dataservices/dataservices-routing.module"; import { DataservicesComponent } from "@dataservices/dataservices.component"; import { DataserviceService } from "@dataservices/shared/dataservice.service"; +import { MockDataserviceService } from "@dataservices/shared/mock-dataservice.service"; +import { MockNotifierService } from "@dataservices/shared/mock-notifier.service"; +import { MockVdbService } from "@dataservices/shared/mock-vdb.service"; import { NotifierService } from "@dataservices/shared/notifier.service"; import { VdbService } from "@dataservices/shared/vdb.service"; import { WizardService } from "@dataservices/shared/wizard.service"; +import { environment } from "@environments/environment"; import { SharedModule } from "@shared/shared.module"; import { CodemirrorModule } from "ng2-codemirror"; import { PatternFlyNgModule } from "patternfly-ng"; @@ -71,13 +77,87 @@ import { TestDataserviceComponent } from "./test-dataservice/test-dataservice.co DataserviceCardComponent ], providers: [ - DataserviceService, - VdbService, + { + provide: DataserviceService, + useFactory: dataserviceServiceFactory, + deps: [ Http, VdbService, AppSettingsService, NotifierService, LoggerService ], + multi: false + }, + { + provide: NotifierService, + useFactory: notifierServiceFactory, + multi: false + }, + { + provide: VdbService, + useFactory: vdbServiceFactory, + deps: [ Http, AppSettingsService, NotifierService, LoggerService ], + multi: false + }, LoggerService, - NotifierService, WizardService ], exports: [ ] }) export class DataservicesModule { } + +/** + * A factory that produces the appropriate instance of the service based on current environment settings. + * + * @param {Http} http the HTTP service + * @param {VdbService} vdbService the VDB service + * @param {AppSettingsService} appSettings the app settings service + * @param {NotifierService} notifierService the notifier service + * @param {LoggerService} logger the logger + * @returns {DataserviceService} the requested service + */ +export function dataserviceServiceFactory( http: Http, + vdbService: VdbService, + appSettings: AppSettingsService, + notifierService: NotifierService, + logger: LoggerService ): DataserviceService { + return environment.production || !environment.uiDevMode ? new DataserviceService( http, + vdbService, + appSettings, + notifierService, + logger ) + : new MockDataserviceService( http, + vdbService, + appSettings, + notifierService, + logger ); +} + +/** + * A factory that produces the appropriate instance of the service based on current environment settings. + * + * @returns {NotifierService} the requested service + */ +export function notifierServiceFactory(): NotifierService { + return environment.production || !environment.uiDevMode ? new NotifierService() + : new MockNotifierService(); +} + +/** + * A factory that produces the appropriate instance of the service based on current environment settings. + * + * @param {Http} http the HTTP service + * @param {AppSettingsService} appSettings the app settings service + * @param {NotifierService} notifierService the notifier service + * @param {LoggerService} logger the logger + * @returns {VdbService} the requested service + */ +export function vdbServiceFactory( http: Http, + appSettings: AppSettingsService, + notifierService: NotifierService, + logger: LoggerService ): VdbService { + return environment.production || !environment.uiDevMode ? new VdbService( http, + appSettings, + notifierService, + logger ) + : new MockVdbService( http, + appSettings, + notifierService, + logger ); +} diff --git a/ngapp/src/app/dataservices/shared/mock-dataservice.service.ts b/ngapp/src/app/dataservices/shared/mock-dataservice.service.ts index 918921bf..f1f022ce 100644 --- a/ngapp/src/app/dataservices/shared/mock-dataservice.service.ts +++ b/ngapp/src/app/dataservices/shared/mock-dataservice.service.ts @@ -106,20 +106,20 @@ export class MockDataserviceService extends DataserviceService { return tables; } - /** - * Updates the current Dataservice states - triggers update to be broadcast to interested components - */ - public updateDataserviceStates(): void { - // Nothing to do - } + // /** + // * Updates the current Dataservice states - triggers update to be broadcast to interested components + // */ + // public updateDataserviceStates(): void { + // // Nothing to do + // } - /** - * Polls the server and sends Dataservice state updates at the specified interval - * @param {number} pollIntervalSec the interval (sec) between polling attempts - */ - public pollDataserviceStatus(pollIntervalSec: number): void { - // Nothing to do - } + // /** + // * Polls the server and sends Dataservice state updates at the specified interval + // * @param {number} pollIntervalSec the interval (sec) between polling attempts + // */ + // public pollDataserviceStatus(pollIntervalSec: number): void { + // // Nothing to do + // } /** * Query a Dataservice via the komodo rest interface diff --git a/ngapp/src/app/dataservices/shared/mock-notifier.service.ts b/ngapp/src/app/dataservices/shared/mock-notifier.service.ts new file mode 100644 index 00000000..339d0f37 --- /dev/null +++ b/ngapp/src/app/dataservices/shared/mock-notifier.service.ts @@ -0,0 +1,11 @@ +import { Injectable } from "@angular/core"; +import { NotifierService } from "@dataservices/shared/notifier.service"; + +@Injectable() +export class MockNotifierService extends NotifierService { + + constructor() { + super(); + } + +} diff --git a/ngapp/src/app/dataservices/shared/mock-vdb.service.ts b/ngapp/src/app/dataservices/shared/mock-vdb.service.ts index c5b5cc6a..e53a0b7c 100644 --- a/ngapp/src/app/dataservices/shared/mock-vdb.service.ts +++ b/ngapp/src/app/dataservices/shared/mock-vdb.service.ts @@ -48,8 +48,19 @@ export class MockVdbService extends VdbService { constructor(http: Http, appSettings: AppSettingsService, notifierService: NotifierService, logger: LoggerService ) { super(http, appSettings, notifierService, logger); this.vdb1.setId("serv1"); + this.vdbStatus1.setName( "serv1" ); + this.vdbStatus1.setLoading( false ); + this.vdbStatus1.setActive( true ); + this.vdb2.setId("serv2"); + this.vdbStatus2.setName("serv2"); + this.vdbStatus2.setLoading( false ); + this.vdbStatus2.setActive( true ); + this.vdb3.setId("serv3"); + this.vdbStatus3.setName("serv2"); + this.vdbStatus3.setLoading( false ); + this.vdbStatus3.setActive( true ); } /** @@ -65,6 +76,7 @@ export class MockVdbService extends VdbService { * @returns {Observable} */ public getTeiidVdbStatuses(): Observable { + super.getTeiidVdbStatuses(); return Observable.of(this.statuses); } diff --git a/ngapp/src/environments/environment.ts b/ngapp/src/environments/environment.ts index dea1a9bf..7cd88872 100644 --- a/ngapp/src/environments/environment.ts +++ b/ngapp/src/environments/environment.ts @@ -56,6 +56,9 @@ export const environment = { komodoTeiidUrl: komodoUrlPrefix + komodoEngine + "/" + komodoRestVersion + "/metadata", // REST URL - Komodo service - komodoServiceUrl: komodoUrlPrefix + komodoEngine + "/" + komodoRestVersion + "/service" + komodoServiceUrl: komodoUrlPrefix + komodoEngine + "/" + komodoRestVersion + "/service", + + // Indicates if in UI development mode where OpenShift will not be used. + uiDevMode: true };