Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jj! committed May 2, 2018
2 parents 5ac7c14 + b27378d commit 615b43a
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 56 deletions.
2 changes: 1 addition & 1 deletion ui/src/app/dashboard/container/dashboard.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<li *ngFor="let entity of limited$ | async; index as i" [ngClass]="{'mt-2': i > 0}" aria-label="Provider Item Accordion. Press Spacebar to open">
<entity-item
[entity]="entity"
[isOpen]="(entitiesOpen$ | async)[entity.entityId]"
[isOpen]="(entitiesOpen$ | async)[entity.id || entity.entityId]"
(select)="edit(entity)"
(toggle)="toggleProvider(entity)"
(preview)="openPreviewDialog(entity)"
Expand Down
3 changes: 2 additions & 1 deletion ui/src/app/dashboard/container/dashboard.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ export class DashboardComponent implements OnInit {
}

toggleProvider(entity: MetadataEntity): void {
this.store.dispatch(new ToggleEntityDisplay(entity.entityId));
let id = entity.id ? entity.id : entity.entityId;
this.store.dispatch(new ToggleEntityDisplay(id));
}

openPreviewDialog(entity: MetadataEntity): void {
Expand Down
8 changes: 0 additions & 8 deletions ui/src/app/metadata-filter/action/filter.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { MDUI } from '../../domain/model/mdui';

export const SELECT_ID = '[Filter] Select Entity ID';

export const CREATE_FILTER = '[Filter] Create Filter';
export const UPDATE_FILTER = '[Filter] Update Filter';
export const CANCEL_CREATE_FILTER = '[Filter] Cancel Create Filter';

Expand Down Expand Up @@ -36,12 +35,6 @@ export class LoadEntityPreviewError implements Action {
constructor(public payload: string) { }
}

export class CreateFilter implements Action {
readonly type = CREATE_FILTER;

constructor(public payload: MetadataFilter) { }
}

export class CancelCreateFilter implements Action {
readonly type = CANCEL_CREATE_FILTER;
}
Expand All @@ -54,7 +47,6 @@ export class UpdateFilterChanges implements Action {

export type Actions =
| SelectId
| CreateFilter
| UpdateFilterChanges
| CancelCreateFilter
| LoadEntityPreview
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
<ng-container i18n="@@action--save-changes">Preview XML</ng-container>
</button>
<button
(click)="this.save()"
(click)="this.save($event)"
type="submit"
class="btn btn-primary"
[disabled]="form.invalid || (isSaving$ | async)">
Expand Down
57 changes: 33 additions & 24 deletions ui/src/app/metadata-filter/container/edit-filter.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import * as fromFilter from '../reducer';
import * as fromCollection from '../../domain/reducer';
import { ProviderStatusEmitter, ProviderValueEmitter } from '../../domain/service/provider-change-emitter.service';
import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
import { CancelCreateFilter, SelectId, CreateFilter, UpdateFilterChanges } from '../action/filter.action';
import { CancelCreateFilter, SelectId, UpdateFilterChanges } from '../action/filter.action';
import { AddFilterRequest, UpdateFilterRequest } from '../../domain/action/filter-collection.action';
import { MetadataFilter } from '../../domain/model/metadata-filter';
import { Filter } from '../../domain/entity/filter';
Expand Down Expand Up @@ -50,7 +50,10 @@ export class EditFilterComponent implements OnInit, OnDestroy {
isSaving$: Observable<boolean>;

form: FormGroup = this.fb.group({
entityId: ['', [Validators.required]],
entityId: [
'',
[Validators.required]
],
filterName: ['', [Validators.required]],
filterEnabled: [false]
});
Expand Down Expand Up @@ -81,23 +84,23 @@ export class EditFilterComponent implements OnInit, OnDestroy {

this.entityIds$.subscribe(ids => this.ids = ids);

this.filter$.subscribe(filter => {
let { entityId, filterName, filterEnabled } = new Filter(filter);
this.form.reset({
entityId,
filterName,
filterEnabled
});
this.filter = filter;
this.filterEntity = new Filter(filter);
this.filter$
.withLatestFrom(this.isSaving$)
.subscribe(([filter, saving]) => {
let { entityId, filterName, filterEnabled } = new Filter(filter);
this.form.reset({
entityId,
filterName,
filterEnabled
});
this.filter = filter;
this.filterEntity = new Filter(filter);

this.store.dispatch(new SelectId(entityId));
});
this.store.dispatch(new SelectId(entityId));
});
}

ngOnInit(): void {
this.store.dispatch(new ClearSearch());

let id = this.form.get('entityId');
id.valueChanges
.distinctUntilChanged()
Expand All @@ -116,14 +119,19 @@ export class EditFilterComponent implements OnInit, OnDestroy {

this.form.get('entityId').disable();

id
.valueChanges
.distinctUntilChanged()
.subscribe(entityId => {
if (id.valid) {
this.store.dispatch(new SelectId(entityId));
}
});
id.valueChanges
.distinctUntilChanged()
.subscribe(entityId => {
if (id.valid) {
this.store.dispatch(new SelectId(entityId));
}
});

this.selected$
.distinctUntilChanged()
.subscribe(entityId => {
id.setValue(entityId);
});
}

ngOnDestroy(): void {
Expand Down Expand Up @@ -163,7 +171,8 @@ export class EditFilterComponent implements OnInit, OnDestroy {
this.isValid = status === 'VALID';
}

save(): void {
save($event): void {
$event.preventDefault();
this.store.dispatch(new UpdateFilterRequest({...this.filter, ...this.changes.serialize()}));
}

Expand Down
23 changes: 10 additions & 13 deletions ui/src/app/metadata-filter/container/new-filter.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import 'rxjs/add/observable/fromPromise';
import * as fromFilter from '../reducer';
import { ProviderStatusEmitter, ProviderValueEmitter } from '../../domain/service/provider-change-emitter.service';
import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
import { CancelCreateFilter, SelectId, CreateFilter, UpdateFilterChanges } from '../action/filter.action';
import { CancelCreateFilter, SelectId, UpdateFilterChanges } from '../action/filter.action';
import { AddFilterRequest } from '../../domain/action/filter-collection.action';
import { MetadataFilter } from '../../domain/model/metadata-filter';
import { Filter } from '../../domain/entity/filter';
Expand Down Expand Up @@ -71,6 +71,7 @@ export class NewFilterComponent implements OnInit, OnDestroy {
private valueEmitter: ProviderValueEmitter,
private fb: FormBuilder
) {
this.store.dispatch(new ClearSearch());
this.changes$ = this.store.select(fromFilter.getFilter);
this.changes$.subscribe(c => this.changes = new Filter(c));

Expand All @@ -86,8 +87,6 @@ export class NewFilterComponent implements OnInit, OnDestroy {
}

ngOnInit(): void {
this.store.dispatch(new ClearSearch());

let id = this.form.get('entityId');
id.valueChanges
.distinctUntilChanged()
Expand All @@ -104,21 +103,19 @@ export class NewFilterComponent implements OnInit, OnDestroy {
.startWith(this.form.value)
.subscribe(changes => this.store.dispatch(new UpdateFilterChanges(changes)));

/*this.statusEmitSubscription = this.form
.statusChanges
.takeUntil(this.ngUnsubscribe)
.startWith(this.form.status)
.subscribe(status => this.onStatusChange.emit(status));*/


id
.valueChanges
id.valueChanges
.distinctUntilChanged()
.subscribe(entityId => {
if (id.valid) {
this.store.dispatch(new SelectId(entityId));
}
});
this.selected$
.distinctUntilChanged()
.subscribe(entityId => {
console.log(entityId);
id.setValue(entityId);
});
}

ngOnDestroy(): void {
Expand All @@ -127,7 +124,7 @@ export class NewFilterComponent implements OnInit, OnDestroy {
}

searchEntityIds(term: string): void {
if (term.length >= 4 && this.ids.indexOf(term) < 0) {
if (term && term.length >= 4 && this.ids.indexOf(term) < 0) {
this.store.dispatch(new QueryEntityIds({
term,
limit: 10
Expand Down
13 changes: 5 additions & 8 deletions ui/src/app/metadata-filter/reducer/filter.reducer.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { createSelector, createFeatureSelector } from '@ngrx/store';
import * as filter from '../action/filter.action';
import * as search from '../action/search.action';
import * as collection from '../../domain/action/filter-collection.action';
import { FilterCollectionActionTypes, FilterCollectionActionsUnion } from '../../domain/action/filter-collection.action';
import * as fromRoot from '../../core/reducer';
import { MetadataFilter, MDUI } from '../../domain/domain.type';
import { SearchAction } from '../../dashboard/action/search.action';

export interface FilterState {
selected: string | null;
Expand All @@ -19,7 +21,7 @@ export const initialState: FilterState = {
saving: false
};

export function reducer(state = initialState, action: filter.Actions | FilterCollectionActionsUnion): FilterState {
export function reducer(state = initialState, action: filter.Actions | search.Actions | FilterCollectionActionsUnion): FilterState {
switch (action.type) {
case filter.SELECT_ID: {
return {
Expand All @@ -33,12 +35,6 @@ export function reducer(state = initialState, action: filter.Actions | FilterCol
preview: action.payload
};
}
case filter.CREATE_FILTER: {
return {
...state,
changes: action.payload
};
}
case filter.UPDATE_FILTER: {
return {
...state,
Expand All @@ -51,12 +47,13 @@ export function reducer(state = initialState, action: filter.Actions | FilterCol
case FilterCollectionActionTypes.ADD_FILTER:
case FilterCollectionActionTypes.UPDATE_FILTER_REQUEST: {
return {
...initialState,
...state,
saving: true
};
}
case FilterCollectionActionTypes.ADD_FILTER_SUCCESS:
case FilterCollectionActionTypes.UPDATE_FILTER_SUCCESS:
case search.CLEAR_SEARCH:
case filter.CANCEL_CREATE_FILTER: {
return {
...initialState
Expand Down

0 comments on commit 615b43a

Please sign in to comment.