Adding Custom Logic
This commit is contained in:
46
app/launchpage.html
Normal file
46
app/launchpage.html
Normal file
@@ -0,0 +1,46 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<script>
|
||||
window['sap-ushell-config'] = {
|
||||
defaultRenderer: 'fiori2',
|
||||
services: {
|
||||
NavTargetResolution: {
|
||||
config: {
|
||||
allowTestUrlComponentConfig: true,
|
||||
enableClientSideTargetResolution: true
|
||||
}
|
||||
}
|
||||
},
|
||||
applications: {
|
||||
"incidents-app": {
|
||||
title: 'Incident-Management',
|
||||
description: 'Incidents',
|
||||
additionalInformation: 'SAPUI5.Component=ns.incidents',
|
||||
applicationType: 'URL',
|
||||
url: "./incidents/webapp",
|
||||
navigationMode: 'embedded'
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<script src="https://ui5.sap.com/test-resources/sap/ushell/bootstrap/sandbox.js"></script>
|
||||
<script
|
||||
src="https://ui5.sap.com/resources/sap-ui-core.js"
|
||||
data-sap-ui-libs="sap.m, sap.ushell, sap.fe.templates"
|
||||
data-sap-ui-compatVersion="edge"
|
||||
data-sap-ui-theme="sap_horizon"
|
||||
data-sap-ui-frameOptions="allow"
|
||||
data-sap-ui-bindingSyntax="complex"
|
||||
></script>
|
||||
<script>
|
||||
sap.ui.getCore().attachInit(function() {
|
||||
sap.ushell.Container.createRenderer().placeAt('content');
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
<body class="sapUiBody" id="content"></body>
|
||||
</html>
|
||||
23
srv/services.js
Normal file
23
srv/services.js
Normal file
@@ -0,0 +1,23 @@
|
||||
const cds = require('@sap/cds')
|
||||
|
||||
class ProcessorService extends cds.ApplicationService {
|
||||
/** Registering custom event handlers */
|
||||
init() {
|
||||
this.before("UPDATE", "Incidents", (req) => this.onUpdate(req));
|
||||
this.before("CREATE", "Incidents", (req) => this.changeUrgencyDueToSubject(req.data));
|
||||
|
||||
return super.init();
|
||||
}
|
||||
|
||||
changeUrgencyDueToSubject(data) {
|
||||
let urgent = data.title?.match(/urgent/i)
|
||||
if (urgent) data.urgency_code = 'H'
|
||||
}
|
||||
|
||||
/** Custom Validation */
|
||||
async onUpdate (req) {
|
||||
let closed = await SELECT.one(1) .from (req.subject) .where `status.code = 'C'`
|
||||
if (closed) req.reject `Can't modify a closed incident!`
|
||||
}
|
||||
}
|
||||
module.exports = { ProcessorService }
|
||||
Reference in New Issue
Block a user