diff --git a/ui/src/app/metadata/provider/container/new-provider.component.scss b/ui/src/app/metadata/provider/container/new-provider.component.scss deleted file mode 100644 index e3d0c671e..000000000 --- a/ui/src/app/metadata/provider/container/new-provider.component.scss +++ /dev/null @@ -1,5 +0,0 @@ -// :host { -// .provider-nav-option { -// width: 160px; -// } -// } diff --git a/ui/src/app/metadata/provider/container/provider-wizard-step.component.html b/ui/src/app/metadata/provider/container/provider-wizard-step.component.html new file mode 100644 index 000000000..842a4a2c2 --- /dev/null +++ b/ui/src/app/metadata/provider/container/provider-wizard-step.component.html @@ -0,0 +1,5 @@ + \ No newline at end of file diff --git a/ui/src/app/metadata/provider/container/provider-wizard-step.component.ts b/ui/src/app/metadata/provider/container/provider-wizard-step.component.ts new file mode 100644 index 000000000..b4c553f0a --- /dev/null +++ b/ui/src/app/metadata/provider/container/provider-wizard-step.component.ts @@ -0,0 +1,92 @@ +import { Component, OnDestroy } from '@angular/core'; +import { Observable, Subject } from 'rxjs'; +import { withLatestFrom } from 'rxjs/operators'; +import { Store } from '@ngrx/store'; + +import * as fromProvider from '../reducer'; +import * as fromWizard from '../../../wizard/reducer'; + +import { SetDisabled, SetDefinition } from '../../../wizard/action/wizard.action'; +import { LoadSchemaRequest, UpdateStatus } from '../action/editor.action'; +import { startWith } from 'rxjs/operators'; +import { Wizard } from '../../../wizard/model'; +import { MetadataProvider } from '../../domain/model'; +import { MetadataProviderTypes, MetadataProviderWizard } from '../model'; +import { UpdateProvider } from '../action/entity.action'; +import { pick } from '../../../shared/util'; + +@Component({ + selector: 'provider-wizard-step', + templateUrl: './provider-wizard-step.component.html', + styleUrls: [] +}) + +export class ProviderWizardStepComponent implements OnDestroy { + changeSubject = new Subject>(); + private changeEmitted$ = this.changeSubject.asObservable(); + + schema$: Observable; + schema: any; + definition$: Observable>; + changes$: Observable; + currentPage: string; + valid$: Observable; + + constructor( + private store: Store + ) { + this.store + .select(fromWizard.getCurrentWizardSchema) + .subscribe(s => { + this.store.dispatch(new LoadSchemaRequest(s)); + }); + + this.schema$ = this.store.select(fromProvider.getSchema); + this.valid$ = this.store.select(fromProvider.getEditorIsValid); + this.definition$ = this.store.select(fromWizard.getWizardDefinition); + this.changes$ = this.store.select(fromProvider.getEntityChanges); + + this.valid$ + .pipe(startWith(false)) + .subscribe((valid) => { + this.store.dispatch(new SetDisabled(!valid)); + }); + + this.schema$.subscribe(s => this.schema = s); + + this.changeEmitted$ + .pipe( + withLatestFrom(this.schema$, this.definition$), + ) + .subscribe( + ([changes, schema, definition]) => { + const type = changes.value['@type']; + if (type && type !== definition.type) { + const newDefinition = MetadataProviderTypes.find(def => def.type === type); + if (newDefinition) { + this.store.dispatch(new SetDefinition({ + ...MetadataProviderWizard, + ...newDefinition, + steps: [ + ...MetadataProviderWizard.steps, + ...newDefinition.steps + ] + })); + changes = { value: pick(Object.keys(schema.properties))(changes.value) }; + } + } + this.store.dispatch(new UpdateProvider(changes.value)); + } + ); + } + + ngOnDestroy() { + this.changeSubject.complete(); + } + + onStatusChange(value): void { + const status = { [this.currentPage]: value ? 'VALID' : 'INVALID' }; + this.store.dispatch(new UpdateStatus(status)); + } +} + diff --git a/ui/src/app/metadata/provider/container/new-provider.component.spec.ts b/ui/src/app/metadata/provider/container/provider-wizard-summary.component.html similarity index 100% rename from ui/src/app/metadata/provider/container/new-provider.component.spec.ts rename to ui/src/app/metadata/provider/container/provider-wizard-summary.component.html diff --git a/ui/src/app/metadata/provider/container/provider-wizard-summary.component.ts b/ui/src/app/metadata/provider/container/provider-wizard-summary.component.ts new file mode 100644 index 000000000..d16ee2498 --- /dev/null +++ b/ui/src/app/metadata/provider/container/provider-wizard-summary.component.ts @@ -0,0 +1,21 @@ +import { Component } from '@angular/core'; +import { Store } from '@ngrx/store'; + +import * as fromProvider from '../reducer'; + +@Component({ + selector: 'provider-wizard-summary', + templateUrl: './provider-wizard-summary.component.html', + styleUrls: [] +}) + +export class ProviderWizardSummaryComponent { + constructor( + private store: Store + ) {} + + save(): void { + console.log('Save!'); + } +} + diff --git a/ui/src/app/metadata/provider/container/provider-wizard.component.html b/ui/src/app/metadata/provider/container/provider-wizard.component.html index 58adb7221..cbeb7c675 100644 --- a/ui/src/app/metadata/provider/container/provider-wizard.component.html +++ b/ui/src/app/metadata/provider/container/provider-wizard.component.html @@ -3,11 +3,7 @@
- +