Skip to content

Commit

Permalink
Merge 753acf1 into de43ddd
Browse files Browse the repository at this point in the history
  • Loading branch information
fisuda committed Jan 2, 2020
2 parents de43ddd + 753acf1 commit a889b1a
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 34 deletions.
17 changes: 17 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
language: node_js
node_js:
- "lts/*"
sudo: false
addons:
chrome: stable
firefox: latest-esr

before_install:
- npm install grunt-cli -g

script:
- xvfb-run grunt ci

branches:
only:
- master
12 changes: 10 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ module.exports = function (grunt) {
}
},

coveralls: {
library: {
src: 'build/coverage/lcov/lcov.info',
}
},

strip_code: {
multiple_files: {
src: ['build/src/js/**/*.js']
Expand Down Expand Up @@ -124,6 +130,8 @@ module.exports = function (grunt) {
}
},
files: [
'tests/helpers/ace.js',
'tests/helpers/StyledElements.min.js',
'node_modules/mock-applicationmashup/dist/MockMP.js',
'src/js/*.js',
'tests/js/*Spec.js'
Expand Down Expand Up @@ -191,13 +199,13 @@ module.exports = function (grunt) {
grunt.registerTask('test', [
'bower:install',
'eslint',
// 'karma:widget'
'karma:widget'
]);

grunt.registerTask('ci', [
'bower:install',
'eslint',
// 'karma:widgetci',
'karma:widgetci',
'coveralls'
]);

Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# json-injector widget

The json-injector widget is a WireCloud widget that provides ...
[![](https://nexus.lab.fiware.org/repository/raw/public/badges/chapters/visualization.svg)](https://www.fiware.org/developers/catalogue/)
[![License: MIT](https://img.shields.io/github/license/lets-fiware/json-injector.svg)](https://opensource.org/licenses/MIT)<br/>
[![Build Status](https://travis-ci.org/lets-fiware/json-injector.svg?branch=master)](https://travis-ci.org/lets-fiware/json-injector)
[![Coverage Status](https://coveralls.io/repos/github/lets-fiware/json-injector/badge.svg?branch=master)](https://coveralls.io/github/lets-fiware/json-injector?branch=master)

The json-injector widget is a WireCloud widget that allows you to send Json data to an output endpoint.

Build
-----
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"karma-firefox-launcher": "^1.2.0",
"karma-jasmine": "^2.0.1",
"karma-junit-reporter": "^2.0.1",
"mock-applicationmashup": "^1.0.0-d",
"mock-applicationmashup": "^1.0.0-g",
"wirecloud-config-parser": "^0.2.2"
},
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion src/config.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='UTF-8'?>
<widget xmlns="http://wirecloud.conwet.fi.upm.es/ns/macdescription/1" vendor="FISUDA" name="json-injector" version="0.1.4">
<widget xmlns="http://wirecloud.conwet.fi.upm.es/ns/macdescription/1" vendor="FISUDA" name="json-injector" version="0.1.5">

<details>
<title>Json Injector</title>
Expand Down
19 changes: 14 additions & 5 deletions src/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,22 @@
border: 1px solid rgb(231, 231, 231);
}

.header > h4 {
display: flex;
align-items: center;
flex-wrap: wrap;
}

.type-selector {
flex-grow: 1;
}

.text-primary {
margin-left: 10px;
margin-right: 10px;
margin: 5px;
}

.text-primary > .se-select {
margin-bottom: 0px;
.se-select {
margin: 3px;
}

#buttons {
Expand All @@ -18,4 +27,4 @@

.acecontainer {
padding: 2px;
}
}
45 changes: 25 additions & 20 deletions src/js/JsonInjector.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,12 @@
*/

/* exported JsonInjector */
/* global $, ace, MashupPlatform, StyledElements */
/* global ace, MashupPlatform, StyledElements */

var JsonInjector = (function () {

'use strict';

var layout;
var editor;
var typeSelector;
var sendbtn;

// =========================================================================
// CLASS DEFINITION
// =========================================================================
Expand All @@ -27,14 +22,7 @@ var JsonInjector = (function () {
const editorData = 'JsonInjector-data-' + title + MashupPlatform.widget.id;
const editorMode = 'JsonInjector-mode-' + title + MashupPlatform.widget.id;

layout = new StyledElements.VerticalLayout();
layout.insertInto(document.body);
layout.north.addClassName('header');
layout.north.appendChild(new StyledElements.Fragment('<h4 class="text-primary">Type: <span id="type-data">No data</span><div id="buttons"></div></h4>'));

var typed = $('#type-data')[0];
var parent = typed.parentNode;
parent.removeChild(typed);
var builder = new StyledElements.GUIBuilder();

var entries = [
{label: 'JSON - (Text)', value: 'JSON - (Text)'},
Expand All @@ -54,21 +42,27 @@ var JsonInjector = (function () {
return '';
}

typeSelector = new StyledElements.Select();
var typeSelector = new StyledElements.Select();
typeSelector.addEntries(entries);
typeSelector.setValue(sessionStorage.getItem(editorMode) || 'JSON - (Object)');
typeSelector.addEventListener('change', () => {
const mode = typeSelector.getValue();
editor.session.setMode(getEditorMode(mode));
sessionStorage.setItem(editorMode, mode);
});
typeSelector.insertInto(parent);

var buttons = document.createElement('div');
buttons.className = "buttons";

var action_buttons = document.createElement('div');
action_buttons.className = 'btn-group';
document.getElementById('buttons').appendChild(action_buttons);
buttons.appendChild(action_buttons);

sendbtn = new StyledElements.Button({'class': 'btn-info', 'iconClass': 'fa fa-play', 'title': 'Output data'});
var sendbtn = new StyledElements.Button({
iconClass: 'fa fa-play',
state: 'info',
title: 'Output data'
});
sendbtn.addEventListener('click', () => {
if (MashupPlatform.widget.outputs.output.connected) {
var value = editor.getValue();
Expand All @@ -80,10 +74,21 @@ var JsonInjector = (function () {
});
sendbtn.insertInto(action_buttons);

var layout = new StyledElements.VerticalLayout();
layout.insertInto(document.body);
layout.north.addClassName('header');
layout.north.appendChild(builder.parse(
builder.DEFAULT_OPENING + '<h4 class="text-primary"><div class="type-selector">Type: <t:typeSelector/></div><t:buttons/></h4>' + builder.DEFAULT_CLOSING,
{
buttons: buttons,
typeSelector: typeSelector
}
));

layout.center.addClassName('acecontainer');
editor = ace.edit(layout.center.wrapperElement);
var editor = ace.edit(layout.center.wrapperElement);
editor.setFontSize(14);
editor.session.setMode(getEditorMode(sessionStorage.getItem(editorMode)));
editor.session.setMode(getEditorMode(sessionStorage.getItem(editorMode)) || 'ace/mode/json');
editor.session.setTabSize(2);
editor.setValue(sessionStorage.getItem(editorData) || '');
editor.session.on('change', (e) => {
Expand Down
1 change: 1 addition & 0 deletions tests/helpers/StyledElements.min.js

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions tests/helpers/ace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
(function () {

"use strict";

window.ace = {
edit: function () {
return {
setFontSize: function () {},
setValue: function () {},
session: {
setMode: function () {},
setTabSize: function () {},
on: function () {}
}
}
}
};

})();
Empty file removed tests/helpers/empty.js
Empty file.
4 changes: 3 additions & 1 deletion tests/js/JsonInjectorSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

beforeAll(function () {
window.MashupPlatform = new MockMP({
type: 'widget'
type: 'widget',
inputs: ['input'],
outputs: ['output']
});
});

Expand Down

0 comments on commit a889b1a

Please sign in to comment.