Skip to content

Commit

Permalink
Progress (xml and json import / export, fix sidebar layout)
Browse files Browse the repository at this point in the history
  • Loading branch information
oxixes committed Jun 13, 2024
1 parent 41fc23c commit b073a2b
Show file tree
Hide file tree
Showing 10 changed files with 242 additions and 93 deletions.
1 change: 1 addition & 0 deletions src/wirecloud/commons/static/js/StyledElements/CodeArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
if (!window.monaco) {
// If monaco is not available, use the TextArea class
se.CodeArea = se.TextArea;
se.__Testing__CodeArea = CodeAreaClass; // For testing purposes
} else {
se.CodeArea = CodeAreaClass;
}
Expand Down
39 changes: 29 additions & 10 deletions src/wirecloud/commons/utils/template/parsers/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,16 +242,35 @@ def _init(self):
self._check_string_fields(('title',), place=tab, required=False)
self._check_array_fields(('resources',), place=tab)
for widget in tab['resources']:
rendering = widget.get('rendering', {})
self._check_integer_fields(('layout',), place=rendering, default=0, allow_cast=True)
layout = rendering['layout']
self._check_boolean_fields(('relwidth',), place=rendering, default=True)
self._check_boolean_fields(('relheight',), place=rendering, default=(layout != 1))

position = widget.get('position', {})
self._check_string_fields(('anchor',), place=position, default="top-left")
self._check_boolean_fields(('relx',), place=position, default=True)
self._check_boolean_fields(('rely',), place=position, default=(layout != 1))
screenSizes = widget.get('screenSizes', None)
if screenSizes is None:
screenSizes = [
{
'moreOrEqual': 0,
'lessOrEqual': -1,
'id': 0,
'rendering': widget.get('rendering', {}),
'position': widget.get('position', {})
}
]

layout = screenSizes[0]['rendering'].get('layout', 0)
widget['layout'] = layout
else:
layout = widget.get('layout', 0)

for screenSize in screenSizes:
self._check_integer_fields(('moreOrEqual', 'lessOrEqual', 'id'), place=screenSize, required=True)

rendering = screenSize.get('rendering', {})
self._check_integer_fields(('layout',), place=rendering, default=0, allow_cast=True)
self._check_boolean_fields(('relwidth',), place=rendering, default=True)
self._check_boolean_fields(('relheight',), place=rendering, default=(layout != 1))

position = screenSize.get('position', {})
self._check_string_fields(('anchor',), place=position, default="top-left")
self._check_boolean_fields(('relx',), place=position, default=True)
self._check_boolean_fields(('rely',), place=position, default=(layout != 1))

for preference in self._info['params']:
self._check_string_fields(('name', 'type'), place=preference, required=True)
Expand Down
95 changes: 73 additions & 22 deletions src/wirecloud/commons/utils/template/parsers/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
TAB_XPATH = 't:tab'
RESOURCE_XPATH = 't:resource'
POSITION_XPATH = 't:position'
SCREEN_SIZES_XPATH = 't:screensizes'
RENDERING_XPATH = 't:rendering'
PARAM_XPATH = 't:preferences/t:preference'
EMBEDDEDRESOURCE_XPATH = 't:embedded/t:resource'
Expand Down Expand Up @@ -568,39 +569,89 @@ def _parse_workspace_info(self):
}

for widget in self._xpath(RESOURCE_XPATH, tab):
position = self.get_xpath(POSITION_XPATH, widget)
rendering = self.get_xpath(RENDERING_XPATH, widget)
position = self.get_xpath(POSITION_XPATH, widget, required=False)
screenSizes = self.get_xpath(SCREEN_SIZES_XPATH, widget, required=False)
rendering = self.get_xpath(RENDERING_XPATH, widget, required=False)

if (position is None or rendering is None) and screenSizes is None:
raise TemplateParseException(_("Missing position/rendering or screensizes element"))

if (rendering is None and not widget.get('layout')):
raise TemplateParseException(_("Missing layout in resource or rendering element"))

if rendering is None:
layout = int(str(widget.get('layout')))
else:
layout = int(str(rendering.get('layout')))

layout = int(str(rendering.get('layout')))
widget_info = {
'id': str(widget.get('id')),
'name': str(widget.get('name')),
'vendor': str(widget.get('vendor')),
'version': str(widget.get('version')),
'title': str(widget.get('title')),
'readonly': widget.get('readonly', '').lower() == 'true',
'layout': layout,
'properties': {},
'preferences': {},
'position': {
'anchor': str(position.get('anchor', 'top-left')),
'relx': position.get('relx', 'true').lower() == 'true',
'rely': position.get('rely', 'true' if layout != 1 else 'false').lower() == 'true',
'x': str(position.get('x')),
'y': str(position.get('y')),
'z': str(position.get('z')),
},
'rendering': {
'fulldragboard': rendering.get('fulldragboard', 'false').lower() == 'true',
'minimized': rendering.get('minimized', 'false').lower() == 'true',
'relwidth': rendering.get('relwidth', 'true').lower() == 'true',
'relheight': rendering.get('relheight', 'true' if layout != 1 else 'false').lower() == 'true',
'width': str(rendering.get('width')),
'height': str(rendering.get('height')),
'layout': layout,
'titlevisible': rendering.get('titlevisible', 'true').lower() == 'true',
},
'preferences': {}
}

if screenSizes is not None:
widget_info['screenSizes'] = []
for screenSize in screenSizes:
position = self.get_xpath(POSITION_XPATH, screenSize)
rendering = self.get_xpath(RENDERING_XPATH, screenSize)
screen_size_info = {
'moreOrEqual': int(screenSize.get('moreOrEqual')),
'lessOrEqual': int(screenSize.get('lessOrEqual')),
'id': int(screenSize.get('id')),
'position': {
'anchor': str(position.get('anchor', 'top-left')),
'relx': position.get('relx', 'true').lower() == 'true',
'rely': position.get('rely', 'true' if layout != 1 else 'false').lower() == 'true',
'x': int(float(position.get('x'))),
'y': int(float(position.get('y'))),
'z': int(float(position.get('z'))),
},
'rendering': {
'fulldragboard': rendering.get('fulldragboard', 'false').lower() == 'true',
'minimized': rendering.get('minimized', 'false').lower() == 'true',
'relwidth': rendering.get('relwidth', 'true').lower() == 'true',
'relheight': rendering.get('relheight', 'true' if layout != 1 else 'false').lower() == 'true',
'width': int(float(rendering.get('width'))),
'height': int(float(rendering.get('height'))),
'titlevisible': rendering.get('titlevisible', 'true').lower() == 'true',
}
}

widget_info['screenSizes'].append(screen_size_info)
else:
widget_info['screenSizes'] = [
{
'moreOrEqual': 0,
'lessOrEqual': -1,
'id': 0,
'position': {
'anchor': str(position.get('anchor', 'top-left')),
'relx': position.get('relx', 'true').lower() == 'true',
'rely': position.get('rely', 'true' if layout != 1 else 'false').lower() == 'true',
'x': str(position.get('x')),
'y': str(position.get('y')),
'z': str(position.get('z')),
},
'rendering': {
'fulldragboard': rendering.get('fulldragboard', 'false').lower() == 'true',
'minimized': rendering.get('minimized', 'false').lower() == 'true',
'relwidth': rendering.get('relwidth', 'true').lower() == 'true',
'relheight': rendering.get('relheight', 'true' if layout != 1 else 'false').lower() == 'true',
'width': str(rendering.get('width')),
'height': str(rendering.get('height')),
'layout': layout,
'titlevisible': rendering.get('titlevisible', 'true').lower() == 'true',
}
}
]

for prop in self._xpath(PROPERTIES_XPATH, widget):
prop_value = prop.get('value')
widget_info['properties'][str(prop.get('name'))] = {
Expand Down
56 changes: 46 additions & 10 deletions src/wirecloud/commons/utils/template/schemas/xml_schema.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,24 @@
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="Identifier">
<xs:restriction base="xs:integer">
<xs:minInclusive value="0"/>
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="ScreenSizeLessOrEqual">
<xs:restriction base="xs:integer">
<xs:minInclusive value="-1"/>
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="ScreenSizeMoreOrEqual">
<xs:restriction base="xs:integer">
<xs:minInclusive value="0"/>
</xs:restriction>
</xs:simpleType>

<xs:complexType name="ResourceInfo">
<xs:all>
<xs:element name="title" minOccurs="0" maxOccurs="1"
Expand Down Expand Up @@ -754,6 +772,17 @@
</xs:complexContent>
</xs:complexType>

<xs:complexType name="LayoutRendering">
<xs:attribute name="relwidth" type="xs:boolean" use="optional" />
<xs:attribute name="relheight" type="xs:boolean" use="optional" />
<xs:attribute name="width" type="xs:string" use="required" />
<xs:attribute name="minimized" type="xs:boolean" use="optional" />
<xs:attribute name="layout" type="xs:string" use="optional" />
<xs:attribute name="height" type="xs:string" use="required" />
<xs:attribute name="fulldragboard" type="xs:boolean" use="optional" />
<xs:attribute name="titlevisible" type="xs:boolean" use="optional" />
</xs:complexType>

<xs:complexType name="Tab">
<xs:sequence>
<xs:element name="preferencevalue" type="macd:PreferenceValue" minOccurs="0" maxOccurs="unbounded" />
Expand All @@ -762,19 +791,25 @@
<xs:choice minOccurs="1" maxOccurs="unbounded">
<xs:element name="preferencevalue" type="macd:ResourcePreferenceValue" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="variablevalue" type="macd:ResourcePreferenceValue" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="position" type="macd:LayoutPosition" minOccurs="1" maxOccurs="1" />
<xs:element name="rendering" minOccurs="1" maxOccurs="1">
<xs:element name="screensizes" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:attribute name="relwidth" type="xs:boolean" use="optional" />
<xs:attribute name="relheight" type="xs:boolean" use="optional" />
<xs:attribute name="width" type="xs:string" use="required" />
<xs:attribute name="minimized" type="xs:boolean" use="optional" />
<xs:attribute name="layout" type="xs:string" use="required" />
<xs:attribute name="height" type="xs:string" use="required" />
<xs:attribute name="fulldragboard" type="xs:boolean" use="optional" />
<xs:attribute name="titlevisible" type="xs:boolean" use="optional" />
<xs:sequence>
<xs:element name="screensize" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:all>
<xs:element name="position" type="macd:LayoutPosition" />
<xs:element name="rendering" type="macd:LayoutRendering" />
</xs:all>
<xs:attribute name="moreOrEqual" type="macd:ScreenSizeMoreOrEqual" use="required" />
<xs:attribute name="lessOrEqual" type="macd:ScreenSizeLessOrEqual" use="required" />
<xs:attribute name="id" type="macd:Identifier" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="position" type="macd:LayoutPosition" minOccurs="0" maxOccurs="1" />
<xs:element name="rendering" type="macd:LayoutRendering" minOccurs="0" maxOccurs="1" />
</xs:choice>
<xs:attribute name="vendor" type="macd:VendorType" use="required" />
<xs:attribute name="name" use="required" type="macd:NameType" />
Expand All @@ -792,6 +827,7 @@
</xs:annotation>
</xs:attribute>
<xs:attribute name="id" use="required" type="xs:string" />
<xs:attribute name="layout" type="xs:string" use="optional" />
</xs:complexType>
</xs:element>
</xs:sequence>
Expand Down
49 changes: 30 additions & 19 deletions src/wirecloud/commons/utils/template/writers/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def addPreferenceValues(resource, preferences):
addAttribute(pref, element, 'value', type='string', default=None, required=False)
addAttributes(pref, element, ('readonly', 'hidden'), default='false', type='boolean')


# TODO Adrian handle multiple screen sizes
def write_mashup_tree(doc, resources, options):

# Params
Expand Down Expand Up @@ -122,24 +122,35 @@ def write_mashup_tree(doc, resources, options):
if iwidget.get('readonly', False):
resource.set('readonly', 'true')

layout = iwidget['rendering']['layout']

position = etree.SubElement(
resource,
'position',
anchor=str(iwidget['position']['anchor']),
x=str(iwidget['position']['x']),
y=str(iwidget['position']['y']),
z=str(iwidget['position']['z'])
)
addAttributes(iwidget['position'], position, ('relx',), default='true', type='boolean')
addAttributes(iwidget['position'], position, ('rely',), default=('true' if layout != 1 else 'false'), type='boolean')

rendering = etree.SubElement(resource, 'rendering')
addAttributes(iwidget['rendering'], rendering, ('height', 'width', 'layout'), required=True)
addAttributes(iwidget['rendering'], rendering, ('minimized', 'fulldragboard'), default='false', type='boolean')
addAttributes(iwidget['rendering'], rendering, ('relwidth', 'titlevisible'), default='true', type='boolean')
addAttributes(iwidget['rendering'], rendering, ('relheight',), default=('true' if layout != 1 else 'false'), type='boolean')
layout = iwidget['layout']

addAttributes(iwidget, resource, ('layout',), required=True)

screenSizesElem = etree.SubElement(resource, 'screensizes')
for screenSize in iwidget.get('screenSizes', []):
screenSizeElem = etree.SubElement(screenSizesElem,
'screensize',
moreOrEqual=str(screenSize['moreOrEqual']),
lessOrEqual=str(screenSize['lessOrEqual']),
id=str(screenSize['id']))

position = etree.SubElement(
screenSizeElem,
'position',
anchor=str(screenSize['position']['anchor']),
x=str(int(float(screenSize['position']['x']))),
y=str(int(float(screenSize['position']['y']))),
z=str(int(float(screenSize['position']['z'])))
)
addAttributes(screenSize['position'], position, ('relx',), default='true', type='boolean')
addAttributes(screenSize['position'], position, ('rely',), default=('true' if layout != 1 else 'false'), type='boolean')

rendering = etree.SubElement(screenSizeElem, 'rendering',
height=str(int(float(screenSize['rendering']['height']))),
width=str(int(float(screenSize['rendering']['width'])))),
addAttributes(screenSize['rendering'], rendering, ('minimized', 'fulldragboard'), default='false', type='boolean')
addAttributes(screenSize['rendering'], rendering, ('relwidth', 'titlevisible'), default='true', type='boolean')
addAttributes(screenSize['rendering'], rendering, ('relheight',), default=('true' if layout != 1 else 'false'), type='boolean')

addPreferenceValues(resource, iwidget['preferences'])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
padding: 10px;
border-radius: 7px;
right: 50px;
top: 39px;
}

.wc-editing-interval-close {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@
return result;
}

removeHandle() {
this.handle.remove();
}

removeWidget(widget, affectsDragboard) {
const result = super.removeWidget(widget, affectsDragboard);

Expand Down Expand Up @@ -205,7 +209,7 @@
} else {
offset = 0;
}
element.style.left = this.getColumnOffset(widget.position, true);
element.style.left = this.getColumnOffset(widget.position, null, true);
element.style.right = "";
if (this.position === "top") {
element.style.top = offset + "px";
Expand Down
3 changes: 3 additions & 0 deletions src/wirecloud/platform/static/js/wirecloud/ui/WidgetView.js
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,9 @@
};

this.layout.removeWidgetEventListeners(this);
if ('removeHandle' in this.layout) {
this.layout.removeHandle();
}
this.layout = null;

this.setPosition(newPos, false);
Expand Down
Loading

0 comments on commit b073a2b

Please sign in to comment.