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

Commit

Permalink
Fixes for service editing
Browse files Browse the repository at this point in the history
  • Loading branch information
mdrillin committed Jan 2, 2018
1 parent 8b94d64 commit b543c17
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ export class AddDataserviceWizardComponent implements OnInit, OnDestroy {
public basicPropertyForm: FormGroup;
public createComplete = true;
public createSuccessful = false;
public tableSelectorLoadingState = LoadingState.LOADING;

// Wizard Step 1
public step1Config: WizardStepConfig;
Expand Down Expand Up @@ -151,12 +150,10 @@ export class AddDataserviceWizardComponent implements OnInit, OnDestroy {
this.basicPropertyForm.controls["name"].setValue(dsName);
this.basicPropertyForm.controls["description"].setValue(dsDescr);
this.basicPropertyForm.get("name").disable();
this.basicPropertyForm.get("description").disable();
} else {
this.basicPropertyForm.controls["name"].setValue(null);
this.basicPropertyForm.controls["description"].setValue(null);
}
this.tableSelectorLoadingState = LoadingState.LOADING;
this.setNavAway(false);
}

Expand All @@ -175,27 +172,6 @@ export class AddDataserviceWizardComponent implements OnInit, OnDestroy {
return this.wizardService.isEdit();
}

/**
* Determine if table selector is loading
*/
public get tableSelectorLoading( ): boolean {
return this.tableSelectorLoadingState === LoadingState.LOADING;
}

/**
* Determine if table selector is loaded and valid
*/
public get tableSelectorLoadedValid( ): boolean {
return this.tableSelectorLoadingState === LoadingState.LOADED_VALID;
}

/**
* Determine if table selector is loaded and invalid
*/
public get tableSelectorLoadedInvalid( ): boolean {
return this.tableSelectorLoadingState === LoadingState.LOADED_INVALID;
}

public handleNameChanged( input: AbstractControl ): void {
const self = this;

Expand Down Expand Up @@ -356,20 +332,14 @@ export class AddDataserviceWizardComponent implements OnInit, OnDestroy {
this.sourceVdbUnderDeployment = null;
}

if (this.tableSelector && this.tableSelector.hasSelectedConnection()) {
const selectedConnectionName = this.tableSelector.selectedConnection.getId();
const selectedVdbName = selectedConnectionName + VdbsConstants.SOURCE_VDB_SUFFIX;
if (selectedVdbName === status.getName()) {
if (status.isActive()) {
if (this.wizardService.isEdit()) {
this.updateDataserviceForSingleTable();
} else {
this.createDataserviceForSingleTable();
}
} else if (status.isFailed()) {
this.setFinalPageComplete(false);
}
if (status.isActive()) {
if (this.wizardService.isEdit()) {
this.updateDataserviceForSingleTable();
} else {
this.createDataserviceForSingleTable();
}
} else if (status.isFailed()) {
this.setFinalPageComplete(false);
}
}

Expand Down Expand Up @@ -598,7 +568,11 @@ export class AddDataserviceWizardComponent implements OnInit, OnDestroy {
// Get the error from the response json
this.errorDetailMessage = "";
if (resp) {
this.errorDetailMessage = resp.json().error;
try {
this.errorDetailMessage = resp.json().error;
} catch {
this.errorDetailMessage = resp.text();
}
}
// Error visible if message has content
if (this.errorDetailMessage.length === 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ 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 { Table } from "@dataservices/shared/table.model";
import { VdbsConstants } from "@dataservices/shared/vdbs-constants";
import { WizardService } from "@dataservices/shared/wizard.service";
import { LoadingState } from "@shared/loading-state.enum";

Expand Down Expand Up @@ -74,6 +75,9 @@ export class ConnectionTableSelectorComponent implements OnInit {
(conns) => {
self.allConnections = conns;
self.connectionLoadingState = LoadingState.LOADED_VALID;
if (self.wizardService.isEdit()) {
self.initEdit();
}

// load table after setting loading state so table has been constructed
self.allConnections.forEach( ( connection ) => {
Expand Down Expand Up @@ -245,4 +249,33 @@ export class ConnectionTableSelectorComponent implements OnInit {
};
}

/**
* Initialization for edit mode
*/
private initEdit(): void {
// Updates current connections on wizardService
this.wizardService.setCurrentConnections(this.allConnections);

// Initialize the selected tables in the wizard service
this.wizardService.clearWizardSelectedTables();
const srcTables: string[] = this.wizardService.getSelectedDataservice().getServiceViewTables();
const selectedTables: Table[] = [];
for ( const tableStr of srcTables ) {
const subParts = tableStr.split(".");
const connectionName = subParts[0].replace(VdbsConstants.SOURCE_VDB_SUFFIX, "");
const tableName = subParts[1];
let conn = this.wizardService.getCurrentConnection(connectionName);
if (!conn) {
conn = new Connection();
conn.setId(connectionName);
}
const table: Table = new Table();
table.setName(tableName);
table.setConnection(conn);
this.wizardService.addToWizardSelectionTables(table);
}
this.selectedTableListUpdated.emit();

}

}
22 changes: 3 additions & 19 deletions ngapp/src/app/dataservices/dataservices.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import { Component, ViewChild } from "@angular/core";
import { ActivatedRoute, Router } from "@angular/router";
import { Connection } from "@connections/shared/connection.model";
import { AppSettingsService } from "@core/app-settings.service";
import { LoggerService } from "@core/logger.service";
import { ArrayUtils } from "@core/utils/array-utils";
Expand All @@ -26,9 +25,7 @@ import { DataserviceService } from "@dataservices/shared/dataservice.service";
import { DataservicesConstants } from "@dataservices/shared/dataservices-constants";
import { DeploymentState } from "@dataservices/shared/deployment-state.enum";
import { NotifierService } from "@dataservices/shared/notifier.service";
import { Table } from "@dataservices/shared/table.model";
import { VdbService } from "@dataservices/shared/vdb.service";
import { VdbsConstants } from "@dataservices/shared/vdbs-constants";
import { WizardService } from "@dataservices/shared/wizard.service";
import { SqlControlComponent } from "@dataservices/sql-control/sql-control.component";
import { AbstractPageComponent } from "@shared/abstract-page.component";
Expand Down Expand Up @@ -307,22 +304,9 @@ export class DataservicesComponent extends AbstractPageComponent {

this.setQuickLookPanelOpenState(false);

// Initialize the selected tables in the wizard service
this.wizardService.clearWizardSelectedTables();
const srcTables: string[] = selectedService.getServiceViewTables();
const selectedTables: Table[] = [];
for ( const tableStr of srcTables ) {
const subParts = tableStr.split(".");
const connectionName = subParts[0].replace(VdbsConstants.SOURCE_VDB_SUFFIX, "");
const tableName = subParts[1];
const conn: Connection = new Connection();
conn.setId(connectionName);
const table: Table = new Table();
table.setName(tableName);
table.setConnection(conn);
this.wizardService.addToWizardSelectionTables(table);
this.wizardService.setEdit(true);
}
// Sets the selected dataservice and edit mode before transferring
this.wizardService.setSelectedDataservice(selectedService);
this.wizardService.setEdit(true);

const link: string[] = [ DataservicesConstants.addDataservicePath ];
this.logger.log("[DataservicesPageComponent] Navigating to: %o", link);
Expand Down
51 changes: 51 additions & 0 deletions ngapp/src/app/dataservices/shared/wizard.service.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { Injectable } from "@angular/core";
import { Connection } from "@connections/shared/connection.model";
import { Dataservice } from "@dataservices/shared/dataservice.model";
import { Table } from "@dataservices/shared/table.model";

@Injectable()
export class WizardService {

private wizardSelectedTablesArray: Table[] = [];
private edit = false;
private currentConnections: Connection[] = [];
private selectedDataservice: Dataservice;

constructor() {
// Nothing to do
Expand All @@ -26,6 +30,23 @@ export class WizardService {
public isEdit(): boolean {
return this.edit;
}

/**
* Gets the selected dataservice
* @returns {Dataservice} the selected dataservice
*/
public getSelectedDataservice(): Dataservice {
return this.selectedDataservice;
}

/**
* Sets the selected dataservice
* @param {Dataservice} dataservice the selected dataservice
*/
public setSelectedDataservice(dataservice: Dataservice): void {
this.selectedDataservice = dataservice;
}

/**
* Get the wizard table selections
* @returns {Table[]} the selections
Expand Down Expand Up @@ -76,6 +97,36 @@ export class WizardService {
return wasRemoved;
}

/**
* Set the current connections to the supplied array
* @param {Connection[]} conns the current array of Connections
*/
public setCurrentConnections(conns: Connection[]): void {
this.currentConnections = conns;
}

/**
* Get the current connections array
* @returns {Connection[]} the current connections
*/
public getCurrentConnections( ): Connection[] {
return this.currentConnections;
}

/**
* Get the current connection with the supplied name. If not found, returns null.
* @returns {Connection} the current connection
*/
public getCurrentConnection(connName: string): Connection {
// No connections, return null
if (!this.currentConnections || this.currentConnections.length === 0) {
return null;
}

// Returns the matching connection, if found.
return this.currentConnections.find((x) => x.getId() === connName);
}

/**
* Find index of the table in the wizard selected tables list. -1 if not found
* @param {Table} table
Expand Down

0 comments on commit b543c17

Please sign in to comment.