本文目录
- 一级目录
- 二级目录
- 三级目录
- 本系列之前的文章
- 业务场景及Service定义
- DB Schema
- Service的定义
- AdminService
- BookService
- 添加`app`文件夹
- 文件 `package.json`
- 文件 `fiori.html`
- 文件夹`appconfig`
一级目录
二级目录
三级目录
本系列之前的文章
SAP CAP篇一:快速创建一个Service,基于Java的实现
SAP CAP篇二:为Service加上数据库支持
SAP CAP篇三:定义Model
业务场景及Service定义
添加Fiori Elements程序之前,首先先定义业务场景。SAP CAP 采用Book Shop作为业务场景,我们不妨也使用类似的业务背景。
使用如下的简易Model:
- Book Category。
- Book。
- User Wish List。
其中,Book Category
以及Book
只能被Admin维护。普通用户可以查看Book
并将其添加到Wish List
。
至于是Wish List
还是Shopping List
,对本篇主要是阐述“添加Fiori Elements程序”而言,没有本质区别。
DB Schema
首先,看看DB Schema的定义:
entity Books : cuid, managed {title : localized String(111);descr : localized String(1111);stock : Integer;price : Decimal(9,2);currency : Currency;category : Association to Categories;
}entity Categories : CodeList {key ID : Integer;parent : Association to Categories;children : Composition of many Categories on children.parent = $self;
}entity WishLists: managed {key userID : User;key book : Association to Books;
}
Service的定义
这里,定义两个Service。
AdminService
这个Service是给后台Admin使用的。
using { alvachien.learncap.db as db } from '../db/schema';service AdminService {entity Books as projection on db.Books;entity Categories as projection on db.Categories;}
BookService
这个Service是给前台用户使用的。
service AdminService {@readonlyentity Products as projection on db.Books;@readonlyentity Categories as projection on db.Categories;entity WishLists as projection on db.WishLists;
}
添加app
文件夹
在项目文件夹中,创建app
文件夹。这里的app
文件夹实际上为approuter
准备的,但是这个文件夹在本地开发测试的时候也非常有用。
并在文件夹中添加如下文件:
- package.json
- fiori.html
appconfig
folder
文件 package.json
正如之前提到的那样,这里的这个nodejs
程序,是用于approuter
,所以,package.json
的定义如下:
{"name": "approuter","dependencies": {"@sap/approuter": "^13"},"scripts": {"start": "node node_modules/@sap/approuter/approuter.js"}
}
文件 fiori.html
文件fiori.html
是用作Fiori Launchpad
的入口程序——类似于绝大多数的HTML程序的index.html
一样。所以,这个fiori.html
是标准的Fiori Launchpad
的定义文件。
<!DOCTYPE html>
<html>
<head><meta http-equiv="X-UA-Compatible" content="IE=edge" /><meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>Fiori</title><script>window["sap-ushell-config"] = {defaultRenderer: "fiori2",applications: {}};</script><script id="sap-ushell-bootstrap" src="https://sapui5.hana.ondemand.com/1.115.0/test-resources/sap/ushell/bootstrap/sandbox.js"></script><script id="sap-ui-bootstrap" src="https://sapui5.hana.ondemand.com/1.115.0/resources/sap-ui-core.js"data-sap-ui-libs="sap.m, sap.ushell, sap.collaboration, sap.ui.layout"data-sap-ui-compatVersion="edge"data-sap-ui-theme="sap_horizon"data-sap-ui-frameOptions="allow"></script><script>sap.ui.getCore().attachInit(()=> sap.ushell.Container.createRenderer().placeAt("content"))</script></head>
<body class="sapUiBody" id="content"></body>
</html>
文件夹appconfig
文件夹appconfig
用来提供Fiori Launchpad
的Sandbox系统。真正Deploy到SAP BTP上时,需要遵循Launchpad 定义的标准。
{"services": {"LaunchPage": {"adapter": {"config": {"catalogs": [],"groups": [{"id": "Admin","title": "Admin","isPreset": true,"isVisible": true,"isGroupLocked": false,"tiles": [{"id": "manage-books","tileType": "sap.ushell.ui.tile.StaticTile","properties": {"targetURL": "#Books-manage","title": "Manage Books","description": "Find your favorite book"}}]}, {"id": "Book","title": "Book","isPreset": true,"isVisible": true,"isGroupLocked": false,"tiles": [{"id": "browse-books","tileType": "sap.ushell.ui.tile.StaticTile","properties": {"targetURL": "#Books-display","title": "Display Books","description": "Find your favorite book"}}]}] }}},"NavTargetResolution": {"config": {"enableClientSideTargetResolution": true}},"ClientSideTargetResolution": {"adapter": {"config": {"inbounds": {"manage-books": {"semanticObject": "Books","action": "manage","signature": {"parameters": {},"additionalParameters": "allowed"},"resolutionResult": {"applicationType": "SAPUI5","additionalInformation": "SAPUI5.Component=ManageBooks","url": "/manage-books/webapp"}},"browse-books": {"semanticObject": "Books","action": "display","signature": {"parameters": {},"additionalParameters": "allowed"},"resolutionResult": {"applicationType": "SAPUI5","additionalInformation": "SAPUI5.Component=BrowseBooks","url": "/browse-books/webapp"}}}}}} }
}
这里对该文件的内容,暂时不具体介绍。
未完待续。