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 operators #4

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: 2 additions & 1 deletion root/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"env": {
"browser": true
"browser": true,
"es6": true
},
"globals": {
"MashupPlatform": false,
Expand Down
2 changes: 1 addition & 1 deletion root/Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ module.exports = function (grunt) {
'images/**/*',{% if(!js) { %}
'ts/**/*',{% }%}{% if (json) { %}
"config.json",{% } else { %}
"config.xml", {% } %}
"config.xml",{% } %}
]
},
{
Expand Down
2 changes: 2 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",
"default_lang": "en",
"description": "{%= description %}",
Expand All @@ -17,6 +18,7 @@
"js_files": [
"js/main.js"
],
"entrypoint": "{%= entrypoint %}",
"license": "{%= licenses %}",
"longdescription": "DESCRIPTION.md",
"name": "{%= name %}",
Expand Down
4 changes: 4 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'?>
<operator 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 Down Expand Up @@ -32,4 +34,6 @@
<script src="js/main.js"/>
</scripts>

<entrypoint name="{%= entrypoint %}" />

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

/* exported {%= entrypoint %} */

(function () {

"use strict";

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

MashupPlatform.prefs.registerCallback(function (new_preferences) {

}.bind(this));
}
}

}.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 */

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

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

constructor(MashupPlatform: MashupPlatform, extra: any) {
this.MashupPlatform = MashupPlatform;
{% if (ngsi) { %}this.NGSI = extra.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 %};
4 changes: 3 additions & 1 deletion root/tests/js/nameSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

describe("{%= jsname %}", function () {

var MashupPlatform;

beforeAll(function () {
window.MashupPlatform = new MockMP({
MashupPlatform = new MockMP({
type: 'operator'
});
});
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 @@ -44,6 +44,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 @@ -124,6 +131,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 = props.jquery; // Change way to determine bower?
props.ngsi = false; // ??
var bowerdeps = {};
Expand Down