From f50b8fa083156480f75b986bde572f26bb235340 Mon Sep 17 00:00:00 2001
From: juanf <juanf>
Date: Wed, 15 Mar 2017 15:21:24 +0000
Subject: [PATCH] SSDM-4184 : Operators for search

SVN: 37910
---
 .../eln-lims/html/js/server/ServerFacade.js   | 65 ++++++++++++++++---
 .../AdvancedSearch/AdvancedSearchView.js      | 32 ++++++++-
 2 files changed, 86 insertions(+), 11 deletions(-)

diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/server/ServerFacade.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/server/ServerFacade.js
index af17617d228..1a82bad8267 100644
--- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/server/ServerFacade.js
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/server/ServerFacade.js
@@ -837,7 +837,8 @@ function ServerFacade(openbisServer) {
 					var fieldName = advancedSearchCriteria.rules[ruleKeys[idx]].name;
 					var fieldNameType = null;
 					var fieldValue = advancedSearchCriteria.rules[ruleKeys[idx]].value;
-				
+					var fieldOperator = advancedSearchCriteria.rules[ruleKeys[idx]].operator;
+					
 					if(fieldName) {
 						var firstDotIndex = fieldName.indexOf(".");
 						fieldNameType = fieldName.substring(0, firstDotIndex);
@@ -848,8 +849,54 @@ function ServerFacade(openbisServer) {
 						fieldValue = "*";
 					}
 				
-					var setPropertyCriteria = function(criteria, propertyName, propertyValue) {
-						criteria.withProperty(propertyName).thatContains(propertyValue);
+					var setPropertyCriteria = function(criteria, propertyName, propertyValue, comparisonOperator) {
+						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) {
@@ -899,7 +946,7 @@ function ServerFacade(openbisServer) {
 							}
 							break;
 						case "Property":
-							setPropertyCriteria(setOperator(searchCriteria, advancedSearchCriteria.logicalOperator), fieldName, fieldValue);
+							setPropertyCriteria(setOperator(searchCriteria, advancedSearchCriteria.logicalOperator), fieldName, fieldValue, fieldOperator);
 							break;
 						case "Attribute":
 							setAttributeCriteria(setOperator(searchCriteria, advancedSearchCriteria.logicalOperator), fieldName, fieldValue);
@@ -907,7 +954,7 @@ function ServerFacade(openbisServer) {
 						case "Property/Attribute":
 							switch(fieldNameType) {
 								case "PROP":
-									setPropertyCriteria(setOperator(searchCriteria, advancedSearchCriteria.logicalOperator), fieldName, fieldValue);
+									setPropertyCriteria(setOperator(searchCriteria, advancedSearchCriteria.logicalOperator), fieldName, fieldValue, fieldOperator);
 									break;
 								case "ATTR":
 									setAttributeCriteria(setOperator(searchCriteria, advancedSearchCriteria.logicalOperator), fieldName, fieldValue);
@@ -917,7 +964,7 @@ function ServerFacade(openbisServer) {
 						case "Sample":
 							switch(fieldNameType) {
 								case "PROP":
-									setPropertyCriteria(setOperator(searchCriteria.withSample(),advancedSearchCriteria.logicalOperator), fieldName, fieldValue);
+									setPropertyCriteria(setOperator(searchCriteria.withSample(),advancedSearchCriteria.logicalOperator), fieldName, fieldValue, fieldOperator);
 									break;
 								case "ATTR":
 									setAttributeCriteria(setOperator(searchCriteria.withSample(),advancedSearchCriteria.logicalOperator), fieldName, fieldValue);
@@ -930,7 +977,7 @@ function ServerFacade(openbisServer) {
 						case "Experiment":
 							switch(fieldNameType) {
 								case "PROP":
-									setPropertyCriteria(setOperator(searchCriteria.withExperiment(),advancedSearchCriteria.logicalOperator), fieldName, fieldValue);
+									setPropertyCriteria(setOperator(searchCriteria.withExperiment(),advancedSearchCriteria.logicalOperator), fieldName, fieldValue, fieldOperator);
 									break;
 								case "ATTR":
 									setAttributeCriteria(setOperator(searchCriteria.withExperiment(),advancedSearchCriteria.logicalOperator), fieldName, fieldValue);
@@ -943,7 +990,7 @@ function ServerFacade(openbisServer) {
 						case "Parent":
 							switch(fieldNameType) {
 								case "PROP":
-									setPropertyCriteria(setOperator(searchCriteria.withParents(),advancedSearchCriteria.logicalOperator), fieldName, fieldValue);
+									setPropertyCriteria(setOperator(searchCriteria.withParents(),advancedSearchCriteria.logicalOperator), fieldName, fieldValue, fieldOperator);
 									break;
 								case "ATTR":
 									setAttributeCriteria(setOperator(searchCriteria.withParents(),advancedSearchCriteria.logicalOperator), fieldName, fieldValue);
@@ -953,7 +1000,7 @@ function ServerFacade(openbisServer) {
 						case "Children":
 							switch(fieldNameType) {
 								case "PROP":
-									setPropertyCriteria(setOperator(searchCriteria.withChildren(),advancedSearchCriteria.logicalOperator), fieldName, fieldValue);
+									setPropertyCriteria(setOperator(searchCriteria.withChildren(),advancedSearchCriteria.logicalOperator), fieldName, fieldValue, fieldOperator);
 									break;
 								case "ATTR":
 									setAttributeCriteria(setOperator(searchCriteria.withChildren(),advancedSearchCriteria.logicalOperator), fieldName, fieldValue);
diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/AdvancedSearch/AdvancedSearchView.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/AdvancedSearch/AdvancedSearchView.js
index 67d0cf952b5..8ff78b2abf7 100644
--- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/AdvancedSearch/AdvancedSearchView.js
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/AdvancedSearch/AdvancedSearchView.js
@@ -121,6 +121,7 @@ function AdvancedSearchView(advancedSearchController, advancedSearchModel) {
 			.append($("<tr>")
 						.append($("<th>").text("Field Type"))
 						.append($("<th>").text("Field Name"))
+						.append($("<th>").text("Comparator Operator"))
 						.append($("<th>").text("Field Value"))
 						.append($("<th>").append(this._$addButton))
 					);
@@ -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($("<td>").append(comparisonDropdown))
 					.append($("<td>").append($fieldValue))
 					.append($("<td>").append(this._getMinusButtonComponentForRow(this._$tbody, $newRow)));
-					
+		
 		this._$tbody.append($newRow);
 		
+		comparisonDropdown.select2({ width: '100%', theme: "bootstrap" });
+		
 		if(this._advancedSearchModel.forceFreeTextSearch) {
 			$fieldValue.val(this._advancedSearchModel.forceFreeTextSearch);
 			this._advancedSearchModel.criteria.rules[uuidValue].value = this._advancedSearchModel.forceFreeTextSearch; //Update model
-- 
GitLab