Skip to content

Commit

Permalink
SHIBUI-985 Fixing issue with modal
Browse files Browse the repository at this point in the history
  • Loading branch information
rmathis committed Dec 3, 2018
1 parent 50f92c5 commit 2ec81aa
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ export class MetadataSourceBase implements Wizard<MetadataResolver> {
errors.push(error);
}
});
console.log(errors, form_current);
return errors;
},
'/entityId': (value, property, form) => {
Expand Down
4 changes: 4 additions & 0 deletions ui/src/app/metadata/domain/service/draft.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ export class EntityDraftService {
);
}

exists(id: string, attr: string = 'id'): boolean {
return this.storage.query().some(entity => entity[attr] === id);
}

save(provider: MetadataResolver): Observable<MetadataResolver> {
this.storage.add(provider);
return of(provider);
Expand Down
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', 'org-info'], {
this.router.navigate(['metadata', 'resolver', 'new', 'blank', 'common'], {
queryParams: {
id: entity.getId()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ <h3 translate="label.how-are-you-adding-the-metadata-information">How are you ad
class="btn btn-lg btn-block btn-secondary"
aria-label="Upload local metadata file or use a metadata URL"
role="button"
routerLink="upload"
[routerLink]="['./', 'upload']"
queryParamsHandling="merge"
routerLinkActive="btn-success">
<translate-i18n key="label.upload-url">Upload/URL</translate-i18n>
<i class="fa fa-link fa-2x d-block"></i>
Expand All @@ -33,7 +34,8 @@ <h3 translate="label.how-are-you-adding-the-metadata-information">How are you ad
class="btn btn-lg btn-block btn-secondary"
aria-label="Create metadata source using the wizard"
role="button"
[routerLink]="['./']"
[routerLink]="['./', 'blank', 'common']"
queryParamsHandling="merge"
routerLinkActive="btn-info">
<translate-i18n key="action.create">Create</translate-i18n>
<i class="fa fa-plus-square fa-2x d-block"></i>
Expand All @@ -47,7 +49,8 @@ <h3 translate="label.how-are-you-adding-the-metadata-information">How are you ad
class="btn btn-lg btn-block btn-secondary"
aria-label="Copy a metadata source"
role="button"
routerLink="copy"
[routerLink]="['./', 'copy']"
queryParamsHandling="merge"
routerLinkActive="btn-warning">
<translate-i18n key="action.copy">Copy</translate-i18n>
<i class="fa fa-copy fa-2x d-block"></i>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class NewResolverComponent {
debounceTime(10),
map(url => {
let child = this.route.snapshot.firstChild;
return child.routeConfig.path.match('blank').length === 0 || child.params.index === 'common';
return !child.routeConfig.path.match('blank') || child.params.index === 'common';
})
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,10 @@ export class ResolverWizardStepComponent implements OnDestroy {
this.valueChangeEmitted$.pipe(
withLatestFrom(this.definition$),
filter(([ changes, definition ]) => (!!definition && !!changes)),
map(([ changes, definition ]) => definition.parser(changes.value)),
withLatestFrom(this.store.select(fromResolver.getSelectedDraft)),
map(([changes, original]) => ({ ...original, ...changes }))
map(([ changes, definition ]) => definition.parser(changes.value))
)
.subscribe(changes => {
if (changes.id) {
this.store.dispatch(new UpdateChanges(changes));
}
this.store.dispatch(new UpdateChanges(changes));
});

this.statusChangeEmitted$.pipe(distinctUntilChanged()).subscribe(errors => this.updateStatus(errors));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import { Observable, Subject, of, combineLatest as combine } from 'rxjs';
import { skipWhile, startWith, distinctUntilChanged, map, takeUntil, combineLatest } from 'rxjs/operators';
import { Store } from '@ngrx/store';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';

import { MetadataResolver } from '../../domain/model/metadata-resolver';
import * as fromCollections from '../reducer';
Expand All @@ -26,8 +27,8 @@ import { SetDefinition, SetIndex, SetDisabled, ClearWizard } from '../../../wiza
import * as fromWizard from '../../../wizard/reducer';
import { LoadSchemaRequest } from '../../../wizard/action/wizard.action';
import { UnsavedEntityComponent } from '../../domain/component/unsaved-entity.dialog';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { Clear } from '../action/entity.action';
import { DifferentialService } from '../../../core/service/differential.service';

@Component({
selector: 'resolver-wizard-page',
Expand Down Expand Up @@ -66,6 +67,7 @@ export class ResolverWizardComponent implements OnDestroy, CanComponentDeactivat
private route: ActivatedRoute,
private router: Router,
private modalService: NgbModal,
private diffService: DifferentialService,
@Inject(METADATA_SOURCE_WIZARD) private sourceWizard: Wizard<MetadataResolver>
) {
this.store
Expand Down Expand Up @@ -113,6 +115,8 @@ 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 All @@ -128,6 +132,7 @@ export class ResolverWizardComponent implements OnDestroy, CanComponentDeactivat
);

this.changes$.pipe(takeUntil(this.ngUnsubscribe)).subscribe(c => this.changes = c);
this.resolver$.pipe(takeUntil(this.ngUnsubscribe)).subscribe(r => this.resolver = r);
}

next(): void {
Expand Down Expand Up @@ -160,6 +165,18 @@ export class ResolverWizardComponent implements OnDestroy, CanComponentDeactivat
this.store.dispatch(new SetIndex(page));
}

hasChanges(changes: MetadataResolver): boolean {
// const updated = this.diffService.updatedDiff(this.resolver, changes);
// const deleted = this.diffService.deletedDiff(this.resolver, changes);
let blacklist = ['id', 'resourceId'];
return Object.keys(changes).filter(key => !(blacklist.indexOf(key) > -1)).length > 0;
}

isNew(changes: MetadataResolver): boolean {
let blacklist = ['id', 'resourceId'];
return Object.keys(changes).filter(key => !(blacklist.indexOf(key) > -1)).length === 0;
}

ngOnDestroy(): void {
this.ngUnsubscribe.next();
this.ngUnsubscribe.complete();
Expand All @@ -171,18 +188,23 @@ export class ResolverWizardComponent implements OnDestroy, CanComponentDeactivat
currentState: RouterStateSnapshot,
nextState: RouterStateSnapshot
): Observable<boolean> {
if (nextState.url.match('blank') && !!nextState.root.queryParams.id) { return of(true); }
if (Object.keys(this.changes).length > 0) {
if (nextState.url.match('blank') && !!nextState.root.queryParams.id) {
return of(true);
}
if (this.hasChanges(this.changes)) {
let modal = this.modalService.open(UnsavedEntityComponent);
modal.componentInstance.message = 'resolver';
modal.result.then(
() => {
this.store.dispatch(new Clear());
this.router.navigate([nextState.url]);
this.router.navigateByUrl(nextState.url);
},
() => console.warn('denied')
);
}
if (this.isNew(this.latest)) {
return of(true);
}
return this.store.select(fromResolver.getEntityIsSaved);
}
}
5 changes: 4 additions & 1 deletion ui/src/app/metadata/resolver/effect/collection.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@ export class ResolverCollectionEffects {
addResolverSuccessRemoveDraft$ = this.actions$.pipe(
ofType<providerActions.AddResolverSuccess>(ResolverCollectionActionTypes.ADD_RESOLVER_SUCCESS),
map(action => action.payload),
map(provider => new draftActions.RemoveDraftRequest(provider))
map(provider => {
console.log(provider);
return new draftActions.RemoveDraftRequest(provider);
})
);

@Effect()
Expand Down
5 changes: 3 additions & 2 deletions ui/src/app/metadata/resolver/effect/wizard.effect.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable } from '@angular/core';
import { Effect, Actions, ofType } from '@ngrx/effects';
import { ActivatedRoute, Router } from '@angular/router';
import { map, filter, tap } from 'rxjs/operators';
import { map, filter, tap, withLatestFrom } from 'rxjs/operators';
import { Store } from '@ngrx/store';

import {
Expand Down Expand Up @@ -29,7 +29,8 @@ export class WizardEffects {
ofType<UpdateChanges>(ResolverEntityActionTypes.UPDATE_CHANGES),
map(action => action.payload),
filter(provider => !provider.createdDate),
map(provider => new UpdateDraftRequest(provider))
withLatestFrom(this.store.select(fromResolver.getSelectedDraft)),
map(([provider, draft]) => new UpdateDraftRequest({ ...draft, ...provider }))
);

@Effect()
Expand Down
19 changes: 14 additions & 5 deletions ui/src/app/metadata/resolver/service/create-draft.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,28 @@ import { Store } from '@ngrx/store';
import { MetadataResolver } from '../../domain/model';
import { AddDraftRequest } from '../action/draft.action';
import * as fromResolver from '../reducer';
import { EntityDraftService } from '../../domain/service/draft.service';

@Injectable()
export class CreateDraftResolverService {
constructor(
private store: Store<fromResolver.State>
private store: Store<fromResolver.State>,
private draftService: EntityDraftService
) { }

resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<string> | Observable<never> {
let id = route.paramMap.get('id');
let resolver = <MetadataResolver>{
id: `r-${Date.now()}`
};
let id = route.queryParamMap.get('id');
if (id) {
let exists = this.draftService.exists(id);
if (!exists) {
let resolver = <MetadataResolver>{id};
this.store.dispatch(new AddDraftRequest(resolver));
}
}
if (!id) {
let resolver = <MetadataResolver>{
id: `r-${Date.now()}`
};
id = resolver.id;
this.store.dispatch(new AddDraftRequest(resolver));
}
Expand Down

0 comments on commit 2ec81aa

Please sign in to comment.