Skip to content

Commit 99f13a4

Browse files
authored
chore: enable compliance with SAPUI5 2.0 (#269)
* chore: enable compliance with SAPUI5 2.0 * chore: inprove retreival of version and buildTimestamp
1 parent f8b5edd commit 99f13a4

File tree

5 files changed

+367
-90
lines changed

5 files changed

+367
-90
lines changed

app/scripts/injected/main.js

+24-23
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,12 @@ sap.ui.require(['ToolsAPI'], function (ToolsAPI) {
4646

4747
if (isMutationValid === true) {
4848
controlTreeModel = ToolsAPI.getRenderedControlTree();
49-
commonInformation = ToolsAPI.getFrameworkInformation().commonInformation;
50-
51-
message.send({
52-
action: 'on-application-dom-update',
53-
controlTree: controlUtils.getControlTreeModel(controlTreeModel, commonInformation)
49+
ToolsAPI.getFrameworkInformation().then(function(frameworkInformation) {
50+
commonInformation = frameworkInformation.commonInformation;
51+
message.send({
52+
action: 'on-application-dom-update',
53+
controlTree: controlUtils.getControlTreeModel(controlTreeModel, commonInformation)
54+
});
5455
});
5556
}
5657
}),
@@ -93,25 +94,25 @@ sap.ui.require(['ToolsAPI'], function (ToolsAPI) {
9394
*/
9495
'get-initial-information': function () {
9596
var controlTreeModel = ToolsAPI.getRenderedControlTree();
96-
var frameworkInformation = ToolsAPI.getFrameworkInformation();
97-
98-
message.send({
99-
action: 'on-receiving-initial-data',
100-
applicationInformation: applicationUtils.getApplicationInfo(frameworkInformation),
101-
controlTree: controlUtils.getControlTreeModel(controlTreeModel, frameworkInformation.commonInformation),
102-
elementRegistry: ToolsAPI.getRegisteredElements()
97+
ToolsAPI.getFrameworkInformation().then(function(frameworkInformation) {
98+
message.send({
99+
action: 'on-receiving-initial-data',
100+
applicationInformation: applicationUtils.getApplicationInfo(frameworkInformation),
101+
controlTree: controlUtils.getControlTreeModel(controlTreeModel, frameworkInformation.commonInformation),
102+
elementRegistry: ToolsAPI.getRegisteredElements()
103+
});
103104
});
104105
},
105106

106107
/**
107108
* Send framework information.
108109
*/
109110
'get-framework-information': function () {
110-
var frameworkInformation = ToolsAPI.getFrameworkInformation();
111-
112-
message.send({
113-
action: 'on-framework-information',
114-
frameworkInformation: applicationUtils.getInformationForPopUp(frameworkInformation)
111+
ToolsAPI.getFrameworkInformation().then(function(frameworkInformation) {
112+
message.send({
113+
action: 'on-framework-information',
114+
frameworkInformation: applicationUtils.getInformationForPopUp(frameworkInformation)
115+
});
115116
});
116117
},
117118

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

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

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

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

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

256257
if (!oControl) {
257258
return;
@@ -303,7 +304,7 @@ sap.ui.require(['ToolsAPI'], function (ToolsAPI) {
303304
'do-copy-control-to-console': function (event) {
304305
var oData = event.detail.data;
305306
var sControlId = oData.controlId;
306-
const control = sap.ui.getCore().byId(sControlId);
307+
const control = controlUtils.getElementById(sControlId);
307308
if (control) {
308309
try {
309310
const tempVarName = ui5Temp[sControlId] && ui5Temp[sControlId].savedAs || `ui5$${tempVarCount++}`;

app/scripts/modules/injected/controlUtils.js

+25-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,21 @@ function _assembleDataToView(options) {
2525
return object;
2626
}
2727

28+
/**
29+
* Returns the registered element with the given ID, if any.
30+
* @param {sap.ui.core.ID|null|undefined} sId ID of the element to search for
31+
* @returns {sap.ui.core.Element|undefined} Element with the given ID or <code>undefined</code>
32+
*/
33+
function _getElementById(sId) {
34+
var Element = sap.ui.require('sap/ui/core/Element');
35+
if (typeof Element.getElementById === 'function') {
36+
return Element.getElementById(sId);
37+
}
38+
if (typeof sap.ui.getCore === 'function' && typeof sap.ui.getCore().byId === 'function') {
39+
return sap.ui.getCore().byId(sId);
40+
}
41+
}
42+
2843
/**
2944
* Create a clickable value for the DataView.
3045
* @param {Object} options
@@ -227,7 +242,7 @@ var controlProperties = (function () {
227242
*/
228243
function _formatTypes (type) {
229244
var objectType;
230-
if (type.startsWith('sap.') && sap.ui.base.DataType.getType(type).getDefaultValue()) {
245+
if (type.startsWith('sap.') && sap.ui.require('sap/ui/base/DataType').getType(type).getDefaultValue()) {
231246
objectType = _transformStringTypeToObject(type);
232247
} else {
233248
objectType = type;
@@ -308,7 +323,7 @@ var controlProperties = (function () {
308323
* @private
309324
*/
310325
function _getControlPropertiesAssociations(controlId, properties) {
311-
var control = sap.ui.getCore().byId(controlId);
326+
var control = _getElementById(controlId);
312327

313328
if (!control) {
314329
return;
@@ -879,5 +894,12 @@ module.exports = {
879894
}
880895
}
881896
};
882-
}
897+
},
898+
899+
/**
900+
* Returns UI5 element, given its id.
901+
* @param {string} sId
902+
* @returns {Object}
903+
*/
904+
getElementById: _getElementById
883905
};

app/scripts/modules/utils/utils.js

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ function _convertUI5TimeStampToHumanReadableFormat(timeStamp) {
4242
return;
4343
}
4444

45+
timeStamp = timeStamp.replace(/-/g, '');
46+
4547
// Year
4648
formattedTime += timeStamp.substr(0, 4) + '/';
4749
// Month

0 commit comments

Comments
 (0)