Skip to content

Commit 299c81f

Browse files
authored
Merge pull request #285 from netgrif/NAE-2119
[NAE-2119] Fix menuItem
2 parents 866f9af + 670dd67 commit 299c81f

File tree

7 files changed

+65
-32
lines changed

7 files changed

+65
-32
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export abstract class AbstractBreadcrumbsComponent implements OnDestroy, AfterVi
9797
this.nicePathSubscription = this.nicePath.subscribe(np => {
9898
if (!!np) {
9999
const path = np;
100-
if (path?.length > this.partsAfterDots + 1 && this._uriService.activeNode?.uriPath.length > this.lengthOfPath && !this._showPaths) {
100+
if (path?.length > this.partsAfterDots + 1 && this._uriService.activeNode?.path.length > this.lengthOfPath && !this._showPaths) {
101101
const newPath = [path[0], AbstractBreadcrumbsComponent.DOTS];
102102
for (let i = path.length - this.partsAfterDots; i < path.length; i++) {
103103
newPath.push(path[i]);
@@ -114,7 +114,7 @@ export abstract class AbstractBreadcrumbsComponent implements OnDestroy, AfterVi
114114
if (!this.redirectOnClick) {
115115
return;
116116
}
117-
this._router.navigate(this.redirectUrls.get(this._uriService.activeNode.uriPath)).then(r => {})
117+
this._router.navigate(this.redirectUrls.get(this._uriService.activeNode.path)).then(r => {})
118118
}
119119

120120
public reset(): void {
@@ -146,7 +146,7 @@ export abstract class AbstractBreadcrumbsComponent implements OnDestroy, AfterVi
146146
}
147147

148148
private resultCounter(count: number, tmp: string[]): number {
149-
if (tmp?.length > this.partsAfterDots + 1 && this._uriService.activeNode?.uriPath.length > this.lengthOfPath && !this._showPaths) {
149+
if (tmp?.length > this.partsAfterDots + 1 && this._uriService.activeNode?.path.length > this.lengthOfPath && !this._showPaths) {
150150
return tmp.length - this.partsAfterDots + (count - 2);
151151
}
152152
return count;

projects/netgrif-components-core/src/lib/navigation/model/uri-resource.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11

22
export interface UriNodeResource {
3-
id: string;
4-
uriPath: string;
3+
id?: string;
4+
uriPath?: string;
5+
path: string;
56
name: string;
67
parentId: string;
7-
parent: UriNodeResource;
8+
parent?: UriNodeResource;
89
childrenId: Set<string>;
9-
children: Set<UriNodeResource>;
10+
children?: Set<UriNodeResource>;
1011
level: number;
11-
contentTypes: Set<UriContentType>
12+
contentTypes?: Set<UriContentType>
1213
}
1314

1415
export enum UriContentType {

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ export abstract class AbstractNavigationDoubleDrawerComponent implements OnInit,
206206
this.leftItems = [];
207207
this.loadRightSide();
208208
} else {
209-
if (!this.leftItems.find(item => item.resource?.immediateData.find(f => f.stringId === GroupNavigationConstants.ITEM_FIELD_ID_NODE_PATH)?.value === node.uriPath)) {
209+
if (!this.leftItems.find(item => item.resource?.immediateData.find(f => f.stringId === GroupNavigationConstants.ITEM_FIELD_ID_NODE_PATH)?.value === node.path)) {
210210
this.loadLeftSide();
211211
}
212212
this.loadRightSide();
@@ -327,7 +327,7 @@ export abstract class AbstractNavigationDoubleDrawerComponent implements OnInit,
327327
onItemClick(item: NavigationItem): void {
328328
if (item.resource === undefined) {
329329
// custom view represented only in nae.json
330-
if (item.processUri === this.currentNode.uriPath) {
330+
if (item.processUri === this.currentNode.path) {
331331
this._uriService.activeNode = this._currentNode;
332332
} else {
333333
this._uriService.activeNode = this._currentNode.parent;
@@ -340,7 +340,7 @@ export abstract class AbstractNavigationDoubleDrawerComponent implements OnInit,
340340
}, error => {
341341
this._log.error(error);
342342
});
343-
} else if (!path.includes(this.currentNode.uriPath)){
343+
} else if (!path.includes(this.currentNode.path)){
344344
this._uriService.activeNode = this._currentNode.parent;
345345
} else {
346346
this._uriService.activeNode = this._currentNode;
@@ -353,7 +353,7 @@ export abstract class AbstractNavigationDoubleDrawerComponent implements OnInit,
353353
}
354354

355355
isItemAndNodeEqual(item: NavigationItem, node: UriNodeResource): boolean {
356-
return item.resource?.immediateData.find(f => f.stringId === GroupNavigationConstants.ITEM_FIELD_ID_NODE_PATH)?.value === node.uriPath
356+
return item.resource?.immediateData.find(f => f.stringId === GroupNavigationConstants.ITEM_FIELD_ID_NODE_PATH)?.value === node.path
357357
}
358358

359359
protected loadLeftSide() {
@@ -485,14 +485,14 @@ export abstract class AbstractNavigationDoubleDrawerComponent implements OnInit,
485485
}
486486

487487
protected resolveCustomViewsInRightSide() {
488-
if (!!this._childCustomViews[this._currentNode.uriPath]) {
489-
this.rightItems.push(...Object.values(this._childCustomViews[this._currentNode.uriPath]));
488+
if (!!this._childCustomViews[this._currentNode.path]) {
489+
this.rightItems.push(...Object.values(this._childCustomViews[this._currentNode.path]));
490490
}
491491
}
492492

493493
protected resolveCustomViewsInLeftSide() {
494-
if (!!this._childCustomViews[this._currentNode.parent.uriPath]) {
495-
this.leftItems.push(...Object.values(this._childCustomViews[this._currentNode.parent.uriPath]));
494+
if (!!this._childCustomViews[this._currentNode.parent.path]) {
495+
this.leftItems.push(...Object.values(this._childCustomViews[this._currentNode.parent.path]));
496496
}
497497
}
498498

@@ -526,7 +526,7 @@ export abstract class AbstractNavigationDoubleDrawerComponent implements OnInit,
526526

527527
protected getTranslation(value: I18nFieldValue): string {
528528
const locale = this._translateService.currentLang.split('-')[0];
529-
return locale in value.translations ? value.translations[locale] : value.defaultValue;
529+
return value.translations?.[locale] ?? value.defaultValue;
530530
}
531531

532532
protected resolveAccessRoles(filter: Case, roleType: string): Array<RoleAccess> | undefined {
@@ -567,7 +567,7 @@ export abstract class AbstractNavigationDoubleDrawerComponent implements OnInit,
567567
}
568568

569569
uriNodeTrackBy(index: number, node: UriNodeResource) {
570-
return node.id;
570+
return node.path;
571571
}
572572

573573
itemsTrackBy(index: number, item: NavigationItem) {

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

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,53 @@ export class UriResourceService extends AbstractResourceService {
2020

2121
public getRoot(): Observable<UriNodeResource> {
2222
return this._resourceProvider.get$('uri/root', this.SERVER_URL).pipe(
23-
map(r => this.changeType(r, 'uriNode')));
23+
map(r => this.changeType(r, 'uriNode')),
24+
map((r: UriNodeResource) => {
25+
if (r.path) {
26+
r.uriPath = r.path;
27+
r.id = r.path;
28+
}
29+
return r;
30+
}));
2431
}
2532

2633
public getByLevel(level: number): Observable<Array<UriNodeResource>> {
2734
return this._resourceProvider.get$('uri/level/' + level, this.SERVER_URL).pipe(
28-
map(r => this.changeType(r, 'uriNodes')));
35+
map(r => this.changeType(r, 'uriNodes')),
36+
map((ar: Array<UriNodeResource>) => {
37+
return ar.map(r => {
38+
if (r.path) {
39+
r.uriPath = r.path;
40+
r.id = r.path;
41+
}
42+
return r;
43+
})
44+
}));
2945
}
3046

3147
public getNodesByParent(parentId: string): Observable<Array<UriNodeResource>> {
3248
return this._resourceProvider.get$('uri/parent/' + parentId, this.SERVER_URL).pipe(
33-
map(r => this.changeType(r, 'uriNodes')));
49+
map(r => this.changeType(r, 'uriNodes')),
50+
map((ar: Array<UriNodeResource>) => {
51+
return ar.map(r => {
52+
if (r.path) {
53+
r.uriPath = r.path;
54+
r.id = r.path;
55+
}
56+
return r;
57+
})
58+
}));
3459
}
3560

3661
public getNodeByUri(uriPath: string): Observable<UriNodeResource> {
3762
return this._resourceProvider.get$('uri/' + btoa(uriPath), this.SERVER_URL).pipe(
38-
map(r => this.changeType(r, 'uriNode')));
63+
map(r => this.changeType(r, 'uriNode')),
64+
map((r: UriNodeResource) => {
65+
if (r.path) {
66+
r.uriPath = r.path;
67+
r.id = r.path;
68+
}
69+
return r;
70+
}));
3971
}
4072
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ describe('UriService', () => {
5959

6060
it('should get node by path', done => {
6161
service.getNodeByPath(MockUriResourceService.TEST1_PATH).subscribe(res => {
62-
expect(res.uriPath).toEqual(MockUriResourceService.TEST1_PATH);
62+
expect(res.path).toEqual(MockUriResourceService.TEST1_PATH);
6363
expect(res.id).toEqual(MockUriResourceService.TEST1_ID);
6464
done();
6565
});

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export class UriService implements OnDestroy {
6262
}
6363

6464
public isRoot(node: UriNodeResource): boolean {
65-
return node.id === this._rootNode.id && node.uriPath === this._rootNode.uriPath;
65+
return node.path === this._rootNode.path;
6666
}
6767

6868
public get activeNode(): UriNodeResource {
@@ -71,7 +71,7 @@ export class UriService implements OnDestroy {
7171

7272
public set activeNode(node: UriNodeResource) {
7373
if (node.parentId && !node.parent) {
74-
if (node.parentId === this._rootNode.id) {
74+
if (node.parentId === this._rootNode.path) {
7575
node.parent = this._rootNode;
7676
} else {
7777
this._parentLoading$.on();
@@ -182,7 +182,7 @@ export class UriService implements OnDestroy {
182182
}
183183
const searchBody: CaseSearchRequestBody = {
184184
data: {
185-
[GroupNavigationConstants.ITEM_FIELD_ID_NODE_PATH] : node.uriPath
185+
[GroupNavigationConstants.ITEM_FIELD_ID_NODE_PATH] : node.path
186186
},
187187
process: {identifier: "preference_item"}
188188
};
@@ -225,13 +225,13 @@ export class UriService implements OnDestroy {
225225

226226
public resolveParentPath(node?: UriNodeResource): string {
227227
if (!node) node = this.activeNode;
228-
const lastDelimiter = node.uriPath.lastIndexOf('/');
228+
const lastDelimiter = node.path.lastIndexOf('/');
229229
if (lastDelimiter === 0) return '/';
230-
return node.uriPath.substring(0, lastDelimiter);
230+
return node.path.substring(0, lastDelimiter);
231231
}
232232

233233
public splitNodePath(node: UriNodeResource): Array<string> {
234-
return node?.uriPath.split('/').filter(s => s !== UriService.ROOT);
234+
return node?.path.split('/').filter(s => s !== UriService.ROOT);
235235
}
236236

237237
private capitalizeNames(nodes: Array<UriNodeResource>) {

projects/netgrif-components-core/src/lib/utility/tests/mocks/mock-uri-resource.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class MockUriResourceService extends UriResourceService {
1515

1616
private _root: UriNodeResource = {
1717
id: 'root',
18-
uriPath: 'root',
18+
path: 'root',
1919
name: 'root',
2020
parentId: null,
2121
parent: undefined,
@@ -26,7 +26,7 @@ export class MockUriResourceService extends UriResourceService {
2626
} as UriNodeResource;
2727
private _test1Node: UriNodeResource = {
2828
id: MockUriResourceService.TEST1_ID,
29-
uriPath: MockUriResourceService.TEST1_PATH,
29+
path: MockUriResourceService.TEST1_PATH,
3030
name: MockUriResourceService.TEST1_ID,
3131
parentId: 'root',
3232
parent: this._root,
@@ -37,7 +37,7 @@ export class MockUriResourceService extends UriResourceService {
3737
} as UriNodeResource;
3838
private _test2Node: UriNodeResource = {
3939
id: MockUriResourceService.TEST2_ID,
40-
uriPath: MockUriResourceService.TEST2_PATH,
40+
path: MockUriResourceService.TEST2_PATH,
4141
name: MockUriResourceService.TEST2_ID,
4242
parentId: 'root',
4343
parent: this._root,

0 commit comments

Comments
 (0)