Commit 75499001 authored by Jerome Mariette's avatar Jerome Mariette
Browse files

handle exclusion rules

parent 990f6173
......@@ -256,7 +256,7 @@ class Workflow(threading.Thread):
self.__setattr__(name, new_param)
def add_exclusion_rule(self, *args2exclude):
# first of all, are this parameter exist
# first of all, does this parameter exist
params2exclude = []
for arg2exclude in args2exclude:
try:
......@@ -269,20 +269,23 @@ class Workflow(threading.Thread):
paramsexclude.group = new_group
# it might be a mutliple param rule
else:
for attribute_value in self.__dict__.values():
if issubclass(attribute_value.__class__, MultiParameter) or issubclass(attribute_value.__class__, MultiParameterList):
params2exclude = []
for sub_param in attribute_value.sub_parameters:
if sub_param.name in args2exclude:
params2exclude.append(sub_param)
if len(params2exclude) == len(args2exclude):
new_group = "exclude-"+uuid.uuid4().hex[:5]
flags2exclude = []
for paramsexclude in params2exclude:
paramsexclude.group = new_group
flags2exclude.append(paramsexclude.flag)
attribute_value.type.excludes[new_group] = flags2exclude
break
logging.getLogger("wf." + str(self.__class__.__name__)).exception("Exclusion rule cannot be applied within a MultiParameter or a MultiParameterList")
raise
# save this for MultiParameter internal exclusion rules, works on command line, not supported on gui
# for attribute_value in self.__dict__.values():
# if issubclass(attribute_value.__class__, MultiParameter) or issubclass(attribute_value.__class__, MultiParameterList):
# params2exclude = []
# for sub_param in attribute_value.sub_parameters:
# if sub_param.name in args2exclude:
# params2exclude.append(sub_param)
# if len(params2exclude) == len(args2exclude):
# new_group = "exclude-"+uuid.uuid4().hex[:5]
# flags2exclude = []
# for paramsexclude in params2exclude:
# paramsexclude.group = new_group
# flags2exclude.append(paramsexclude.flag)
# attribute_value.type.excludes[new_group] = flags2exclude
# break
def _prepare_parameter(self, args, parameter, key="name"):
new_param = None
......@@ -339,7 +342,7 @@ class Workflow(threading.Thread):
if param.__class__ == MultiParameter:
new_param = MultiParameter(param.name, param.help, required=param.required, flag=param.flag, group=param.group, display_name=param.display_name)
new_param.sub_parameters = param.sub_parameters
if args[param.name]:
if args.has_key(param.name):
sub_args = {}
for sarg in args[param.name]:
sub_args[sarg[0]] = sarg[1]
......
......@@ -113,30 +113,6 @@ var _isSet = function( $element ) {
errorClass: "has-error"
});
jQuery.validator.addMethod("exclude_required", function(value, element, options) {
var validator = this,
selector = options;
var numberFilled = $(selector, element.form).filter(function() {
return _isSet($(this));
}).length;
var valid = false;
if (numberFilled === 1) {
valid = true;
}
/*$(selector).each(function() {
if( !$(this).is(element) ){
if( valid ){
$( "#" + $(this).attr("id") + "-error" ).remove();
validator.settings.unhighlight( $(this), validator.settings.errorClass, validator.settings.validClass );
} else {
validator.settings.highlight( $(this), validator.settings.errorClass, validator.settings.validClass );
validator.showLabel( validator.findByName( $(this).attr("name") )[0], "Please fill one and only one of these fields." );
}
}
});*/
return valid;
}, jQuery.validator.format("Please fill one and only one of these fields."));
jQuery.validator.addMethod("maxfilesize", function(value, element, params) {
if (params[0] != 0) {
if ($(element).data("data2upload").files.length == 1) {
......@@ -386,6 +362,7 @@ Handsontable.cellTypes["bootdate"] = Handsontable.BootstrapDateCell;
// when serializing, multiple data are repeated, so build a hash to gather values from the same parameter
$.each ( $('#workflow_form').serializeArray(), function(_, kv) {
if (!$('#'+kv.name).hasClass("hidden-exclude")) {
if (hash_param.hasOwnProperty(kv.name)) {
hash_param[kv.name].push(kv.value);
} else if( kv.value != "" ) { //Empty are not sended
......@@ -396,6 +373,7 @@ Handsontable.cellTypes["bootdate"] = Handsontable.BootstrapDateCell;
hash_param[kv.name] = new Array(kv.value);
}
}
}
});
// handle multiple variables
......@@ -665,7 +643,8 @@ Handsontable.cellTypes["bootdate"] = Handsontable.BootstrapDateCell;
// for exclude-required first check if there is no exclusion group with a required option
var excludereq = new Array(),
params_per_name = {};
params_per_name = {},
params_per_group = {};
for (var i in $this.workflow.parameters) {
if ($this.workflow.parameters[i].group.indexOf("exclude-") != -1 && $this.workflow.parameters[i].required) {
if (excludereq.indexOf($this.workflow.parameters[i].group) == -1) {
......@@ -673,6 +652,10 @@ Handsontable.cellTypes["bootdate"] = Handsontable.BootstrapDateCell;
}
}
params_per_name[$this.workflow.parameters[i].name] = $this.workflow.parameters[i];
if( !params_per_group.hasOwnProperty( $this.workflow.parameters[i].group ) ){
params_per_group[$this.workflow.parameters[i].group] = new Array();
}
params_per_group[$this.workflow.parameters[i].group].push($this.workflow.parameters[i].name);
}
for (var i in $this.workflow.parameters) {
// if it's a multiple parameter add its sub parameters as rules
......@@ -687,6 +670,46 @@ Handsontable.cellTypes["bootdate"] = Handsontable.BootstrapDateCell;
$("#workflow_form").validate({ rules: rules });
$("[id^=prev_btn_]").click(function() {
var group = $(this).attr("id").split("prev_btn_")[1],
current_param = $('.'+group+':visible'),
param_name = current_param.attr("id").split("content_")[1],
idx_param = params_per_group[group].indexOf( param_name ),
prev_idx = null ;
// Change content
current_param.addClass( "hidden hidden-exclude" );
if( idx_param == 0 ) {
prev_idx = params_per_group[group].length - 1 ;
} else {
prev_idx = idx_param - 1;
}
$('#content_' + params_per_group[group][prev_idx]).removeClass( "hidden hidden-exclude" );
// Change label
$('#label_'+group).html( params_per_name[params_per_group[group][prev_idx]].display_name );
});
$("[id^=next_btn_]").click(function() {
var group = $(this).attr("id").split("next_btn_")[1],
current_param = $('.'+group+':visible'),
param_name = current_param.attr("id").split("content_")[1],
idx_param = params_per_group[group].indexOf( param_name ),
next_idx = null ;
// Change content
current_param.addClass( "hidden hidden-exclude" );
if( idx_param == params_per_group[group].length - 1 ) {
next_idx = 0 ;
} else {
next_idx = idx_param + 1;
}
$('#content_' + params_per_group[group][next_idx]).removeClass( "hidden hidden-exclude" );
// Change label
$('#label_'+group).html( params_per_name[params_per_group[group][next_idx]].display_name );
});
// for multiple and append values, use the handsontable
$("[id^=handsontable_]").each(function(){
var id_parts = $(this).attr("id").split("handsontable_"),
......@@ -946,9 +969,9 @@ Handsontable.cellTypes["bootdate"] = Handsontable.BootstrapDateCell;
}
};
}
if (excludereq.indexOf(param.group) != -1) {
crule["exclude_required"] = "."+param.group;
crule["required"] = false;
crule["required"] = true;
} else if (param.group.indexOf("exclude-") == -1) {
crule["required"] = param.required;
}
......@@ -1021,7 +1044,7 @@ Handsontable.cellTypes["bootdate"] = Handsontable.BootstrapDateCell;
'{{else}}',
' <div id="date_${param.name}" class="input-group date" data-date="${param.default}" data-date-format="${param.format}">',
'{{/if}}',
' <input id="${param.name}" name="${param.name}" class="form-control ${param.group}" type="text" value="${param.default}">',
' <input id="${param.name}" name="${param.name}" class="form-control" type="text" value="${param.default}">',
' <span class="input-group-btn">',
' <button class="btn btn-default" type="button"><span class="glyphicon glyphicon-calendar"></span>&nbsp;</button>',
' </span>',
......@@ -1031,9 +1054,9 @@ Handsontable.cellTypes["bootdate"] = Handsontable.BootstrapDateCell;
choiceTemplate: [
'<div>',
'{{if param.action == "append"}}', // if it's a multiple choice parameter, add a multiple select
' <select id="${param.name}" multiple name="${param.name}" class="form-control ${param.group} list">',
' <select id="${param.name}" multiple name="${param.name}" class="form-control list">',
'{{else}}', // if it's a single choice parameter, add a simple select
' <select id="${param.name}" name="${param.name}" class="form-control ${param.group}">',
' <select id="${param.name}" name="${param.name}" class="form-control">',
'{{/if}}',
' {{if param.default != null}}',
' <option></option>',
......@@ -1072,9 +1095,9 @@ Handsontable.cellTypes["bootdate"] = Handsontable.BootstrapDateCell;
' </ul>',
' </div>',
' {{if param.action == "append"}}',
' <textarea id="${param.name}" style="resize:none" name="${param.name}" class="list form-control ${param.group}">${param.default.join("\n")}</textarea>',
' <textarea id="${param.name}" style="resize:none" name="${param.name}" class="list form-control">${param.default.join("\n")}</textarea>',
' {{else}}',
' <input id="${param.name}" name="${param.name}" class="form-control ${param.group}" type="text" value="${param.default}">',
' <input id="${param.name}" name="${param.name}" class="form-control" type="text" value="${param.default}">',
' {{/if}}',
' <span class="input-group-btn">',
// ' {{if param.action == "append"}}',
......@@ -1090,9 +1113,9 @@ Handsontable.cellTypes["bootdate"] = Handsontable.BootstrapDateCell;
'<div>',
' <div class="input-group">',
' {{if param.action == "append"}}',
' <textarea id="${param.name}" style="resize:none" name="${param.name}" readonly="readonly" class="list form-control ${param.group}">${param.default.join("\n")}</textarea>',
' <textarea id="${param.name}" style="resize:none" name="${param.name}" readonly="readonly" class="list form-control">${param.default.join("\n")}</textarea>',
' {{else}}',
' <input id="${param.name}" name="${param.name}" class="form-control ${param.group}" type="text" value="${param.default}" readonly="readonly">',
' <input id="${param.name}" name="${param.name}" class="form-control" type="text" value="${param.default}" readonly="readonly">',
' {{/if}}',
' <span class="input-group-btn">',
' <button id="urlfile_btn_${param.name}" class="btn btn-default" type="button"><span class="glyphicon glyphicon-folder-open"></span>&nbsp;</button>',
......@@ -1102,7 +1125,7 @@ Handsontable.cellTypes["bootdate"] = Handsontable.BootstrapDateCell;
].join('\n'),
regexpfilesTemplate: [
'<div>',
' <textarea id="${param.name}" style="resize:none" name="${param.name}" class="list form-control ${param.group}">${param.default.join("\n")}</textarea>',
' <textarea id="${param.name}" style="resize:none" name="${param.name}" class="list form-control">${param.default.join("\n")}</textarea>',
'</div>'
].join('\n'),
booleanTemplate: [
......@@ -1110,9 +1133,9 @@ Handsontable.cellTypes["bootdate"] = Handsontable.BootstrapDateCell;
// ' <div class="checkbox-inline">',
// ' <label>',
' {{if param.default == true}}',
' <input id="${param.name}" name="${param.name}" class="${param.group}" value="${param.default}" type="checkbox" checked> ${check_title}',
' <input id="${param.name}" name="${param.name}" value="${param.default}" type="checkbox" checked> ${check_title}',
' {{else}}',
' <input id="${param.name}" name="${param.name}" class="${param.group}" value="${param.default}" type="checkbox"> ${check_title}',
' <input id="${param.name}" name="${param.name}" value="${param.default}" type="checkbox"> ${check_title}',
' {{/if}}',
// ' </label>',
// ' </div>',
......@@ -1121,9 +1144,9 @@ Handsontable.cellTypes["bootdate"] = Handsontable.BootstrapDateCell;
textTemplate: [
'<div>',
' {{if param.action == "append"}}',
' <textarea id="${param.name}" style="resize:none" name="${param.name}" class="list form-control ${param.group}">${param.default.join("\n")}</textarea>',
' <textarea id="${param.name}" style="resize:none" name="${param.name}" class="list form-control">${param.default.join("\n")}</textarea>',
' {{else}}',
' <input id="${param.name}" name="${param.name}" value="${param.default}" class="form-control ${param.group}" type="text">',
' <input id="${param.name}" name="${param.name}" value="${param.default}" class="form-control" type="text">',
' {{/if}}',
'</div>'
].join('\n'),
......@@ -1137,11 +1160,19 @@ Handsontable.cellTypes["bootdate"] = Handsontable.BootstrapDateCell;
' {{each(index, param) workflow.parameters_per_groups[group]}}',
// it the parameter has not already been settled
' {{if Object.keys(parameters).indexOf(param.name) == -1 }}',
// if this is an exclusion group, only display one label and make only one structure
' {{if (group.indexOf("exclude-") == 0 && index ==0) || group.indexOf("exclude-") != 0}}',
' <div class="form-group param-field">',
' <label class="col-sm-2 control-label" for="${param.name}">${param.display_name}</label>',
' <label id="label_${param.group}" class="col-sm-2 control-label" for="${param.name}">${param.display_name}</label>',
' {{/if}}',
' {{if group.indexOf("exclude-") == 0 }}',
' <div id="content_${param.name}" class="col-sm-9 ${param.group}{{if index != 0}} hidden hidden-exclude{{/if}}">',
' {{else}}',
' <div class="col-sm-10">',
' {{/if}}',
// if it's a multiple type
' {{if param.type == "MultipleParameters"}}',
' <div class="col-sm-10">',
' <blockquote style="font-size:14px;">',
' {{if param.action == "MiltipleAppendAction"}}', // if it's an append and multiple type
' <div id="handsontable_${param.name}" > </div>',
......@@ -1163,18 +1194,28 @@ Handsontable.cellTypes["bootdate"] = Handsontable.BootstrapDateCell;
' {{/each}}',
' {{/if}}',
' </blockquote>',
' </div>',
// if it's a std type
// if it's a single type
' {{else}}',
' <div class="col-sm-10">',
' {{html getParameterDisplay(templates, getTplName(param), param)}}',
' <span class="help-block">${param.help}</span>',
' {{/if}}',
' </div>',
' {{if group.indexOf("exclude-") == 0 && index == workflow.parameters_per_groups[group].length-1 }}',
' {{if group.indexOf("exclude-") == 0 }}',
' <div class="col-sm-1">',
' <span class="input-group-btn btn-group-xs">',
' <button id="prev_btn_${param.group}" class="btn btn-default" type="button"><span class="glyphicon glyphicon-chevron-left"></span>&nbsp;</button>',
' <button id="next_btn_${param.group}" class="btn btn-default" type="button"><span class="glyphicon glyphicon-chevron-right"></span>&nbsp;</button>',
' </span>',
' </div>',
' {{/if}}',
' </div>',
' {{else group.indexOf("exclude-") != 0}}',
' </div>',
' {{/if}}',
' {{else}}',
// if the param is already settled, hide it
' <input id="${param.name}" name="${param.name}" class="${param.group}" value="${parameters[param.name]}" type="hidden">',
' <input id="${param.name}" name="${param.name}" value="${parameters[param.name]}" type="hidden">',
' {{/if}}',
' {{/each}}',
' </fieldset>',
......
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