Commit 8dea4323 authored by Anze Vavpetic's avatar Anze Vavpetic
Browse files

added a javascript snippet widget

parent 94ac0f76
import json
from django.shortcuts import render
def base_js_snippet(request, input_dict, output_dict, widget):
inputs = json.dumps(input_dict['in'])
raise Exception("Problem serializing the inputs. Only JSON-serializable objects can be used.")
return render(request, 'interactions/base_js_snippet.html',
{'widget': widget, 'snippet': input_dict['snippet'], 'inputs': inputs})
import cPickle
import json
def base_concatenate_lists(input_dict):
lists = input_dict['lists']
......@@ -219,3 +220,14 @@ def base_average_list(input_dict):
average = None
return {'average': average}
def base_js_snippet(input_dict):
return {'out': None}
def base_js_snippet_finished(postdata, input_dict, output_dict):
out_list = json.loads(postdata['out'][0])
out = out_list[0]
raise Exception("Problem de-serializing the output.")
return {'out': out}
"model": "workflows.abstractwidget",
"fields": {
"category": "01ad639d-acb8-45c0-bc5e-bc8739bb4c95",
"treeview_image": "",
"uid": "f07ffb9c-64c9-42dd-809d-5ae8991fbd13",
"windows_queue": false,
"package": "base",
"interaction_view": "base_js_snippet",
"has_progress_bar": false,
"image": "",
"description": "",
"static_image": "",
"action": "base_js_snippet",
"visualization_view": "",
"streaming_visualization_view": "",
"post_interact_action": "base_js_snippet_finished",
"wsdl_method": "",
"wsdl": "",
"interactive": true,
"is_streaming": false,
"order": 1,
"name": "Javascript Snippet"
"model": "workflows.abstractinput",
"fields": {
"widget": "f07ffb9c-64c9-42dd-809d-5ae8991fbd13",
"name": "Input",
"short_name": "in",
"default": "",
"description": "Input",
"required": false,
"multi": true,
"parameter_type": null,
"variable": "in",
"parameter": false,
"order": 1,
"uid": "7a0d740b-e669-4ff3-b688-0f86ee591b4f"
"model": "workflows.abstractinput",
"fields": {
"widget": "f07ffb9c-64c9-42dd-809d-5ae8991fbd13",
"name": "Snippet",
"short_name": "snp",
"default": "/*\r\n Access input objects using the inputs array.\r\n Assign the result to the out variable.\r\n\r\n Useful for manipulating simple objects, such as lists, strings and dictionaries.\r\n*/\r\nvar out = inputs[0];",
"description": "Snippet",
"required": false,
"multi": false,
"parameter_type": "textarea",
"variable": "snippet",
"parameter": true,
"order": 2,
"uid": "9d42c5b3-6961-47ea-a756-91cad1ba8da0"
"model": "workflows.abstractoutput",
"fields": {
"widget": "f07ffb9c-64c9-42dd-809d-5ae8991fbd13",
"name": "Output",
"short_name": "out",
"description": "Output",
"variable": "out",
"order": 1,
"uid": "497da2eb-9590-47d8-84ba-1d3b38559bdf"
\ No newline at end of file
<div id="widgetinteract-{{}}" rel="{{}}" class="widgetinteractdialog" title="{{}} interaction">
<p>Running code, yo.</p>
<form id="widget-form-{{}}">
<input id="out-{{}}" type="hidden" name="out"/>
<input type="hidden" name="widget_id" value="{{}}"/>
<!-- Behaviour -->
<script type="text/javascript">
function execCode() {
var inputs = {{ inputs|safe }};
{{ snippet|safe }}
// To ensure that `out` is always json-serializable, always add it to a list
out = [out];
// Finish interaction after the code executes
setTimeout(execCode, 500);
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment