Skip to content

Commit

Permalink
chore: enable compliance with SAPUI5 2.0 (#269)
Browse files Browse the repository at this point in the history
* chore: enable compliance with SAPUI5 2.0

* chore: inprove retreival of version and buildTimestamp
  • Loading branch information
kineticjs authored Sep 27, 2024
1 parent f8b5edd commit 99f13a4
Show file tree
Hide file tree
Showing 5 changed files with 367 additions and 90 deletions.
47 changes: 24 additions & 23 deletions app/scripts/injected/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ sap.ui.require(['ToolsAPI'], function (ToolsAPI) {

if (isMutationValid === true) {
controlTreeModel = ToolsAPI.getRenderedControlTree();
commonInformation = ToolsAPI.getFrameworkInformation().commonInformation;

message.send({
action: 'on-application-dom-update',
controlTree: controlUtils.getControlTreeModel(controlTreeModel, commonInformation)
ToolsAPI.getFrameworkInformation().then(function(frameworkInformation) {
commonInformation = frameworkInformation.commonInformation;
message.send({
action: 'on-application-dom-update',
controlTree: controlUtils.getControlTreeModel(controlTreeModel, commonInformation)
});
});
}
}),
Expand Down Expand Up @@ -93,25 +94,25 @@ sap.ui.require(['ToolsAPI'], function (ToolsAPI) {
*/
'get-initial-information': function () {
var controlTreeModel = ToolsAPI.getRenderedControlTree();
var frameworkInformation = ToolsAPI.getFrameworkInformation();

message.send({
action: 'on-receiving-initial-data',
applicationInformation: applicationUtils.getApplicationInfo(frameworkInformation),
controlTree: controlUtils.getControlTreeModel(controlTreeModel, frameworkInformation.commonInformation),
elementRegistry: ToolsAPI.getRegisteredElements()
ToolsAPI.getFrameworkInformation().then(function(frameworkInformation) {
message.send({
action: 'on-receiving-initial-data',
applicationInformation: applicationUtils.getApplicationInfo(frameworkInformation),
controlTree: controlUtils.getControlTreeModel(controlTreeModel, frameworkInformation.commonInformation),
elementRegistry: ToolsAPI.getRegisteredElements()
});
});
},

/**
* Send framework information.
*/
'get-framework-information': function () {
var frameworkInformation = ToolsAPI.getFrameworkInformation();

message.send({
action: 'on-framework-information',
frameworkInformation: applicationUtils.getInformationForPopUp(frameworkInformation)
ToolsAPI.getFrameworkInformation().then(function(frameworkInformation) {
message.send({
action: 'on-framework-information',
frameworkInformation: applicationUtils.getInformationForPopUp(frameworkInformation)
});
});
},

Expand All @@ -121,7 +122,7 @@ sap.ui.require(['ToolsAPI'], function (ToolsAPI) {
*/
'do-console-log-event-listener': function (event) {
var evtData = event.detail.data;
console.log(sap.ui.getCore().byId(evtData.controlId).mEventRegistry[evtData.eventName][evtData.listenerIndex].fFunction);
console.log(controlUtils.getElementById(evtData.controlId).mEventRegistry[evtData.eventName][evtData.listenerIndex].fFunction);
},

/**
Expand Down Expand Up @@ -196,7 +197,7 @@ sap.ui.require(['ToolsAPI'], function (ToolsAPI) {
'do-control-property-change': function (event) {
var oData = event.detail.data;
var sControlId = oData.controlId;
var oControl = sap.ui.getCore().byId(sControlId);
var oControl = controlUtils.getElementById(sControlId);

if (!oControl) {
return;
Expand All @@ -215,7 +216,7 @@ sap.ui.require(['ToolsAPI'], function (ToolsAPI) {
'do-control-invalidate': function (event) {
var oData = event.detail.data;
var sControlId = oData.controlId;
var oControl = sap.ui.getCore().byId(sControlId);
var oControl = controlUtils.getElementById(sControlId);

if (!oControl) {
return;
Expand All @@ -234,7 +235,7 @@ sap.ui.require(['ToolsAPI'], function (ToolsAPI) {
'do-control-focus': function (event) {
var oData = event.detail.data;
var sControlId = oData.controlId;
var oControl = sap.ui.getCore().byId(sControlId);
var oControl = controlUtils.getElementById(sControlId);

if (!oControl) {
return;
Expand All @@ -251,7 +252,7 @@ sap.ui.require(['ToolsAPI'], function (ToolsAPI) {
'do-control-property-change-elements-registry': function (event) {
var oData = event.detail.data;
var sControlId = oData.controlId;
var oControl = sap.ui.getCore().byId(sControlId);
var oControl = controlUtils.getElementById(sControlId);

if (!oControl) {
return;
Expand Down Expand Up @@ -303,7 +304,7 @@ sap.ui.require(['ToolsAPI'], function (ToolsAPI) {
'do-copy-control-to-console': function (event) {
var oData = event.detail.data;
var sControlId = oData.controlId;
const control = sap.ui.getCore().byId(sControlId);
const control = controlUtils.getElementById(sControlId);
if (control) {
try {
const tempVarName = ui5Temp[sControlId] && ui5Temp[sControlId].savedAs || `ui5$${tempVarCount++}`;
Expand Down
28 changes: 25 additions & 3 deletions app/scripts/modules/injected/controlUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ function _assembleDataToView(options) {
return object;
}

/**
* Returns the registered element with the given ID, if any.
* @param {sap.ui.core.ID|null|undefined} sId ID of the element to search for
* @returns {sap.ui.core.Element|undefined} Element with the given ID or <code>undefined</code>
*/
function _getElementById(sId) {
var Element = sap.ui.require('sap/ui/core/Element');
if (typeof Element.getElementById === 'function') {
return Element.getElementById(sId);
}
if (typeof sap.ui.getCore === 'function' && typeof sap.ui.getCore().byId === 'function') {
return sap.ui.getCore().byId(sId);
}
}

/**
* Create a clickable value for the DataView.
* @param {Object} options
Expand Down Expand Up @@ -227,7 +242,7 @@ var controlProperties = (function () {
*/
function _formatTypes (type) {
var objectType;
if (type.startsWith('sap.') && sap.ui.base.DataType.getType(type).getDefaultValue()) {
if (type.startsWith('sap.') && sap.ui.require('sap/ui/base/DataType').getType(type).getDefaultValue()) {
objectType = _transformStringTypeToObject(type);
} else {
objectType = type;
Expand Down Expand Up @@ -308,7 +323,7 @@ var controlProperties = (function () {
* @private
*/
function _getControlPropertiesAssociations(controlId, properties) {
var control = sap.ui.getCore().byId(controlId);
var control = _getElementById(controlId);

if (!control) {
return;
Expand Down Expand Up @@ -879,5 +894,12 @@ module.exports = {
}
}
};
}
},

/**
* Returns UI5 element, given its id.
* @param {string} sId
* @returns {Object}
*/
getElementById: _getElementById
};
2 changes: 2 additions & 0 deletions app/scripts/modules/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ function _convertUI5TimeStampToHumanReadableFormat(timeStamp) {
return;
}

timeStamp = timeStamp.replace(/-/g, '');

// Year
formattedTime += timeStamp.substr(0, 4) + '/';
// Month
Expand Down
Loading

0 comments on commit 99f13a4

Please sign in to comment.