Skip to content

Commit

Permalink
feat: show XML of XMLViews in elements registry (#205)
Browse files Browse the repository at this point in the history
* feat: show XML of XMLViews in elements registry

* feat: added cursor pointer style to editorAlt
  • Loading branch information
erlethor authored Dec 1, 2022
1 parent 9a872ff commit cf996d9
Show file tree
Hide file tree
Showing 9 changed files with 174 additions and 6 deletions.
4 changes: 4 additions & 0 deletions app/html/panel/ui5/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
</tab>
<tab id="elements-registry-tab-aggregations">Aggregations</tab>
<tab id="elements-registry-tab-events">Events</tab>
<tab id="elements-registry-tab-xmlview">XML View</tab>
</tabs>
<contents>
<content for="elements-registry-tab-properties">
Expand All @@ -140,6 +141,9 @@
<content for="elements-registry-tab-events">
<data-view id="elements-registry-control-events"></data-view>
</content>
<content for="elements-registry-tab-xmlview">
<xml-view id="elements-registry-control-xmlview"></xml-view>
</content>
</contents>
</tabbar>
<!-- Control tree tabbar /end-->
Expand Down
4 changes: 4 additions & 0 deletions app/scripts/devtools/panel/ui5/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
var Splitter = require('../../../modules/ui/SplitContainer.js');
var ODataDetailView = require('../../../modules/ui/ODataDetailView.js');
var ODataMasterView = require('../../../modules/ui/ODataMasterView.js');
var XMLDetailView = require('../../../modules/ui/XMLDetailView.js');
var OElementsRegistryMasterView = require('../../../modules/ui/OElementsRegistryMasterView.js');

// Apply theme
Expand Down Expand Up @@ -220,7 +221,10 @@
}
});

// XML visualization for XML Views
var oXMLDetailView = new XMLDetailView('elements-registry-control-xmlview');
var oElementsRegistryMasterView = new OElementsRegistryMasterView('elements-registry-tab-master', {
XMLDetailView: oXMLDetailView,
/**
* Method fired when a Control is selected.
* @param {string} sControlId
Expand Down
2 changes: 2 additions & 0 deletions app/scripts/modules/ui/OElementsRegistryMasterView.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ function OElementsRegistryMasterView(domId, options) {

this.oContainerDOM = document.getElementById(domId);
this.sNotSupportedMessage = '<h1>Current version of OpenUI5/SAPUI5 doesn\'t support element registry</h1>';
this.XMLDetailView = options.XMLDetailView;

/**
* Selects an element.
Expand Down Expand Up @@ -522,6 +523,7 @@ OElementsRegistryMasterView.prototype.sortHandler = function () {
*/
OElementsRegistryMasterView.prototype.selectHandler = function (oEvent) {
this.onSelectItem(oEvent.data._data.id);
this.XMLDetailView.update(oEvent.data._data);
this._sSelectedItem = oEvent.data._data.id;
};

Expand Down
85 changes: 85 additions & 0 deletions app/scripts/modules/ui/XMLDetailView.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/* globals ResizeObserver */

'use strict';
const formatXML = require('prettify-xml');
const NOXMLVIEWMESSAGE = 'Select a \'sap.ui.core.mvc.XMLView\' to see its XML content. Click to filter on XMLViews';

/**
* @param {string} containerId - id of the DOM container
* @constructor
*/
function XMLDetailView(containerId) {
this.oContainer = document.getElementById(containerId);
this.oEditorDOM = document.createElement('div');
this.oEditorDOM.id = 'xmlEditor';
this.oEditorDOM.classList.toggle('hidden', true);
this.oContainer.appendChild(this.oEditorDOM);

this.oEditorAltDOM = document.createElement('div');
this.oEditorAltDOM.classList.add('editorAlt');
this.oEditorAltDOM.classList.toggle('hidden', false);
this.oEditorAltMessageDOM = document.createElement('div');
this.oEditorAltMessageDOM.innerText = NOXMLVIEWMESSAGE;

this.oEditorAltMessageDOM.addEventListener('click', function() {
var searchField = document.getElementById('elementsRegistrySearch');
var filterCheckbox = document.getElementById('elementsRegistryCheckbox');
searchField.value = 'sap.ui.core.mvc.XMLView';
if (!filterCheckbox.checked) {
filterCheckbox.click();
}
return false;
});
this.oContainer.appendChild(this.oEditorAltDOM);
this.oEditorAltDOM.appendChild(this.oEditorAltMessageDOM);

this.oEditor = ace.edit(this.oEditorDOM.id);
this.oEditor.getSession().setUseWrapMode(true);

this._setTheme();

const oResizeObserver = new ResizeObserver(function () {
this.oEditor.resize();
}.bind(this));
oResizeObserver.observe(this.oEditorDOM);
}

/**
* Updates data.
* @param {Object} data - object structure as JSON
*/
XMLDetailView.prototype.update = function (data) {
const xml = data.xml && formatXML(data.xml);
let sAltMessage;

this.oEditorDOM.classList.toggle('hidden', !xml);
this.oEditorAltDOM.classList.toggle('hidden', !!xml);

if (xml) {
this.oEditor.session.setMode('ace/mode/xml');
this.oEditor.setValue(xml, 0);
} else {
sAltMessage = data.altMessage || NOXMLVIEWMESSAGE;
this.oEditorAltMessageDOM.innerText = sAltMessage;
}

this.oEditor.clearSelection();
};

/**
* Clears editor.
*/
XMLDetailView.prototype.clear = function () {
this.oEditor.setValue('', -1);
};

/**
* Sets theme.
*/
XMLDetailView.prototype._setTheme = function () {
var bDarkMode = chrome.devtools.panels.themeName === 'dark';

this.oEditor.setTheme(bDarkMode ? 'ace/theme/vibrant_ink' : 'ace/theme/chrome');
};

module.exports = XMLDetailView;
26 changes: 26 additions & 0 deletions app/styles/less/modules/XMLView.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
xml-view {
height: 100%;
}

#elements-registry-control-xmlview {
.editorAlt {
display: flex;
div {
margin: auto;
cursor: pointer;
}
}

div.hidden {
visibility: hidden;
}

.editorAlt, #xmlEditor {
position: absolute;
top: 25px;
left: 0;
right: 0;
bottom: 0;
height: auto;
}
}
1 change: 1 addition & 0 deletions app/styles/less/themes/base/base.less
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
@import "../../modules/SplitContainer.less";
@import "../../modules/JSONView.less";
@import "../../modules/ODataView.less";
@import "../../modules/XMLView.less";
@import "../../modules/DataGrid.less";
@import "../../modules/ElementsRegistry.less";

14 changes: 8 additions & 6 deletions app/vendor/ToolsAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -630,15 +630,17 @@ sap.ui.define(["jquery.sap.global", "sap/ui/core/ElementMetadata"],
oElements = sap.ui.core.Element.registry.all();

Object.keys(oElements).forEach(function (sKey) {
var oParent = oElements[sKey].getParent();
var oElement = oElements[sKey];
var oParent = oElement.getParent();

aRegisteredElements.push({
id: oElements[sKey].getId(),
type: oElements[sKey].getMetadata().getName(),
isControl: oElements[sKey].isA("sap.ui.core.Control"),
isRendered: oElements[sKey].isActive(),
id: oElement.getId(),
type: oElement.getMetadata().getName(),
isControl: oElement.isA("sap.ui.core.Control"),
isRendered: oElement.isActive(),
parentId: oParent && (oParent.isA("sap.ui.core.Control") || oParent.isA("sap.ui.core.Element")) ? oParent.getId() : '',
aggregation: oElements[sKey].sParentAggregationName ? oElements[sKey].sParentAggregationName : ''
aggregation: oElement.sParentAggregationName ? oElement.sParentAggregationName : '',
xml: oElement._xContent && (new XMLSerializer()).serializeToString(oElement._xContent)
})
});
}
Expand Down
22 changes: 22 additions & 0 deletions tests/styles/themes/dark/dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,28 @@ odata-detail-view {
border: none;
white-space: pre;
}
xml-view {
height: 100%;
}
#elements-registry-control-xmlview .editorAlt {
display: flex;
}
#elements-registry-control-xmlview .editorAlt div {
margin: auto;
cursor: pointer;
}
#elements-registry-control-xmlview div.hidden {
visibility: hidden;
}
#elements-registry-control-xmlview .editorAlt,
#elements-registry-control-xmlview #xmlEditor {
position: absolute;
top: 25px;
left: 0;
right: 0;
bottom: 0;
height: auto;
}
/*
* Copyright (C) 2008 Apple Inc. All Rights Reserved.
*
Expand Down
22 changes: 22 additions & 0 deletions tests/styles/themes/light/light.css
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,28 @@ odata-detail-view {
border: none;
white-space: pre;
}
xml-view {
height: 100%;
}
#elements-registry-control-xmlview .editorAlt {
display: flex;
}
#elements-registry-control-xmlview .editorAlt div {
margin: auto;
cursor: pointer;
}
#elements-registry-control-xmlview div.hidden {
visibility: hidden;
}
#elements-registry-control-xmlview .editorAlt,
#elements-registry-control-xmlview #xmlEditor {
position: absolute;
top: 25px;
left: 0;
right: 0;
bottom: 0;
height: auto;
}
/*
* Copyright (C) 2008 Apple Inc. All Rights Reserved.
*
Expand Down

0 comments on commit cf996d9

Please sign in to comment.