Skip to content

Commit

Permalink
SHIBUI-914 Implemented localstorage drafts
Browse files Browse the repository at this point in the history
  • Loading branch information
rmathis committed Oct 12, 2018
1 parent 2c95d4d commit 95e93e5
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class DashboardResolversListComponent implements OnInit {

edit(entity: MetadataEntity): void {
if (entity.isDraft()) {
this.router.navigate(['metadata', 'resolver', 'new', 'blank'], {
this.router.navigate(['metadata', 'resolver', 'new'], {
queryParams: {
entityId: entity.getId()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@ export class ResolverWizardStepComponent implements OnDestroy {
this.model$ = this.schema$.pipe(
withLatestFrom(
this.store.select(fromWizard.getModel),
this.store.select(fromResolver.getSelectedDraft),
this.changes$,
this.definition$
),
map(([schema, model, changes, definition]) => ({
map(([schema, model, selected, changes, definition]) => ({
model: {
...model,
...selected,
...changes
},
definition
Expand All @@ -70,7 +72,7 @@ export class ResolverWizardStepComponent implements OnDestroy {
skipWhile(([ changes, definition ]) => !definition || !changes),
map(([ changes, definition ]) => definition.parser(changes.value)),
withLatestFrom(this.store.select(fromResolver.getSelectedDraft)),
map(([changes, original]) => ({ ...changes }))
map(([changes, original]) => ({ ...original, ...changes }))
)
.subscribe(changes => {
this.store.dispatch(new UpdateChanges(changes));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@
<hr />
<div class="py-4">
<router-outlet></router-outlet>
</div>
<pre>{{ changes$ | async | json }}</pre>
<pre>{{ schema$ | async | json }}</pre>
</div>
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 } from 'rxjs';
import { skipWhile, startWith } from 'rxjs/operators';
import { skipWhile, startWith, distinctUntilChanged, map, defaultIfEmpty } from 'rxjs/operators';
import { Store } from '@ngrx/store';

import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
Expand Down Expand Up @@ -93,13 +93,14 @@ export class ResolverWizardComponent implements OnDestroy, CanComponentDeactivat
this.changes$ = this.store.select(fromResolver.getEntityChanges);
this.schema$ = this.store.select(fromWizard.getSchema);

this.route.queryParams.subscribe(params => {
if (params.index) {
this.store.dispatch(new SetIndex(params.index));
} else {
this.store.dispatch(new SetIndex(this.sourceWizard.steps[0].id));
}
});
this.route.params
.pipe(
map(params => params.index),
distinctUntilChanged()
)
.subscribe(index => {
this.store.dispatch(new SetIndex(index));
});
}

next(): void {
Expand All @@ -116,7 +117,16 @@ export class ResolverWizardComponent implements OnDestroy, CanComponentDeactivat
}

go(index: string): void {
this.store.dispatch(new SetIndex(index));
this.router.navigate(
[
'../',
index
],
{
relativeTo: this.route,
queryParamsHandling: 'preserve'
}
);
}

ngOnDestroy(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export class DraftCollectionEffects {
ofType<actions.UpdateDraftRequest>(DraftActionTypes.UPDATE_DRAFT_REQUEST),
map(getPayload),
switchMap(provider => {
console.log(provider);
return this.draftService
.update(provider)
.pipe(
Expand Down
35 changes: 13 additions & 22 deletions ui/src/app/metadata/resolver/effect/wizard.effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@ import * as fromResolver from '../reducer';

import { EntityDraftService } from '../../domain/service/draft.service';
import { SetIndex, WizardActionTypes } from '../../../wizard/action/wizard.action';
import { UpdateDraftRequest } from '../action/draft.action';



@Injectable()
export class WizardEffects {

@Effect({ dispatch: false })
@Effect()
updateResolver$ = this.actions$.pipe(
ofType<UpdateChanges>(ResolverEntityActionTypes.UPDATE_CHANGES),
map(action => action.payload),
switchMap(provider => this.draftService.update(provider))
map(provider => new UpdateDraftRequest(provider))
);

@Effect()
Expand All @@ -38,32 +39,22 @@ export class WizardEffects {
map(provider => new Clear())
);

@Effect({ dispatch: false })
updateIndexInUrl$ = this.actions$.pipe(
ofType<SetIndex>(WizardActionTypes.SET_INDEX),
map(action => action.payload),
tap(index => {
const params = { ...this.activatedRoute.snapshot.queryParams, index };
this.router.navigate([], {
relativeTo: this.activatedRoute,
queryParams: params,
queryParamsHandling: 'preserve'
});
})
);

@Effect({ dispatch: false })
updateEntityIdInUrl$ = this.actions$.pipe(
ofType<UpdateChanges>(ResolverEntityActionTypes.UPDATE_CHANGES),
map(action => action.payload),
withLatestFrom(this.store.select(fromResolver.getEntityChanges)),
map(([id, changes]) => changes.entityId ),
tap(entityId => {
const params = { ...this.activatedRoute.snapshot.queryParams, entityId };
withLatestFrom(
this.store.select(fromResolver.getEntityChanges),
this.activatedRoute.queryParams
),
tap(([id, changes, params]) => {
this.router.navigate([], {
relativeTo: this.activatedRoute,
queryParams: params,
queryParamsHandling: 'preserve'
queryParams: {
...params,
entityId: changes.entityId
},
queryParamsHandling: 'merge'
});
})
);
Expand Down
4 changes: 2 additions & 2 deletions ui/src/app/metadata/resolver/resolver.routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ export const ResolverRoutes: Routes = [
path: 'new',
component: NewResolverComponent,
children: [
{ path: '', redirectTo: 'blank', pathMatch: 'prefix' },
{ path: '', redirectTo: 'blank/common', pathMatch: 'prefix' },
{
path: 'blank',
path: 'blank/:index',
component: ResolverWizardComponent,
canDeactivate: [],
children: [
Expand Down

0 comments on commit 95e93e5

Please sign in to comment.