Skip to content

Commit

Permalink
Merge branch 'Wirecloud:develop' into screen-sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
oxixes authored Jun 13, 2024
2 parents bc7e8dc + b197d37 commit 41fc23c
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 24 deletions.
11 changes: 6 additions & 5 deletions src/js_tests/wirecloud/WidgetMetaSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,21 @@
}).toThrowError(TypeError);
});

it("throws a TypeError exception when the entrypoint is missing for mac version 2", () => {
it("does not throw a TypeError exception when the entrypoint is missing for mac version 2", () => {
expect(() => {
new Wirecloud.WidgetMeta({
vendor: "Wirecloud",
name: "TestWidget",
preferences: [],
properties: [],
version: "1.0",
type: "widget",
js_files: [],
macversion: 2,
preferences: [],
js_files: [],
contents: {
src: "index.html"
}
});
}).toThrowError(TypeError);
}).not.toThrow();
});

it("throws a TypeError exception when the js_files is missing for mac version 2", () => {
Expand All @@ -95,6 +95,7 @@
macversion: 2,
entrypoint: "Test",
preferences: [],
properties: [],
contents: {
src: "index.html"
}
Expand Down
4 changes: 2 additions & 2 deletions src/js_tests/wirecloud/wiring/OperatorMetaSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
}).toThrowError(TypeError);
});

it("throws a TypeError exception when the entrypoint is missing for mac version 2", () => {
it("does not throw a TypeError exception when the entrypoint is missing for mac version 2", () => {
expect(() => {
new ns.OperatorMeta({
vendor: "Wirecloud",
Expand All @@ -75,7 +75,7 @@
macversion: 2,
js_files: ["Test"]
});
}).toThrowError(TypeError);
}).not.toThrow();
});

it("throws a TypeError exception when the js_files is missing for mac version 2", () => {
Expand Down
4 changes: 2 additions & 2 deletions src/wirecloud/commons/utils/template/parsers/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def _init(self):

if self._info['type'] == 'widget':
if self._info['macversion'] > 1:
self._check_string_fields(('entrypoint', ), required=True)
self._check_string_fields(('entrypoint', ), required=False)

self._check_array_fields(('altcontents',))
if self._info.get('contents', None) is None:
Expand All @@ -231,7 +231,7 @@ def _init(self):

elif self._info['type'] == 'operator':
if self._info['macversion'] > 1:
self._check_string_fields(('entrypoint', ), required=True)
self._check_string_fields(('entrypoint', ), required=False)

elif self._info['type'] == 'mashup':

Expand Down
2 changes: 1 addition & 1 deletion src/wirecloud/commons/utils/template/parsers/rdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ def _parse_component_info(self):
raise TemplateParseException(_('Missing required field: Javascript files'))

if self._info['macversion'] > 1:
self._info['entrypoint'] = self._get_field(WIRE, 'entryPoint', self._rootURI, required=True)
self._info['entrypoint'] = self._get_field(WIRE, 'entryPoint', self._rootURI, required=False)

def _parse_translation_catalogue(self):
self._info['default_lang'] = 'en'
Expand Down
8 changes: 6 additions & 2 deletions src/wirecloud/commons/utils/template/parsers/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,9 @@ def _parse_widget_info(self):
for script in js_files:
self._info['js_files'].append(str(script.get('src')))

self._info["entrypoint"] = self.get_xpath(ENTRYPOINT_XPATH, self._doc, required=True).get('name')
entrypoint = self.get_xpath(ENTRYPOINT_XPATH, self._doc, required=False)
if entrypoint is not None:
self._info["entrypoint"] = entrypoint.get('name')
else:
js_files = self._xpath(SCRIPT_XPATH, self._doc)
if len(js_files) > 0:
Expand All @@ -467,7 +469,9 @@ def _parse_operator_info(self):
self._info['js_files'].append(str(script.get('src')))

if self._info["macversion"] > 1:
self._info["entrypoint"] = self.get_xpath(ENTRYPOINT_XPATH, self._doc, required=True).get('name')
entrypoint = self.get_xpath(ENTRYPOINT_XPATH, self._doc, required=False)
if entrypoint is not None:
self._info["entrypoint"] = entrypoint.get('name')

def _parse_component_preferences(self):

Expand Down
2 changes: 1 addition & 1 deletion src/wirecloud/commons/utils/template/writers/rdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ def build_rdf_graph(template_info):
graph.add((js_node, WIRE['index'], rdflib.Literal(str(index))))
graph.add((resource_uri, USDL['utilizedResource'], js_node))

if (template_info['type'] == 'operator' or template_info['type'] == 'widget') and template_info['macversion'] > 1:
if (template_info['type'] == 'operator' or template_info['type'] == 'widget') and template_info['macversion'] > 1 and 'entrypoint' in template_info:
# Add entryPoint
graph.add((resource_uri, WIRE['entryPoint'], rdflib.Literal(template_info.get('entrypoint'))))

Expand Down
2 changes: 1 addition & 1 deletion src/wirecloud/commons/utils/template/writers/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ def build_xml_document(options):
for script in options['js_files']:
etree.SubElement(scripts, 'script', src=script)

if (options['type'] == 'operator' or options['type'] == 'widget') and options['macversion'] > 1:
if (options['type'] == 'operator' or options['type'] == 'widget') and options['macversion'] > 1 and 'entrypoint' in options:
# Add entrypoint
etree.SubElement(template, 'entrypoint', name=options['entrypoint'])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,16 @@
ComponentManagement: privates._ComponentManagementAPI
};

Wirecloud.APIComponents = {}
const registerWidgetClass = function registerWidgetClass(script, widgetClass) {
Wirecloud.APIComponents[script.dataset.id] = widgetClass;
};

const registerOperatorClass = function registerOperatorClass(script, operatorClass) {
Wirecloud.APIComponents[script.dataset.id] = operatorClass;
}

Wirecloud.registerWidgetClass = registerWidgetClass;
Wirecloud.registerOperatorClass = registerOperatorClass;

})(window.Wirecloud);
7 changes: 6 additions & 1 deletion src/wirecloud/platform/static/js/wirecloud/Widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@
const script = document.createElement('script');
script.setAttribute('type', 'text/javascript');
script.setAttribute('src', js_file);
script.dataset.id = this.meta.uri;
script.async = false;
document.body.appendChild(script);
this.loaded_scripts.push(script);
Expand Down Expand Up @@ -330,7 +331,11 @@
// If this is a v2 or later widget, we need to instantiate it's entrypoint class
_unloadScripts.call(this);
_loadScripts.call(this).then(() => {
const entrypoint = window[this.meta.entrypoint];
let entrypoint = Wirecloud.APIComponents[this.meta.uri];
if (!entrypoint) {
entrypoint = window[this.meta.entrypoint];
}

if (entrypoint === undefined) {
this.logManager.log("Widget entrypoint class not found!", {console: false});
} else {
Expand Down
4 changes: 0 additions & 4 deletions src/wirecloud/platform/static/js/wirecloud/WidgetMeta.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@
if (!this.js_files) {
throw new TypeError("missing js_files attribute in widget description");
}

if (!this.entrypoint) {
throw new TypeError("missing entrypoint attribute in widget description");
}
}
}
if (this.codeurl.indexOf('?') === -1) {
Expand Down
2 changes: 2 additions & 0 deletions src/wirecloud/platform/static/js/wirecloud/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

"use strict";

window.parent = window; // Avoid problems with embedded Wirecloud instances

const preferencesChanged = function preferencesChanged(preferences, modifiedValues) {
/* istanbul ignore if */
if ('language' in modifiedValues) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
const script = document.createElement('script');
script.setAttribute('type', 'text/javascript');
script.setAttribute('src', js_file);
script.dataset.id = this.meta.uri;
script.async = false;
document.body.appendChild(script);
this.loaded_scripts.push(script);
Expand Down Expand Up @@ -203,7 +204,11 @@
this.wrapperElement.contentDocument.defaultView.addEventListener('unload', on_unload.bind(this), true);
} else if (!this.meta.missing && this.meta.macversion > 1) {
// If this is a v2 or later operator, we need to instantiate it's entrypoint class
const entrypoint = window[this.meta.entrypoint];
let entrypoint = Wirecloud.APIComponents[this.meta.uri];
if (!entrypoint) {
entrypoint = window[this.meta.entrypoint];
}

if (entrypoint === undefined) {
this.logManager.log("Operator entrypoint class not found!", {console: false});
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@
if (!this.js_files) {
throw new TypeError("missing js_files attribute in operator description");
}

if (!this.entrypoint) {
throw new TypeError("missing entrypoint attribute in operator description");
}
}

desc.properties.forEach((property_info) => {
Expand Down

0 comments on commit 41fc23c

Please sign in to comment.