From 5a56c912abe9637031fbfe6744d620fc8ec23075 Mon Sep 17 00:00:00 2001 From: I568346 Date: Fri, 22 Nov 2024 17:51:43 +0530 Subject: [PATCH 01/12] feat: Ensuring UI5 2.x compliance for cards-editor-middleware Plugin --- .../cards-editor-middleware/templates/Init.js | 87 +++++++++++++++++++ .../templates/editor.html | 79 +---------------- 2 files changed, 88 insertions(+), 78 deletions(-) create mode 100644 packages/cards-editor-middleware/templates/Init.js diff --git a/packages/cards-editor-middleware/templates/Init.js b/packages/cards-editor-middleware/templates/Init.js new file mode 100644 index 0000000000..9aa21ca7bc --- /dev/null +++ b/packages/cards-editor-middleware/templates/Init.js @@ -0,0 +1,87 @@ +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) => { + sap.ui.require(["sap/ushell/Container"], async function (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/ui/core/Core"], (Core) => { + console.log("Init.js loaded"); + debugger; + Core.ready().then(function() { + sap.ui.require("sap/ushell/Container").attachRendererCreatedEvent(function() { + 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; + + 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){ + oRenderer.placeAt("content"); + }); + }); + console.log("Init.js loaded"); +}); + + diff --git a/packages/cards-editor-middleware/templates/editor.html b/packages/cards-editor-middleware/templates/editor.html index 358b6688c4..a284a722ff 100644 --- a/packages/cards-editor-middleware/templates/editor.html +++ b/packages/cards-editor-middleware/templates/editor.html @@ -50,84 +50,7 @@ // NON-SECURE setting for testing environment - + From c82633205722c4d4ab710730bf0c4e4901dc3be4 Mon Sep 17 00:00:00 2001 From: I568346 Date: Mon, 25 Nov 2024 17:32:47 +0530 Subject: [PATCH 02/12] Adding changes for review comments and removing console logs and debugger statements --- packages/cards-editor-middleware/src/index.ts | 2 +- .../cards-editor-middleware/templates/Init.js | 2 - .../templates/flpSandbox.html | 59 +++++++++++++++++++ 3 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 packages/cards-editor-middleware/templates/flpSandbox.html diff --git a/packages/cards-editor-middleware/src/index.ts b/packages/cards-editor-middleware/src/index.ts index 744c7773cd..52b1a740b5 100644 --- a/packages/cards-editor-middleware/src/index.ts +++ b/packages/cards-editor-middleware/src/index.ts @@ -48,7 +48,7 @@ module.exports = async ({ resources }: MiddlewareParameters): Promise { 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 diff --git a/packages/cards-editor-middleware/templates/Init.js b/packages/cards-editor-middleware/templates/Init.js index 9aa21ca7bc..fac874d677 100644 --- a/packages/cards-editor-middleware/templates/Init.js +++ b/packages/cards-editor-middleware/templates/Init.js @@ -51,7 +51,6 @@ function addCardGenerationUserAction(oComponentInstance) { sap.ui.require(["sap/ui/core/Core"], (Core) => { console.log("Init.js loaded"); - debugger; Core.ready().then(function() { sap.ui.require("sap/ushell/Container").attachRendererCreatedEvent(function() { sap.ui.require("sap/ushell/Container").getServiceAsync('AppLifeCycle').then((serviceInstance) => { @@ -81,7 +80,6 @@ sap.ui.require(["sap/ui/core/Core"], (Core) => { oRenderer.placeAt("content"); }); }); - console.log("Init.js loaded"); }); diff --git a/packages/cards-editor-middleware/templates/flpSandbox.html b/packages/cards-editor-middleware/templates/flpSandbox.html new file mode 100644 index 0000000000..4f097d7eb5 --- /dev/null +++ b/packages/cards-editor-middleware/templates/flpSandbox.html @@ -0,0 +1,59 @@ + + + + + + + + + <%- templateModel.appTitle %> + + + + + + + + + + + + + + \ No newline at end of file From 8b3ac4f9243a07c3f85c6e8ec30950b33007cf36 Mon Sep 17 00:00:00 2001 From: I568346 Date: Mon, 25 Nov 2024 17:36:39 +0530 Subject: [PATCH 03/12] Removing console long statement --- packages/cards-editor-middleware/templates/Init.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/cards-editor-middleware/templates/Init.js b/packages/cards-editor-middleware/templates/Init.js index fac874d677..c653146105 100644 --- a/packages/cards-editor-middleware/templates/Init.js +++ b/packages/cards-editor-middleware/templates/Init.js @@ -50,7 +50,6 @@ function addCardGenerationUserAction(oComponentInstance) { } sap.ui.require(["sap/ui/core/Core"], (Core) => { - console.log("Init.js loaded"); Core.ready().then(function() { sap.ui.require("sap/ushell/Container").attachRendererCreatedEvent(function() { sap.ui.require("sap/ushell/Container").getServiceAsync('AppLifeCycle').then((serviceInstance) => { From d87fcc68737714f2592a650c0fe226d9d69ecc34 Mon Sep 17 00:00:00 2001 From: UBSusmitha <140173458+UBSusmitha@users.noreply.github.com> Date: Tue, 3 Dec 2024 14:58:41 +0530 Subject: [PATCH 04/12] Update packages/cards-editor-middleware/templates/Init.js Co-authored-by: Dominik Heim <73878785+heimwege@users.noreply.github.com> --- packages/cards-editor-middleware/templates/Init.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cards-editor-middleware/templates/Init.js b/packages/cards-editor-middleware/templates/Init.js index c653146105..05e4486514 100644 --- a/packages/cards-editor-middleware/templates/Init.js +++ b/packages/cards-editor-middleware/templates/Init.js @@ -61,7 +61,7 @@ sap.ui.require(["sap/ui/core/Core"], (Core) => { const sapCoreVersionInfo = await VersionInfo.load({ library: "sap.ui.core" }); - const sapCoreVersion = sapCoreVersionInfo && sapCoreVersionInfo.version; + 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."); From ceff10c6bf1f7b145f51b90a875349f417002dde Mon Sep 17 00:00:00 2001 From: UBSusmitha <140173458+UBSusmitha@users.noreply.github.com> Date: Tue, 3 Dec 2024 15:01:05 +0530 Subject: [PATCH 05/12] Update packages/cards-editor-middleware/templates/flpSandbox.html Co-authored-by: Dominik Heim <73878785+heimwege@users.noreply.github.com> --- .../cards-editor-middleware/templates/flpSandbox.html | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/cards-editor-middleware/templates/flpSandbox.html b/packages/cards-editor-middleware/templates/flpSandbox.html index 4f097d7eb5..466ce98482 100644 --- a/packages/cards-editor-middleware/templates/flpSandbox.html +++ b/packages/cards-editor-middleware/templates/flpSandbox.html @@ -44,10 +44,13 @@ From ed833d10e0510b126a4ac130ffe2efcc03f43934 Mon Sep 17 00:00:00 2001 From: I568346 Date: Wed, 4 Dec 2024 10:13:56 +0530 Subject: [PATCH 06/12] Adding changes for the review comments --- .../cards-editor-middleware/templates/Init.js | 91 +++++++++---------- .../templates/editor.html | 59 ------------ .../templates/flpSandbox.html | 3 +- 3 files changed, 46 insertions(+), 107 deletions(-) delete mode 100644 packages/cards-editor-middleware/templates/editor.html diff --git a/packages/cards-editor-middleware/templates/Init.js b/packages/cards-editor-middleware/templates/Init.js index 05e4486514..60e1b50824 100644 --- a/packages/cards-editor-middleware/templates/Init.js +++ b/packages/cards-editor-middleware/templates/Init.js @@ -24,60 +24,57 @@ function isLowerThanMinimalUi5Version(version, minVersion) { function addCardGenerationUserAction(oComponentInstance) { sap.ui.require([ - "sap/cards/ap/generator/CardGenerator" - ], (CardGenerator) => { - sap.ui.require(["sap/ushell/Container"], async function (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/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/ui/core/Core"], (Core) => { - Core.ready().then(function() { - sap.ui.require("sap/ushell/Container").attachRendererCreatedEvent(function() { - 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?.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.ui.require(["sap/ushell/Container"], (Container) => { + Container.attachRendererCreatedEvent(function() { + 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?.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.ui.require("sap/ushell/Container").createRenderer(true).then(function(oRenderer){ - oRenderer.placeAt("content"); - }); + }); + Container.createRenderer(true).then(function(oRenderer){ + oRenderer.placeAt("content"); }); }); diff --git a/packages/cards-editor-middleware/templates/editor.html b/packages/cards-editor-middleware/templates/editor.html deleted file mode 100644 index a284a722ff..0000000000 --- a/packages/cards-editor-middleware/templates/editor.html +++ /dev/null @@ -1,59 +0,0 @@ - - - - - - - - - <%- templateModel.appTitle %> - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/cards-editor-middleware/templates/flpSandbox.html b/packages/cards-editor-middleware/templates/flpSandbox.html index 466ce98482..ea6cce94f9 100644 --- a/packages/cards-editor-middleware/templates/flpSandbox.html +++ b/packages/cards-editor-middleware/templates/flpSandbox.html @@ -46,9 +46,10 @@ 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" data-sap-ui-async="true" data-sap-ui-preload="async" - data-sap-ui-theme="sap_horizon" + data-sap-ui-theme="<%- 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 From 9ff92b7a5a069a053ab31335f823226b47745bde Mon Sep 17 00:00:00 2001 From: I568346 Date: Wed, 4 Dec 2024 20:16:44 +0530 Subject: [PATCH 07/12] Adding changes for the review comments --- .../cards-editor-middleware/templates/Init.js | 35 ++++++++----------- .../templates/flpSandbox.html | 2 +- 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/packages/cards-editor-middleware/templates/Init.js b/packages/cards-editor-middleware/templates/Init.js index 60e1b50824..d5b59eb449 100644 --- a/packages/cards-editor-middleware/templates/Init.js +++ b/packages/cards-editor-middleware/templates/Init.js @@ -1,5 +1,5 @@ function parseUI5Version(version) { - const versionParts = version.replace(/snapshot-untested|snapshot-|snapshot/, '').split('.'); + const versionParts = version.split('.'); const major = parseInt(versionParts[0], 10); const minor = parseInt(versionParts[1], 10); @@ -8,7 +8,7 @@ function parseUI5Version(version) { function isLowerThanMinimalUi5Version(version, minVersion) { if (version && minVersion) { - const minVersionParsed = parseUI5Version(minVersion); + const minVersionParsed = { major: 1, minor: 121 }; const ui5VersionParsed = parseUI5Version(version); if (!isNaN(ui5VersionParsed.major) && !isNaN(ui5VersionParsed.minor)) { if (ui5VersionParsed.major < minVersionParsed.major) { @@ -48,32 +48,25 @@ function addCardGenerationUserAction(oComponentInstance) { }); } -sap.ui.require(["sap/ushell/Container"], (Container) => { +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) => { - sap.ui.require([ - "sap/m/MessageBox", - "sap/ui/VersionInfo" - ], async (MessageBox, VersionInfo) => { - 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); + 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.createRenderer(true).then(function(oRenderer){ + Container.createRendererInternal(undefined, true).then(function(oRenderer){ oRenderer.placeAt("content"); }); }); diff --git a/packages/cards-editor-middleware/templates/flpSandbox.html b/packages/cards-editor-middleware/templates/flpSandbox.html index ea6cce94f9..96097317de 100644 --- a/packages/cards-editor-middleware/templates/flpSandbox.html +++ b/packages/cards-editor-middleware/templates/flpSandbox.html @@ -43,7 +43,7 @@