diff --git a/ui/src/app/metadata/provider/container/provider-edit.component.ts b/ui/src/app/metadata/provider/container/provider-edit.component.ts index 19e101e75..a0a3ad0ea 100644 --- a/ui/src/app/metadata/provider/container/provider-edit.component.ts +++ b/ui/src/app/metadata/provider/container/provider-edit.component.ts @@ -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'; @@ -25,6 +25,7 @@ import { FilterableProviders } from '../model'; }) export class ProviderEditComponent implements OnDestroy, CanComponentDeactivate { + private ngUnsubscribe: Subject = new Subject(); provider$: Observable; definition$: Observable>; @@ -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) @@ -82,6 +83,8 @@ export class ProviderEditComponent implements OnDestroy, CanComponentDeactivate ngOnDestroy() { this.clear(); + this.ngUnsubscribe.next(); + this.ngUnsubscribe.complete(); } clear(): void { diff --git a/ui/src/app/metadata/provider/container/provider-wizard-step.component.ts b/ui/src/app/metadata/provider/container/provider-wizard-step.component.ts index a0b145078..a78f76db0 100644 --- a/ui/src/app/metadata/provider/container/provider-wizard-step.component.ts +++ b/ui/src/app/metadata/provider/container/provider-wizard-step.component.ts @@ -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'; @@ -21,6 +21,8 @@ import { pick } from '../../../shared/util'; }) export class ProviderWizardStepComponent implements OnDestroy { + private ngUnsubscribe: Subject = new Subject(); + valueChangeSubject = new Subject>(); private valueChangeEmitted$ = this.valueChangeSubject.asObservable(); @@ -79,6 +81,7 @@ 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), @@ -86,9 +89,12 @@ export class ProviderWizardStepComponent implements OnDestroy { ) .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 } { @@ -117,6 +123,8 @@ export class ProviderWizardStepComponent implements OnDestroy { ngOnDestroy() { this.valueChangeSubject.complete(); + this.ngUnsubscribe.next(); + this.ngUnsubscribe.complete(); } } diff --git a/ui/src/app/metadata/provider/container/provider-wizard.component.ts b/ui/src/app/metadata/provider/container/provider-wizard.component.ts index 24140a0a2..125966878 100644 --- a/ui/src/app/metadata/provider/container/provider-wizard.component.ts +++ b/ui/src/app/metadata/provider/container/provider-wizard.component.ts @@ -1,5 +1,5 @@ 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'; @@ -7,7 +7,7 @@ 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'; @@ -22,6 +22,8 @@ import { MetadataProviderWizard } from '../model'; }) export class ProviderWizardComponent implements OnDestroy { + private ngUnsubscribe: Subject = new Subject(); + definition$: Observable>; changes$: Observable; model$: Observable; @@ -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)); @@ -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)); }); @@ -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)); @@ -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 { diff --git a/ui/src/app/metadata/resolver/component/finish-form.component.html b/ui/src/app/metadata/resolver/component/finish-form.component.html index 397712d0f..881c68206 100644 --- a/ui/src/app/metadata/resolver/component/finish-form.component.html +++ b/ui/src/app/metadata/resolver/component/finish-form.component.html @@ -6,8 +6,8 @@
+ translate="label.enable-this-service" + for="serviceEnabled">Enable this service?
diff --git a/ui/src/app/metadata/resolver/container/new-resolver.component.ts b/ui/src/app/metadata/resolver/container/new-resolver.component.ts index fa51a426d..9d8f8b40b 100644 --- a/ui/src/app/metadata/resolver/container/new-resolver.component.ts +++ b/ui/src/app/metadata/resolver/container/new-resolver.component.ts @@ -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'; @@ -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 = new Subject(); actionsSubscription: Subscription; @@ -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(); + } } diff --git a/ui/src/app/metadata/resolver/container/resolver-edit.component.ts b/ui/src/app/metadata/resolver/container/resolver-edit.component.ts index 9b121c1b2..6161919f9 100644 --- a/ui/src/app/metadata/resolver/container/resolver-edit.component.ts +++ b/ui/src/app/metadata/resolver/container/resolver-edit.component.ts @@ -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'; @@ -23,7 +23,7 @@ import { UnsavedEntityComponent } from '../../domain/component/unsaved-entity.di }) export class ResolverEditComponent implements OnDestroy, CanComponentDeactivate { - + private ngUnsubscribe: Subject = new Subject(); resolver$: Observable; definition$: Observable>; index$: Observable; @@ -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) @@ -73,6 +73,8 @@ export class ResolverEditComponent implements OnDestroy, CanComponentDeactivate ngOnDestroy() { this.clear(); + this.ngUnsubscribe.next(); + this.ngUnsubscribe.complete(); } clear(): void { diff --git a/ui/src/app/metadata/resolver/container/resolver-wizard.component.ts b/ui/src/app/metadata/resolver/container/resolver-wizard.component.ts index c3c7881f1..c4c4f7192 100644 --- a/ui/src/app/metadata/resolver/container/resolver-wizard.component.ts +++ b/ui/src/app/metadata/resolver/container/resolver-wizard.component.ts @@ -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'; @@ -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$ @@ -102,6 +101,7 @@ export class ResolverWizardComponent implements OnDestroy, CanComponentDeactivat this.route.params .pipe( + takeUntil(this.ngUnsubscribe), map(params => params.index), distinctUntilChanged() ) @@ -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), diff --git a/ui/src/app/metadata/resolver/effect/collection.effects.ts b/ui/src/app/metadata/resolver/effect/collection.effects.ts index d101b0cbf..f3b4a4ac8 100644 --- a/ui/src/app/metadata/resolver/effect/collection.effects.ts +++ b/ui/src/app/metadata/resolver/effect/collection.effects.ts @@ -87,13 +87,6 @@ export class ResolverCollectionEffects { tap(provider => this.router.navigate(['dashboard'])) ); - @Effect() - updateResolverSuccessReload$ = this.actions$.pipe( - ofType(ResolverCollectionActionTypes.UPDATE_RESOLVER_SUCCESS), - map(action => action.payload), - map(provider => new LoadResolverRequest()) - ); - @Effect() updateResolverFailNotification$ = this.actions$.pipe( ofType(ResolverCollectionActionTypes.UPDATE_RESOLVER_FAIL), @@ -147,12 +140,6 @@ export class ResolverCollectionEffects { map(action => action.payload), tap(provider => this.router.navigate(['dashboard'])) ); - @Effect() - addResolverSuccessReload$ = this.actions$.pipe( - ofType(ResolverCollectionActionTypes.ADD_RESOLVER_SUCCESS), - map(action => action.payload), - map(provider => new LoadResolverRequest()) - ); @Effect() addResolverSuccessRemoveDraft$ = this.actions$.pipe( diff --git a/ui/src/app/metadata/resolver/effect/draft-collection.effects.ts b/ui/src/app/metadata/resolver/effect/draft-collection.effects.ts index ac94d2410..6db7c2ffe 100644 --- a/ui/src/app/metadata/resolver/effect/draft-collection.effects.ts +++ b/ui/src/app/metadata/resolver/effect/draft-collection.effects.ts @@ -104,7 +104,7 @@ export class DraftCollectionEffects { removeDraft$ = this.actions$.pipe( ofType(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)) ) diff --git a/ui/src/app/metadata/resolver/effect/wizard.effect.ts b/ui/src/app/metadata/resolver/effect/wizard.effect.ts index 1632fb441..e64362c32 100644 --- a/ui/src/app/metadata/resolver/effect/wizard.effect.ts +++ b/ui/src/app/metadata/resolver/effect/wizard.effect.ts @@ -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 {