// @ts-nocheck //Load the fake lrep connector only if ui5 version < 1.78 const version = sap.ui.version.split("."); if (Number.parseInt(version[0], 10) <= 1 && Number.parseInt(version[1], 10) < 78) { sap.ui.getCore().loadLibraries(["sap/ui/fl"]); sap.ui.require(["sap/ui/fl/FakeLrepConnector"], function (FakeLrepConnector) { jQuery.extend(FakeLrepConnector.prototype, { create: function (oChange) { return Promise.resolve(); }, stringToAscii: function (sCodeAsString) { if (!sCodeAsString || sCodeAsString.length === 0) { return ""; } const sAsciiString = ""; for (const i = 0; i < sCodeAsString.length; i++) { sAsciiString += sCodeAsString.charCodeAt(i) + ","; } if ( sAsciiString !== null && sAsciiString.length > 0 && sAsciiString.charAt(sAsciiString.length - 1) === "," ) { sAsciiString = sAsciiString.substring(0, sAsciiString.length - 1); } return sAsciiString; }, /* * Get the content of the sap-ui-cachebuster-info.json file * to get the paths to the changes files * and get their content */ loadChanges: function () { const oResult = { changes: [], settings: { isKeyUser: true, isAtoAvailable: false, isProductiveSystem: false } }; //Get the content of the changes folder. const aPromises = []; const sCacheBusterFilePath = "/sap-ui-cachebuster-info.json"; return new Promise(function (resolve, reject) { $.ajax({ url: sCacheBusterFilePath, type: "GET", cache: false }) .then(function (oCachebusterContent) { //we are looking for only change files const aChangeFilesPaths = Object.keys(oCachebusterContent).filter(function (sPath) { return sPath.endsWith(".change"); }); $.each(aChangeFilesPaths, function (index, sFilePath) { //now as we support MTA projects we need to take only changes which are relevant for //the current HTML5 module //sap-ui-cachebuster-info.json for MTA doesn"t start with "webapp/changes" but from //possible change file path patterns //webapp/changes/ ///webapp/changes/ if (sFilePath.indexOf("changes") === 0) { /*eslint-disable no-param-reassign*/ aPromises.push( $.ajax({ url: "/" + sFilePath, type: "GET", cache: false }).then(function (sChangeContent) { return JSON.parse(sChangeContent); }) ); } }); }) .always(function () { return Promise.all(aPromises).then(function (aChanges) { return new Promise(function (resolveInner, rejectInner) { // If no changes found, maybe because the app was executed without doing a build. // Check for changes folder and load the changes, if any. if (aChanges.length === 0) { $.ajax({ url: "/changes/", type: "GET", cache: false }) .then(function (sChangesFolderContent) { const regex = /(\/changes\/[^"]*\.[a-zA-Z]*)/g; const result = regex.exec(sChangesFolderContent); while (result !== null) { aPromises.push( $.ajax({ url: result[1], type: "GET", cache: false }).then(function (sChangeContent) { return JSON.parse(sChangeContent); }) ); result = regex.exec(sChangesFolderContent); } resolveInner(Promise.all(aPromises)); }) .fail(function (obj) { // No changes folder, then just resolve resolveInner(aChanges); }); } else { resolveInner(aChanges); } }).then(function (aCheckChanges) { const aChangePromises = [], aProcessedChanges = []; aCheckChanges.forEach(function (oChange) { const sChangeType = oChange.changeType; if (sChangeType === "addXML" || sChangeType === "codeExt") { /*eslint-disable no-nested-ternary*/ const sPath = sChangeType === "addXML" ? oChange.content.fragmentPath : sChangeType === "codeExt" ? oChange.content.codeRef : ""; const sWebappPath = sPath.match(/webapp(.*)/); const sUrl = "/" + sWebappPath[0]; aChangePromises.push( $.ajax({ url: sUrl, type: "GET", cache: false }).then(function (oFileDocument) { if (sChangeType === "addXML") { oChange.content.fragment = FakeLrepConnector.prototype.stringToAscii( oFileDocument.documentElement.outerHTML ); oChange.content.selectedFragmentContent = oFileDocument.documentElement.outerHTML; } else if (sChangeType === "codeExt") { oChange.content.code = FakeLrepConnector.prototype.stringToAscii( oFileDocument ); oChange.content.extensionControllerContent = oFileDocument; } return oChange; }) ); } else { aProcessedChanges.push(oChange); } }); // aChanges holds the content of all change files from the project (empty array if no such files) // sort the array by the creation timestamp of the changes if (aChangePromises.length > 0) { return Promise.all(aChangePromises).then(function (aUpdatedChanges) { aUpdatedChanges.forEach(function (oChange) { aProcessedChanges.push(oChange); }); aProcessedChanges.sort(function (change1, change2) { return new Date(change1.creation) - new Date(change2.creation); }); oResult.changes = aProcessedChanges; const oLrepChange = { changes: oResult, componentClassName: "<%- app.id %>" }; resolve(oLrepChange); }); } else { aProcessedChanges.sort(function (change1, change2) { return new Date(change1.creation) - new Date(change2.creation); }); oResult.changes = aProcessedChanges; const oLrepChange = { changes: oResult, componentClassName: "<%- app.id %>" }; resolve(oLrepChange); } }); }); }); }); } }); FakeLrepConnector.enableFakeConnector(); }); }