-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged in feature/SHIBUI-284 (pull request #5)
Added fields for entity ID search * Added fields for entity ID search * Fixed unit tests * Added test for action Approved-by: Ryan Mathis <rmathis@unicon.net>
- Loading branch information
Showing
14 changed files
with
346 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { Action } from '@ngrx/store'; | ||
|
|
||
| export const CANCEL_CREATE_FILTER = '[Filter Collection] Cancel Create Filter'; | ||
|
|
||
| export class CancelCreateFilter implements Action { | ||
| readonly type = CANCEL_CREATE_FILTER; | ||
|
|
||
| constructor(public payload: boolean) { } | ||
| } | ||
|
|
||
| /* | ||
| export class SaveChanges implements Action { | ||
| readonly type = SAVE_CHANGES; | ||
| constructor(public payload: MetadataProvider) { } | ||
| } | ||
| */ | ||
|
|
||
| export type Actions = | ||
| | CancelCreateFilter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 42 additions & 6 deletions
48
ui/src/app/metadata-filter/container/new-filter.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,54 @@ | ||
| import { Component } from '@angular/core'; | ||
| import { Component, OnInit, OnChanges, OnDestroy } from '@angular/core'; | ||
| import { FormBuilder, Validators } from '@angular/forms'; | ||
| import { Store } from '@ngrx/store'; | ||
| import { Observable } from 'rxjs/Observable'; | ||
| import 'rxjs/add/observable/of'; | ||
|
|
||
| import * as fromFilter from '../reducer'; | ||
| import { ProviderFormFragmentComponent } from '../../metadata-provider/component/forms/provider-form-fragment.component'; | ||
| import { ProviderStatusEmitter, ProviderValueEmitter } from '../../metadata-provider/service/provider-change-emitter.service'; | ||
| import { CancelCreateFilter } from '../action/collection.action'; | ||
|
|
||
| @Component({ | ||
| selector: 'new-filter-page', | ||
| templateUrl: './new-filter.component.html' | ||
| }) | ||
| export class NewFilterComponent { | ||
| export class NewFilterComponent extends ProviderFormFragmentComponent implements OnInit, OnChanges, OnDestroy { | ||
|
|
||
| entityIds$: Observable<string[]>; | ||
|
|
||
| constructor( | ||
| private store: Store<fromFilter.State> | ||
| ) {} | ||
| private store: Store<fromFilter.State>, | ||
| protected statusEmitter: ProviderStatusEmitter, | ||
| protected valueEmitter: ProviderValueEmitter, | ||
| protected fb: FormBuilder | ||
| ) { | ||
| super(fb, statusEmitter, valueEmitter); | ||
| } | ||
|
|
||
| createForm(): void { | ||
| this.form = this.fb.group({ | ||
| entityId: ['', Validators.required], | ||
| filterName: ['', Validators.required] | ||
| }); | ||
| } | ||
|
|
||
| ngOnInit(): void { | ||
| super.ngOnInit(); | ||
| this.entityIds$ = Observable.of(['foo', 'bar', 'baz']); | ||
| } | ||
|
|
||
| ngOnChanges(): void {} | ||
|
|
||
| ngOnDestroy(): void {} | ||
|
|
||
| onViewMore($event): void {} | ||
|
|
||
| save(): void {} | ||
| save(): void { | ||
| console.log('Save!'); | ||
| } | ||
|
|
||
| cancel(): void {} | ||
| cancel(): void { | ||
| this.store.dispatch(new CancelCreateFilter(true)); | ||
| } | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { Injectable } from '@angular/core'; | ||
| import { Effect, Actions } from '@ngrx/effects'; | ||
|
|
||
| import * as filter from '../action/collection.action'; | ||
| import { Router } from '@angular/router'; | ||
|
|
||
| @Injectable() | ||
| export class FilterEffects { | ||
|
|
||
| @Effect({ dispatch: false }) | ||
| cancelChanges$ = this.actions$ | ||
| .ofType<filter.CancelCreateFilter>(filter.CANCEL_CREATE_FILTER) | ||
| .map(action => action.payload) | ||
| .switchMap(() => this.router.navigate(['/dashboard'])); | ||
|
|
||
| constructor( | ||
| private actions$: Actions, | ||
| private router: Router | ||
| ) { } | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
ui/src/app/widget/autocomplete/autocomplete-validators.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import { TestBed, async, inject } from '@angular/core/testing'; | ||
| import { Observable } from 'rxjs/Observable'; | ||
| import { AbstractControl, FormBuilder, ReactiveFormsModule } from '@angular/forms'; | ||
| import 'rxjs/add/observable/of'; | ||
|
|
||
| import * as AutoCompleteValidators from './autocomplete-validators.service'; | ||
|
|
||
| let ids = ['foo', 'bar', 'baz']; | ||
|
|
||
| describe(`existsInCollection`, () => { | ||
|
|
||
| beforeEach(() => { | ||
| TestBed.configureTestingModule({ | ||
| imports: [ | ||
| ReactiveFormsModule | ||
| ], | ||
| providers: [ | ||
| FormBuilder | ||
| ] | ||
| }); | ||
| }); | ||
|
|
||
| describe('createUniqueIdValidator', () => { | ||
| it('should detect that a provided id is in the collection', async(inject([FormBuilder], (fb) => { | ||
| let obs = Observable.of(ids), | ||
| validator = AutoCompleteValidators.existsInCollection(obs), | ||
| ctrl = fb.control('foo'); | ||
| validator(ctrl).subscribe(next => { | ||
| expect(next).toBeNull(); | ||
| }); | ||
| }))); | ||
|
|
||
| it('should detect that a provided id is not in the collection', async(inject([FormBuilder], (fb) => { | ||
| let obs = Observable.of(ids), | ||
| validator = AutoCompleteValidators.existsInCollection(obs), | ||
| ctrl = fb.control('hi'); | ||
| validator(ctrl).subscribe(next => { | ||
| expect(next).toBeTruthy(); | ||
| }); | ||
| }))); | ||
| }); | ||
| }); |
17 changes: 17 additions & 0 deletions
17
ui/src/app/widget/autocomplete/autocomplete-validators.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import { Observable } from 'rxjs/Observable'; | ||
| import { AbstractControl } from '@angular/forms'; | ||
| import 'rxjs/add/operator/take'; | ||
| import 'rxjs/add/operator/startWith'; | ||
| import 'rxjs/add/operator/map'; | ||
|
|
||
| export function existsInCollection (ids$: Observable<string[]>) { | ||
| return(control: AbstractControl) => { | ||
| return ids$ | ||
| .map(ids => ids.find(id => id === control.value)) | ||
| .map(ids => ids && !!ids.length) | ||
| .map((exists: boolean) => { | ||
| return exists ? null : { exists: true }; | ||
| }) | ||
| .take(1); | ||
| }; | ||
| } |
Oops, something went wrong.