Skip to content

Commit

Permalink
require sap ushell
Browse files Browse the repository at this point in the history
  • Loading branch information
schreckstefan committed Jul 25, 2024
1 parent ed9c37d commit c053827
Showing 1 changed file with 60 additions and 59 deletions.
119 changes: 60 additions & 59 deletions packages/preview-middleware-client/src/flp/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,74 +243,75 @@ export async function init({
customInit?: string | null;
}): Promise<void> {
const urlParams = new URLSearchParams(window.location.search);
const container = sap?.ushell?.Container ?? (sap.ui.require('sap/ushell/Container') as typeof sap.ushell.Container);
let scenario: string = '';
const { version } = (await VersionInfo.load()) as { version: string };
// Register RTA if configured
if (flex) {
const flexSettings = JSON.parse(flex) as FlexSettings;
scenario = flexSettings.scenario;
container.attachRendererCreatedEvent(async function () {
const lifecycleService = await container.getServiceAsync<AppLifeCycle>('AppLifeCycle');
lifecycleService.attachAppLoaded((event) => {
const minor = parseInt(version.split('.')[1], 10);
const view = event.getParameter('componentInstance');
const flexSettings = JSON.parse(flex) as FlexSettings;
const pluginScript = flexSettings.pluginScript ?? '';
sap.ui.require(['sap/ushell/Container'], async function (container: typeof sap.ushell.Container) {

This comment has been minimized.

Copy link
@tobiasqueck

tobiasqueck Jul 26, 2024

Contributor

That won't work in old UI5 versions

let scenario: string = '';
const { version } = (await VersionInfo.load()) as { version: string };
// Register RTA if configured
if (flex) {
const flexSettings = JSON.parse(flex) as FlexSettings;
scenario = flexSettings.scenario;
container.attachRendererCreatedEvent(async function () {
const lifecycleService = await container.getServiceAsync<AppLifeCycle>('AppLifeCycle');
lifecycleService.attachAppLoaded((event) => {
const minor = parseInt(version.split('.')[1], 10);
const view = event.getParameter('componentInstance');
const flexSettings = JSON.parse(flex) as FlexSettings;
const pluginScript = flexSettings.pluginScript ?? '';

let libs: string[] = [];
if (minor > 71) {
libs.push('sap/ui/rta/api/startAdaptation');
} else {
libs.push('open/ux/preview/client/flp/initRta');
}
let libs: string[] = [];
if (minor > 71) {
libs.push('sap/ui/rta/api/startAdaptation');
} else {
libs.push('open/ux/preview/client/flp/initRta');
}

if (flexSettings.pluginScript) {
libs.push(pluginScript as string);
delete flexSettings.pluginScript;
}
if (flexSettings.pluginScript) {
libs.push(pluginScript as string);
delete flexSettings.pluginScript;
}

const options: RTAOptions = {
rootControl: view,
validateAppVersion: false,
flexSettings
};
const options: RTAOptions = {
rootControl: view,
validateAppVersion: false,
flexSettings
};

sap.ui.require(
libs,
async function (startAdaptation: StartAdaptation | InitRtaScript, pluginScript: RTAPlugin) {
await startAdaptation(options, pluginScript);
}
);
sap.ui.require(
libs,
async function (startAdaptation: StartAdaptation | InitRtaScript, pluginScript: RTAPlugin) {
await startAdaptation(options, pluginScript);
}
);
});
});
});
}
}

// reset app state if requested
if (urlParams.get('fiori-tools-iapp-state')?.toLocaleLowerCase() !== 'true') {
await resetAppState(container);
}
// reset app state if requested
if (urlParams.get('fiori-tools-iapp-state')?.toLocaleLowerCase() !== 'true') {
await resetAppState(container);
}

// Load custom library paths if configured
if (appUrls) {
await registerComponentDependencyPaths(JSON.parse(appUrls), urlParams);
}
// Load custom library paths if configured
if (appUrls) {
await registerComponentDependencyPaths(JSON.parse(appUrls), urlParams);
}

// Load custom initialization module
if (customInit) {
sap.ui.require([customInit]);
}
// Load custom initialization module
if (customInit) {
sap.ui.require([customInit]);
}

// init
const resourceBundle = await loadI18nResourceBundle(scenario as Scenario);
setI18nTitle(resourceBundle);
registerSAPFonts();
const major = version ? parseInt(version.split('.')[0], 10) : 2;
const renderer =
major < 2
? await container.createRenderer(undefined, true)
: await (container as any).createRendererInternal(undefined, true);
renderer.placeAt('content');
// init
const resourceBundle = await loadI18nResourceBundle(scenario as Scenario);
setI18nTitle(resourceBundle);
registerSAPFonts();
const major = version ? parseInt(version.split('.')[0], 10) : 2;
const renderer =
major < 2
? await container.createRenderer(undefined, true)
: await (container as any).createRendererInternal(undefined, true);
renderer.placeAt('content');
});
}

const bootstrapConfig = document.getElementById('sap-ui-bootstrap');
Expand Down

0 comments on commit c053827

Please sign in to comment.