diff --git a/bin/index.html b/bin/index.html index f6e9b77668d34d358135a400d1405fce5012751d..ef4d627ec739a2fb2d6abd85b874965a54851195 100644 --- a/bin/index.html +++ b/bin/index.html @@ -1,134 +1,184 @@ - - - Jflow - Test page - - - + + + Jflow - - - - + + + + + + - - - - - - - - - - - - - - - -
- - -
-

Hello, world!

-

This is a template for a simple marketing or informational website. It includes a large callout called the hero unit and three supporting pieces of content. Use it as a starting point to create something more unique.

-

Learn more »

-
- - -
-
-

Heading

-

Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui.

-

View details »

-
-
-

Heading

-

Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui.

-

View details »

-
-
-

Heading

-

Donec sed odio dui. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Vestibulum id ligula porta felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.

-

View details »

-
-
+ + + + +
+
+ + +
+

Hello, world!

+

This is a template for a simple workflow manager website. It includes a large callout called the hero unit and three supporting pieces of content. Use it as a starting point to create something more unique.

+

Learn more »

+
-
-
-
-
-
-

© Company 2013

-
+
+
+ +
+
+
+ +
+
+
+ + + + + + + +
+
+

PF bioinformatic GenoToul 2013

+
-
+
- - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - + + + + \ No newline at end of file diff --git a/bin/jflow.js b/bin/jflow.js index defa747bc6619cc080400ddb825a65bcce4370c8..f0090015f44eeb922739e5cefe1e006f11dc5b6e 100644 --- a/bin/jflow.js +++ b/bin/jflow.js @@ -18,83 +18,149 @@ * * This copyright notice MUST APPEAR in all copies of the script! ***************************************************************/ - -(function($) { +(function($) { + $.fn.jflow = function(options) { var JFLOW_CONTAINER_PREFIX = "jflow_container_"; var defaults = { + jflowServerWebPath: "http://localhost:8080", - template: "workflowsList", - workflow_class: null, - workflowsList: ['{{each(index, workflow) workflows}}', - '
', - '

${workflow.name}

', - '${workflow.help}', - '
', - '{{/each}}'].join('\n'), - workflowForm: ['
', - '
', - '
', - ' ${workflow.name} ${workflow.help}', - '
', - ' {{each(index, param) workflow.parameters}}', - '
', - ' ', - '
', - // if it's a multiple choice parameter, add a select - ' {{if param.choices}}', - ' ', - // else a simple text input - ' {{else}}', - ' ', - ' {{/if}}', - '

${param.help}

', - '
', - '
', - ' {{/each}}', - '
', - ' ', - '
', - '
', - '
', - ' Reset', - ' Run', - '
', - '
', - '
', - '
', - '
', - '
'].join('\n'), - errorTemplate: ['
', - '', - '${title} ${message}', - '
'].join('\n') + view: "workflowsList", + template: "basic", + + availableWorkflowsList: { + templates: { + basic: ['', + '', + '', + '', + '', + '', + '', + '{{each(index, workflow) workflows}}', + '', + '', + '', + '', + '{{/each}}', + ''].join('\n') + }, + setAndRunCallback: function(workflow) { alert("clicking on " + workflow.name); } + }, + + activeWorkflowsList: { + templates: { + basic: ['
NameDescription
${workflow.name}${workflow.help}
', + '', + '', + '', + '', + '', + '', + '', + '', + '{{each(index, workflow) workflows}}', + '', + '', + '{{if workflow.status == "completed"}}', + '', + '{{else workflow.status == "aborted"}}', + '', + '{{else workflow.status == "started"}}', + '', + '{{else}}', + '', + '{{/if}}', + '', + '', + '', + '{{/each}}', + '
ID', + 'NameStatusStart timeEnd time
${workflow.id}', + '${workflow.name} ${workflow.status} ${workflow.status} ${workflow.status}${workflow.status}${workflow.start_time}${workflow.end_time}
'].join('\n') + }, + viewCallback: function(workflow) { alert("clicking on " + workflow.id); } + }, + + /** + * Workflow form template + * + * @param service: + * @param service: + */ + workflowForm: { + templates: { + basic: ['
', + '
', + ' {{each(index, param) workflow.parameters}}', + '
', + ' ', + '
', + // if it's a multiple choice parameter, add a select + ' {{if param.choices}}', + ' ', + // else a simple text input + ' {{else}}', + ' ', + ' {{/if}}', + '

${param.help}

', + '
', + '
', + ' {{/each}}', + // for all workflow add the workflow_class + ' ', + '
', + '
'].join('\n') + }, + workflow_class: null, + run_function: function() { + alert(run); + } + } }; - var opts = $.extend(defaults, options); + var opts = $.extend(true, defaults, options); - var _displayWorkflowsList = function(div) { + var _generateAvailableWorkflowsListView = function(div) { $.ajax({ url: opts.jflowServerWebPath + '/get_available_workflows?callback=?', dataType: "json", success: function(data) { - $.tmpl(opts["workflowsList"], {workflows: data}).appendTo(div); + var workflow_by_class = {}; + for (var i in data) { + workflow_by_class[data[i]["class"]] = data[i]; + } + $.tmpl(opts["availableWorkflowsList"].templates[opts.template], {workflows: data}).appendTo(div); + $("[id^=set_and_run_]").click(function(){ + var workflow_class = $(this).attr("id").split("set_and_run_")[1]; + opts.availableWorkflowsList.setAndRunCallback(workflow_by_class[workflow_class]); + }); } }); } - - var _displayWorkflowForm = function(div) { - if (opts.workflow_class == null) { - $.tmpl(opts["errorTemplate"], {"title": "Error!", "message": "workflow_class option is required."}).appendTo(div); + + var _run_workflow = function() { + $.ajax({ + url: opts.jflowServerWebPath + '/run_workflow?callback=?', + dataType: "json", + success: function(data) { + alert("runnnnnnnnnnn"); + } + }); + } + + var _generateWorkflowFormView = function(div) { + if (opts.workflowForm.workflow_class == null) { + alert("error") } else { $.ajax({ url: opts.jflowServerWebPath + '/get_available_workflows?callback=?', @@ -102,17 +168,35 @@ success: function(data) { var workflow = null; for (var i in data) { - if (data[i]["class"] == opts.workflow_class) { + if (data[i]["class"] == opts.workflowForm.workflow_class) { workflow = data[i]; break; } } - $.tmpl(opts["workflowForm"], {workflow: workflow}).appendTo(div); + $.tmpl(opts["workflowForm"].templates[opts.template], {workflow: workflow}).appendTo(div); } }); } } + var _generateActiveWorkflowsListView = function(div) { + $.ajax({ + url: opts.jflowServerWebPath + '/get_workflows_status?callback=?', + dataType: "json", + success: function(data) { + var workflow_by_id = {}; + for (var i in data) { + workflow_by_id[data[i]["id"]] = data[i]; + } + $.tmpl(opts["activeWorkflowsList"].templates[opts.template], {workflows: data}).appendTo(div); + $("[id^=monitor_]").click(function(){ + var workflow_id = $(this).attr("id").split("monitor_")[1]; + opts.activeWorkflowsList.viewCallback(workflow_by_id[workflow_id]); + }); + } + }); + } + this.each(function() { var $t = $(this), indexes = new Array(), @@ -127,12 +211,15 @@ } $t.html('
'); var $div = $("#"+JFLOW_CONTAINER_PREFIX+index.toString()); - switch (opts.template) { + switch (opts.view) { case "workflowForm": - _displayWorkflowForm($div); + _generateWorkflowFormView($div); + break; + case "activeWorkflowsList": + _generateActiveWorkflowsListView($div); break; default: - _displayWorkflowsList($div); + _generateAvailableWorkflowsListView($div); break } }); diff --git a/bin/jflow_server.py b/bin/jflow_server.py index 85f46862e9048ed331537642cb635890425f4ba2..8b0d5e8bf4e80bd338aa2109442985766c487082 100644 --- a/bin/jflow_server.py +++ b/bin/jflow_server.py @@ -88,7 +88,24 @@ class JFlowServer (object): "components": components} return status - + + def extend_parameters(self, workflow_class, kwargs): + extended_kwargs = {} + workflow = self.wfmanager.get_workflow_by_class(workflow_class) + for param in workflow.parameters: + # if it's an append parameter, the result should be a list + if param.action == "append": + if kwargs.has_key(param.name): + extended_kwargs[param.name] = kwargs[param.name].split(",") + else: + extended_kwargs[param.name] = [] + else: + if kwargs.has_key(param.name): + extended_kwargs[param.name] = kwargs[param.name] + else: + extended_kwargs[param.name] = param.default + return extended_kwargs + @cherrypy.expose @jsonify def get_available_workflows(self, **kwargs): @@ -111,9 +128,8 @@ class JFlowServer (object): @cherrypy.expose @jsonify def run_workflow(self, **kwargs): - print kwargs - return [{"return": "sdsdsd"}] - # self.wfmanager.run_workflow(workflow_class, args, True) + args = self.extend_parameters(kwargs["workflow_class"], kwargs) + self.wfmanager.run_workflow(kwargs["workflow_class"], args) @cherrypy.expose @jsonify diff --git a/src/jflow/workflows_manager.py b/src/jflow/workflows_manager.py index d4e9bfa3129026e28e1dc7eb21885eace8b853b2..ffa74553a7de0be7ca3815b37e8fc4b461e2f6a2 100644 --- a/src/jflow/workflows_manager.py +++ b/src/jflow/workflows_manager.py @@ -87,6 +87,16 @@ class WorkflowsManager(object): workflow_dump.close() except: pass return workflows + + def get_workflow_by_class(self, workflow_class): + # Load all modules within the workflow module + for importer, modname, ispkg in pkgutil.iter_modules(workflows.__path__, workflows.__name__ + "."): + __import__(modname) + # Search for Workflow classes + for class_name, obj in inspect.getmembers(sys.modules[modname], inspect.isclass): + if class_name == workflow_class: + return obj() + return None def get_workflow(self, workflow_id): from jflow.workflow import Workflow