Skip to content

Commit

Permalink
SHIBUI-914 Fixing validation
Browse files Browse the repository at this point in the history
  • Loading branch information
rmathis committed Oct 11, 2018
1 parent 6fd5c07 commit 2c95d4d
Show file tree
Hide file tree
Showing 13 changed files with 119 additions and 37 deletions.
6 changes: 3 additions & 3 deletions ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"deep-object-diff": "^1.1.0",
"file-saver": "^1.3.3",
"font-awesome": "^4.7.0",
"ngx-schema-form": "^2.0.0-beta.3",
"ngx-schema-form": "^2.2.0-beta.1",
"rxjs": "^6.1.0",
"rxjs-compat": "^6.1.0",
"xml-formatter": "^1.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export class MetadataSourceWizard implements Wizard<MetadataResolver> {
}

getValidators(...args: any[]): { [key: string]: any } {
return {};
const validators = {};
return validators;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,15 @@ export class DashboardResolversListComponent implements OnInit {
}

edit(entity: MetadataEntity): void {
this.router.navigate(['metadata', 'resolver', entity.getId(), entity.isDraft() ? 'wizard' : 'edit']);
if (entity.isDraft()) {
this.router.navigate(['metadata', 'resolver', 'new', 'blank'], {
queryParams: {
entityId: entity.getId()
}
});
} else {
this.router.navigate(['metadata', 'resolver', entity.getId(), 'edit']);
}
}

toggleEntity(entity: MetadataEntity): void {
Expand Down
17 changes: 14 additions & 3 deletions ui/src/app/metadata/resolver/container/new-resolver.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { Component } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Observable } from 'rxjs';
import { map, withLatestFrom } from 'rxjs/operators';
import { Observable, Subscription } from 'rxjs';
import { map, withLatestFrom, distinctUntilChanged } from 'rxjs/operators';
import { SelectDraft } from '../action/draft.action';
import { Store } from '@ngrx/store';
import * as fromCollection from '../reducer';

@Component({
selector: 'new-resolver-page',
Expand All @@ -10,14 +13,22 @@ import { map, withLatestFrom } from 'rxjs/operators';
})
export class NewResolverComponent {

actionsSubscription: Subscription;

canSetNewType$: Observable<boolean>;

constructor(
private route: ActivatedRoute
private route: ActivatedRoute,
private store: Store<fromCollection.State>
) {
this.canSetNewType$ = this.route.queryParams.pipe(
withLatestFrom(this.route.url),
map(([params, url]) => this.route.snapshot.firstChild.routeConfig.path !== 'blank' || params.index === 'common')
);

this.actionsSubscription = this.route.queryParams.pipe(
distinctUntilChanged(),
map(params => new SelectDraft(params.entityId))
).subscribe(store);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ import { Store } from '@ngrx/store';
import * as fromResolver from '../reducer';
import * as fromWizard from '../../../wizard/reducer';

import { SetDefinition } from '../../../wizard/action/wizard.action';
import { UpdateStatus, UpdateChanges } from '../action/entity.action';
import { Wizard } from '../../../wizard/model';
import { MetadataResolver } from '../../domain/model';
import { pick } from '../../../shared/util';

@Component({
selector: 'resolver-wizard-step',
Expand Down Expand Up @@ -70,10 +68,11 @@ export class ResolverWizardStepComponent implements OnDestroy {
this.valueChangeEmitted$.pipe(
withLatestFrom(this.definition$),
skipWhile(([ changes, definition ]) => !definition || !changes),
map(([ changes, definition ]) => definition.parser(changes.value))
map(([ changes, definition ]) => definition.parser(changes.value)),
withLatestFrom(this.store.select(fromResolver.getSelectedDraft)),
map(([changes, original]) => ({ ...changes }))
)
.subscribe(changes => {
// console.log(changes);
this.store.dispatch(new UpdateChanges(changes));
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
<hr />
<div class="py-4">
<router-outlet></router-outlet>
</div>
</div>
<pre>{{ changes$ | async | json }}</pre>
<pre>{{ schema$ | async | json }}</pre>
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
RouterStateSnapshot
} from '@angular/router';
import { Observable, Subject, of } from 'rxjs';
import { skipWhile } from 'rxjs/operators';
import { skipWhile, startWith } from 'rxjs/operators';
import { Store } from '@ngrx/store';

import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
Expand Down Expand Up @@ -55,6 +55,9 @@ export class ResolverWizardComponent implements OnDestroy, CanComponentDeactivat
saved$: Observable<boolean>;
saving: boolean;

valid$: Observable<boolean>;
schema$: Observable<any>;

constructor(
private store: Store<fromCollections.State>,
private route: ActivatedRoute,
Expand All @@ -73,13 +76,22 @@ export class ResolverWizardComponent implements OnDestroy, CanComponentDeactivat
}
});

this.valid$ = this.store.select(fromResolver.getEntityIsValid);

this.valid$
.pipe(startWith(false))
.subscribe((valid) => {
this.store.dispatch(new SetDisabled(!valid));
});

this.store.dispatch(new SetDefinition(this.sourceWizard));

this.store.select(fromWizard.getNext).subscribe(n => this.nextStep = n);
this.store.select(fromWizard.getPrevious).subscribe(p => this.previousStep = p);
this.store.select(fromWizard.getWizardIndex).subscribe(i => this.currentPage = i);

this.changes$ = this.store.select(fromResolver.getEntityChanges);
this.schema$ = this.store.select(fromWizard.getSchema);

this.route.queryParams.subscribe(params => {
if (params.index) {
Expand Down
6 changes: 4 additions & 2 deletions ui/src/app/metadata/resolver/effect/wizard.effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ export class WizardEffects {
const params = { ...this.activatedRoute.snapshot.queryParams, index };
this.router.navigate([], {
relativeTo: this.activatedRoute,
queryParams: params
queryParams: params,
queryParamsHandling: 'preserve'
});
})
);
Expand All @@ -61,7 +62,8 @@ export class WizardEffects {
const params = { ...this.activatedRoute.snapshot.queryParams, entityId };
this.router.navigate([], {
relativeTo: this.activatedRoute,
queryParams: params
queryParams: params,
queryParamsHandling: 'preserve'
});
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
Component, AfterViewInit, ChangeDetectorRef
} from '@angular/core';
import { ButtonWidget } from 'ngx-schema-form';
import { ɵb as ActionRegistry } from 'ngx-schema-form';
import { ActionRegistry } from 'ngx-schema-form';
import { interval } from 'rxjs';

@Component({
Expand Down
3 changes: 2 additions & 1 deletion ui/src/app/wizard/reducer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ export const getSplitSchema = (schema: any, step: WizardStep) => {
const keys = Object.keys(schema.properties).filter(key => step.fields.indexOf(key) > -1);
const required = (schema.required || []).filter(val => keys.indexOf(val) > -1);
let s: any = {
...schema,
type: schema.type,
definitions: schema.definitions,
properties: {
...keys.reduce( (properties, key) => ({ ...properties, [key]: schema.properties[key] }) , {})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
]
},
{
"type": "group-lg",
"fields": [
"xmlId",
"metadataURL",
Expand Down
Loading

0 comments on commit 2c95d4d

Please sign in to comment.