Commit 6ca08bcc authored by Jerome Mariette's avatar Jerome Mariette

save

parent 6f225cb0
This diff is collapsed.
...@@ -18,83 +18,149 @@ ...@@ -18,83 +18,149 @@
* *
* This copyright notice MUST APPEAR in all copies of the script! * This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/ ***************************************************************/
(function($) {
(function($) {
$.fn.jflow = function(options) { $.fn.jflow = function(options) {
var JFLOW_CONTAINER_PREFIX = "jflow_container_"; var JFLOW_CONTAINER_PREFIX = "jflow_container_";
var defaults = { var defaults = {
jflowServerWebPath: "http://localhost:8080", jflowServerWebPath: "http://localhost:8080",
template: "workflowsList", view: "workflowsList",
workflow_class: null, template: "basic",
workflowsList: ['{{each(index, workflow) workflows}}',
'<blockquote>', availableWorkflowsList: {
'<p>${workflow.name}</p>', templates: {
'<small>${workflow.help}</small>', basic: ['<table class="table table-striped table-striped">',
'</blockquote>', '<thead>',
'{{/each}}'].join('\n'), '<tr>',
workflowForm: ['<form class="form-horizontal">', '<th>Name</th>',
'<fieldset>', '<th>Description</th>',
' <div id="legend" class="">', '</tr>',
' <legend class="">${workflow.name} <small>${workflow.help}</small></legend>', '</thead>',
' </div>', '{{each(index, workflow) workflows}}',
' {{each(index, param) workflow.parameters}}', '<tr>',
' <div class="control-group">', '<td><a id="set_and_run_${workflow.class}" href="#">${workflow.name}</a></td>',
' <label class="control-label">${param.name}</label>', '<td>${workflow.help}</td>',
' <div class="controls">', '</tr>',
// if it's a multiple choice parameter, add a select '{{/each}}',
' {{if param.choices}}', '</dl>'].join('\n')
' <select class="input-xlarge">', },
' {{each(j, choice) param.choices}}', setAndRunCallback: function(workflow) { alert("clicking on " + workflow.name); }
' {{if choice == param.default}}', },
' <option selected>${choice}</option>',
' {{else}}', activeWorkflowsList: {
' <option>${choice}</option>', templates: {
' {{/if}}', basic: ['<table class="table table-striped table-striped">',
' {{/each}}', '<thead>',
' </select>', '<tr>',
// else a simple text input '<th>ID<th>',
' {{else}}', '<th>Name</th>',
' <input placeholder="${param.default}" class="input-xlarge" type="text">', '<th>Status</th>',
' {{/if}}', '<th>Start time</th>',
' <p class="help-block">${param.help}</p>', '<th>End time</th>',
' </div>', '</tr>',
' </div>', '</thead>',
' {{/each}}', '{{each(index, workflow) workflows}}',
' <div class="control-group">', '<tr>',
' <label class="control-label"></label>', '<td><a id="monitor_${workflow.id}" href="#">${workflow.id}</a><td>',
' <div class="controls">', '<td>${workflow.name}</td>',
' <div class="btn-toolbar">', '{{if workflow.status == "completed"}}',
' <div class="btn-group">', '<td> <span class="label label-success">${workflow.status}</span></td>',
' <a class="btn" href="#"><i class="icon-refresh"></i>Reset</a>', '{{else workflow.status == "aborted"}}',
' <a class="btn btn-primary" href="#"><i class="icon-cog icon-white"></i> Run</a>', '<td> <span class="label label-important">${workflow.status}</span></td>',
' </div>', '{{else workflow.status == "started"}}',
' </div>', '<td> <span class="label label-info">${workflow.status}</span></td>',
' </div>', '{{else}}',
' </div>', '<td>${workflow.status}</td>',
'</fieldset>', '{{/if}}',
'</form>'].join('\n'), '<td>${workflow.start_time}</td>',
errorTemplate: ['<div class="alert alert-error">', '<td>${workflow.end_time}</td>',
'<button type="button" class="close" data-dismiss="alert">&times;</button>', '</tr>',
'<strong>${title}</strong> ${message}', '{{/each}}',
'</div>'].join('\n') '</table>'].join('\n')
},
viewCallback: function(workflow) { alert("clicking on " + workflow.id); }
},
/**
* Workflow form template
*
* @param service:
* @param service:
*/
workflowForm: {
templates: {
basic: ['<form id="workflow_form" class="form-horizontal">',
'<fieldset>',
' {{each(index, param) workflow.parameters}}',
' <div class="control-group">',
' <label class="control-label">${param.name}</label>',
' <div class="controls">',
// if it's a multiple choice parameter, add a select
' {{if param.choices}}',
' <select name="${param.name}" class="input-xlarge">',
' {{each(j, choice) param.choices}}',
' {{if choice == param.default}}',
' <option selected>${choice}</option>',
' {{else}}',
' <option>${choice}</option>',
' {{/if}}',
' {{/each}}',
' </select>',
// else a simple text input
' {{else}}',
' <input name="${param.name}" value="${param.default}" class="input-xlarge" type="text">',
' {{/if}}',
' <p class="help-block">${param.help}</p>',
' </div>',
' </div>',
' {{/each}}',
// for all workflow add the workflow_class
' <input name="workflow_class" value="${workflow.class}" type="hidden">',
'</fieldset>',
'</form>'].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({ $.ajax({
url: opts.jflowServerWebPath + '/get_available_workflows?callback=?', url: opts.jflowServerWebPath + '/get_available_workflows?callback=?',
dataType: "json", dataType: "json",
success: function(data) { 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) { var _run_workflow = function() {
if (opts.workflow_class == null) { $.ajax({
$.tmpl(opts["errorTemplate"], {"title": "Error!", "message": "workflow_class option is required."}).appendTo(div); 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 { } else {
$.ajax({ $.ajax({
url: opts.jflowServerWebPath + '/get_available_workflows?callback=?', url: opts.jflowServerWebPath + '/get_available_workflows?callback=?',
...@@ -102,17 +168,35 @@ ...@@ -102,17 +168,35 @@
success: function(data) { success: function(data) {
var workflow = null; var workflow = null;
for (var i in data) { for (var i in data) {
if (data[i]["class"] == opts.workflow_class) { if (data[i]["class"] == opts.workflowForm.workflow_class) {
workflow = data[i]; workflow = data[i];
break; 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() { this.each(function() {
var $t = $(this), var $t = $(this),
indexes = new Array(), indexes = new Array(),
...@@ -127,12 +211,15 @@ ...@@ -127,12 +211,15 @@
} }
$t.html('<div id="'+JFLOW_CONTAINER_PREFIX+index.toString()+'"></div>'); $t.html('<div id="'+JFLOW_CONTAINER_PREFIX+index.toString()+'"></div>');
var $div = $("#"+JFLOW_CONTAINER_PREFIX+index.toString()); var $div = $("#"+JFLOW_CONTAINER_PREFIX+index.toString());
switch (opts.template) { switch (opts.view) {
case "workflowForm": case "workflowForm":
_displayWorkflowForm($div); _generateWorkflowFormView($div);
break;
case "activeWorkflowsList":
_generateActiveWorkflowsListView($div);
break; break;
default: default:
_displayWorkflowsList($div); _generateAvailableWorkflowsListView($div);
break break
} }
}); });
......
...@@ -88,7 +88,24 @@ class JFlowServer (object): ...@@ -88,7 +88,24 @@ class JFlowServer (object):
"components": components} "components": components}
return status 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 @cherrypy.expose
@jsonify @jsonify
def get_available_workflows(self, **kwargs): def get_available_workflows(self, **kwargs):
...@@ -111,9 +128,8 @@ class JFlowServer (object): ...@@ -111,9 +128,8 @@ class JFlowServer (object):
@cherrypy.expose @cherrypy.expose
@jsonify @jsonify
def run_workflow(self, **kwargs): def run_workflow(self, **kwargs):
print kwargs args = self.extend_parameters(kwargs["workflow_class"], kwargs)
return [{"return": "sdsdsd"}] self.wfmanager.run_workflow(kwargs["workflow_class"], args)
# self.wfmanager.run_workflow(workflow_class, args, True)
@cherrypy.expose @cherrypy.expose
@jsonify @jsonify
......
...@@ -87,6 +87,16 @@ class WorkflowsManager(object): ...@@ -87,6 +87,16 @@ class WorkflowsManager(object):
workflow_dump.close() workflow_dump.close()
except: pass except: pass
return workflows 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): def get_workflow(self, workflow_id):
from jflow.workflow import Workflow from jflow.workflow import Workflow
......
Markdown is supported
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