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

save

parent 6f225cb0
This diff is collapsed.
......@@ -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}}',
'<blockquote>',
'<p>${workflow.name}</p>',
'<small>${workflow.help}</small>',
'</blockquote>',
'{{/each}}'].join('\n'),
workflowForm: ['<form class="form-horizontal">',
'<fieldset>',
' <div id="legend" class="">',
' <legend class="">${workflow.name} <small>${workflow.help}</small></legend>',
' </div>',
' {{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 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 placeholder="${param.default}" class="input-xlarge" type="text">',
' {{/if}}',
' <p class="help-block">${param.help}</p>',
' </div>',
' </div>',
' {{/each}}',
' <div class="control-group">',
' <label class="control-label"></label>',
' <div class="controls">',
' <div class="btn-toolbar">',
' <div class="btn-group">',
' <a class="btn" href="#"><i class="icon-refresh"></i>Reset</a>',
' <a class="btn btn-primary" href="#"><i class="icon-cog icon-white"></i> Run</a>',
' </div>',
' </div>',
' </div>',
' </div>',
'</fieldset>',
'</form>'].join('\n'),
errorTemplate: ['<div class="alert alert-error">',
'<button type="button" class="close" data-dismiss="alert">&times;</button>',
'<strong>${title}</strong> ${message}',
'</div>'].join('\n')
view: "workflowsList",
template: "basic",
availableWorkflowsList: {
templates: {
basic: ['<table class="table table-striped table-striped">',
'<thead>',
'<tr>',
'<th>Name</th>',
'<th>Description</th>',
'</tr>',
'</thead>',
'{{each(index, workflow) workflows}}',
'<tr>',
'<td><a id="set_and_run_${workflow.class}" href="#">${workflow.name}</a></td>',
'<td>${workflow.help}</td>',
'</tr>',
'{{/each}}',
'</dl>'].join('\n')
},
setAndRunCallback: function(workflow) { alert("clicking on " + workflow.name); }
},
activeWorkflowsList: {
templates: {
basic: ['<table class="table table-striped table-striped">',
'<thead>',
'<tr>',
'<th>ID<th>',
'<th>Name</th>',
'<th>Status</th>',
'<th>Start time</th>',
'<th>End time</th>',
'</tr>',
'</thead>',
'{{each(index, workflow) workflows}}',
'<tr>',
'<td><a id="monitor_${workflow.id}" href="#">${workflow.id}</a><td>',
'<td>${workflow.name}</td>',
'{{if workflow.status == "completed"}}',
'<td> <span class="label label-success">${workflow.status}</span></td>',
'{{else workflow.status == "aborted"}}',
'<td> <span class="label label-important">${workflow.status}</span></td>',
'{{else workflow.status == "started"}}',
'<td> <span class="label label-info">${workflow.status}</span></td>',
'{{else}}',
'<td>${workflow.status}</td>',
'{{/if}}',
'<td>${workflow.start_time}</td>',
'<td>${workflow.end_time}</td>',
'</tr>',
'{{/each}}',
'</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({
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('<div id="'+JFLOW_CONTAINER_PREFIX+index.toString()+'"></div>');
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
}
});
......
......@@ -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
......
......@@ -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
......
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