This repository was archived by the owner on Aug 29, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 552
Fiori Tree Views towards GA #839
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d9d6391
Fiori Tree Views towards GA
danjoa d46956d
Also automate addition of Aggregation.RecursiveHierarchy
danjoa b5b1e56
Merged main into current
danjoa ecef6b1
Cleanup models for Genres Tree View
danjoa 332e6d4
Implementing @hierarchy shortcut
danjoa fd6c4c9
.
danjoa 84b3e2d
Formatting
danjoa e880ed0
Using verbose config
danjoa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,33 @@ | ||
| /* | ||
| All annotations needed for UI5 Tree Table View are located in '../common' | ||
| */ | ||
| using { sap.capire.bookshop.Genres } from '@capire/bookstore'; | ||
|
|
||
| annotate Genres with @cds.search: {name}; | ||
| annotate Genres with @readonly; | ||
| annotate Genres with { | ||
| name @title: '{i18n>Genre}'; | ||
| } | ||
|
|
||
| // Lists | ||
| annotate Genres with @( | ||
| Common.SemanticKey : [name], | ||
| UI.SelectionFields : [name], | ||
| UI.LineItem : [ | ||
| { Value: name, Label: '{i18n>Name}' }, | ||
| ], | ||
| ); | ||
|
|
||
| // Details | ||
| annotate Genres with @(UI : { | ||
| Identification : [{ Value: name }], | ||
| HeaderInfo : { | ||
| TypeName : '{i18n>Genre}', | ||
| TypeNamePlural : '{i18n>Genres}', | ||
| Title : { Value: name }, | ||
| Description : { Value: ID } | ||
| } | ||
| }); | ||
|
|
||
|
|
||
| // Tree Views | ||
| // annotate AdminService.Genres with @hierarchy; // upcomming simplification | ||
| using from './tree-view'; | ||
| using from './value-help'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| using { AdminService } from '@capire/bookstore'; | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////// | ||
| // | ||
| // Genres Tree View | ||
| // | ||
|
|
||
| // Tell Fiori about the structure of the hierarchy | ||
| annotate AdminService.Genres with @Aggregation.RecursiveHierarchy #GenresHierarchy : { | ||
| ParentNavigationProperty : parent, // navigates to a node's parent | ||
| NodeProperty : ID, // identifies a node, usually the key | ||
| }; | ||
|
|
||
| // Fiori expects the following to be defined explicitly, even though they're always the same | ||
| extend AdminService.Genres with @( | ||
| // The columns expected by Fiori to be present in hierarchy entities | ||
| Hierarchy.RecursiveHierarchy #GenresHierarchy : { | ||
| LimitedDescendantCount : LimitedDescendantCount, | ||
| DistanceFromRoot : DistanceFromRoot, | ||
| DrillState : DrillState, | ||
| LimitedRank : LimitedRank | ||
| }, | ||
| // Disallow filtering on these properties from Fiori UIs | ||
| Capabilities.FilterRestrictions.NonFilterableProperties: [ | ||
| 'LimitedDescendantCount', | ||
| 'DistanceFromRoot', | ||
| 'DrillState', | ||
| 'LimitedRank' | ||
| ], | ||
| // Disallow sorting on these properties from Fiori UIs | ||
| Capabilities.SortRestrictions.NonSortableProperties : [ | ||
| 'LimitedDescendantCount', | ||
| 'DistanceFromRoot', | ||
| 'DrillState', | ||
| 'LimitedRank' | ||
| ], | ||
| ) columns { // Ensure we can query these fields from database | ||
| null as LimitedDescendantCount : Int16, | ||
| null as DistanceFromRoot : Int16, | ||
| null as DrillState : String, | ||
| null as LimitedRank : Int16, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| // Value help with Tree View | ||
| using from '../admin-books/fiori-service'; | ||
| annotate AdminService.Books:genre with @Common.ValueList.PresentationVariantQualifier: 'VH'; | ||
| annotate AdminService.Genres with @UI.PresentationVariant #VH: { | ||
| RecursiveHierarchyQualifier : 'GenresHierarchy', | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| const cds = require('@sap/cds/lib') | ||
|
|
||
| // PoC for simplified Fiori Tree Views | ||
| cds.on('compile.for.runtime', csn => { | ||
| for (let each of cds.linked(csn).definitions) { | ||
| if (each.is_entity && each._service && each['@hierarchy']) _hierarchy (each) | ||
| } | ||
| }) | ||
|
|
||
|
|
||
| const _hierarchy = entity => { | ||
|
|
||
| // Add annotations explaining the hierarchy structure to Fiori | ||
| const Qualifier = entity.name.slice (entity._service.name.length+1) + 'Hierarchy' | ||
| const parent = _parent4(entity) | ||
| entity[`@Aggregation.RecursiveHierarchy#${Qualifier}.ParentNavigationProperty`] ??= {'=': parent.name } | ||
| entity[`@Aggregation.RecursiveHierarchy#${Qualifier}.NodeProperty`] ??= {'=': parent.keys[0].ref[0] } | ||
|
|
||
| // Add expected hierarchy elements to the entity | ||
| const columns = entity.projection.columns ??= ['*'] | ||
| const elements = entity.elements | ||
| for (let e of Hierarchy.elements) { | ||
| entity[`@Hierarchy.RecursiveHierarchy#${Qualifier}.${e.name}`] = {'=': e.name } | ||
| if (e.name in elements) continue | ||
| const { name, value, ...rest } = e | ||
| elements[e.name] = Object.defineProperty ({ __proto__:e, ...rest }, 'parent', { value: entity }) | ||
| columns.push ({ ...value, as: name, cast: { type: e.type } }) | ||
| } | ||
|
|
||
| // Disable filter and sort for hierarchy elements | ||
| entity['@Capabilities.FilterRestrictions.NonFilterableProperties'] = | ||
| entity['@Capabilities.SortRestrictions.NonSortableProperties'] = | ||
| Object.keys (Hierarchy.elements) | ||
| } | ||
|
|
||
|
|
||
| const _parent4 = entity => { | ||
| const parent = entity['@hierarchy.parent'] || entity['@hierarchy.via'] | ||
| if (parent) return entity.elements [parent['=']||parent] | ||
| else for (let e of entity.elements) // use first recursive uplink association | ||
| if (e.is2one && e._target === entity) return e | ||
| } | ||
|
|
||
|
|
||
| const { Hierarchy } = cds.linked `aspect Hierarchy { | ||
| LimitedDescendantCount : Int16 = null; | ||
| DistanceFromRoot : Int16 = null; | ||
| DrillState : String = null; | ||
| LimitedRank : Int16 = null; | ||
| }`.definitions |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should capture these as a reusable aspect. Unfortunately, an aspect can't have virtual or computed elements.