Skip to content

Commit 6ee6330

Browse files
authored
Merge branch 'release/7.0.0-rev8' into NAE-2217
2 parents c79cdc6 + 68b9d8d commit 6ee6330

File tree

8 files changed

+122
-24
lines changed

8 files changed

+122
-24
lines changed

projects/netgrif-components-core/src/lib/navigation/dashboard/abstract-dashboard.component.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,14 +265,13 @@ export abstract class AbstractDashboardComponent {
265265
}
266266
const itemRoute = this._doubleDrawerNavigationService.getItemRoutingPath(menuItemCase);
267267
const nodePath = this.getFieldValue(menuItemCase, GroupNavigationConstants.ITEM_FIELD_ID_NODE_PATH);
268+
const menuItem = this._doubleDrawerNavigationService.resolveItemCaseToNavigationItem(menuItemCase);
269+
if (menuItem) {
270+
this._doubleDrawerNavigationService.currentNavigationItem = menuItem;
271+
}
268272
if (menuItemCase.immediateData.find(f => f.stringId === GroupNavigationConstants.ITEM_FIELD_ID_HAS_CHILDREN)?.value && nodePath) {
269-
this._doubleDrawerNavigationService.currentNavigationItem = undefined;
270273
this._pathService.activePath = nodePath;
271274
} else if (nodePath) {
272-
const menuItem = this._doubleDrawerNavigationService.resolveItemCaseToNavigationItem(menuItemCase);
273-
if (menuItem) {
274-
this._doubleDrawerNavigationService.currentNavigationItem = menuItem;
275-
}
276275
this._pathService.activePath = this._doubleDrawerNavigationService.extractParentPath(nodePath);
277276
}
278277
this._router.navigate([itemRoute]);

projects/netgrif-components-core/src/lib/navigation/group-navigation-component-resolver/group-navigation-component-resolver.service.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {LoggerService} from '../../logger/services/logger.service';
66
import {TestMockDependenciesModule} from '../../utility/tests/test-mock-dependencies.module';
77
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
88
import {HttpClientTestingModule} from '@angular/common/http/testing';
9+
import {PathService} from '../service/path.service';
910

1011
describe('GroupNavigationComponentResolverService', () => {
1112
let service: GroupNavigationComponentResolverService;
@@ -46,8 +47,9 @@ class TestPortalComponent {
4647
export class TestGroupNavigationComponentResolverService extends GroupNavigationComponentResolverService {
4748

4849
constructor(taskResourceService: TaskResourceService,
50+
pathService: PathService,
4951
log: LoggerService) {
50-
super(taskResourceService, log);
52+
super(taskResourceService, pathService, log);
5153
}
5254

5355
protected resolveViewComponent(navigationItemTaskData: any): Type<any> {

projects/netgrif-components-core/src/lib/navigation/group-navigation-component-resolver/group-navigation-component-resolver.service.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ import {TaskResourceService} from '../../resources/engine-endpoint/task-resource
66
import {LoggerService} from '../../logger/services/logger.service';
77
import {DataGroup} from '../../resources/interface/data-groups';
88
import {HttpErrorResponse} from '@angular/common/http';
9+
import { PathService } from '../service/path.service';
910

1011
export abstract class GroupNavigationComponentResolverService {
1112

1213
protected constructor(protected _taskResourceService: TaskResourceService,
14+
protected _pathService: PathService,
1315
protected _log: LoggerService) {
1416
}
1517

@@ -19,6 +21,9 @@ export abstract class GroupNavigationComponentResolverService {
1921
const result = new ReplaySubject<ComponentPortal<any>>(1);
2022
this._taskResourceService.getData(taskId).subscribe(taskData => {
2123
try {
24+
if (!this._pathService.isMenuResolverClosed) {
25+
this._pathService.datafieldsForMenuResolver = taskData;
26+
}
2227
result.next(new ComponentPortal(
2328
this.resolveViewComponent(taskData),
2429
null,
@@ -41,6 +46,9 @@ export abstract class GroupNavigationComponentResolverService {
4146
}
4247

4348
private forwardError(result: Subject<any>, error: Error): void {
49+
if (!this._pathService.isMenuResolverClosed) {
50+
this._pathService.datafieldsForMenuResolverError = error;
51+
}
4452
result.error(error instanceof HttpErrorResponse ? error.error.message : error.message);
4553
result.complete();
4654
}

projects/netgrif-components-core/src/lib/navigation/navigation-double-drawer/abstract-navigation-double-drawer.ts

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {TranslateService} from '@ngx-translate/core';
55
import {ResizeEvent} from 'angular-resizable-element';
66
import {Observable, Subscription} from 'rxjs';
77
import {filter, take} from 'rxjs/operators';
8-
import {AccessService} from '../../authorization/permission/access.service';
98
import {ConfigurationService} from '../../configuration/configuration.service';
109
import {ImpersonationUserSelectService} from '../../impersonation/services/impersonation-user-select.service';
1110
import {ImpersonationService} from '../../impersonation/services/impersonation.service';
@@ -32,6 +31,8 @@ import {
3231
} from '../model/navigation-menu-events';
3332
import {DoubleDrawerNavigationService} from "./service/double-drawer-navigation.service";
3433
import {GroupNavigationConstants} from "../model/group-navigation-constants";
34+
import {extractFieldValueFromData} from "../utility/navigation-item-task-utility-methods";
35+
import {LoadingEmitter} from "../../utility/loading-emitter";
3536

3637
@Component({
3738
selector: 'ncc-abstract-navigation-double-drawer',
@@ -72,6 +73,7 @@ export abstract class AbstractNavigationDoubleDrawerComponent implements OnInit,
7273
* Siblings of the node are on the left, children are on the right
7374
*/
7475
protected _currentPath: string;
76+
protected _pathResolverLoading$: LoadingEmitter;
7577

7678
protected _configLeftMenu: ConfigDoubleMenu = {
7779
mode: 'side',
@@ -113,6 +115,7 @@ export abstract class AbstractNavigationDoubleDrawerComponent implements OnInit,
113115
this._navigationService.itemLoaded$.subscribe((itemLoadedEvent: MenuItemLoadedEvent) => {
114116
this.itemLoaded.emit(itemLoadedEvent);
115117
})
118+
this._pathResolverLoading$ = new LoadingEmitter();
116119
}
117120

118121
public ngOnInit(): void {
@@ -125,10 +128,12 @@ export abstract class AbstractNavigationDoubleDrawerComponent implements OnInit,
125128
});
126129

127130
this._userService.user$.pipe(filter(u => !!u && u.id !== ''), take(1)).subscribe(() => {
131+
this.resolveInitialValueOfPath();
132+
128133
this._currentPathSubscription = this._pathService.activePath$.subscribe(path => {
129-
if (path !== this.currentPath) {
134+
if (path !== this.currentPath && !this._pathResolverLoading$.isActive) {
130135
this.currentPath = path;
131-
} else {
136+
} else if (!this._pathResolverLoading$.isActive) {
132137
this.openAvailableView();
133138
}
134139
});
@@ -151,8 +156,6 @@ export abstract class AbstractNavigationDoubleDrawerComponent implements OnInit,
151156
this.hideMoreMenu = !hiddenCustomItems?.length;
152157
})
153158
});
154-
155-
156159
}
157160

158161
public ngOnDestroy(): void {
@@ -223,6 +226,10 @@ export abstract class AbstractNavigationDoubleDrawerComponent implements OnInit,
223226
return this._navigationService.rightLoading$;
224227
}
225228

229+
public get pathResolverLoading$() {
230+
return this._pathResolverLoading$;
231+
}
232+
226233
public toggleMenu() {
227234
this.toggleRightMenu();
228235
if (this.allClosable) {
@@ -376,4 +383,40 @@ export abstract class AbstractNavigationDoubleDrawerComponent implements OnInit,
376383
protected openAvailableView() {
377384
this._navigationService.openAvailableView();
378385
}
386+
387+
protected resolveInitialValueOfPath() {
388+
if (this.currentPath === undefined) {
389+
const groupNavigationRoute = this._config.getServicesConfiguration()?.groupNavigation?.groupNavigationRoute;
390+
if (this._router.url.includes(groupNavigationRoute)) {
391+
this._pathResolverLoading$.on();
392+
this._pathService.datafieldsForMenuResolver.pipe(take(1)).subscribe(data => {
393+
this._pathResolverLoading$.off();
394+
let nodePath;
395+
let hasChildren;
396+
try {
397+
nodePath = extractFieldValueFromData<string>(data, GroupNavigationConstants.ITEM_FIELD_ID_NODE_PATH);
398+
hasChildren = extractFieldValueFromData<boolean>(data, GroupNavigationConstants.ITEM_FIELD_ID_HAS_CHILDREN);
399+
} catch (e) {
400+
this._log.info("Couldn't resolve menu, skipping...")
401+
}
402+
if (hasChildren && nodePath) {
403+
this._navigationService.fromResolver = true;
404+
this._pathService.activePath = nodePath;
405+
} else if (nodePath) {
406+
this._navigationService.fromResolver = true;
407+
this._pathService.activePath = this._navigationService.extractParentPath(nodePath);
408+
}
409+
}, error => {
410+
this._pathResolverLoading$.off();
411+
this.currentPath = this._pathService.activePath;
412+
});
413+
} else {
414+
const viewConfiguration = this._config.getViewByUrl(this._router.url)
415+
if (viewConfiguration?.processUri) {
416+
this._navigationService.fromResolver = true;
417+
this._pathService.activePath = viewConfiguration.processUri;
418+
}
419+
}
420+
}
421+
}
379422
}

projects/netgrif-components-core/src/lib/navigation/navigation-double-drawer/service/double-drawer-navigation.service.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export class DoubleDrawerNavigationService implements OnDestroy {
7373
* Siblings of the node are on the left, children are on the right
7474
*/
7575
protected _currentPath: string;
76+
private _fromResolver: boolean;
7677
/**
7778
* Currently selected navigation item
7879
*/
@@ -213,6 +214,10 @@ export class DoubleDrawerNavigationService implements OnDestroy {
213214
return this._nodeLoading$;
214215
}
215216

217+
set fromResolver(value: boolean) {
218+
this._fromResolver = value;
219+
}
220+
216221
public loadNavigationItems(node: UriNodeResource) {
217222
if (this.currentPath === PathService.SEPARATOR) {
218223
this._leftItems$.next([]);
@@ -256,8 +261,8 @@ export class DoubleDrawerNavigationService implements OnDestroy {
256261
* On second check if the clicked item has a view. On third, pick any other children's view, else show nothing.
257262
* */
258263
public onItemClick(item: NavigationItem): void {
264+
this._currentNavigationItem = item;
259265
if (item.resource === undefined) {
260-
this._currentNavigationItem = undefined;
261266
// custom view represented only in nae.json
262267
if (item.processUri === this.currentPath) {
263268
this._pathService.activePath = this.currentPath;
@@ -266,7 +271,6 @@ export class DoubleDrawerNavigationService implements OnDestroy {
266271
}
267272
this.itemClicked.emit({path: this._pathService.activePath, isHome: false});
268273
} else {
269-
this._currentNavigationItem = item;
270274
const path = item.resource.immediateData.find(f => f.stringId === GroupNavigationConstants.ITEM_FIELD_ID_NODE_PATH)?.value
271275

272276
if (DoubleDrawerUtils.hasItemChildren(item) && !this.leftLoading$.isActive && !this.rightLoading$.isActive) {
@@ -307,6 +311,11 @@ export class DoubleDrawerNavigationService implements OnDestroy {
307311
}
308312
}
309313

314+
if (this._fromResolver) {
315+
this._fromResolver = false;
316+
return;
317+
}
318+
310319
let autoOpenItems: Array<NavigationItem> = allItems.filter(item => DoubleDrawerUtils.hasItemAutoOpenView(item));
311320
if (autoOpenItems.length > 0) {
312321
this._redirectService.redirect(autoOpenItems[0].routing.path);
@@ -598,10 +607,10 @@ export class DoubleDrawerNavigationService implements OnDestroy {
598607
if (path === '/') {
599608
return path;
600609
}
601-
if (path.lastIndexOf('/') === 0) {
610+
if (path?.lastIndexOf('/') === 0) {
602611
return '/';
603612
}
604-
return path.substring(0, path.lastIndexOf('/'));
613+
return path?.substring(0, path?.lastIndexOf('/'));
605614
}
606615

607616

projects/netgrif-components-core/src/lib/navigation/service/path.service.ts

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1-
import {Inject, Injectable, Optional} from '@angular/core';
2-
import {BehaviorSubject, Observable} from 'rxjs';
1+
import {Inject, Injectable, OnDestroy, Optional} from '@angular/core';
2+
import {BehaviorSubject, Observable, ReplaySubject} from 'rxjs';
33
import {LoggerService} from '../../logger/services/logger.service';
44
import {NAE_URI_NODE_CASES_PAGE_SIZE} from '../model/size-menu-injection-token';
5+
import {DataGroup} from "../../resources/interface/data-groups";
6+
import {HttpErrorResponse} from "@angular/common/http";
57

68
/**
79
* Service for managing URIs
810
*/
911
@Injectable({
1012
providedIn: 'root',
1113
})
12-
export class PathService {
14+
export class PathService implements OnDestroy {
1315

1416
public static SEPARATOR: string = '/';
1517
private readonly _activePath$: BehaviorSubject<string>;
1618
protected pageSize: number;
19+
private readonly _datafieldsForMenuResolver$: ReplaySubject<Array<DataGroup>>;
1720

1821
constructor(
1922
protected _logger: LoggerService,
@@ -40,20 +43,47 @@ export class PathService {
4043
this._logger.debug('PathService initialized with pageSize', { pageSize: this.pageSize });
4144

4245
this._activePath$ = new BehaviorSubject<string>(PathService.SEPARATOR);
46+
this._datafieldsForMenuResolver$ = new ReplaySubject<Array<DataGroup>>();
4347
}
4448

4549
public set activePath(path: string) {
4650
this._activePath$.next(path);
4751
}
4852

4953
public get activePath$(): Observable<string> {
50-
return this._activePath$;
54+
return this._activePath$.asObservable();
5155
}
5256

5357
public get activePath(): string {
5458
return this._activePath$.getValue();
5559
}
5660

61+
public set datafieldsForMenuResolver(data: Array<DataGroup>) {
62+
if (!this._datafieldsForMenuResolver$.closed) {
63+
this._datafieldsForMenuResolver$.next(data);
64+
this._datafieldsForMenuResolver$.complete();
65+
} else {
66+
this._logger.error('PathService can have datafields for Menu resolver set only once');
67+
}
68+
}
69+
70+
public set datafieldsForMenuResolverError(error: Error) {
71+
if (!this._datafieldsForMenuResolver$.closed) {
72+
this._datafieldsForMenuResolver$.error(error instanceof HttpErrorResponse ? error.error.message : error.message);
73+
this._datafieldsForMenuResolver$.complete();
74+
} else {
75+
this._logger.error('PathService can\'t handle error for datafields for Menu resolver, because stream is already closed');
76+
}
77+
}
78+
79+
public get datafieldsForMenuResolver(): Observable<Array<DataGroup>> {
80+
return this._datafieldsForMenuResolver$.asObservable();
81+
}
82+
83+
get isMenuResolverClosed(): boolean {
84+
return this._datafieldsForMenuResolver$.closed;
85+
}
86+
5787
public reset(): string {
5888
this.activePath = PathService.SEPARATOR;
5989
return PathService.SEPARATOR;
@@ -62,4 +92,11 @@ export class PathService {
6292
public splitPath(path: string): Array<string> {
6393
return path.split(PathService.SEPARATOR);
6494
}
95+
96+
ngOnDestroy() {
97+
this._activePath$.complete();
98+
if (!this._datafieldsForMenuResolver$.closed) {
99+
this._datafieldsForMenuResolver$.complete();
100+
}
101+
}
65102
}

projects/netgrif-components/src/lib/navigation/group-navigation-component-resolver/default-group-navigation-component-resolver.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
ViewService,
1010
extractFieldValueFromData,
1111
hasView,
12-
RoutingBuilderService
12+
RoutingBuilderService, PathService
1313
} from '@netgrif/components-core';
1414
import {DefaultTabViewComponent} from './default-components/tabbed/default-tab-view/default-tab-view.component';
1515
import {
@@ -19,8 +19,8 @@ import {
1919
@Injectable()
2020
export class DefaultGroupNavigationComponentResolverService extends GroupNavigationComponentResolverService {
2121

22-
constructor(taskResourceService: TaskResourceService, log: LoggerService, private _configService: ConfigurationService, private _viewService: ViewService,) {
23-
super(taskResourceService, log);
22+
constructor(taskResourceService: TaskResourceService, log: LoggerService, protected _configService: ConfigurationService, protected _viewService: ViewService, protected _pathService: PathService) {
23+
super(taskResourceService, _pathService, log);
2424
}
2525

2626
public resolveViewComponent(navItemData: Array<DataGroup>): Type<any> {

projects/netgrif-components/src/lib/navigation/navigation-double-drawer/navigation-double-drawer.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@
154154
<img *ngIf="image !== undefined" [alt]="imageAlt" [src]="image" class="logoimg"
155155
[routerLink]="imageRouterLink !== undefined ? imageRouterLink : []">
156156
</div>
157-
<div *ngIf="(rightLoading$ | async) === false">
157+
<div *ngIf="(rightLoading$ | async) === false && (pathResolverLoading$ | async) === false">
158158
<div fxLayout="column" fxLayoutAlign="end end" class="order-icon-wrapper">
159159
<button mat-icon-button fxLayout="column" fxLayoutAlign="center center"
160160
class="mat-button mat-typography menu-font-color order-icon" (click)="switchOrder()"
@@ -175,7 +175,7 @@
175175
</button>
176176
</div>
177177
</div>
178-
<div *ngIf="(rightLoading$ | async)" fxLayout="column" fxLayoutAlign="center center" class="margin-top-default">
178+
<div *ngIf="(rightLoading$ | async) || (pathResolverLoading$ | async)" fxLayout="column" fxLayoutAlign="center center" class="margin-top-default">
179179
<mat-spinner color="primary" diameter="40" mode="indeterminate"></mat-spinner>
180180
</div>
181181
</ng-template>

0 commit comments

Comments
 (0)