Skip to content

Commit

Permalink
Merged in feature/SHIBUI-624 (pull request #131)
Browse files Browse the repository at this point in the history
SHIBUI-624 Created filter list, Integrated filters functionality

* SHIBUI-624 structured routes for filter list

* SHIBUI-624 Integrated filters functionality

* Implemented Filter editor, fixed tests

* SHIBUI-624 Added tests

Approved-by: Shibui Jenkins <shibui.jenkins@gmail.com>
Approved-by: Ryan Mathis <rmathis@unicon.net>
  • Loading branch information
rmathis committed Jul 31, 2018
1 parent b75e14b commit 67ab1bc
Show file tree
Hide file tree
Showing 37 changed files with 635 additions and 215 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class EntityAttributesFilter implements MetadataFilter, MetadataEntity {
return {
attributeRelease: this.attributeRelease,
relyingPartyOverrides: this.relyingPartyOverrides,
entityAttributesFilterTarget: { ...this.entityAttributesFilterTarget },
entityAttributesFilterTarget: this.entityAttributesFilterTarget,
filterEnabled: this.filterEnabled,
name: this.name,
'@type': 'EntityAttributes'
Expand Down
34 changes: 18 additions & 16 deletions ui/src/app/metadata/domain/service/filter.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { EntityAttributesFilter } from '../entity';

describe(`Metadata Filter Service`, () => {

const provider = 'foo';

beforeEach(() => {
TestBed.configureTestingModule({
imports: [
Expand All @@ -21,53 +23,53 @@ describe(`Metadata Filter Service`, () => {
describe('query method', () => {
it(`should send an expected GET[] request`, async(inject([MetadataFilterService, HttpTestingController],
(service: MetadataFilterService, backend: HttpTestingController) => {
service.query().subscribe();
service.query(provider).subscribe();

backend.expectOne((req: HttpRequest<any>) => {
return req.url === `${service.base}${service.endpoint}`
return req.url === `${service.base}${service.endpoint}/${provider}/Filters`
&& req.method === 'GET';
}, `GET MetadataResolvers collection`);
}, `GET MetadataFilter collection`);
}
)));
});
describe('find method', () => {
it(`should send an expected GET request`, async(inject([MetadataFilterService, HttpTestingController],
(service: MetadataFilterService, backend: HttpTestingController) => {
const id = 'foo';
service.find(id).subscribe();
const id = 'bar';
service.find(provider, id).subscribe();

backend.expectOne((req: HttpRequest<any>) => {
return req.url === `${service.base}${service.endpoint}/${id}`
return req.url === `${service.base}${service.endpoint}/${provider}/Filters/${id}`
&& req.method === 'GET';
}, `GET MetadataResolvers collection`);
}, `GET MetadataFilter`);
}
)));
});
describe('update method', () => {
it(`should send an expected PUT request`, async(inject([MetadataFilterService, HttpTestingController],
(service: MetadataFilterService, backend: HttpTestingController) => {
const id = 'foo';
const filter = new EntityAttributesFilter({ id });
service.update(filter).subscribe();
const id = 'bar';
const filter = new EntityAttributesFilter({ resourceId: id });
service.update(provider, filter).subscribe();

backend.expectOne((req: HttpRequest<any>) => {
return req.url === `${service.base}${service.endpoint}/${id}`
return req.url === `${service.base}${service.endpoint}/${provider}/Filters/${ id }`
&& req.method === 'PUT';
}, `PUT (update) MetadataResolvers collection`);
}, `PUT (update) MetadataFilter`);
}
)));
});
describe('save method', () => {
it(`should send an expected POST request`, async(inject([MetadataFilterService, HttpTestingController],
(service: MetadataFilterService, backend: HttpTestingController) => {
const id = 'foo';
const id = 'bar';
const filter = new EntityAttributesFilter({ id });
service.save(filter).subscribe();
service.save(provider, filter).subscribe();

backend.expectOne((req: HttpRequest<any>) => {
return req.url === `${service.base}${service.endpoint}`
return req.url === `${service.base}${service.endpoint}/${provider}/Filters`
&& req.method === 'POST';
}, `POST MetadataResolvers collection`);
}, `POST MetadataFilter`);
}
)));
});
Expand Down
16 changes: 8 additions & 8 deletions ui/src/app/metadata/domain/service/filter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ export class MetadataFilterService {
constructor(
private http: HttpClient
) { }
query(): Observable<MetadataFilter[]> {
return this.http.get<MetadataFilter[]>(`${this.base}${this.endpoint}`, {});
query(providerId: string): Observable<MetadataFilter[]> {
return this.http.get<MetadataFilter[]>(`${this.base}${this.endpoint}/${providerId}/Filters`);
}

find(id: string): Observable<MetadataFilter> {
find(providerId: string, filterId: string): Observable<MetadataFilter> {
// console.log(id);
return this.http.get<MetadataFilter>(`${this.base}${this.endpoint}/${id}`);
return this.http.get<MetadataFilter>(`${this.base}${this.endpoint}/${providerId}/Filters/${ filterId }`);
}

update(filter: MetadataFilter): Observable<MetadataFilter> {
return this.http.put<MetadataFilter>(`${this.base}${this.endpoint}/${filter.id}`, filter);
update(providerId: string, filter: MetadataFilter): Observable<MetadataFilter> {
return this.http.put<MetadataFilter>(`${this.base}${this.endpoint}/${providerId}/Filters/${ filter.resourceId }`, filter);
}

save(filter: MetadataFilter): Observable<MetadataFilter> {
return this.http.post<MetadataFilter>(`${this.base}${this.endpoint}`, filter);
save(providerId: string, filter: MetadataFilter): Observable<MetadataFilter> {
return this.http.post<MetadataFilter>(`${this.base}${this.endpoint}/${providerId}/Filters`, filter);
}
}
2 changes: 1 addition & 1 deletion ui/src/app/metadata/filter/action/collection.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class SelectFilterFail implements Action {
export class LoadFilterRequest implements Action {
readonly type = FilterCollectionActionTypes.LOAD_FILTER_REQUEST;

constructor() { }
constructor(public payload: string) { }
}

export class LoadFilterSuccess implements Action {
Expand Down
6 changes: 4 additions & 2 deletions ui/src/app/metadata/filter/container/edit-filter.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,14 @@ export class EditFilterComponent implements OnInit, OnDestroy {
private valueEmitter: ProviderValueEmitter,
private fb: FormBuilder
) {
this.changes$ = this.store.select(fromFilter.getFilter);
this.changes$ = this.store.select(fromFilter.getFilterWithChanges);
this.changes$
.pipe(
distinctUntilChanged()
)
.subscribe(c => this.changes = new EntityAttributesFilter(c));
.subscribe(c => {
this.changes = new EntityAttributesFilter(c);
});

this.showMore$ = this.store.select(fromFilter.getViewingMore);
this.selected$ = this.store.select(fromFilter.getSelected);
Expand Down
4 changes: 3 additions & 1 deletion ui/src/app/metadata/filter/container/filter.component.html
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
<router-outlet></router-outlet>
<ng-container *ngIf="filter$ | async">
<router-outlet></router-outlet>
</ng-container>
51 changes: 23 additions & 28 deletions ui/src/app/metadata/filter/effect/collection.effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import { Store } from '@ngrx/store';
import { Router } from '@angular/router';

import { of } from 'rxjs';
import { switchMap, map, catchError, tap } from 'rxjs/operators';
import { switchMap, map, catchError, tap, combineLatest, skipWhile } from 'rxjs/operators';

import * as actions from '../action/collection.action';
import { FilterCollectionActionTypes } from '../action/collection.action';
import * as fromFilter from '../reducer';
import * as fromProvider from '../../provider/reducer';
import { MetadataFilter } from '../../domain/model';
import { removeNulls } from '../../../shared/util';
import { EntityAttributesFilter } from '../../domain/entity/filter/entity-attributes-filter';
Expand All @@ -21,9 +22,11 @@ export class FilterCollectionEffects {
@Effect()
loadFilters$ = this.actions$.pipe(
ofType<actions.LoadFilterRequest>(FilterCollectionActionTypes.LOAD_FILTER_REQUEST),
switchMap(() =>
map(action => action.payload),
skipWhile(providerId => !providerId),
switchMap(providerId =>
this.filterService
.query()
.query(providerId)
.pipe(
map(filters => new actions.LoadFilterSuccess(filters)),
catchError(error => of(new actions.LoadFilterError(error)))
Expand All @@ -34,9 +37,10 @@ export class FilterCollectionEffects {
selectFilterRequest$ = this.actions$.pipe(
ofType<actions.SelectFilter>(FilterCollectionActionTypes.SELECT_FILTER),
map(action => action.payload),
switchMap(id => {
combineLatest(this.store.select(fromProvider.getSelectedProviderId).pipe(skipWhile(id => !id))),
switchMap(([filterId, providerId]) => {
return this.filterService
.find(id)
.find(providerId, filterId)
.pipe(
map(p => new actions.SelectFilterSuccess(p)),
catchError(error => of(new actions.SelectFilterFail(error)))
Expand All @@ -55,41 +59,37 @@ export class FilterCollectionEffects {
relyingPartyOverrides: removeNulls(new EntityAttributesFilter(filter).relyingPartyOverrides)
};
}),
switchMap(unsaved =>
this.filterService
.save(unsaved as MetadataFilter)
combineLatest(this.store.select(fromProvider.getSelectedProviderId).pipe(skipWhile(id => !id))),
switchMap(([unsaved, providerId]) => {
return this.filterService
.save(providerId, unsaved as MetadataFilter)
.pipe(
map(saved => new actions.AddFilterSuccess(saved)),
catchError(error => of(new actions.AddFilterFail(error)))
)
)
);
})
);
@Effect({ dispatch: false })
addFilterSuccessRedirect$ = this.actions$.pipe(
ofType<actions.AddFilterSuccess>(FilterCollectionActionTypes.ADD_FILTER_SUCCESS),
map(action => action.payload),
tap(filter => this.router.navigate(['/dashboard']))
);

@Effect()
addFilterSuccessReload$ = this.actions$.pipe(
ofType<actions.AddFilterSuccess>(FilterCollectionActionTypes.ADD_FILTER_SUCCESS),
map(action => action.payload),
map(filter => new actions.LoadFilterRequest())
combineLatest(this.store.select(fromProvider.getSelectedProviderId).pipe(skipWhile(id => !id))),
tap(([filter, provider]) => this.router.navigate(['/', 'metadata', 'provider', provider, 'filters']))
);

@Effect()
updateFilter$ = this.actions$.pipe(
ofType<actions.UpdateFilterRequest>(FilterCollectionActionTypes.UPDATE_FILTER_REQUEST),
map(action => action.payload),
switchMap(filter => {
combineLatest(this.store.select(fromProvider.getSelectedProviderId).pipe(skipWhile(id => !id))),
switchMap(([filter, providerId]) => {
delete filter.modifiedDate;
delete filter.createdDate;
return this.filterService
.update(filter)
.update(providerId, filter)
.pipe(
map(p => new actions.UpdateFilterSuccess({
id: p.id,
id: p.resourceId,
changes: p
})),
catchError(err => of(new actions.UpdateFilterFail(filter)))
Expand All @@ -100,13 +100,8 @@ export class FilterCollectionEffects {
updateFilterSuccessRedirect$ = this.actions$.pipe(
ofType<actions.UpdateFilterSuccess>(FilterCollectionActionTypes.UPDATE_FILTER_SUCCESS),
map(action => action.payload),
tap(filter => this.router.navigate(['/dashboard']))
);
@Effect()
updateFilterSuccessReload$ = this.actions$.pipe(
ofType<actions.UpdateFilterSuccess>(FilterCollectionActionTypes.UPDATE_FILTER_SUCCESS),
map(action => action.payload),
map(filter => new actions.LoadFilterRequest())
combineLatest(this.store.select(fromProvider.getSelectedProviderId).pipe(skipWhile(id => !id))),
tap(([filter, provider]) => this.router.navigate(['/', 'metadata', 'provider', provider, 'filters']))
);

constructor(
Expand Down
3 changes: 2 additions & 1 deletion ui/src/app/metadata/filter/effect/filter.effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,19 @@ export class FilterEffects {
)
);

/*
@Effect({ dispatch: false })
saveFilterSuccess$ = this.actions$.pipe(
ofType<AddFilterSuccess>(FilterCollectionActionTypes.ADD_FILTER_SUCCESS),
switchMap(() => this.router.navigate(['/dashboard']))
);

@Effect()
cancelChanges$ = this.actions$.pipe(
ofType<CancelCreateFilter>(FilterActionTypes.CANCEL_CREATE_FILTER),
map(() => new LoadFilterRequest()),
tap(() => this.router.navigate(['/dashboard']))
);
*/

constructor(
private store: Store<fromRoot.State>,
Expand Down
25 changes: 2 additions & 23 deletions ui/src/app/metadata/filter/filter.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,7 @@ import { SearchIdEffects } from './effect/search.effect';
import { FilterExistsGuard } from './guard/filter-exists.guard';
import { DomainModule } from '../domain/domain.module';
import { ModuleWithProviders } from '@angular/compiler/src/core';


export const routes: Routes = [
{
path: 'new',
component: NewFilterComponent,
canActivate: []
},
{
path: ':id',
component: FilterComponent,
canActivate: [FilterExistsGuard],
children: [
{
path: 'edit',
component: EditFilterComponent,
canDeactivate: []
}
]
}
];
import { FilterCollectionEffects } from './effect/collection.effect';

@NgModule({
declarations: [
Expand Down Expand Up @@ -77,9 +57,8 @@ export class FilterModule {
@NgModule({
imports: [
FilterModule,
RouterModule.forChild(routes),
StoreModule.forFeature('filter', reducers),
EffectsModule.forFeature([FilterEffects, SearchIdEffects]),
EffectsModule.forFeature([FilterEffects, SearchIdEffects, FilterCollectionEffects]),
],
})
export class RootFilterModule { }
Loading

0 comments on commit 67ab1bc

Please sign in to comment.