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 20 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
56 changes: 53 additions & 3 deletions packages/cards-editor-middleware/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { MiddlewareParameters } from '@ui5/server';
import { json, Router as createRouter } from 'express';
import path, { join } from 'path';
import { promises } from 'fs';
import { getWebappPath, FileName } from '@sap-ux/project-access';
import { getWebappPath, FileName, type Manifest } from '@sap-ux/project-access';
import { render } from 'ejs';
import * as utils from './utilities';
import os from 'os';
Expand All @@ -13,6 +13,32 @@ export const enum ApiRoutes {
cardsStore = '/cards/store',
i18nStore = '/editor/i18n'
}
export const DEFAULT_THEME = 'sap_horizon';

const UI5_LIBS = [
heimwege marked this conversation as resolved.
Show resolved Hide resolved
'sap.apf',
'sap.base',
'sap.chart',
'sap.collaboration',
'sap.f',
'sap.fe',
'sap.fileviewer',
'sap.gantt',
'sap.landvisz',
'sap.m',
'sap.ndc',
'sap.ovp',
'sap.rules',
'sap.suite',
'sap.tnt',
'sap.ui',
'sap.uiext',
'sap.ushell',
'sap.uxap',
'sap.viz',
'sap.webanalytics',
'sap.zen'
];

/**
* Check if a file exists.
Expand All @@ -33,6 +59,23 @@ async function pathExists(path: string) {
}
}

function getUI5Libs(manifest: Partial<Manifest>): string {
const libs = manifest['sap.ui5']?.dependencies?.libs ?? {};
// add libs that should always be preloaded
libs['sap.m'] = {};
libs['sap.ui.core'] = {};
libs['sap.ushell'] = {};
libs['sap.rta'] = {};
UBSusmitha marked this conversation as resolved.
Show resolved Hide resolved

return Object.keys(libs)
.filter((key) => {
return UI5_LIBS.some((substring) => {
return key === substring || key.startsWith(substring + '.');
});
})
.join(',');
}

module.exports = async ({ resources }: MiddlewareParameters<any>): Promise<RequestHandler> => {
const router = createRouter();
router.use(json());
Expand All @@ -47,11 +90,18 @@ 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'];
const ui5libs = getUI5Libs(JSON.parse(await manifest.getString()));
const supportedThemes: string[] = (JSON.parse(await manifest.getString())['sap.ui5']?.supportedThemes as []) ?? [DEFAULT_THEME];
const ui5Theme = supportedThemes.includes(DEFAULT_THEME) ? DEFAULT_THEME : supportedThemes[0];
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
component: app.id,
ui5: {
libs: ui5libs,
theme: ui5Theme
}
}
})
);
Expand Down
74 changes: 74 additions & 0 deletions packages/cards-editor-middleware/templates/Init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
function parseUI5Version(version) {
const versionParts = version.split('.');
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 = { major: 1, minor: 121 };
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",
"sap/ushell/Container"
], async (CardGenerator, Container) => {
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/ushell/Container", "sap/m/MessageBox", "sap/ui/VersionInfo"], async (Container, MessageBox, VersionInfo) => {
Container.attachRendererCreatedEvent(function() {
Container.getServiceAsync('AppLifeCycle').then((serviceInstance) => {
serviceInstance.attachAppLoaded(async (event) => {
const sapCoreVersionInfo = await VersionInfo.load({
library: "sap.ui.core"
});
const sapCoreVersion = 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);
});
});
});
Container.createRendererInternal(undefined, true).then(function(oRenderer){
oRenderer.placeAt("content");
});
});


136 changes: 0 additions & 136 deletions packages/cards-editor-middleware/templates/editor.html

This file was deleted.

63 changes: 63 additions & 0 deletions packages/cards-editor-middleware/templates/flpSandbox.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<!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="<%- templateModel.ui5.libs %>"
data-sap-ui-async="true"
data-sap-ui-preload="async"
data-sap-ui-theme="<%- templateModel.ui5.theme %>"
data-sap-ui-compat-version="edge"
data-sap-ui-language="en"
data-sap-ui-oninit="module:Init"
data-sap-ui-resource-roots='{"<%- templateModel.component %>": "../"}'
data-sap-ui-frame-options="allow"> // NON-SECURE setting for testing environment
</script>

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

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

</html>
Loading