<script src="../../../changes_preview.js"></script>
<script>(function(){
document.addEventListener("load",function(e){
if("OpaFrame"===e.target.id){
var t=document.getElementById("OpaFrame").contentWindow.document,
n=t.createElement("script");
n.type="text/javascript",n.innerHTML="sap.ui.getCore().loadLibrary('sap.ui.fl');
jQuery.getScript('../../../changes_preview.js')",t.head.appendChild(n)
}
},!0)
})()
</script>
//This file used only for loading the changes in the webide preview and not required to be checked in.
//Load the fake lrep connector
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 "";
}
var sAsciiString = "";
for (var 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 () {
var oResult = {
"changes": [],
"settings": {
"isKeyUser": true,
"isAtoAvailable": false,
"isProductiveSystem": false
}
};
//Get the content of the changes folder.
var aPromises = [];
var sCacheBusterFilePath = "/sap-ui-cachebuster-info.json";
/*eslint-disable promise/avoid-new*/
/*eslint-disable promise/catch-or-return*/
/*eslint-disable promise/always-return*/
/*eslint-disable promise/no-nesting*/
/*eslint-disable consistent-return*/
/*eslint-disable xss/no-mixed-html*/
return new Promise(function (resolve, reject) {
$.ajax({
url: window.location.origin + sCacheBusterFilePath,
type: "GET",
cache: false
}).then(function (oCachebusterContent) {
//we are looking for only change files
var 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 <MTA-HTML5-MODULE-NAME>
//possible change file path patterns
//webapp/changes/<change-file>
//<MTA-HTML5-MODULE-NAME>/webapp/changes/<change-file>
var sChangesRelativePathIndex = sFilePath.indexOf("webapp/changes");
if (sChangesRelativePathIndex > 0 && sFilePath.split("/")[0] !== "your.project.name.on.git") {
return true;
} else {
sFilePath = sFilePath.slice(sChangesRelativePathIndex);
/*eslint-disable no-param-reassign*/
aPromises.push(
$.ajax({
url: window.location.origin + "/" + sFilePath,
type: "GET",
cache: false
}).then(function (sChangeContent) {
return JSON.parse(sChangeContent);
})
);
}
});
}).always(function () {
return Promise.all(aPromises).then(function (aChanges) {
var aChangePromises = [],
aProcessedChanges = [];
aChanges.forEach(function (oChange) {
var sChangeType = oChange.changeType;
if (sChangeType === "addXML" || sChangeType === "codeExt") {
/*eslint-disable no-nested-ternary*/
var sPath = sChangeType === "addXML" ? oChange.content.fragmentPath : sChangeType === "codeExt" ? oChange.content.codeRef :
"";
var sWebappPath = sPath.match(/webapp(.*)/);
var 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;
var oLrepChange = {
changes: oResult,
componentClassName: "your.project.name.on.git"
};
resolve(oLrepChange);
});
} else {
aProcessedChanges.sort(function (change1, change2) {
return new Date(change1.creation) - new Date(change2.creation);
});
oResult.changes = aProcessedChanges;
var oLrepChange = {
changes: oResult,
componentClassName: "your.project.name.on.git"
};
resolve(oLrepChange);
}
});
});
});
}
});
FakeLrepConnector.enableFakeConnector();
});
<script type="text/javascript">
sap.ui.getCore().attachInit(function() {
//----------------8<----------------------------------------------------------------------------------
sap.ui.require(["sap/ui/fl/FakeLrepConnector", "your/project/name/on/git/localService/mockserver"], function (FakeLrepConnector, server) {
jQuery.extend(FakeLrepConnector.prototype, {
create: function (oChange) {
return Promise.resolve();
},
stringToAscii: function (sCodeAsString) {
if (!sCodeAsString || sCodeAsString.length === 0) {
return "";
}
var sAsciiString = "";
for (var 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 () {
var oResult = {
"changes": [],
"settings": {
"isKeyUser": true,
"isAtoAvailable": false,
"isProductiveSystem": false
}
};
//Get the current path, most efficient way:
var fullPath = window.location.href;
//Remove the file to get the current directory
//this is because Jenkins removes the webapp file, and so
//I had to find a way around it: I copied the changes folder
//in the same directory as this file, and took the path to
//this folder by taking window.location.href, bypassing a
//hardcoded "webapp" folder in my path.
var divByFolders = fullPath.split("/");
var extractedString = divByFolders[divByFolders.length - 1];
//Get the current directory we are in
fullPath = fullPath.replace(extractedString, '');
//Dont forget the trailing / at the end of the path
//console.log("Full path: "+fullPath);
//Get the content of the changes folder.
var aPromises = [];
//copied this from sap-ui-cachebuster-info.json. You can access
//that file in SAP Web IDE by creating a new file and naming it
//"sap-ui-cachebuster-info.json", and all the content of that file
//will appear.
//otherwise do them one by one. NOTE: the reason I start from
//the changes directory is because I copied the changes into the
//same folder as this file.
var paths = {
"changes/a.change": 1552336604000,
"changes/b.change": 1552336602000,
};
return new Promise(function (resolve, reject) {
var aChangeFilesPaths = Object.keys(paths).filter(function (sPath) {
return sPath.endsWith(".change");
});
//creating a counter to know how many calls were COMPLETED
var completedCalls = 0;
//my function to callback
function callback(){
//sorts the changes based on their date of creation.
aPromises.sort(function(change1, change2){
return new Date(change1.creation) - new Date(change2.creation);
});
oResult.changes = aPromises;
var oLrepChange = {
changes: oResult,
componentClassName: "your.project.name.on.git"
};
resolve(oLrepChange);
}
$.each(aChangeFilesPaths, function (index, sFilePath) {
//this pushes into aPromises new information once the ajax call has been resolved.
$.ajax({
url: fullPath + sFilePath,
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
'dataType': 'json',
type: "GET",
cache: false,
}).then(function (sChangeContent) {
//console.log(sChangeContent);
aPromises.push(JSON.parse(JSON.stringify(sChangeContent)));
completedCalls+=1;
//once all AJAX calls are completed, call the callback.
//this number will have to be modified depending on
//the number of changes that are in the project.
if (completedCalls === Object.keys(paths).length){
callback();
}
})
});
})
}
});
FakeLrepConnector.enableFakeConnector();
//initialize the server. put it in same sap.ui.require as the FakeLrep object.
server.init();
// initialize the ushell sandbox component
sap.ushell.Container.createRenderer().placeAt("content");
});
//-------------------------8<--------------------------------------------------------------------------
});
</script>
jQuery.sap.require("sap.ui.fl.FakeLrepConnector");
sap.ui.fl.FakeLrepConnector.enableFakeConnector("fakeLRep.json");
sap.ui.require([
"your/git/repo/localService/mockserver"
], function (server) {
// set up test service for local testing
server.init();
// initialize the ushell sandbox component
sap.ushell.Container.createRenderer().placeAt("content");
});
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
37 | |
25 | |
17 | |
13 | |
7 | |
7 | |
7 | |
6 | |
6 | |
6 |