Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix the navigation #614

Draft
wants to merge 1 commit into
base: staging
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions projects/rero/ng-core/src/lib/record/editor/editor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import { Location } from '@angular/common';
import { Component, EventEmitter, Input, OnChanges, OnDestroy, OnInit, Output, SimpleChanges, ViewEncapsulation } from '@angular/core';
import { UntypedFormControl, UntypedFormGroup } from '@angular/forms';
import { ActivatedRoute } from '@angular/router';
import { ActivatedRoute, Router } from '@angular/router';
import { FormlyFieldConfig, FormlyFormOptions } from '@ngx-formly/core';
import { FormlyJsonschema } from '@ngx-formly/core/json-schema';
import { TranslateService } from '@ngx-translate/core';
Expand Down Expand Up @@ -138,6 +138,9 @@ export class EditorComponent extends AbstractCanDeactivateComponent implements O
// Observable of hidden fields
private _hiddenFieldsSubject: BehaviorSubject<FormlyFieldConfig[]> = new BehaviorSubject([]);

// Previous Url for navigation
private previousUrl?: string = undefined;

// current list of hidden fields
public get hiddenFields$(): Observable<any[]> {
return this._hiddenFieldsSubject.asObservable();
Expand Down Expand Up @@ -176,6 +179,7 @@ export class EditorComponent extends AbstractCanDeactivateComponent implements O
* @param modalService BsModalService.
* @param routeCollectionService RouteCollectionService
* @param loggerService LoggerService
* @param router Router
*/
constructor(
protected formlyJsonschema: FormlyJsonschema,
Expand All @@ -188,10 +192,12 @@ export class EditorComponent extends AbstractCanDeactivateComponent implements O
protected location: Location,
protected modalService: BsModalService,
protected routeCollectionService: RouteCollectionService,
protected loggerService: LoggerService
protected loggerService: LoggerService,
protected router: Router
) {
super();
this.form = new UntypedFormGroup({});
this.previousUrl = this.router.getCurrentNavigation()?.previousNavigation?.extractedUrl?.toString();
}

/**
Expand Down Expand Up @@ -576,13 +582,17 @@ export class EditorComponent extends AbstractCanDeactivateComponent implements O
this.translateService.instant(result.message),
this.translateService.instant(this.recordType)
);
this.recordUiService.redirectAfterSave(
result.record.id,
result.record,
this.recordType,
result.action,
this.route
);
if (this.previousUrl) {
this.router.navigateByUrl(this.previousUrl, { replaceUrl: true });
} else {
this.recordUiService.redirectAfterSave(
result.record.id,
result.record,
this.recordType,
result.action,
this.route
);
}
this.loadingChange.emit(true);
});
}
Expand Down