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

Commit

Permalink
TT-465 fix ViewDefinition issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mdrillin committed Oct 26, 2018
1 parent 6aded93 commit b994c2d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
30 changes: 25 additions & 5 deletions ngapp/src/app/dataservices/shared/view-definition.model.ts
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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();
}

/**
Expand Down Expand Up @@ -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();
}

/**
Expand All @@ -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();
}

/**
Expand Down Expand Up @@ -186,6 +191,8 @@ export class ViewDefinition {

if ( index === -1 ) {
this.compositions.push( compositionToAdd );
// adding composition will re-init the projected columns
this.initProjectedColumns();
}
}

Expand All @@ -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();
}
}

Expand All @@ -212,6 +221,8 @@ export class ViewDefinition {

if ( index === -1 ) {
this.sourcePaths.push( sourcePathToAdd );
// adding source will re-init the projected columns
this.initProjectedColumns();
}
}

Expand All @@ -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();
}
}

Expand Down Expand Up @@ -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
Expand Down
Expand Up @@ -7,7 +7,8 @@ <h3>No View Selected</h3>
<h3>View Columns</h3>
<!-- View projected columns are '*' -->
<div class="col-md-12" *ngIf="hasSelectAllProjectedColumns">
<h4>All columns included. Save the view to populate the specific columns</h4>
<h4>All view columns are included.</h4>
<h5>Save the view to populate columns table</h5>
</div>
<!-- Display the table of projected columns -->
<div class="col-md-12" *ngIf="!hasSelectAllProjectedColumns">
Expand Down
Expand Up @@ -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',
Expand Down Expand Up @@ -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());
}
}
}
}
Expand Down

0 comments on commit b994c2d

Please sign in to comment.