Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Ensuring UI5 2.x compliance for cards-editor-middleware Plugin #2613

Merged
merged 32 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
5a56c91
feat: Ensuring UI5 2.x compliance for cards-editor-middleware Plugin
UBSusmitha Nov 22, 2024
c826332
Adding changes for review comments and removing console logs and debu…
UBSusmitha Nov 25, 2024
090d555
Merge branch 'main' into feat/ensure-UI5-2.0-compliance
UBSusmitha Nov 25, 2024
8b3ac4f
Removing console long statement
UBSusmitha Nov 25, 2024
e023e5e
Merge branch 'feat/ensure-UI5-2.0-compliance' of https://github.com/S…
UBSusmitha Nov 25, 2024
13de9c9
Merge branch 'main' into feat/ensure-UI5-2.0-compliance
UBSusmitha Nov 26, 2024
12809df
Merge branch 'main' into feat/ensure-UI5-2.0-compliance
UBSusmitha Nov 28, 2024
10e7a2e
Merge branch 'main' into feat/ensure-UI5-2.0-compliance
UBSusmitha Dec 2, 2024
739bc6c
Merge branch 'main' into feat/ensure-UI5-2.0-compliance
UBSusmitha Dec 3, 2024
d87fcc6
Update packages/cards-editor-middleware/templates/Init.js
UBSusmitha Dec 3, 2024
ceff10c
Update packages/cards-editor-middleware/templates/flpSandbox.html
UBSusmitha Dec 3, 2024
ed833d1
Adding changes for the review comments
UBSusmitha Dec 4, 2024
4495f75
Merge branch 'main' into feat/ensure-UI5-2.0-compliance
UBSusmitha Dec 4, 2024
aa97996
Merge branch 'main' into feat/ensure-UI5-2.0-compliance
UBSusmitha Dec 4, 2024
9ff92b7
Adding changes for the review comments
UBSusmitha Dec 4, 2024
d4270d5
Merge branch 'feat/ensure-UI5-2.0-compliance' of https://github.com/S…
UBSusmitha Dec 4, 2024
10c8328
reverting change causing build failure
UBSusmitha Dec 4, 2024
c5d3958
Merge branch 'main' into feat/ensure-UI5-2.0-compliance
UBSusmitha Dec 4, 2024
02b3336
Adding changes for the review comments
UBSusmitha Dec 5, 2024
c9a2bf9
Merge branch 'main' into feat/ensure-UI5-2.0-compliance
UBSusmitha Dec 5, 2024
bbd3c8f
Merge branch 'main' into feat/ensure-UI5-2.0-compliance
UBSusmitha Dec 6, 2024
4f93c33
Merge branch 'main' into feat/ensure-UI5-2.0-compliance
UBSusmitha Dec 6, 2024
dbe6672
Merge branch 'main' into feat/ensure-UI5-2.0-compliance
UBSusmitha Dec 6, 2024
d3327e1
Adding changes for review comments
UBSusmitha Dec 6, 2024
9796bdf
Linting auto fix commit
github-actions[bot] Dec 6, 2024
b6f9894
Merge branch 'main' into feat/ensure-UI5-2.0-compliance
UBSusmitha Dec 6, 2024
00da8f5
Merge branch 'main' into feat/ensure-UI5-2.0-compliance
UBSusmitha Dec 6, 2024
2b6ac18
add changeset
heimwege Dec 6, 2024
cd90e77
Merge remote-tracking branch 'origin/feat/ensure-UI5-2.0-compliance' …
heimwege Dec 6, 2024
a79670e
Merge branch 'main' into feat/ensure-UI5-2.0-compliance
heimwege Dec 6, 2024
9f69525
Merge branch 'main' into feat/ensure-UI5-2.0-compliance
UBSusmitha Dec 9, 2024
3c9b09a
Merge branch 'main' into feat/ensure-UI5-2.0-compliance
UBSusmitha Dec 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/cards-editor-middleware/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module.exports = async ({ resources }: MiddlewareParameters<any>): Promise<Reque
router.get(ApiRoutes.previewGeneratorSandbox, async (_req, res: Response) => {
const app = JSON.parse(await manifest.getString())['sap.app'];
res.status(200).send(
render(await promises.readFile(join(__dirname, '../templates/editor.html'), 'utf-8'), {
render(await promises.readFile(join(__dirname, '../templates/flpSandbox.html'), 'utf-8'), {
templateModel: {
appTitle: app.title || 'Card Editor Preview',
component: app.id
Expand Down
84 changes: 84 additions & 0 deletions packages/cards-editor-middleware/templates/Init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
function parseUI5Version(version) {
const versionParts = version.replace(/snapshot-untested|snapshot-|snapshot/, '').split('.');
UBSusmitha marked this conversation as resolved.
Show resolved Hide resolved
const major = parseInt(versionParts[0], 10);
const minor = parseInt(versionParts[1], 10);

return { major, minor };
}

function isLowerThanMinimalUi5Version(version, minVersion) {
UBSusmitha marked this conversation as resolved.
Show resolved Hide resolved
if (version && minVersion) {
const minVersionParsed = parseUI5Version(minVersion);
const ui5VersionParsed = parseUI5Version(version);
if (!isNaN(ui5VersionParsed.major) && !isNaN(ui5VersionParsed.minor)) {
if (ui5VersionParsed.major < minVersionParsed.major) {
return true;
}
if (ui5VersionParsed.major === minVersionParsed.major && ui5VersionParsed.minor < minVersionParsed.minor) {
return true;
}
}
}
return false;
}

function addCardGenerationUserAction(oComponentInstance) {
sap.ui.require([
"sap/cards/ap/generator/CardGenerator"
], (CardGenerator) => {
sap.ui.require(["sap/ushell/Container"], async function (Container) {
UBSusmitha marked this conversation as resolved.
Show resolved Hide resolved
const oRenderer = await Container.getServiceAsync("fiori2");
if (oRenderer) {
var generateCardBtn = {
controlType: "sap.ushell.ui.launchpad.ActionItem",
bCurrentState: true,
oControlProperties: {
icon: "sap-icon://add",
id: "generate_card",
text: "Generate Card",
tooltip: "Generate Card",
press: function () {
CardGenerator.initializeAsync(oComponentInstance);
}
},
bIsVisible: true
};
oRenderer.addUserAction(generateCardBtn);
}
});
});
}

sap.ui.require(["sap/ui/core/Core"], (Core) => {
UBSusmitha marked this conversation as resolved.
Show resolved Hide resolved
Core.ready().then(function() {
sap.ui.require("sap/ushell/Container").attachRendererCreatedEvent(function() {
UBSusmitha marked this conversation as resolved.
Show resolved Hide resolved
sap.ui.require("sap/ushell/Container").getServiceAsync('AppLifeCycle').then((serviceInstance) => {
serviceInstance.attachAppLoaded(async (event) => {
sap.ui.require([
"sap/m/MessageBox",
"sap/ui/VersionInfo"
], async (MessageBox, VersionInfo) => {
const sapCoreVersionInfo = await VersionInfo.load({
library: "sap.ui.core"
});
const sapCoreVersion = sapCoreVersionInfo && sapCoreVersionInfo.version;
UBSusmitha marked this conversation as resolved.
Show resolved Hide resolved

if (isLowerThanMinimalUi5Version(sapCoreVersion, "1.121")) {
MessageBox.error("Card Generation feature is not supported for the current UI5 version. Please use UI5 version 1.121 or higher.");
return;
}

var oCurrentApplication = serviceInstance.getCurrentApplication();
var oComponentInstance = oCurrentApplication.componentInstance;
addCardGenerationUserAction(oComponentInstance);
});
});
});
});
sap.ui.require("sap/ushell/Container").createRenderer(true).then(function(oRenderer){
UBSusmitha marked this conversation as resolved.
Show resolved Hide resolved
oRenderer.placeAt("content");
});
});
});


79 changes: 1 addition & 78 deletions packages/cards-editor-middleware/templates/editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,84 +50,7 @@
// NON-SECURE setting for testing environment
</script>

<script>
UBSusmitha marked this conversation as resolved.
Show resolved Hide resolved
function parseUI5Version(version) {
const versionParts = version.replace(/snapshot-untested|snapshot-|snapshot/, '').split('.');
const major = parseInt(versionParts[0], 10);
const minor = parseInt(versionParts[1], 10);

return { major, minor };
}

function isLowerThanMinimalUi5Version(version, minVersion) {
if (version && minVersion) {
const minVersionParsed = parseUI5Version(minVersion);
const ui5VersionParsed = parseUI5Version(version);
if (!isNaN(ui5VersionParsed.major) && !isNaN(ui5VersionParsed.minor)) {
if (ui5VersionParsed.major < minVersionParsed.major) {
return true;
}
if (ui5VersionParsed.major === minVersionParsed.major && ui5VersionParsed.minor < minVersionParsed.minor) {
return true;
}
}
}
return false;
}

function addCardGenerationUserAction(oComponentInstance) {
sap.ui.require([
"sap/cards/ap/generator/CardGenerator"
], (CardGenerator) => {
var oRenderer = sap.ushell.Container.getRenderer("fiori2");
if (oRenderer) {
var generateCardBtn = {
controlType: "sap.ushell.ui.launchpad.ActionItem",
bCurrentState: true,
oControlProperties: {
icon: "sap-icon://add",
id: "generate_card",
text: "Generate Card",
tooltip: "Generate Card",
press: function () {
CardGenerator.initializeAsync(oComponentInstance);
}
},
bIsVisible: true
};
oRenderer.addUserAction(generateCardBtn);
}
});
}

sap.ui.getCore().attachInit(() => {
sap.ushell.Container.attachRendererCreatedEvent(() => {
sap.ushell.Container.getServiceAsync('AppLifeCycle').then((serviceInstance) => {
serviceInstance.attachAppLoaded(async (event) => {
sap.ui.require([
"sap/m/MessageBox",
"sap/ui/VersionInfo"
], async (MessageBox, VersionInfo) => {
const sapCoreVersionInfo = await VersionInfo.load({
library: "sap.ui.core"
});
const sapCoreVersion = sapCoreVersionInfo && sapCoreVersionInfo.version;

if (isLowerThanMinimalUi5Version(sapCoreVersion, "1.121")) {
MessageBox.error("Card Generation feature is not supported for the current UI5 version. Please use UI5 version 1.121 or higher.");
return;
}

var oCurrentApplication = serviceInstance.getCurrentApplication();
var oComponentInstance = oCurrentApplication.componentInstance;
addCardGenerationUserAction(oComponentInstance);
});
});
});
});
sap.ushell.Container.createRenderer().placeAt("content");
});
</script>
<script src="./Init.js"></script>
</head>
<!-- UI Content -->

Expand Down
59 changes: 59 additions & 0 deletions packages/cards-editor-middleware/templates/flpSandbox.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!DOCTYPE HTML>
<!-- Copyright (c) 2015 SAP AG, All Rights Reserved -->
<html lang="en">

<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">
<title><%- templateModel.appTitle %></title>
<script type="text/javascript">
window["sap-ushell-config"] = {
defaultRenderer: "fiori2",
bootstrapPlugins: {
"RuntimeAuthoringPlugin": {
component: "sap.ushell.plugins.rta",
config: {
validateAppVersion: false
}
}
},
renderers: {
fiori2: {
componentData: {
config: {
search: "hidden"
}
}
}
},
applications: {
"Cards-generator": {
title: "<%- templateModel.appTitle %>",
description: "",
additionalInformation: "SAPUI5.Component=<%- templateModel.component %>",
applicationType: "URL",
url: "../"
}
}
};
</script>

<script src="../resources/sap/ushell/bootstrap/sandbox2.js" id="sap-ushell-bootstrap"></script>
UBSusmitha marked this conversation as resolved.
Show resolved Hide resolved

<!-- Bootstrap the UI5 core library -->
<script id="sap-ui-bootstrap" src="../resources/sap-ui-core.js"
data-sap-ui-libs="sap.m, sap.f, sap.ushell, sap.ui.core, sap.ui.layout, sap.ui.generic.app, sap.ui.comp, sap.suite.ui.generic.template, sap.ovp, sap.ui.rta"
UBSusmitha marked this conversation as resolved.
Show resolved Hide resolved
data-sap-ui-async="true" data-sap-ui-preload="async" data-sap-ui-theme="sap_horizon"
UBSusmitha marked this conversation as resolved.
Show resolved Hide resolved
data-sap-ui-compat-version="edge" data-sap-ui-language="en"
data-sap-ui-resource-roots='{"<%- templateModel.component %>": "../"}' data-sap-ui-frameOptions="allow">
// NON-SECURE setting for testing environment
</script>
UBSusmitha marked this conversation as resolved.
Show resolved Hide resolved

<script src="./Init.js"></script>
</head>
<!-- UI Content -->

<body class="sapUiBody" id="content"></body>

</html>
Loading