Skip to content
This repository has been archived by the owner on Nov 22, 2019. It is now read-only.

Commit

Permalink
Refactors Wizard functions into WizardService
Browse files Browse the repository at this point in the history
  • Loading branch information
mdrillin committed Dec 14, 2017
1 parent a8217bf commit da290cc
Show file tree
Hide file tree
Showing 13 changed files with 134 additions and 99 deletions.
Expand Up @@ -13,6 +13,7 @@ import { MockDataserviceService } from "@dataservices/shared/mock-dataservice.se
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 { PropertyFormPropertyComponent } from "@shared/property-form/property-form-property/property-form-property.component";
import { PropertyFormComponent } from "@shared/property-form/property-form.component";
import { NgxDatatableModule } from "@swimlane/ngx-datatable";
Expand All @@ -29,7 +30,7 @@ describe("AddDataserviceWizardComponent", () => {
declarations: [ AddDataserviceWizardComponent, ConnectionTableSelectorComponent, JdbcTableSelectorComponent,
PropertyFormComponent, PropertyFormPropertyComponent, SelectedTableComponent ],
providers: [
NotifierService,
NotifierService, WizardService,
{ provide: DataserviceService, useClass: MockDataserviceService },
{ provide: ConnectionService, useClass: MockConnectionService },
{ provide: VdbService, useClass: MockVdbService },
Expand Down
Expand Up @@ -14,6 +14,7 @@ import { MockDataserviceService } from "@dataservices/shared/mock-dataservice.se
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 { SharedModule } from "@shared/shared.module";
import { NgxDatatableModule } from "@swimlane/ngx-datatable";
import { PatternFlyNgModule } from "patternfly-ng";
Expand All @@ -29,7 +30,7 @@ describe("AddDataserviceComponent", () => {
declarations: [ AddDataserviceComponent, AddDataserviceWizardComponent,
ConnectionTableSelectorComponent, JdbcTableSelectorComponent, SelectedTableComponent ],
providers: [
NotifierService,
NotifierService, WizardService,
{ provide: DataserviceService, useClass: MockDataserviceService },
{ provide: ConnectionService, useClass: MockConnectionService },
{ provide: VdbService, useClass: MockVdbService }
Expand Down
Expand Up @@ -8,11 +8,10 @@ import { AppSettingsService } from "@core/app-settings.service";
import { LoggerService } from "@core/logger.service";
import { JdbcTableSelectorComponent } from "@dataservices/jdbc-table-selector/jdbc-table-selector.component";
import { SelectedTableComponent } from "@dataservices/selected-table/selected-table.component";
import { DataserviceService } from "@dataservices/shared/dataservice.service";
import { MockDataserviceService } from "@dataservices/shared/mock-dataservice.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 { NgxDatatableModule } from "@swimlane/ngx-datatable";
import { ConnectionTableSelectorComponent } from "./connection-table-selector.component";

Expand All @@ -25,9 +24,8 @@ describe("ConnectionTableSelectorComponent", () => {
imports: [ FormsModule, HttpModule, NgxDatatableModule ],
declarations: [ ConnectionTableSelectorComponent, JdbcTableSelectorComponent, SelectedTableComponent ],
providers: [
AppSettingsService, LoggerService, NotifierService,
AppSettingsService, LoggerService, NotifierService, WizardService,
{ provide: ConnectionService, useClass: MockConnectionService },
{ provide: DataserviceService, useClass: MockDataserviceService },
{ provide: VdbService, useClass: MockVdbService }
]
})
Expand Down
Expand Up @@ -20,8 +20,8 @@ import { Connection } from "@connections/shared/connection.model";
import { ConnectionService } from "@connections/shared/connection.service";
import { LoggerService } from "@core/logger.service";
import { JdbcTableSelectorComponent } from "@dataservices/jdbc-table-selector/jdbc-table-selector.component";
import { DataserviceService } from "@dataservices/shared/dataservice.service";
import { Table } from "@dataservices/shared/table.model";
import { WizardService } from "@dataservices/shared/wizard.service";
import { LoadingState } from "@shared/loading-state.enum";

@Component({
Expand All @@ -48,16 +48,16 @@ export class ConnectionTableSelectorComponent implements OnInit {
};

private connectionService: ConnectionService;
private dataserviceService: DataserviceService;
private wizardService: WizardService;
private allConnections: Connection[] = [];
private selectedConn: Connection;
private connectionLoadingState: LoadingState = LoadingState.LOADING;
private logger: LoggerService;

constructor( connectionService: ConnectionService, dataserviceService: DataserviceService,
constructor( connectionService: ConnectionService, wizardService: WizardService,
logger: LoggerService ) {
this.connectionService = connectionService;
this.dataserviceService = dataserviceService;
this.wizardService = wizardService;
this.logger = logger;
}

Expand All @@ -66,7 +66,7 @@ export class ConnectionTableSelectorComponent implements OnInit {
*/
public ngOnInit(): void {
// clears table selections
this.dataserviceService.clearWizardSelectedTables();
this.wizardService.clearWizardSelectedTables();

// Load the connections
this.connectionLoadingState = LoadingState.LOADING;
Expand Down Expand Up @@ -202,7 +202,7 @@ export class ConnectionTableSelectorComponent implements OnInit {
* @param {Table} addedTable the table to add to the accumulator list
*/
public onTableSelectionAdded(addedTable: Table): void {
this.dataserviceService.addToWizardSelectionTables(addedTable);
this.wizardService.addToWizardSelectionTables(addedTable);
this.selectedTableListUpdated.emit();
}

Expand All @@ -212,7 +212,7 @@ export class ConnectionTableSelectorComponent implements OnInit {
* @param {Table} removedTable the table to remove from the accumulator list
*/
public onTableSelectionRemoved(removedTable: Table): void {
const wasRemoved = this.dataserviceService.removeFromWizardSelectionTables(removedTable);
const wasRemoved = this.wizardService.removeFromWizardSelectionTables(removedTable);
if (wasRemoved) {
this.selectedTableListUpdated.emit();
}
Expand All @@ -231,7 +231,7 @@ export class ConnectionTableSelectorComponent implements OnInit {
* @returns {Table[]} the list of selected Tables
*/
public getSelectedTables(): Table[] {
return this.dataserviceService.getWizardSelectedTables();
return this.wizardService.getWizardSelectedTables();
}

// used by table
Expand Down
Expand Up @@ -23,7 +23,8 @@ <h2 class="dataservice-card-title">
</h2>
<hr/>
<div class="pull-right">
<span class="pull-right fa fa-search dataservice-card-action-icon" (click)="onQuickLookDataservice(dataservice.getId())"></span>
<span *ngIf="dataservice.serviceDeploymentActive" class="pull-right fa fa-search dataservice-card-action-icon" (click)="onQuickLookDataservice(dataservice.getId())"></span>
<span *ngIf="!dataservice.serviceDeploymentActive" class="pull-right fa fa-search dataservice-card-action-disabled-icon"></span>
</div>
<div>
<span>{{ dataservice.getDescription() }}</span>
Expand Down
Expand Up @@ -9,6 +9,12 @@
cursor: pointer;
}

.dataservice-list-quicklook-disabled-icon {
margin-left: 20px;
font-size: 1.3em;
color: lightgray;
}

.list-view-pf-main-info {
padding-bottom: 5px;
padding-top: 5px;
Expand Down
Expand Up @@ -25,7 +25,8 @@
<span *ngIf="dataservice.getServiceViewTables().length==2">{{dataservice.getServiceViewTables()[0]}}, {{dataservice.getServiceViewTables()[1]}}</span>
</div>
<div>
<span class="fa fa-search dataservice-list-quicklook-icon" (click)="onQuickLookDataservice(dataservice.getId())"></span>
<span *ngIf="dataservice.serviceDeploymentActive" class="fa fa-search dataservice-list-quicklook-icon" (click)="onQuickLookDataservice(dataservice.getId())"></span>
<span *ngIf="!dataservice.serviceDeploymentActive" class="fa fa-search dataservice-list-quicklook-disabled-icon"></span>
</div>
<!--
<div class="dataservice-tags" *ngIf="dataservice.tags && dataservice.tags.length > 0">
Expand Down
4 changes: 3 additions & 1 deletion ngapp/src/app/dataservices/dataservices.module.ts
Expand Up @@ -28,6 +28,7 @@ import { DataservicesComponent } from "@dataservices/dataservices.component";
import { DataserviceService } from "@dataservices/shared/dataservice.service";
import { NotifierService } from "@dataservices/shared/notifier.service";
import { VdbService } from "@dataservices/shared/vdb.service";
import { WizardService } from "@dataservices/shared/wizard.service";
import { SharedModule } from "@shared/shared.module";
import { NgxDatatableModule } from "@swimlane/ngx-datatable";
import { CodemirrorModule } from "ng2-codemirror";
Expand Down Expand Up @@ -69,7 +70,8 @@ import { TestDataserviceComponent } from "./test-dataservice/test-dataservice.co
DataserviceService,
VdbService,
LoggerService,
NotifierService
NotifierService,
WizardService
],
exports: [
]
Expand Down
Expand Up @@ -7,11 +7,10 @@ import { MockConnectionService } from "@connections/shared/mock-connection.servi
import { AppSettingsService } from "@core/app-settings.service";
import { LoggerService } from "@core/logger.service";
import { SelectedTableComponent } from "@dataservices/selected-table/selected-table.component";
import { DataserviceService } from "@dataservices/shared/dataservice.service";
import { MockDataserviceService } from "@dataservices/shared/mock-dataservice.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 { JdbcTableSelectorComponent } from "./jdbc-table-selector.component";

describe("JdbcTableSelectorComponent", () => {
Expand All @@ -23,9 +22,8 @@ describe("JdbcTableSelectorComponent", () => {
imports: [ FormsModule, HttpModule ],
declarations: [ JdbcTableSelectorComponent, SelectedTableComponent ],
providers: [
AppSettingsService, LoggerService, NotifierService,
AppSettingsService, LoggerService, NotifierService, WizardService,
{ provide: ConnectionService, useClass: MockConnectionService },
{ provide: DataserviceService, useClass: MockDataserviceService },
{ provide: VdbService, useClass: MockVdbService },
]
})
Expand Down
Expand Up @@ -16,18 +16,18 @@
*/

import { Component, OnInit } from "@angular/core";
import { Input } from "@angular/core";
import { EventEmitter } from "@angular/core";
import { Output } from "@angular/core";
import { Input } from "@angular/core";
import { Connection } from "@connections/shared/connection.model";
import { ConnectionService } from "@connections/shared/connection.service";
import { JdbcTableFilter } from "@connections/shared/jdbc-table-filter.model";
import { SchemaInfo } from "@connections/shared/schema-info.model";
import { LoggerService } from "@core/logger.service";
import { CatalogSchema } from "@dataservices/shared/catalog-schema.model";
import { DataserviceService } from "@dataservices/shared/dataservice.service";
import { TableSelector } from "@dataservices/shared/table-selector";
import { Table } from "@dataservices/shared/table.model";
import { WizardService } from "@dataservices/shared/wizard.service";
import { LoadingState } from "@shared/loading-state.enum";

@Component({
Expand All @@ -43,17 +43,17 @@ export class JdbcTableSelectorComponent implements OnInit, TableSelector {
@Output() public tableSelectionRemoved: EventEmitter<Table> = new EventEmitter<Table>();

private connectionService: ConnectionService;
private dataserviceService: DataserviceService;
private wizardService: WizardService;
private logger: LoggerService;
private schemas: CatalogSchema[] = [];
private tables: Table[] = [];
private currentSchema: CatalogSchema = null;
private schemaLoadingState: LoadingState = LoadingState.LOADING;
private tableLoadingState: LoadingState = LoadingState.LOADING;

constructor( connectionService: ConnectionService, dataserviceService: DataserviceService, logger: LoggerService ) {
constructor(connectionService: ConnectionService, wizardService: WizardService, logger: LoggerService ) {
this.connectionService = connectionService;
this.dataserviceService = dataserviceService;
this.wizardService = wizardService;
this.logger = logger;
}

Expand Down Expand Up @@ -322,7 +322,7 @@ export class JdbcTableSelectorComponent implements OnInit, TableSelector {
const schemaName = table.getSchemaName();
const tableName = table.getName();
const connName = table.getConnection().getId();
for ( const initialTable of this.dataserviceService.getWizardSelectedTables() ) {
for ( const initialTable of this.wizardService.getWizardSelectedTables() ) {
// const iCatName = initialTable.getCatalogName();
const iSchemaName = initialTable.getSchemaName();
const iTableName = initialTable.getName();
Expand Down
72 changes: 0 additions & 72 deletions ngapp/src/app/dataservices/shared/dataservice.service.ts
Expand Up @@ -56,7 +56,6 @@ export class DataserviceService extends ApiService {
private selectedDataservice: Dataservice;
private cachedDataserviceStates: Map<string, DeploymentState> = new Map<string, DeploymentState>();
private updatesSubscription: Subscription;
private wizardSelectedTablesArray: Table[] = [];

constructor(http: Http, vdbService: VdbService, appSettings: AppSettingsService,
notifierService: NotifierService, logger: LoggerService ) {
Expand Down Expand Up @@ -375,77 +374,6 @@ export class DataserviceService extends ApiService {
});
}

/**
* Get the wizard table selections
* @returns {Table[]} the selections
*/
public getWizardSelectedTables( ): Table[] {
return this.wizardSelectedTablesArray;
}

/**
* Clears the list of wizard table selections
*/
public clearWizardSelectedTables( ): void {
this.wizardSelectedTablesArray = [];
}

/**
* Determine if the supplied table is one of the current selections in the wizard
* @param {Table} table the table
*/
public isWizardSelectedTable(table: Table): boolean {
return this.getWizardTableIndex(table) > -1;
}

/**
* Add a table to the current wizard selections
* @param {Table} tableToAdd table to add
*/
public addToWizardSelectionTables(tableToAdd: Table): void {
if (!this.isWizardSelectedTable(tableToAdd)) {
this.wizardSelectedTablesArray.push(tableToAdd);
}
}

/**
* Remove a table from the current wizard selections
* @param {Table} tableToRemove
* @returns {boolean}
*/
public removeFromWizardSelectionTables(tableToRemove: Table): boolean {
let wasRemoved = false;

const index = this.getWizardTableIndex(tableToRemove);
if (index > -1) {
this.wizardSelectedTablesArray.splice(index, 1);
wasRemoved = true;
}

return wasRemoved;
}

/**
* Find index of the table in the wizard selected tables list. -1 if not found
* @param {Table} table
* @returns {number}
*/
private getWizardTableIndex(table: Table): number {
// supplied table and connection
const connName = table.getConnection().getId();
const tableName = table.getName();
let i = 0;
for (const wizTable of this.wizardSelectedTablesArray) {
const wizTableName = wizTable.getName();
const wizConnName = wizTable.getConnection().getId();
if (wizTableName === tableName && wizConnName === connName) {
return i;
}
i++;
}
return -1;
}

/*
* Get updates for the provided array of Dataservices and broadcast the map of states
* @param {Dataservice[]} services the array of Dataservices
Expand Down
15 changes: 15 additions & 0 deletions ngapp/src/app/dataservices/shared/wizard.service.spec.ts
@@ -0,0 +1,15 @@
import { inject, TestBed } from "@angular/core/testing";

import { WizardService } from "./wizard.service";

describe("WizardService", () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [WizardService]
});
});

it("should be created", inject([WizardService], (service: WizardService) => {
expect(service).toBeTruthy();
}));
});

0 comments on commit da290cc

Please sign in to comment.