Skip to content

Commit

Permalink
Merged in bugfix/remove-modal (pull request #309)
Browse files Browse the repository at this point in the history
SHIBUI Fixed modal issue #21
  • Loading branch information
rmathis committed Feb 28, 2019
2 parents df22bf9 + 0b8b92b commit 6c05a36
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, OnDestroy } from '@angular/core';
import { Router, ActivatedRoute, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Observable, of } from 'rxjs';
import { skipWhile, map, combineLatest, filter } from 'rxjs/operators';
import { Observable, of, Subject } from 'rxjs';
import { skipWhile, map, combineLatest, filter, takeUntil } from 'rxjs/operators';
import { Store } from '@ngrx/store';
import * as fromWizard from '../../../wizard/reducer';
import * as fromProvider from '../reducer';
Expand All @@ -25,6 +25,7 @@ import { FilterableProviders } from '../model';
})

export class ProviderEditComponent implements OnDestroy, CanComponentDeactivate {
private ngUnsubscribe: Subject<void> = new Subject<void>();

provider$: Observable<MetadataProvider>;
definition$: Observable<Wizard<MetadataProvider>>;
Expand Down Expand Up @@ -59,7 +60,7 @@ export class ProviderEditComponent implements OnDestroy, CanComponentDeactivate
let startIndex$ = this.route.firstChild.params.pipe(map(p => p.form || 'filters'));
startIndex$.subscribe(index => this.store.dispatch(new SetIndex(index)));

this.index$.subscribe(id => id && this.go(id));
this.index$.pipe(takeUntil(this.ngUnsubscribe)).subscribe(id => id && this.go(id));

this.store
.select(fromWizard.getCurrentWizardSchema)
Expand All @@ -82,6 +83,8 @@ export class ProviderEditComponent implements OnDestroy, CanComponentDeactivate

ngOnDestroy() {
this.clear();
this.ngUnsubscribe.next();
this.ngUnsubscribe.complete();
}

clear(): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, OnDestroy } from '@angular/core';
import { Observable, Subject } from 'rxjs';
import { withLatestFrom, map, distinctUntilChanged, skipWhile, filter } from 'rxjs/operators';
import { withLatestFrom, map, distinctUntilChanged, skipWhile, filter, takeUntil } from 'rxjs/operators';
import { Store } from '@ngrx/store';

import * as fromProvider from '../reducer';
Expand All @@ -21,6 +21,8 @@ import { pick } from '../../../shared/util';
})

export class ProviderWizardStepComponent implements OnDestroy {
private ngUnsubscribe: Subject<void> = new Subject<void>();

valueChangeSubject = new Subject<Partial<any>>();
private valueChangeEmitted$ = this.valueChangeSubject.asObservable();

Expand Down Expand Up @@ -79,16 +81,20 @@ export class ProviderWizardStepComponent implements OnDestroy {
);

this.valueChangeEmitted$.pipe(
takeUntil(this.ngUnsubscribe),
withLatestFrom(this.schema$, this.definition$),
map(([changes, schema, definition]) => this.resetSelectedType(changes, schema, definition)),
skipWhile(({ changes, definition }) => !definition || !changes),
map(({ changes, definition }) => definition.parser(changes))
)
.subscribe(changes => this.store.dispatch(new UpdateProvider(changes)));

this.statusChangeEmitted$.pipe(distinctUntilChanged()).subscribe(errors => this.updateStatus(errors));
this.statusChangeEmitted$.pipe(
takeUntil(this.ngUnsubscribe),
distinctUntilChanged())
.subscribe(errors => this.updateStatus(errors));

this.store.select(fromWizard.getWizardIndex).subscribe(i => this.currentPage = i);
this.store.select(fromWizard.getWizardIndex).pipe(takeUntil(this.ngUnsubscribe)).subscribe(i => this.currentPage = i);
}

resetSelectedType(changes: any, schema: any, definition: any): { changes: any, definition: any } {
Expand Down Expand Up @@ -117,6 +123,8 @@ export class ProviderWizardStepComponent implements OnDestroy {

ngOnDestroy() {
this.valueChangeSubject.complete();
this.ngUnsubscribe.next();
this.ngUnsubscribe.complete();
}
}

Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Component, OnDestroy } from '@angular/core';
import { Observable, combineLatest } from 'rxjs';
import { Observable, combineLatest, Subject } from 'rxjs';
import { Store } from '@ngrx/store';

import * as fromProvider from '../reducer';
import * as fromWizard from '../../../wizard/reducer';
import { SetIndex, SetDisabled, ClearWizard, SetDefinition } from '../../../wizard/action/wizard.action';
import { ClearEditor } from '../action/editor.action';
import { LoadSchemaRequest } from '../../../wizard/action/wizard.action';
import { startWith } from 'rxjs/operators';
import { startWith, takeUntil } from 'rxjs/operators';
import { Wizard, WizardStep } from '../../../wizard/model';
import { MetadataProvider } from '../../domain/model';
import { ClearProvider } from '../action/entity.action';
Expand All @@ -22,6 +22,8 @@ import { MetadataProviderWizard } from '../model';
})

export class ProviderWizardComponent implements OnDestroy {
private ngUnsubscribe: Subject<void> = new Subject<void>();

definition$: Observable<Wizard<MetadataProvider>>;
changes$: Observable<MetadataProvider>;
model$: Observable<any>;
Expand All @@ -40,6 +42,7 @@ export class ProviderWizardComponent implements OnDestroy {
) {
this.store
.select(fromWizard.getCurrentWizardSchema)
.pipe(takeUntil(this.ngUnsubscribe))
.subscribe(s => {
if (s) {
this.store.dispatch(new LoadSchemaRequest(s));
Expand All @@ -53,7 +56,7 @@ export class ProviderWizardComponent implements OnDestroy {
this.store.select(fromWizard.getWizardIndex).subscribe(i => this.currentPage = i);

this.valid$
.pipe(startWith(false))
.pipe(startWith(false), takeUntil(this.ngUnsubscribe))
.subscribe((valid) => {
this.store.dispatch(new SetDisabled(!valid));
});
Expand All @@ -66,7 +69,7 @@ export class ProviderWizardComponent implements OnDestroy {
map(([ definition, schema, model ]) => ({ definition, schema, model }))
);

this.changes$.subscribe(c => this.provider = c);
this.changes$.pipe(takeUntil(this.ngUnsubscribe)).subscribe(c => this.provider = c);

this.store.dispatch(new SetDefinition(MetadataProviderWizard));
this.store.dispatch(new SetIndex(MetadataProviderWizard.steps[0].id));
Expand All @@ -76,6 +79,9 @@ export class ProviderWizardComponent implements OnDestroy {
this.store.dispatch(new ClearProvider());
this.store.dispatch(new ClearWizard());
this.store.dispatch(new ClearEditor());

this.ngUnsubscribe.next();
this.ngUnsubscribe.complete();
}

next(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<div class="custom-control custom-checkbox custom-control-inline custom-control-reverse">
<input class="custom-control-input" type="checkbox" id="serviceEnabled" formControlName="serviceEnabled">
<label class="custom-control-label"
translate="label.enable-this-service-opon-saving"
for="serviceEnabled">Enable this service upon saving?</label>
translate="label.enable-this-service"
for="serviceEnabled">Enable this service?</label>
</div>
<info-icon [description]="'tooltip.enable-this-service-upon-saving' | translate"></info-icon>
</div>
Expand Down
19 changes: 14 additions & 5 deletions ui/src/app/metadata/resolver/container/new-resolver.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component } from '@angular/core';
import { Component, OnDestroy } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { Observable, Subscription } from 'rxjs';
import { map, startWith, distinctUntilChanged, debounceTime } from 'rxjs/operators';
import { Observable, Subscription, Subject } from 'rxjs';
import { map, startWith, distinctUntilChanged, debounceTime, withLatestFrom, takeUntil } from 'rxjs/operators';
import { SelectDraftRequest } from '../action/draft.action';
import { Store } from '@ngrx/store';
import * as fromCollection from '../reducer';
Expand All @@ -11,7 +11,9 @@ import * as fromCollection from '../reducer';
templateUrl: './new-resolver.component.html',
styleUrls: ['./new-resolver.component.scss']
})
export class NewResolverComponent {
export class NewResolverComponent implements OnDestroy {

private ngUnsubscribe: Subject<void> = new Subject<void>();

actionsSubscription: Subscription;

Expand All @@ -32,8 +34,15 @@ export class NewResolverComponent {
);

this.actionsSubscription = this.route.data.pipe(
takeUntil(this.ngUnsubscribe),
distinctUntilChanged(),
map(data => new SelectDraftRequest(data.draft))
map(data => {
return new SelectDraftRequest(data.draft);
})
).subscribe(this.store);
}
ngOnDestroy(): void {
this.ngUnsubscribe.next();
this.ngUnsubscribe.complete();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, OnDestroy } from '@angular/core';
import { Router, ActivatedRoute, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Observable, of } from 'rxjs';
import { skipWhile, map, combineLatest, filter } from 'rxjs/operators';
import { Observable, of, Subject } from 'rxjs';
import { skipWhile, map, combineLatest, filter, takeUntil } from 'rxjs/operators';
import { Store } from '@ngrx/store';
import * as fromWizard from '../../../wizard/reducer';
import * as fromResolver from '../reducer';
Expand All @@ -23,7 +23,7 @@ import { UnsavedEntityComponent } from '../../domain/component/unsaved-entity.di
})

export class ResolverEditComponent implements OnDestroy, CanComponentDeactivate {

private ngUnsubscribe: Subject<void> = new Subject<void>();
resolver$: Observable<MetadataResolver>;
definition$: Observable<Wizard<MetadataResolver>>;
index$: Observable<string>;
Expand Down Expand Up @@ -54,9 +54,9 @@ export class ResolverEditComponent implements OnDestroy, CanComponentDeactivate
this.isSaving$ = this.store.select(fromResolver.getEntityIsSaving);

let startIndex$ = this.route.firstChild.params.pipe(map(p => p.form));
startIndex$.subscribe(index => this.store.dispatch(new SetIndex(index)));
startIndex$.pipe(takeUntil(this.ngUnsubscribe)).subscribe(index => this.store.dispatch(new SetIndex(index)));

this.index$.subscribe(index => index && this.go(index));
this.index$.pipe(takeUntil(this.ngUnsubscribe)).subscribe(index => index && this.go(index));

this.store
.select(fromWizard.getCurrentWizardSchema)
Expand All @@ -73,6 +73,8 @@ export class ResolverEditComponent implements OnDestroy, CanComponentDeactivate

ngOnDestroy() {
this.clear();
this.ngUnsubscribe.next();
this.ngUnsubscribe.complete();
}

clear(): void {
Expand Down
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, combineLatest as combine } from 'rxjs';
import { skipWhile, startWith, distinctUntilChanged, map, takeUntil, combineLatest } from 'rxjs/operators';
import { skipWhile, startWith, distinctUntilChanged, map, takeUntil, combineLatest, withLatestFrom } from 'rxjs/operators';
import { Store } from '@ngrx/store';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';

Expand Down Expand Up @@ -80,7 +80,6 @@ export class ResolverWizardComponent implements OnDestroy, CanComponentDeactivat
this.store.dispatch(new LoadSchemaRequest(s));
}
});

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

this.valid$
Expand All @@ -102,6 +101,7 @@ export class ResolverWizardComponent implements OnDestroy, CanComponentDeactivat

this.route.params
.pipe(
takeUntil(this.ngUnsubscribe),
map(params => params.index),
distinctUntilChanged()
)
Expand All @@ -115,8 +115,6 @@ export class ResolverWizardComponent implements OnDestroy, CanComponentDeactivat
combineLatest(this.resolver$, (changes, base) => ({ ...base, ...changes }))
).subscribe(latest => this.latest = latest);

// this.changes$.subscribe(c => console.log(c));

this.summary$ = combine(
this.store.select(fromWizard.getWizardDefinition),
this.store.select(fromWizard.getSchemaCollection),
Expand Down
13 changes: 0 additions & 13 deletions ui/src/app/metadata/resolver/effect/collection.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,6 @@ export class ResolverCollectionEffects {
tap(provider => this.router.navigate(['dashboard']))
);

@Effect()
updateResolverSuccessReload$ = this.actions$.pipe(
ofType<UpdateResolverSuccess>(ResolverCollectionActionTypes.UPDATE_RESOLVER_SUCCESS),
map(action => action.payload),
map(provider => new LoadResolverRequest())
);

@Effect()
updateResolverFailNotification$ = this.actions$.pipe(
ofType<UpdateResolverFail>(ResolverCollectionActionTypes.UPDATE_RESOLVER_FAIL),
Expand Down Expand Up @@ -147,12 +140,6 @@ export class ResolverCollectionEffects {
map(action => action.payload),
tap(provider => this.router.navigate(['dashboard']))
);
@Effect()
addResolverSuccessReload$ = this.actions$.pipe(
ofType<AddResolverSuccess>(ResolverCollectionActionTypes.ADD_RESOLVER_SUCCESS),
map(action => action.payload),
map(provider => new LoadResolverRequest())
);

@Effect()
addResolverSuccessRemoveDraft$ = this.actions$.pipe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class DraftCollectionEffects {
removeDraft$ = this.actions$.pipe(
ofType<actions.RemoveDraftRequest>(DraftActionTypes.REMOVE_DRAFT),
map(getPayload),
switchMap(provider => this.draftService.find(provider.entityId, 'entityId').pipe(
switchMap(provider => this.draftService.find(provider.id, 'id').pipe(
switchMap(selected => this.draftService.remove(selected)),
map(p => new actions.RemoveDraftSuccess(p))
)
Expand Down
2 changes: 0 additions & 2 deletions ui/src/app/metadata/resolver/effect/wizard.effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import * as fromResolver from '../reducer';
import { EntityDraftService } from '../../domain/service/draft.service';
import { UpdateDraftRequest, SelectDraftSuccess, DraftActionTypes } from '../action/draft.action';



@Injectable()
export class WizardEffects {

Expand Down

0 comments on commit 6c05a36

Please sign in to comment.