Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle v2 widgets #3

Merged
merged 2 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions root/Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* Licensed under the {%= licenses.join(', ') %} license{%= licenses.length === 1 ? '' : 's' %}.
*/

const { json } = require('stream/consumers');
var ConfigParser = require('wirecloud-config-parser');
var parser = new ConfigParser('src/{% if (json) { %}config.json{% } else { %}config.xml{% } %}');

Expand Down Expand Up @@ -109,7 +108,7 @@ module.exports = function (grunt) {
'index.html',{% if (!js) { %}
"ts/**/*",{% }%}{% if (json) { %}
"config.json",{% } else { %}
"config.xml", {% } %}
"config.xml",{% } %}
]
},
{
Expand Down
5 changes: 5 additions & 0 deletions root/src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"name": "{%= author_name %}"
}
],
"macversion": 2,
"changelog": "doc/changelog.md",
"contents": {
"cacheable": true,
Expand Down Expand Up @@ -33,6 +34,10 @@
}
{% } %}
],
"js_files": [
"js/{%= jsname %}.js"
],
"entrypoint": "js/{%= entrypoint %}.js",
"title": "{%= project_name %}",
"translations": {},
"type": "widget",
Expand Down
6 changes: 6 additions & 0 deletions root/src/config.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?xml version='1.0' encoding='UTF-8'?>
<widget xmlns="http://wirecloud.conwet.fi.upm.es/ns/macdescription/1" vendor="{%= vendor %}" name="{%= name %}" version="{%= version %}">

<macversion>2</macversion>

<details>
<title>{%= project_name %}</title>
<homepage>{%= homepage %}</homepage>
Expand All @@ -27,6 +29,10 @@
</wiring>

<contents src="index.html"/>
<scripts>
<script src="js/{%= jsname %}.js"/>
</scripts>
<entrypoint name="{%= entrypoint %}"/>
<rendering height="300px" width="30%"/>

</widget>
16 changes: 2 additions & 14 deletions root/src/index.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="css/styles.css" />
<title>Empty {%= name %} widget</title>
</head>
<body>
<link rel="stylesheet" type="text/css" href="css/styles.css" />

<div>Empty {%= name %} widget</div>

<script src="js/{%= jsname %}.js"></script>
<script src="js/main.js"></script>
</body>
</html>
<div>Empty {%= name %} widget</div>
14 changes: 0 additions & 14 deletions root/src/js/main.js

This file was deleted.

26 changes: 13 additions & 13 deletions root/src/js/name.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,32 @@
* Licensed under the {%= licenses.join(', ') %} license{%= licenses.length === 1 ? '' : 's' %}.
*/

/* exported {%= jsname %} */
/* exported {%= entrypoint %} */

var {%= jsname %} = (function () {
(function () {

"use strict";

// =========================================================================
// CLASS DEFINITION
// =========================================================================

var {%= jsname %} = function {%= jsname %}() {
MashupPlatform.prefs.registerCallback(function (new_preferences) {
class {%= entrypoint %} {
constructor(MashupPlatform, shadowDOM, extra) {
this.MashupPlatform = MashupPlatform;
this.shadowDOM = shadowDOM;

}.bind(this));
};
MashupPlatform.prefs.registerCallback(function (new_preferences) {

// =========================================================================
// PRIVATE MEMBERS
// =========================================================================
}.bind(this));
}
}

// We define the class as part of the window object so that it can be instantiated by Wirecloud
window.{%= entrypoint %} = {%= entrypoint %};

/* test-code */
{%= jsname %}.prototype = {
};

/* end-test-code */

return {%= jsname %};

})();
11 changes: 0 additions & 11 deletions root/src/ts/main.ts

This file was deleted.

17 changes: 16 additions & 1 deletion root/src/ts/name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,23 @@ import MashupPlatform = require("MashupPlatform");
{% if (ngsi) { %}import NGSI = require("NGSI");{% }%}
/* end-import-block */

export class {%= jsname %} {
export class {%= entrypoint %} {
private MashupPlatform: MashupPlatform;
private shadowDOM: any;
{% if (ngsi) { %}private NGSI: NGSI;{% }%}

constructor(MashupPlatform: MashupPlatform, shadowDOM: any, extra: any) {
this.MashupPlatform = MashupPlatform;
this.shadowDOM = shadowDOM;
{% if (ngsi) { %}this.NGSI = NGSI;{% }%}

this.init();
}

init() {
console.log("Loaded!!");
}
}

// We define the class as part of the window object so that it can be instantiated by Wirecloud
(<any>window)["{%= entrypoint %}"] = {%= entrypoint %};
7 changes: 4 additions & 3 deletions root/tests/js/nameSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Licensed under the {%= licenses.join(', ') %} license{%= licenses.length === 1 ? '' : 's' %}.
*/

/* globals $, MashupPlatform, MockMP, {%= jsname %} */
/* globals $, MashupPlatform, MockMP, {%= entrypoint %} */

(function () {

Expand All @@ -15,16 +15,17 @@
describe("{%= jsname %}", function () {

var widget;
var MashupPlatform;

beforeAll(function () {
window.MashupPlatform = new MockMP({
MashupPlatform = new MockMP({
type: 'widget'
});
});

beforeEach(function () {
MashupPlatform.reset();
widget = new {%= jsname %}();
widget = new {%= entrypoint %}(MashupPlatform, undefined, {});
});

it("Dummy test", function () {
Expand Down
2 changes: 2 additions & 0 deletions root/typings/MashupPlatform/MashupPlatform.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,6 @@ declare module "MashupPlatform" {
interface onExceptionCB {
(response: Object, exception: Error): void;
}

var location: string;
}
8 changes: 8 additions & 0 deletions template.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ var capitalizeAndRemoveUnderscore = function capitalizeAndRemoveUnderscore(old)
return t.charAt(0).toUpperCase() + t.slice(1);
};

var getEntrypointName = function getEntrypointName(vendor, name) {
// Remove all non-alphanumeric characters. Replace spaces with underscores.
vendor = vendor.replace(/[^a-zA-Z0-9]/g, '').replace(/\s/g, '_');
name = name.replace(/[^a-zA-Z0-9]/g, '').replace(/\s/g, '_');
return vendor + '_' + name;
}

// The actual init template.
exports.template = function(grunt, init, done) {
init.process([
Expand Down Expand Up @@ -123,6 +130,7 @@ exports.template = function(grunt, init, done) {
], function(err, props){
var exportsOverride = {};
props.jsname = capitalizeAndRemoveUnderscore(props.name);
props.entrypoint = getEntrypointName(props.vendor, props.name);
props.bower = true; // Change way to determine bower?
props.ngsi = false; // ??
var bowerdeps = {};
Expand Down