Create an SAP Fiori Elements-Based Analytical UI for your CAP Application
- How to set up your application for analytics
- Add new files to your project
- Generate UI with an SAP Fiori elements template
- Modify the UI with OData annotations
- Check the annotation files
- Visualize Risks in the analytics UI
- Add your application to the launch page
Prerequisites
- Prepare Your Development Environment for CAP
- Before you start with this tutorial, you have two options:
- Follow the instructions in Step 16: Start from an example branch of Prepare Your Development Environment for CAP to checkout the
cap-roles
branch. - Complete the group of tutorials Create a CAP Application and SAP Fiori UI.
- Follow the instructions in Step 16: Start from an example branch of Prepare Your Development Environment for CAP to checkout the
- Step 1
SAP Fiori elements is a framework that comprises the most commonly used floor plans and is designed to:
- Speed up development by reducing the amount of front-end code needed to build SAP Fiori apps.
- Drive UX consistency and compliance with the latest SAP Fiori design guidelines.
SAP Fiori elements for OData version 2 (V2) offers Analytical list page (ALP) as a separate floor plan for a unique way to analyze data step by step from different perspectives, to investigate a root cause through drill-down, and to act on transactional content. On the other hand, in SAP Fiori elements for OData V4, the Analytical List Page (ALP) is not a separate floor plan, but rather a “flavor” of the List Report Object Page floor plan. Hence, you can configure a List Report Object Page floor plan in such a way that it can serve as an “ALP flavor” report page.
Log in to complete tutorial - Step 2
Create a new service for Analytics as given in Create a CAP-Based Application using the following details.
-
Open the
tutorial
directory created in tutorial Prepare Your Development Environment for CAP. -
Open the folder
templates
. -
Copy the file
risk-analysis-service.cds
fromtemplates/analytics/srv
to thesrv
folder of your app.The content of the file looks like this:
JavaScriptCopyusing { sap.ui.riskmanagement as my } from '../db/schema'; using { RiskService } from './risk-service'; extend service RiskService { @readonly entity RisksAnalysis @(restrict : [ { grant : [ 'READ' ], to : [ 'RiskManager' ] } ]) as projection on my.Risks { *, substring(createdAt,1,4) as riskyear:String, cast (substring(createdAt,1,10) as Date) as createdAt }; } // Fix ambiguity in Mitigations.risk association ensuring it points to Risks extend RiskService.Risks with @cds.redirection.target;
It extends the
RiskService
with a newRisksAnalysis
entity that has a couple of date fields for data analysis. -
Run
cds watch
in the VS Code terminal and open the link http://localhost:4004/ in your browser.You should be able to see the new
RisksAnalysis
entity among with the rest of therisk
service entities underService Endpoints
. -
Copy the latest
sap.ui.riskmanagement-Risks.csv
file fromtemplates/analytics/db/data
and replace the existing file in thedb/data
folder of your app.This
.csv
file has a large number of records for analytical purposes.
Log in to complete tutorial -
- Step 3
-
In VS Code, invoke the Command Palette ( View → Command Palette or Shift + Command + P for macOS / Ctrl + Shift + P for Windows) and choose Fiori: Open Application Generator.
VS Code will automatically install
@sap/generator-fiori
if missing and open the Template Wizard.In case you get an error launching the Application Generator, see the SAP Fiori tools FAQ on SAP Help Portal to find a solution.
-
Choose application type SAP Fiori elements and floor plan List Report Object Page.
Why not use the Analytical List Page floor plan?
Although you are using SAP Fiori elements for OData V4, you will notice that there is still a floor plan Analytical List Page in the previous screen. However, it is due to be removed from the Fiori Generator UI, so you are not going to use it for this tutorial.
-
Choose Next.
-
In the next dialog, choose Use a Local CAP Project and point to the folder of your current
cpapp
project.In case you get the error:
Node module @sap/cds isn't found. Please install it and try again.
You might get the error
Node module @sap/cds is not found. Please install it and try again.
after you have chosen your CAP project. This is an issue with the App Generator not finding the corresponding CAP modules, due to different repositories. This should be a temporary issue. For the meantime you can work around it by opening a command line and running the following command:bashCopynpm install --global @sap/cds-dk --@sap:registry=https://npmjs.org/
See the CAP Troubleshooting guide for more details.
-
Select the
RiskService(Node.js)
as the OData service and choose Next. -
Select Risks Analysis as the main entity, choose the option No to avoid adding table columns automatically. Choose Next.
-
Enter
risk-analysis
as the module name andRisk Analysis
as the application title. -
Enter
ns
as the namespace andRisk Analysis
as the description for the application. -
Choose Finish to generate the application.
The application is now generated and in a few seconds you can see it in the
app
folder of your project. It contains arisk-analysis
and awebapp
folder with aComponent.js
file that is characteristic for an SAPUI5 app.Log in to complete tutorial -
- Step 4
-
If it is not still running from the previous tutorial, execute
cds watch
in a VS Code terminal and switch to http://localhost:4004 in your browser.You can now see that the CAP server has discovered an HTML page in your
app
folder: -
Choose the link http://localhost:4004/risk-analysis/webapp/index.html for the HTML page.
-
Choose Go and log in.
- Username:
risk.manager@tester.sap.com
- Password:
initial
You can now see the application without any data. The table is empty because the application is currently missing UI annotations. You add them in the next step.
- Username:
Log in to complete tutorial -
- Step 5
Open the
app/risk-analysis/webapp/manifest.json
file.Add the following lines to it:
JSONCopy{ "_version": "1.40.0", "sap.app": { ... }, "sap.ui5": { "flexEnabled": true, "dependencies": { ... }, "routing": { "config": {}, "routes": [ ... ], "targets": { "RiskAnalysisList": { ... "options": { "settings": { ... "navigation": { ... }, "initialLoad": true, "views": { "paths": [ { "primary": [ { "annotationPath": "@com.sap.vocabularies.UI.v1.Chart" } ], "secondary": [ { "annotationPath": "@com.sap.vocabularies.UI.v1.LineItem" } ], "defaultPath": "both" } ] }, "controlConfiguration": { "@com.sap.vocabularies.UI.v1.LineItem": { "tableSettings": { "type": "AnalyticalTable", "enableExport": true } }, "@com.sap.vocabularies.UI.v1.SelectionFields": { "layout": "CompactVisual", "initialLayout": "Visual", "filterFields": { "prio": { "label": "Priority", "availability": "Default", "visualFilter": { "valueList": "com.sap.vocabularies.Common.v1.ValueList#vlPrio" } }, "createdAt": { "label": "creation Date", "availability": "Default", "visualFilter": { "valueList": "com.sap.vocabularies.Common.v1.ValueList#vlcreatedAt" } } } } } } } }, "RiskAnalysisObjectPage": { ... } } } }, ... }
Copy the file
risks-analysis-service-ui.cds
fromtemplates/analytics/srv
to thesrv
folder of your app.
Log in to complete tutorial - Step 6
Let us have a look at the
risks-analysis-service-ui.cds
.There are three major segments in the List Report Object Page (ALP flavor):
- Visual filters
- Smart chart
- Analytical table
The annotations file
risks-analysis-service-ui.cds
and theapp/risk-analysis/webapp/manifest.json
file are used to specify configurations for these artifacts.Log in to complete tutorial - Step 8
-
With
cds watch
running, open the app in your browser at http://localhost:4004/risk-analysis/webapp/index.html. -
Log in if needed.
- Username:
risk.manager@tester.sap.com
- Password:
initial
- Username:
-
You should be able to see the generated resultant visualization.
Log in to complete tutorial -
- Step 9
Let us add the
Risk Analysis
application to the launch page where you already have theRisks
andMitigations
apps.-
Open the file
launchpage.html
inapp
folder of your application. -
Add the following code after
mitigations-app
:HTMLCopy<script> window['sap-ushell-config'] = { defaultRenderer: 'fiori2', applications: { "risks-app": { title: 'Risks', description: 'Risks', additionalInformation: 'SAPUI5.Component=ns.risks', applicationType: 'URL', url: "./risks/webapp", navigationMode: 'embedded' }, "mitigations-app": { title: "Mitigations", description: "Mitigations", additionalInformation: "SAPUI5.Component=ns.mitigations", applicationType: "URL", url: "./mitigations/webapp", navigationMode: "embedded" }, "risk-analysis-app": { title: "Risk Analysis", description: "Risk Analysis", additionalInformation: "SAPUI5.Component=ns.riskanalysis", applicationType: "URL", url: "./risk-analysis/webapp", navigationMode: "embedded" } } }; </script>
-
With
cds watch
running, open the app in your browser at http://localhost:4004/launchpage.html#Shell-home. -
You can now see the
Risk Analysis
app next to theMitigations
app.
The result of this tutorial can be found in the
analytics
branch. -