Skip to content

Commit

Permalink
Demonstrate Hierarchy Functions (#416)
Browse files Browse the repository at this point in the history
Provides an example of an hierarchy function as `ListReport` and
`ValueHelp`

- currently only `READ`
- to [enable tree
tables](https://ui5.sap.com//#/topic/7cf7a31fd1ee490ab816ecd941bd2f1f)
as `ListReport` add to `manifest.json`:
```
"tableSettings": {
     "type": "TreeTable",
     "hierarchyQualifier": "NodesHierarchy",
   ...
}
```
- to enable tree table for ValueHelp hierarchical entity should be
annotated with `PresentationVariant` and root entity with
`PresentationVariantQualifier`

---------

Co-authored-by: D070615 <[email protected]>
Co-authored-by: Adrian Görler <[email protected]>
Co-authored-by: Evgeny Andreev <[email protected]>
  • Loading branch information
4 people authored Dec 19, 2024
1 parent a195f0e commit bde2090
Show file tree
Hide file tree
Showing 24 changed files with 1,103 additions and 141 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ User Interface related Features:
- [Model Localization](https://cap.cloud.sap/docs/guides/i18n) for [English](app/_i18n/i18n.properties) and [German](app/_i18n/i18n_de.properties) language for static texts
- [Custom File Upload extension](app/admin/webapp/extension/Upload.js) which provides a button for uploading `CSV` files
- A simple Swagger UI for the CatalogService API at <http://localhost:8080/swagger/index.html>
- UI5 [Tree Table](app/genres/webapp/manifest.json) with Value Help for [GenreHierarchy](app/admin/fiori-service.cds)
- [Custom event handlers](https://cap.cloud.sap/docs/java/provisioning-api) for Tree Table such as the [Custom business logic for GenreHierarchy](srv/src/main/java/my/bookshop/handlers/HierarchyHandler.java).
Please note, that Tree Tables must be used with HANA. Custom event handler in this case provides a limited support ment for local testing.

CDS Maven Plugin Features:

Expand Down Expand Up @@ -138,6 +141,14 @@ are defined for local development:
- User: `user`, password: `user` to browse books
- User: `admin`, password: `admin` to manage books and orders

### Testing in hybrid mode

You can test the `GenreHierarchyTest` on H2 using the profile `default` as well as on HANA using the profile `hybrid`

```
cds bind --exec -- mvn clean install -Dspring.profiles.active=hybrid
```

## Using VS Code

VS Code supports the project out-of-the-box, when using the [Extension Pack for Java](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-pack).
Expand Down
38 changes: 38 additions & 0 deletions app/admin/fiori-service.cds
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,44 @@ annotate AdminService.Books with @(UI : {
]}
});

// Add Value Help for Tree Table
annotate AdminService.Books with {
genre @(Common: {
Label : 'Genre',
ValueList: {
CollectionPath : 'GenreHierarchy',
Parameters : [
{
$Type : 'Common.ValueListParameterDisplayOnly',
ValueListProperty: 'name',
},
{
$Type : 'Common.ValueListParameterInOut',
LocalDataProperty: genre_ID,
ValueListProperty: 'ID',
}
],
PresentationVariantQualifier: 'VH',
}
});
}

// Hide ID because of the ValueHelp
annotate AdminService.GenreHierarchy with {
ID @UI.Hidden;
};

annotate AdminService.GenreHierarchy with @UI: {
PresentationVariant #VH: {
$Type : 'UI.PresentationVariantType',
Visualizations : ['@UI.LineItem'],
RecursiveHierarchyQualifier: 'GenreHierarchy'
},
LineItem : [{
$Type: 'UI.DataField',
Value: name,
}]
};

////////////////////////////////////////////////////////////
//
Expand Down
21 changes: 21 additions & 0 deletions app/appconfig/fioriSandboxConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
"title": "Browse Books",
"description": "Find your favorite book"
}
}, {
"id": "browse-genres",
"tileType": "sap.ushell.ui.tile.StaticTile",
"properties": {
"targetURL": "#Genres-display",
"title": "Browse Genres",
"description": "Find your favorite genre"
}
}
]
},
Expand Down Expand Up @@ -112,6 +120,19 @@
"url": "/browse/webapp"
}
},
"browse-genres": {
"semanticObject": "Genres",
"action": "display",
"signature": {
"parameters": {},
"additionalParameters": "allowed"
},
"resolutionResult": {
"applicationType": "SAPUI5",
"additionalInformation": "SAPUI5.Component=genres",
"url": "/genres/webapp"
}
},
"manage-books": {
"semanticObject": "Books",
"action": "manage",
Expand Down
13 changes: 3 additions & 10 deletions app/common.cds
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,8 @@ annotate my.Genres with
UI : {
SelectionFields : [name],
LineItem : [
{Value : name},
{
Value : parent.name,
Label : 'Main Genre'
{Value : name,
Label : '{i18n>Name}',
},
],
}
Expand All @@ -199,12 +197,7 @@ annotate my.Genres with
TypeNamePlural : '{i18n>Genres}',
Title : {Value : name},
Description : {Value : ID}
},
Facets : [{
$Type : 'UI.ReferenceFacet',
Label : '{i18n>SubGenres}',
Target : 'children/@UI.LineItem'
}, ],
}
});


Expand Down
23 changes: 23 additions & 0 deletions app/genres/fiori-service.cds
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
UI annotations for the Browse GenreHierarchy App
*/

using AdminService from '../../srv/admin-service';


annotate AdminService.GenreHierarchy with @Aggregation.RecursiveHierarchy#GenreHierarchy: {
$Type: 'Aggregation.RecursiveHierarchyType',
NodeProperty: ID, // identifies a node
ParentNavigationProperty: parent // navigates to a node's parent
};

annotate AdminService.GenreHierarchy with @Hierarchy.RecursiveHierarchy#GenreHierarchy: {
$Type: 'Hierarchy.RecursiveHierarchyType',
// ExternalKey : null,
LimitedDescendantCount: LimitedDescendantCount,
DistanceFromRoot: DistanceFromRoot,
DrillState: DrillState,
Matched: Matched,
MatchedDescendantCount: MatchedDescendantCount,
LimitedRank: LimitedRank
};
12 changes: 12 additions & 0 deletions app/genres/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "genres",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
3 changes: 3 additions & 0 deletions app/genres/webapp/Component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sap.ui.define(["sap/fe/core/AppComponent"], ac => ac.extend("genres.Component", {
metadata:{ manifest:'json' }
}))
2 changes: 2 additions & 0 deletions app/genres/webapp/i18n/i18n.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
appTitle=Browse Genres
appDescription=Genres as Tree View
2 changes: 2 additions & 0 deletions app/genres/webapp/i18n/i18n_de.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
appTitle=Zeige Genres
appDescription=Genres als Baumansicht
35 changes: 35 additions & 0 deletions app/genres/webapp/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Browse Genres</title>
<style>
html, body, body > div, #container, #container-uiarea {
height: 100%;
}
</style>
<script
id="sap-ui-bootstrap"
src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js"
data-sap-ui-theme="sap_fiori_3"
data-sap-ui-resourceroots='{
"genres": "./"
}'
data-sap-ui-oninit="module:sap/ui/core/ComponentSupport"
data-sap-ui-compatVersion="edge"
data-sap-ui-async="true"
data-sap-ui-frameOptions="trusted"
></script>
</head>
<body class="sapUiBody sapUiSizeCompact" id="content">
<div
data-sap-ui-component
data-name="genres"
data-id="container"
data-settings='{"id" : "genres"}'
data-handle-validation="true"
></div>
</body>
</html>
129 changes: 129 additions & 0 deletions app/genres/webapp/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
{
"_version": "1.8.0",
"sap.app": {
"id": "genres",
"type": "application",
"title": "{{appTitle}}",
"description": "{{appDescription}}",
"applicationVersion": {
"version": "1.0.0"
},
"dataSources": {
"AdminService": {
"uri": "/api/admin/",
"type": "OData",
"settings": {
"odataVersion": "4.0"
}
}
},
"-sourceTemplate": {
"id": "ui5template.basicSAPUI5ApplicationProject",
"-id": "ui5template.smartTemplate",
"-version": "1.40.12"
},
"crossNavigation": {
"inbounds": {
"Genres-show": {
"signature": {
"parameters": {},
"additionalParameters": "allowed"
},
"semanticObject": "GenreHierarchy",
"action": "show"
}
}
}
},
"sap.ui5": {
"dependencies": {
"minUI5Version": "1.122.0",
"libs": {
"sap.fe.templates": {}
}
},
"models": {
"i18n": {
"type": "sap.ui.model.resource.ResourceModel",
"uri": "i18n/i18n.properties"
},
"": {
"dataSource": "AdminService",
"settings": {
"synchronizationMode": "None",
"operationMode": "Server",
"autoExpandSelect" : true,
"earlyRequests": true,
"groupProperties": {
"default": {
"submit": "Auto"
}
}
}
}
},
"routing": {
"routes": [
{
"pattern": ":?query:",
"name": "GenreHierarchyList",
"target": "GenreHierarchyList"
},
{
"pattern": "GenreHierarchy({key}):?query:",
"name": "GenreHierarchyDetails",
"target": "GenreHierarchyDetails"
}
],
"targets": {
"GenreHierarchyList": {
"type": "Component",
"id": "GenreHierarchyList",
"name": "sap.fe.templates.ListReport",
"options": {
"settings" : {
"entitySet" : "GenreHierarchy",
"navigation" : {
"GenreHierarchy" : {
"detail" : {
"route" : "GenreHierarchyDetails"
}
}
},
"controlConfiguration": {
"@com.sap.vocabularies.UI.v1.LineItem": {
"tableSettings": {
"hierarchyQualifier": "GenreHierarchy",
"type": "TreeTable"
}
}
}
}
}
},
"GenreHierarchyDetails": {
"type": "Component",
"id": "GenreHierarchyDetails",
"name": "sap.fe.templates.ObjectPage",
"options": {
"settings" : {
"entitySet": "GenreHierarchy"
}
}
}
}
},
"contentDensities": {
"compact": true,
"cozy": true
}
},
"sap.ui": {
"technology": "UI5",
"fullWidth": false
},
"sap.fiori": {
"registrationIds": [],
"archeType": "transactional"
}
}
1 change: 1 addition & 0 deletions app/index.cds
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ using from './orders/fiori-service';
using from './reviews/fiori-service';
using from './notes/fiori-service';
using from './addresses/fiori-service';
using from './genres/fiori-service';
using from './common';
Loading

0 comments on commit bde2090

Please sign in to comment.