From b994c2da9b8bea432b29185fba8c6eefc567aba1 Mon Sep 17 00:00:00 2001 From: Mark Drilling Date: Fri, 26 Oct 2018 12:26:59 -0500 Subject: [PATCH] TT-465 fix ViewDefinition issue --- .../shared/view-definition.model.ts | 30 +++++++++++++++---- .../projected-columns-editor.component.html | 3 +- .../projected-columns-editor.component.ts | 11 +++++++ 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/ngapp/src/app/dataservices/shared/view-definition.model.ts b/ngapp/src/app/dataservices/shared/view-definition.model.ts index 815eb989..2c26a5df 100644 --- a/ngapp/src/app/dataservices/shared/view-definition.model.ts +++ b/ngapp/src/app/dataservices/shared/view-definition.model.ts @@ -21,7 +21,6 @@ import { VdbsConstants } from "@dataservices/shared/vdbs-constants"; import { CompositionOperator } from "@dataservices/shared/composition-operator.enum"; import { CompositionType } from "@dataservices/shared/composition-type.enum"; import { ProjectedColumn } from "@dataservices/shared/projected-column.model"; -import { select } from "d3-selection"; /** * ViewDefinition model @@ -34,6 +33,7 @@ export class ViewDefinition { private compositions: Composition[] = []; private isSelected = false; private projectedColumns: ProjectedColumn[] = []; + private defaultProjectedColumns: ProjectedColumn[] = []; /** * @param {Object} json the JSON representation of a ViewDefinition @@ -82,14 +82,15 @@ export class ViewDefinition { * Constructor */ constructor() { - // The ViewDefinition is initialized with 'SELECT *' - const prjCols: ProjectedColumn[] = []; + // Define the default projected columns ('SELECT *') const selectStar: ProjectedColumn = new ProjectedColumn(); selectStar.setName("ALL"); selectStar.setType("ALL"); selectStar.selected = true; - prjCols.push(selectStar); - this.setProjectedColumns(prjCols); + this.defaultProjectedColumns.push(selectStar); + + // Init the ViewDefinition with default projected columns + this.initProjectedColumns(); } /** @@ -132,6 +133,8 @@ export class ViewDefinition { */ public setSourcePaths( sourcePaths: string[] = [] ): void { this.sourcePaths = sourcePaths; + // change in source paths will re-init the projected columns + this.initProjectedColumns(); } /** @@ -146,6 +149,8 @@ export class ViewDefinition { */ public setCompositions( compositions: Composition[] = [] ): void { this.compositions = compositions; + // change in compositions will re-init the projected columns + this.initProjectedColumns(); } /** @@ -186,6 +191,8 @@ export class ViewDefinition { if ( index === -1 ) { this.compositions.push( compositionToAdd ); + // adding composition will re-init the projected columns + this.initProjectedColumns(); } } @@ -197,6 +204,8 @@ export class ViewDefinition { if ( index !== -1 ) { this.compositions.splice( index, 1 ); + // removing composition will re-init the projected columns + this.initProjectedColumns(); } } @@ -212,6 +221,8 @@ export class ViewDefinition { if ( index === -1 ) { this.sourcePaths.push( sourcePathToAdd ); + // adding source will re-init the projected columns + this.initProjectedColumns(); } } @@ -237,6 +248,8 @@ export class ViewDefinition { if ( index !== -1 ) { this.sourcePaths.splice( index, 1 ); + // remove source will re-init the projected columns + this.initProjectedColumns(); } } @@ -382,6 +395,13 @@ export class ViewDefinition { return this.getProjectedColumns().length === 1 && this.getProjectedColumns()[0].getName() === "ALL" && this.getProjectedColumns()[0].getType() === "ALL"; } + /** + * Initializes the projected columns for this view. This resets the view projected columns to "*" ("ALL") + */ + private initProjectedColumns(): void { + this.setProjectedColumns(this.defaultProjectedColumns); + } + /** * Get the SQL string for the current projected columns * @return {string} the projected columns SQL diff --git a/ngapp/src/app/dataservices/virtualization/view-editor/view-property-editors/projected-columns-editor/projected-columns-editor.component.html b/ngapp/src/app/dataservices/virtualization/view-editor/view-property-editors/projected-columns-editor/projected-columns-editor.component.html index 9dc48718..3d61ebbe 100644 --- a/ngapp/src/app/dataservices/virtualization/view-editor/view-property-editors/projected-columns-editor/projected-columns-editor.component.html +++ b/ngapp/src/app/dataservices/virtualization/view-editor/view-property-editors/projected-columns-editor/projected-columns-editor.component.html @@ -7,7 +7,8 @@

No View Selected

View Columns

-

All columns included. Save the view to populate the specific columns

+

All view columns are included.

+
Save the view to populate columns table
diff --git a/ngapp/src/app/dataservices/virtualization/view-editor/view-property-editors/projected-columns-editor/projected-columns-editor.component.ts b/ngapp/src/app/dataservices/virtualization/view-editor/view-property-editors/projected-columns-editor/projected-columns-editor.component.ts index 261bbfb7..4198c63f 100644 --- a/ngapp/src/app/dataservices/virtualization/view-editor/view-property-editors/projected-columns-editor/projected-columns-editor.component.ts +++ b/ngapp/src/app/dataservices/virtualization/view-editor/view-property-editors/projected-columns-editor/projected-columns-editor.component.ts @@ -11,6 +11,10 @@ import { LoggerService } from "@core/logger.service"; import { ViewEditorEvent } from "@dataservices/virtualization/view-editor/event/view-editor-event"; import { Subscription } from "rxjs/Subscription"; import { UpdateProjectedColumnsCommand } from "@dataservices/virtualization/view-editor/command/update-projected-columns-command"; +import { AddSourcesCommand } from "@dataservices/virtualization/view-editor/command/add-sources-command"; +import { RemoveSourcesCommand } from "@dataservices/virtualization/view-editor/command/remove-sources-command"; +import { AddCompositionCommand } from "@dataservices/virtualization/view-editor/command/add-composition-command"; +import { RemoveCompositionCommand } from "@dataservices/virtualization/view-editor/command/remove-composition-command"; @Component({ selector: 'app-projected-columns-editor', @@ -100,9 +104,16 @@ export class ProjectedColumnsEditorComponent implements OnInit, OnDestroy { if ( event.args.length === 1 && event.args[ 0 ] instanceof Command ) { const cmd = event.args[ 0 ] as Command; + // Handle updated projected columns if ( cmd instanceof UpdateProjectedColumnsCommand ) { this.updateProjectedColumns(cmd.getNewProjectedColumns()); } + // Change in sources or compositions - forces a reset of the columns + else if ( cmd instanceof AddSourcesCommand || cmd instanceof RemoveSourcesCommand || + cmd instanceof AddCompositionCommand || cmd instanceof RemoveCompositionCommand ) { + const viewDefn = this.editorService.getEditorView(); + this.initProjectedColumns(viewDefn.getProjectedColumns()); + } } } }