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

Commit

Permalink
Use selectionService exclusively
Browse files Browse the repository at this point in the history
  • Loading branch information
mdrillin committed Sep 5, 2018
1 parent 7d248d2 commit 4f14705
Show file tree
Hide file tree
Showing 24 changed files with 103 additions and 184 deletions.
22 changes: 22 additions & 0 deletions ngapp/src/app/core/selection.service.ts
Expand Up @@ -19,6 +19,7 @@ import { Injectable } from "@angular/core";
import { Dataservice } from "@dataservices/shared/dataservice.model";
import { Connection } from "@connections/shared/connection.model";
import { ViewDefinition } from "@dataservices/shared/view-definition.model";
import { SqlView } from "@dataservices/shared/sql-view.model";

@Injectable()
export class SelectionService {
Expand Down Expand Up @@ -56,6 +57,27 @@ export class SelectionService {
return this.selectedVirtualization && this.selectedVirtualization !== null;
}

/**
* Get the current Virtualization selection's views.View
* The ViewDefinition name is currently set to the full "modelName"."viewName" of the view.
* @returns {SqlView[]} the selected Dataservice view definitions
*/
public getSelectedVirtualizationViewNames( ): SqlView[] {
if ( !this.hasSelectedVirtualization ) {
return [];
}

const modelName = this.selectedVirtualization.getServiceViewModel();
const serviceViews = this.selectedVirtualization.getServiceViewNames();

const allViewNames: SqlView[] = [];
for ( const serviceView of serviceViews ) {
allViewNames.push(new SqlView(modelName + "." + serviceView));
}

return allViewNames;
}

/**
* Gets the selected connection
* @returns {Connection} the selected connection
Expand Down
Expand Up @@ -15,6 +15,7 @@ import { CreateVirtualizationDialogComponent } from "./create-virtualization-dia
import { AppSettingsService } from "@core/app-settings.service";
import { LoggerService } from "@core/logger.service";
import { NotifierService } from "@dataservices/shared/notifier.service";
import { SelectionService } from "@core/selection.service";

describe('CreateVirtualizationDialogComponent', () => {
let component: CreateVirtualizationDialogComponent;
Expand All @@ -31,7 +32,7 @@ describe('CreateVirtualizationDialogComponent', () => {
NotificationModule
],
declarations: [ CreateVirtualizationDialogComponent ],
providers: [ AppSettingsService, BsModalRef, LoggerService, NotifierService,
providers: [ AppSettingsService, BsModalRef, LoggerService, NotifierService, SelectionService,
{ provide: DataserviceService, useClass: MockDataserviceService },
{ provide: VdbService, useClass: MockVdbService }
]
Expand Down
Expand Up @@ -25,6 +25,7 @@ import { AbstractControl, FormControl, FormGroup } from "@angular/forms";
import { VdbService } from "@dataservices/shared/vdb.service";
import { DataserviceService } from "@dataservices/shared/dataservice.service";
import { CreateVirtualizationResult } from "@dataservices/create-virtualization-dialog/create-virtualization-result.model";
import { SelectionService } from "@core/selection.service";

@Component({
selector: "app-create-virtualization-dialog",
Expand Down Expand Up @@ -62,15 +63,17 @@ export class CreateVirtualizationDialogComponent implements OnInit {

private loggerService: LoggerService;
private dataserviceService: DataserviceService;
private selectionService: SelectionService;
private vdbService: VdbService;
private serviceVdbName = "";

constructor(bsModalRef: BsModalRef, logger: LoggerService,
dataserviceService: DataserviceService, vdbService: VdbService) {
dataserviceService: DataserviceService, selectionService: SelectionService, vdbService: VdbService) {
this.bsModalRef = bsModalRef;
this.loggerService = logger;
this.dataserviceService = dataserviceService;
const dService = this.dataserviceService.getSelectedDataservice();
this.selectionService = selectionService;
const dService = this.selectionService.getSelectedVirtualization();
if ( dService && dService !== null ) {
this.serviceVdbName = dService.getServiceVdbName();
}
Expand Down
2 changes: 1 addition & 1 deletion ngapp/src/app/dataservices/dataservices.component.html
Expand Up @@ -72,7 +72,7 @@ <h1 class="card-pf-title">
<!-- The list or card view -->
<div class="col-md-12" *ngIf="isLoaded('dataservices')">
<div class="dataservices-toast">
<!-- Notification for Dataservice opertions -->
<!-- Toast Notification for Dataservice operations -->
<pfng-toast-notification *ngIf="showToastNotification" [header]="toastNotificationHeader"
[message]="toastNotificationMessage"
[type]="toastNotificationType">
Expand Down
18 changes: 7 additions & 11 deletions ngapp/src/app/dataservices/dataservices.component.ts
Expand Up @@ -452,8 +452,8 @@ export class DataservicesComponent extends AbstractPageComponent implements OnIn

public onTest(svcName: string): void {
const selectedService = this.filteredDataservices.find((x) => x.getId() === svcName);
this.dataserviceService.setSelectedDataservice(selectedService);
this.allSvcViewNames = this.dataserviceService.getSelectedDataserviceViewNames();
this.selectionService.setSelectedVirtualization(selectedService);
this.allSvcViewNames = this.selectionService.getSelectedVirtualizationViewNames();
this.selectedSvcViewNames = [];
this.selectedSvcViewNames.push(this.allServiceViewNames[0]);

Expand Down Expand Up @@ -661,7 +661,6 @@ export class DataservicesComponent extends AbstractPageComponent implements OnIn
(dataservices) => {
for (const ds of dataservices) {
if (ds.getId() === virtName) {
self.dataserviceService.setSelectedDataservice(ds);
self.selectionService.setSelectedVirtualization(ds);
self.createView(ds, viewDefn);
}
Expand All @@ -678,7 +677,7 @@ export class DataservicesComponent extends AbstractPageComponent implements OnIn
}

private createView(dataservice: Dataservice, viewDefn: ViewDefinition): void {
const selectedDs = this.dataserviceService.getSelectedDataservice();
const selectedDs = this.selectionService.getSelectedVirtualization();
let editorId = "";
if ( selectedDs || selectedDs !== null ) {
editorId = this.getEditorStateId(selectedDs, viewDefn);
Expand Down Expand Up @@ -731,13 +730,10 @@ export class DataservicesComponent extends AbstractPageComponent implements OnIn
*/
public onEdit(svcName: string): void {
const selectedService = this.filteredDataservices.find((x) => x.getId() === svcName);
this.dataserviceService.setSelectedDataservice(selectedService);
this.selectionService.setSelectedVirtualization(selectedService);

this.closeLookPanels();

// Sets the selected dataservice and edit mode before transferring
this.selectionService.setSelectedVirtualization(selectedService);

const link: string[] = [ DataservicesConstants.viewPath ];
this.logger.debug("[DataservicesPageComponent] Navigating to: %o", link);
this.router.navigate(link).then(() => {
Expand All @@ -750,8 +746,8 @@ export class DataservicesComponent extends AbstractPageComponent implements OnIn
*/
public onQuickLook(svcName: string): void {
const selectedService = this.filteredDataservices.find((x) => x.getId() === svcName);
this.dataserviceService.setSelectedDataservice(selectedService);
this.allSvcViewNames = this.dataserviceService.getSelectedDataserviceViewNames();
this.selectionService.setSelectedVirtualization(selectedService);
this.allSvcViewNames = this.selectionService.getSelectedVirtualizationViewNames();
this.selectedSvcViewNames = [];
this.selectedSvcViewNames.push(this.allServiceViewNames[0]);
const viewName = this.selectedSvcViewNames[0];
Expand All @@ -776,7 +772,7 @@ export class DataservicesComponent extends AbstractPageComponent implements OnIn
*/
public onOdataLook(svcName: string): void {
const selectedService = this.filteredDataservices.find((x) => x.getId() === svcName);
this.dataserviceService.setSelectedDataservice(selectedService);
this.selectionService.setSelectedVirtualization(selectedService);

if (!this.odataEditorShowing) {
this.setOdataEditorPanelOpenState(true);
Expand Down
Expand Up @@ -28,6 +28,7 @@ import { Odata } from "@dataservices/odata-control/odata.model";
import { OdataEntity } from "@dataservices/odata-control/odata-entity.model";
import { OdataColumn } from "@dataservices/odata-control/odata-column.model";
import { OdataWhere } from "@dataservices/odata-control/odata-where.model";
import { SelectionService } from "@core/selection.service";

@Component({
encapsulation: ViewEncapsulation.None,
Expand All @@ -44,6 +45,7 @@ export class OdataControlComponent implements OnChanges {
private dataserviceService: DataserviceService;
private dataservice: Dataservice;
private logger: LoggerService;
private selectionService: SelectionService;
public i18n: OdataConstants = new OdataConstants();

public searchMsg: string;
Expand Down Expand Up @@ -91,9 +93,11 @@ export class OdataControlComponent implements OnChanges {
//
public results: string = null;

constructor( dataserviceService: DataserviceService, logger: LoggerService ) {
constructor( dataserviceService: DataserviceService, logger: LoggerService,
selectionService: SelectionService ) {
this.dataserviceService = dataserviceService;
this.logger = logger;
this.selectionService = selectionService;
}

public get rootUrl(): string {
Expand All @@ -105,7 +109,7 @@ export class OdataControlComponent implements OnChanges {
}

public ngOnChanges(changes: SimpleChanges): void {
this.dataservice = this.dataserviceService.getSelectedDataservice();
this.dataservice = this.selectionService.getSelectedVirtualization();

this.metadataFetchInProgress = false;

Expand Down
5 changes: 1 addition & 4 deletions ngapp/src/app/dataservices/shared/dataservice.model.ts
Expand Up @@ -105,10 +105,7 @@ export class Dataservice implements Identifiable< string > {
* @returns {string} the dataservice Vdb name (can be null)
*/
public getServiceVdbName(): string {
if (this.serviceVdbName && this.serviceVdbName !== null) {
return this.serviceVdbName;
}
return "";
return this.serviceVdbName;
}

/**
Expand Down
90 changes: 0 additions & 90 deletions ngapp/src/app/dataservices/shared/dataservice.service.ts
Expand Up @@ -41,8 +41,6 @@ import { Subject } from "rxjs/Subject";
import { Subscription } from "rxjs/Subscription";
import * as _ from "lodash";
import * as vkbeautify from 'vkbeautify';
import { ViewDefinition } from "@dataservices/shared/view-definition.model";
import { SqlView } from "@dataservices/shared/sql-view.model";
import { ViewEditorState } from "@dataservices/shared/view-editor-state.model";

@Injectable()
Expand All @@ -60,8 +58,6 @@ export class DataserviceService extends ApiService {
private notifierService: NotifierService;
private appSettingsService: AppSettingsService;
private vdbService: VdbService;
private selectedDataservice: Dataservice;
private dataserviceCurrentViewDefinition: ViewDefinition[] = [];
private cachedDataserviceDeployStates: Map<string, DeploymentState> = new Map<string, DeploymentState>();
private cachedDataserviceVirtualizations: Map<string, Virtualization> = new Map<string, Virtualization>();
private updatesSubscription: Subscription;
Expand Down Expand Up @@ -93,92 +89,6 @@ export class DataserviceService extends ApiService {
return ds;
}

/**
* Set the current Dataservice selection
* @param {Dataservice} service the Dataservice
*/
public setSelectedDataservice(service: Dataservice): void {
this.selectedDataservice = service;
// When the dataservice is selected, init the selected view
const viewDefns: ViewDefinition[] = this.getSelectedDataserviceViews();
this.dataserviceCurrentViewDefinition = [];
if (viewDefns && viewDefns.length > 0) {
this.dataserviceCurrentViewDefinition.push(viewDefns[0]);
}
}

/**
* Get the current Dataservice selection
* @returns {Dataservice} the selected Dataservice
*/
public getSelectedDataservice( ): Dataservice {
return this.selectedDataservice;
}

/**
* Get the current Dataservice selection's views.View
* The ViewDefinition name is currently set to the full "modelName"."viewName" of the view.
* @returns {ViewDefinition[]} the selected Dataservice view definitions
*/
public getSelectedDataserviceViews( ): ViewDefinition[] {
if (!this.selectedDataservice || this.selectedDataservice === null) {
return [];
}

const modelName = this.selectedDataservice.getServiceViewModel();
const serviceViews = this.selectedDataservice.getServiceViewNames();

// build the views using the model and view names
const allViews: ViewDefinition[] = [];
for ( const serviceView of serviceViews ) {
const aView: ViewDefinition = new ViewDefinition();
aView.setName(modelName + "." + serviceView);

allViews.push(aView);
}

return allViews;
}

/**
* Get the current Dataservice selection's views.View
* The ViewDefinition name is currently set to the full "modelName"."viewName" of the view.
* @returns {ViewDefinition[]} the selected Dataservice view definitions
*/
public getSelectedDataserviceViewNames( ): SqlView[] {
if (!this.selectedDataservice || this.selectedDataservice === null) {
return [];
}

const modelName = this.selectedDataservice.getServiceViewModel();
const serviceViews = this.selectedDataservice.getServiceViewNames();

const allViewNames: SqlView[] = [];
for ( const serviceView of serviceViews ) {
allViewNames.push(new SqlView(modelName + "." + serviceView));
}

return allViewNames;
}

/**
* Get the current Dataservice current view. The table object is used for the view,
* with the View name set to the full "modelName"."viewName" of the view.
* @returns {ViewDefinition[]} the Dataservice current view definition
*/
public getSelectedDataserviceCurrentView( ): ViewDefinition[] {
return this.dataserviceCurrentViewDefinition;
}

/**
* Set the current Dataservice current view. The table object is used for the view,
* with the View name set to the full "modelName"."viewName" of the view.
* @param {ViewDefinition[]} view the current view
*/
public setSelectedDataserviceCurrentView( view: ViewDefinition[] ): void {
this.dataserviceCurrentViewDefinition = view;
}

/**
* Validates the specified data service name. If the name contains valid characters and the name is unique, the
* service returns 'null'. Otherwise, a 'string' containing an error message is returned.
Expand Down
48 changes: 0 additions & 48 deletions ngapp/src/app/dataservices/shared/mock-dataservice.service.ts
Expand Up @@ -32,8 +32,6 @@ import "rxjs/add/operator/catch";
import "rxjs/add/operator/map";
import { Observable } from "rxjs/Observable";
import { ErrorObservable } from "rxjs/observable/ErrorObservable";
import { ViewDefinition } from "@dataservices/shared/view-definition.model";
import { SqlView } from "@dataservices/shared/sql-view.model";
import { ViewEditorState } from "@dataservices/shared/view-editor-state.model";

@Injectable()
Expand All @@ -57,12 +55,6 @@ export class MockDataserviceService extends DataserviceService {
this.queryResults = testDataService.getQueryResults();

this.editorViewStateMap = testDataService.getViewEditorStateMap();

// set selected dataservice, so it's not empty
const ds = new Dataservice();
ds.setId("testDs");
ds.setServiceVdbName("testDsVdb");
this.setSelectedDataservice(ds);
}

/**
Expand Down Expand Up @@ -101,46 +93,6 @@ export class MockDataserviceService extends DataserviceService {
return Observable.of( true );
}

/**
* Set the current Dataservice selection
* @param {Dataservice} service the Dataservice
*/
public setSelectedDataservice(service: Dataservice): void {
this.selectedDs = service;
}

/**
* Get the current Dataservice selection
* @returns {Dataservice} the selected Dataservice
*/
public getSelectedDataservice( ): Dataservice {
return this.selectedDs;
}

/**
* Get the view definitions for the selected Dataservice
* @returns {ViewDefinition[]} the view definitions
*/
public getSelectedDataserviceViews(): ViewDefinition[] {
const table: ViewDefinition = new ViewDefinition();
table.setName("views.View1");
const tables: ViewDefinition[] = [];
tables.push(table);

return tables;
}

/**
* Get the views for the selected Dataservice
* @returns {SqlView[]} the views
*/
public getSelectedDataserviceViewNames(): SqlView[] {
const views: SqlView[] = [];
views.push(new SqlView("views.View1"));

return views;
}

/**
* Query a Dataservice via the komodo rest interface
* @param {string} query the SQL query
Expand Down

0 comments on commit 4f14705

Please sign in to comment.