Skip to content

Commit

Permalink
KYLO-3217 wrangler join
Browse files Browse the repository at this point in the history
  • Loading branch information
scottreisdorf committed Dec 18, 2018
1 parent 042be61 commit a52c04f
Show file tree
Hide file tree
Showing 23 changed files with 546 additions and 80 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import {PreviewStepperStep} from "./preview-stepper-step";
import {Component, Input, OnInit, TemplateRef, ViewChild} from "@angular/core";
import {FormGroup} from "@angular/forms";
import {DatasetPreviewStepperService} from "./dataset-preview-stepper.service";
/*
@Component({selector:"dataset-preview-step",
template:`<ng-template let-data #stepTemplate>
This is my template {{data}}
</ng-template>`})
*/
export abstract class AbstractDatasetPreviewStepComponent<T> implements OnInit, PreviewStepperStep<T>{

additionalStepIndex:number;
index:number;
name:string = "Step";

data:T;

stepControl:FormGroup;

@ViewChild("stepTemplate")
templateRef: TemplateRef<any>;

protected constructor(protected _datasetPreviewStepperService:DatasetPreviewStepperService) {
this.stepControl = new FormGroup({})
}

init(){

}

ngOnInit(): void {
this.init();
}

setAdditionalStepIndex(additionalStepIndex:number){
this.additionalStepIndex = additionalStepIndex;
this.index = this.additionalStepIndex+2+1;
}

onSave(): any {
return null;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</mat-toolbar>
-->
<mat-dialog-content fxFlex="100%">
<dataset-preview-stepper #datasetStepper (previewSaved)="onSaved($event)" (previewCanceled)="cancel()" [allowMultiSelection]="data.allowMultiSelection" [saveLabel]="data.saveLabel"></dataset-preview-stepper>
<dataset-preview-stepper #datasetStepper [additionalSteps]="data.additionalSteps" (previewSaved)="onSaved($event)" (previewCanceled)="cancel()" [allowMultiSelection]="data.allowMultiSelection" [saveLabel]="data.saveLabel"></dataset-preview-stepper>
</mat-dialog-content>
<mat-dialog-actions>
<!-- Action buttons -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import {ChangeDetectionStrategy, ChangeDetectorRef, Component, Inject, OnDestroy, OnInit, ViewChild} from "@angular/core";
import {ChangeDetectionStrategy, ChangeDetectorRef, Component, Inject, Input, OnDestroy, OnInit, ViewChild} from "@angular/core";
import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog";
import {DatasetPreviewStepperComponent, DatasetPreviewStepperSavedEvent} from "./dataset-preview-stepper.component";
import {PreviewStepperStep} from "./preview-stepper-step";

export class DatasetPreviewStepperDialogData {

additionalSteps:PreviewStepperStep<any>[] = []

constructor(public allowMultiSelection:boolean=false,public saveLabel:string = "Save",public title:string="Browse for data") { }



}
@Component({
selector: "dataset-preview-stepper-dialog",
Expand All @@ -31,6 +35,11 @@ export class DatasetPreviewStepperDialogComponent implements OnInit, OnDestroy{


ngOnInit(){
if(this.data && this.data.additionalSteps){
// this.data.additionalSteps.forEach((step:PreviewStepperStep<any>) => {
// step.init()
// })
}

}
ngOnDestroy(){
Expand Down Expand Up @@ -72,7 +81,16 @@ export class DatasetPreviewStepperDialogComponent implements OnInit, OnDestroy{
return this.datasetStepper.saveDisabled();
}
onSave(){
this.datasetStepper.onSave();
let saveEvent = this.datasetStepper.getPreviewSaveEvent();
if(this.data.additionalSteps){
//capture additional info
let lastStep = this.datasetStepper.getLastAdditionalStep();
if(lastStep != null){
let savedData = lastStep.onSave();
saveEvent.data = savedData;
}
}
this.datasetStepper.saved(saveEvent);
}

getDatasets(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,14 @@ <h2 class="mat-title">Unauthorized</h2>
<button mat-button (click)="onCancel()">Cancel</button>
<span fxFlex></span>
<button mat-button matStepperPrevious>Back</button>
<div fxLayout="column">
<div fxLayout="column" *ngIf="additionalSteps.length ==0">
<button mat-button (click)="onSave()" [disabled]="previewForm.invalid">{{saveLabel}}</button>
<!-- <span *ngIf="previewForm.invalid" class="warn">A selection is required</span> -->
</div>
<div fxLayout="column" *ngIf="additionalSteps.length > 0">
<button mat-button matStepperNext [disabled]="previewForm.invalid">Next</button>
<!-- <span *ngIf="previewForm.invalid" class="warn">A selection is required</span> -->
</div>
</div>

<preview-dataset-step #preview [formGroup]="previewForm" ></preview-dataset-step>
Expand All @@ -81,12 +85,47 @@ <h2 class="mat-title">Unauthorized</h2>
<button mat-button (click)="onCancel()">Cancel</button>
<span fxFlex></span>
<button mat-button matStepperPrevious>Back</button>
<div fxLayout="column">
<button mat-raised-button button color="accent" (click)="onSave()" [disabled]="previewForm.invalid">{{saveLabel}}</button>
<!-- <span *ngIf="previewForm.invalid" class="warn">A selection is required</span> -->
<div fxLayout="column" *ngIf="additionalSteps.length == 0">
<button mat-raised-button color="accent" (click)="onSave()" [disabled]="previewForm.invalid">{{saveLabel}}</button>
</div>
<div fxLayout="column" *ngIf="additionalSteps.length > 0">
<button mat-raised-button matStepperNext color="accent" [disabled]="previewForm.invalid">Next</button>
</div>
</div>

</mat-step>
<ng-container *ngFor="let step of additionalSteps; let index = index; let last = last">
<mat-step [stepControl]="step.stepControl">
<ng-template matStepLabel>{{step.name}}</ng-template>

<!-- Action buttons-->
<div fxLayout="row" fxFlex *ngIf="displayTopActionButtons">
<button mat-button (click)="onCancel()">Cancel</button>
<span fxFlex></span>
<button mat-button matStepperPrevious>Back</button>
<div fxLayout="column" *ngIf="last">
<button mat-button (click)="onSave()" [disabled]="stepControl.invalid">{{saveLabel}}</button>
</div>
<div fxLayout="column" *ngIf="last">
<button mat-button matStepperNext [disabled]="stepControl.invalid">Next</button>
</div>
</div>

<ng-container
*ngTemplateOutlet="step.templateRef;context:step"></ng-container>

<div fxLayout="row" fxFlex *ngIf="displayBottomActionButtons" style="margin-top:35px">
<button mat-button (click)="onCancel()">Cancel</button>
<span fxFlex></span>
<button mat-button matStepperPrevious>Back</button>
<div fxLayout="column" *ngIf="last">
<button mat-raised-button color="accent" (click)="onSave()" [disabled]="stepControl.invalid">{{saveLabel}}</button>
</div>
<div fxLayout="column" *ngIf="!last">
<button mat-raised-button matStepperNext color="accent" [disabled]="stepControl.invalid">Next</button>
</div>
</div>
</mat-step>
</ng-container>
</mat-horizontal-stepper>

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, Inject, Input, OnDestroy, OnInit, Output, ViewChild} from "@angular/core";
import {ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, Inject, Input, OnDestroy, OnInit, Output, TemplateRef, ViewChild} from "@angular/core";
import {FormControl, FormGroup} from "@angular/forms";
import {MatStepper} from "@angular/material/stepper";
import {CatalogService} from "../../catalog/api/services/catalog.service";
Expand All @@ -13,8 +13,13 @@ import {Subject} from "rxjs/Subject";
import {DatasetPreviewStepperService} from "./dataset-preview-stepper.service";
import {AccessControlService} from "../../../services/AccessControlService";
import AccessConstants from "../../../constants/AccessConstants";
import {PreviewStepperStep} from "./preview-stepper-step";

export class DatasetPreviewStepperSavedEvent{
/**
* Additional data that can be passed to a subscriber of the save event
*/
data?:any;
constructor(public previews:PreviewDataSet[], public singleSelection:boolean) {}
}

Expand Down Expand Up @@ -96,9 +101,11 @@ export class DatasetPreviewStepperComponent implements OnInit, OnDestroy{

requiredPermissions= [AccessConstants.DATASOURCE_ACCESS];

feedDefintionDatasourceState = undefined;
stateParams = undefined;

@Input()
additionalSteps:PreviewStepperStep<any>[] = []

constructor(private selectionService: SelectionService,
private catalogService:CatalogService,
private dataSourceService:DatasetPreviewStepperService,
Expand All @@ -113,12 +120,10 @@ export class DatasetPreviewStepperComponent implements OnInit, OnDestroy{
this.previewForm = new FormGroup({})

this.selectDataForm.statusChanges.debounceTime(10).subscribe(changes =>{
// this.selectDataFormValid = changes == "VALID"
this.cd.markForCheck()
});

this.previewForm.statusChanges.debounceTime(10).subscribe(changes =>{
// this.previewFormValid = changes == "VALID"
this.cd.markForCheck()
});

Expand Down Expand Up @@ -168,16 +173,23 @@ export class DatasetPreviewStepperComponent implements OnInit, OnDestroy{
showNext(){
let idx = this.dataSourceService.stepIndex;
//dont show next on first step. Require them to select a data source
return idx != undefined && idx ==1;
let lastIndex = this.getLastIndex();
return idx != undefined && idx >0 && idx <lastIndex;
}

showSave(){
let idx = this.dataSourceService.stepIndex;
// show on last step
return idx != undefined && idx ==2;
let lastIndex = this.getLastIndex();
return idx != undefined && idx == lastIndex ;
}

private getLastIndex(){
return this.additionalSteps ? this.additionalSteps.length +2 : 2;
}



saveDisabled(){
return this.previewForm.invalid;
}
Expand Down Expand Up @@ -206,11 +218,38 @@ export class DatasetPreviewStepperComponent implements OnInit, OnDestroy{
//preview data form
return this.previewForm.invalid;
}
else if(this.additionalSteps){
let step = this.getAdditionalStepForIndex(idx);
return step != null ? step.stepControl.invalid : false;
}
else {
false;
return false;
}
}

/**
* Get the additional step object for a given index
* Additional steps start on index 3
* @param idx
*/
private getAdditionalStepForIndex(idx:number) {
if(this.additionalSteps && idx >2) {
let additionalIndex = idx - 3;
let step = this.additionalSteps.length >= additionalIndex + 1 ? this.additionalSteps[additionalIndex] : null;
return step != null ? step : null;
}
return null;
}

public getLastAdditionalStep() {
if (this.additionalSteps != null && this.additionalSteps.length > 0) {
let idx = this.getLastIndex();
return this.getAdditionalStepForIndex(idx)
}
else {
return null;
}
}

ngOnInit(){
//clear any previous selections
Expand Down Expand Up @@ -257,13 +296,21 @@ export class DatasetPreviewStepperComponent implements OnInit, OnDestroy{
return this.getDataSets().length
}


getPreviewSaveEvent() {
let previews = this.preview.previews || [];
return new DatasetPreviewStepperSavedEvent(previews,this.singleSelection);
}

saved(saveEvent:DatasetPreviewStepperSavedEvent){
this.previewSaved.emit(saveEvent);
}
/**
* Callback when the user clicks the "Save/Add" button from the last step to do something with one or more datasets with previews
*/
onSave(){
let previews = this.preview.previews || [];
let event = new DatasetPreviewStepperSavedEvent(previews,this.singleSelection);
this.previewSaved.emit(event);
let event = this.getPreviewSaveEvent()
this.saved(event);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {FormGroup} from "@angular/forms";
import {DatasetPreviewService, DataSourceChangedEvent, PreviewDataSetResultEvent} from "../../catalog/datasource/preview-schema/service/dataset-preview.service";
import {Observable} from "rxjs/Observable";
import {Node} from "../../catalog/api/models/node";
import {PreviewDataSet} from "../../catalog/datasource/preview-schema/model/preview-data-set";


@Injectable()
Expand All @@ -14,6 +15,10 @@ export class DatasetPreviewStepperService {

public stepChanged$ = new Subject<number>();

public previews: PreviewDataSet[] = [];




constructor(private _datasetPreviewService: DatasetPreviewService) {

Expand Down Expand Up @@ -43,6 +48,10 @@ export class DatasetPreviewStepperService {
}
}

public savePreviews(previews:PreviewDataSet[]){
this.previews = previews;
}


markFormAsInvalid(formGroup: FormGroup) {
if (formGroup.contains("hiddenValidFormCheck")) {
Expand All @@ -58,6 +67,7 @@ export class DatasetPreviewStepperService {
}
}


public prepareAndPopulatePreview(node: Node, datasource: DataSource): Observable<PreviewDataSetResultEvent> {
return this._datasetPreviewService.prepareAndPopulatePreview(node,datasource);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,13 @@ export class PreviewDatasetStepComponent extends CatalogPreviewDatasetComponent
protected startLoading(){
super.startLoading();
this.cd.markForCheck();
this._datasetPreviewStepperService.savePreviews([]);
}

protected finishedLoading(){
super.finishedLoading();
this.cd.markForCheck();
this._datasetPreviewStepperService.savePreviews(this.previews);
}


Expand Down
Loading

0 comments on commit a52c04f

Please sign in to comment.