Skip to content
Snippets Groups Projects
Commit f50b8fa0 authored by juanf's avatar juanf
Browse files

SSDM-4184 : Operators for search

SVN: 37910
parent 567d2ea4
No related branches found
No related tags found
No related merge requests found
...@@ -837,7 +837,8 @@ function ServerFacade(openbisServer) { ...@@ -837,7 +837,8 @@ function ServerFacade(openbisServer) {
var fieldName = advancedSearchCriteria.rules[ruleKeys[idx]].name; var fieldName = advancedSearchCriteria.rules[ruleKeys[idx]].name;
var fieldNameType = null; var fieldNameType = null;
var fieldValue = advancedSearchCriteria.rules[ruleKeys[idx]].value; var fieldValue = advancedSearchCriteria.rules[ruleKeys[idx]].value;
var fieldOperator = advancedSearchCriteria.rules[ruleKeys[idx]].operator;
if(fieldName) { if(fieldName) {
var firstDotIndex = fieldName.indexOf("."); var firstDotIndex = fieldName.indexOf(".");
fieldNameType = fieldName.substring(0, firstDotIndex); fieldNameType = fieldName.substring(0, firstDotIndex);
...@@ -848,8 +849,54 @@ function ServerFacade(openbisServer) { ...@@ -848,8 +849,54 @@ function ServerFacade(openbisServer) {
fieldValue = "*"; fieldValue = "*";
} }
var setPropertyCriteria = function(criteria, propertyName, propertyValue) { var setPropertyCriteria = function(criteria, propertyName, propertyValue, comparisonOperator) {
criteria.withProperty(propertyName).thatContains(propertyValue); if(comparisonOperator) {
try {
switch(comparisonOperator) {
case "thatEqualsString":
criteria.withProperty(propertyName).thatEquals(propertyValue);
break;
case "thatEqualsNumber":
criteria.withNumberProperty(propertyName).thatEquals(parseFloat(propertyValue));
break;
case "thatEqualsDate":
criteria.withDateProperty(propertyName).thatEquals(propertyValue);
break;
case "thatContainsString":
criteria.withProperty(propertyName).thatContains(propertyValue);
break;
case "thatStartsWithString":
criteria.withProperty(propertyName).thatStartsWith(propertyValue);
break;
case "thatEndsWithString":
criteria.withProperty(propertyName).thatEndsWith(propertyValue);
break;
case "thatIsLessThanNumber":
criteria.withNumberProperty(propertyName).thatIsLessThan(parseFloat(propertyValue));
break;
case "thatIsLessThanOrEqualToNumber":
criteria.withNumberProperty(propertyName).thatIsLessThanOrEqualTo(parseFloat(propertyValue));
break;
case "thatIsGreaterThanNumber":
criteria.withNumberProperty(propertyName).thatIsGreaterThan(parseFloat(propertyValue));
break;
case "thatIsGreaterThanOrEqualToNumber":
criteria.withNumberProperty(propertyName).thatIsGreaterThanOrEqualTo(parseFloat(propertyValue));
break;
case "thatIsLaterThanOrEqualToDate":
criteria.withDateProperty(propertyName).thatIsLaterThanOrEqualTo(propertyValue);
break;
case "thatIsEarlierThanOrEqualToDate":
criteria.withDateProperty(propertyName).thatIsEarlierThanOrEqualTo(propertyValue);
break;
}
} catch(error) {
Util.showError("Error parsing criteria: " + error.message);
return;
}
} else {
criteria.withProperty(propertyName).thatContains(propertyValue);
}
} }
var setAttributeCriteria = function(criteria, attributeName, attributeValue) { var setAttributeCriteria = function(criteria, attributeName, attributeValue) {
...@@ -899,7 +946,7 @@ function ServerFacade(openbisServer) { ...@@ -899,7 +946,7 @@ function ServerFacade(openbisServer) {
} }
break; break;
case "Property": case "Property":
setPropertyCriteria(setOperator(searchCriteria, advancedSearchCriteria.logicalOperator), fieldName, fieldValue); setPropertyCriteria(setOperator(searchCriteria, advancedSearchCriteria.logicalOperator), fieldName, fieldValue, fieldOperator);
break; break;
case "Attribute": case "Attribute":
setAttributeCriteria(setOperator(searchCriteria, advancedSearchCriteria.logicalOperator), fieldName, fieldValue); setAttributeCriteria(setOperator(searchCriteria, advancedSearchCriteria.logicalOperator), fieldName, fieldValue);
...@@ -907,7 +954,7 @@ function ServerFacade(openbisServer) { ...@@ -907,7 +954,7 @@ function ServerFacade(openbisServer) {
case "Property/Attribute": case "Property/Attribute":
switch(fieldNameType) { switch(fieldNameType) {
case "PROP": case "PROP":
setPropertyCriteria(setOperator(searchCriteria, advancedSearchCriteria.logicalOperator), fieldName, fieldValue); setPropertyCriteria(setOperator(searchCriteria, advancedSearchCriteria.logicalOperator), fieldName, fieldValue, fieldOperator);
break; break;
case "ATTR": case "ATTR":
setAttributeCriteria(setOperator(searchCriteria, advancedSearchCriteria.logicalOperator), fieldName, fieldValue); setAttributeCriteria(setOperator(searchCriteria, advancedSearchCriteria.logicalOperator), fieldName, fieldValue);
...@@ -917,7 +964,7 @@ function ServerFacade(openbisServer) { ...@@ -917,7 +964,7 @@ function ServerFacade(openbisServer) {
case "Sample": case "Sample":
switch(fieldNameType) { switch(fieldNameType) {
case "PROP": case "PROP":
setPropertyCriteria(setOperator(searchCriteria.withSample(),advancedSearchCriteria.logicalOperator), fieldName, fieldValue); setPropertyCriteria(setOperator(searchCriteria.withSample(),advancedSearchCriteria.logicalOperator), fieldName, fieldValue, fieldOperator);
break; break;
case "ATTR": case "ATTR":
setAttributeCriteria(setOperator(searchCriteria.withSample(),advancedSearchCriteria.logicalOperator), fieldName, fieldValue); setAttributeCriteria(setOperator(searchCriteria.withSample(),advancedSearchCriteria.logicalOperator), fieldName, fieldValue);
...@@ -930,7 +977,7 @@ function ServerFacade(openbisServer) { ...@@ -930,7 +977,7 @@ function ServerFacade(openbisServer) {
case "Experiment": case "Experiment":
switch(fieldNameType) { switch(fieldNameType) {
case "PROP": case "PROP":
setPropertyCriteria(setOperator(searchCriteria.withExperiment(),advancedSearchCriteria.logicalOperator), fieldName, fieldValue); setPropertyCriteria(setOperator(searchCriteria.withExperiment(),advancedSearchCriteria.logicalOperator), fieldName, fieldValue, fieldOperator);
break; break;
case "ATTR": case "ATTR":
setAttributeCriteria(setOperator(searchCriteria.withExperiment(),advancedSearchCriteria.logicalOperator), fieldName, fieldValue); setAttributeCriteria(setOperator(searchCriteria.withExperiment(),advancedSearchCriteria.logicalOperator), fieldName, fieldValue);
...@@ -943,7 +990,7 @@ function ServerFacade(openbisServer) { ...@@ -943,7 +990,7 @@ function ServerFacade(openbisServer) {
case "Parent": case "Parent":
switch(fieldNameType) { switch(fieldNameType) {
case "PROP": case "PROP":
setPropertyCriteria(setOperator(searchCriteria.withParents(),advancedSearchCriteria.logicalOperator), fieldName, fieldValue); setPropertyCriteria(setOperator(searchCriteria.withParents(),advancedSearchCriteria.logicalOperator), fieldName, fieldValue, fieldOperator);
break; break;
case "ATTR": case "ATTR":
setAttributeCriteria(setOperator(searchCriteria.withParents(),advancedSearchCriteria.logicalOperator), fieldName, fieldValue); setAttributeCriteria(setOperator(searchCriteria.withParents(),advancedSearchCriteria.logicalOperator), fieldName, fieldValue);
...@@ -953,7 +1000,7 @@ function ServerFacade(openbisServer) { ...@@ -953,7 +1000,7 @@ function ServerFacade(openbisServer) {
case "Children": case "Children":
switch(fieldNameType) { switch(fieldNameType) {
case "PROP": case "PROP":
setPropertyCriteria(setOperator(searchCriteria.withChildren(),advancedSearchCriteria.logicalOperator), fieldName, fieldValue); setPropertyCriteria(setOperator(searchCriteria.withChildren(),advancedSearchCriteria.logicalOperator), fieldName, fieldValue, fieldOperator);
break; break;
case "ATTR": case "ATTR":
setAttributeCriteria(setOperator(searchCriteria.withChildren(),advancedSearchCriteria.logicalOperator), fieldName, fieldValue); setAttributeCriteria(setOperator(searchCriteria.withChildren(),advancedSearchCriteria.logicalOperator), fieldName, fieldValue);
......
...@@ -121,6 +121,7 @@ function AdvancedSearchView(advancedSearchController, advancedSearchModel) { ...@@ -121,6 +121,7 @@ function AdvancedSearchView(advancedSearchController, advancedSearchModel) {
.append($("<tr>") .append($("<tr>")
.append($("<th>").text("Field Type")) .append($("<th>").text("Field Type"))
.append($("<th>").text("Field Name")) .append($("<th>").text("Field Name"))
.append($("<th>").text("Comparator Operator"))
.append($("<th>").text("Field Value")) .append($("<th>").text("Field Value"))
.append($("<th>").append(this._$addButton)) .append($("<th>").append(this._$addButton))
); );
...@@ -170,14 +171,41 @@ function AdvancedSearchView(advancedSearchController, advancedSearchModel) { ...@@ -170,14 +171,41 @@ function AdvancedSearchView(advancedSearchController, advancedSearchModel) {
}); });
var operatorOptions = [
{ value : "thatEqualsString", label : "thatEquals (String)" },
{ value : "thatEqualsNumber", label : "thatEquals (Number)" },
{ value : "thatEqualsDate", label : "thatEquals (Date)" },
{ value : "thatContainsString", label : "thatContains (String)", selected : true },
{ value : "thatStartsWithString", label : "thatStartsWith (String)" },
{ value : "thatEndsWithString", label : "thatEndsWith (String)" },
{ value : "thatIsLessThanNumber", label : "thatIsLessThan (Number)" },
{ value : "thatIsLessThanOrEqualToNumber", label : "thatIsLessThanOrEqualTo (Number)" },
{ value : "thatIsGreaterThanNumber", label : "thatIsGreaterThan (Number)" },
{ value : "thatIsGreaterThanOrEqualToNumber", label : "thatIsGreaterThanOrEqualTo (Number)" },
{ value : "thatIsLaterThanOrEqualToDate", label : "thatIsLaterThanOrEqualTo (Date)" },
{ value : "thatIsEarlierThanOrEqualToDate", label : "thatIsEarlierThanOrEqualTo (Date)" },
];
var comparisonDropdown = FormUtil.getDropdown(operatorOptions, "Select Comparison operator");
comparisonDropdown.change(function() {
var $thisComponent = $(this);
//Get uuid and value and update model (type only)
var uuid = $($($thisComponent.parent()).parent()).attr("id");
var selectedValue = $thisComponent.val();
_this._advancedSearchModel.criteria.rules[uuid].operator = selectedValue; //Update model
});
$newRow.append($("<td>").append($fieldTypeDropdown))
$newRow.append($("<td>").append($fieldTypeDropdown))
.append($newFieldNameContainer) .append($newFieldNameContainer)
.append($("<td>").append(comparisonDropdown))
.append($("<td>").append($fieldValue)) .append($("<td>").append($fieldValue))
.append($("<td>").append(this._getMinusButtonComponentForRow(this._$tbody, $newRow))); .append($("<td>").append(this._getMinusButtonComponentForRow(this._$tbody, $newRow)));
this._$tbody.append($newRow); this._$tbody.append($newRow);
comparisonDropdown.select2({ width: '100%', theme: "bootstrap" });
if(this._advancedSearchModel.forceFreeTextSearch) { if(this._advancedSearchModel.forceFreeTextSearch) {
$fieldValue.val(this._advancedSearchModel.forceFreeTextSearch); $fieldValue.val(this._advancedSearchModel.forceFreeTextSearch);
this._advancedSearchModel.criteria.rules[uuidValue].value = this._advancedSearchModel.forceFreeTextSearch; //Update model this._advancedSearchModel.criteria.rules[uuidValue].value = this._advancedSearchModel.forceFreeTextSearch; //Update model
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment