From 980095381359d97507a8cdb92acd6e57eead0ee9 Mon Sep 17 00:00:00 2001 From: parkera <parkera> Date: Fri, 11 Mar 2016 14:43:27 +0000 Subject: [PATCH] SSDM-3024 : Search call for samples (ongoing work) SVN: 35886 --- .../eln-lims/html/js/server/ServerFacade.js | 199 ++++++------------ .../AdvancedSearch/AdvancedSearchView.js | 12 +- .../SideMenu/SideMenuWidgetController.js | 3 + 3 files changed, 75 insertions(+), 139 deletions(-) diff --git a/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/server/ServerFacade.js b/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/server/ServerFacade.js index 5b77aafdf23..77d59c1c99e 100644 --- a/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/server/ServerFacade.js +++ b/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/server/ServerFacade.js @@ -602,7 +602,8 @@ function ServerFacade(openbisServer) { this.searchForSamplesAdvanced = function(advancedSearchCriteria, callback) { require(['openbis', 'as/dto/sample/search/SampleSearchCriteria', - 'as/dto/sample/fetchoptions/SampleFetchOptions'], function(openbis, SampleSearchCriteria, SampleFetchOptions) { + 'as/dto/sample/fetchoptions/SampleFetchOptions', + 'as/dto/common/search/DateObjectEqualToValue'], function(openbis, SampleSearchCriteria, SampleFetchOptions, DateObjectEqualToValue) { //Boilerplate var testProtocol = window.location.protocol; @@ -615,175 +616,105 @@ function ServerFacade(openbisServer) { var v3Api = new openbis(testApiUrl); v3Api._private.sessionToken = mainController.serverFacade.getSession(); - //SearchResult<Sample> searchSamples(String sessionToken, SampleSearchCriteria searchCriteria, SampleFetchOptions fetchOptions); - //TO-DO Setting the searchCriteria given the advancedSearchCriteria model + //Setting the searchCriteria given the advancedSearchCriteria model var searchCriteria = new SampleSearchCriteria(); + //Setting the fetchOptions given standard settings + var fetchOptions = new SampleFetchOptions(); + fetchOptions.withTags(); + fetchOptions.withType(); + fetchOptions.withSpace(); + fetchOptions.withExperiment(); + fetchOptions.withRegistrator(); + fetchOptions.withModifier(); + fetchOptions.withParents(); + fetchOptions.withProperties(); + + //Operator var operator = advancedSearchCriteria.logicalOperator; if (!operator) { operator = "AND"; } searchCriteria.withOperator(operator); - + //Rules var ruleKeys = Object.keys(advancedSearchCriteria.rules); for (var idx = 0; idx < ruleKeys.length; idx++) { - var fieldType = null; - var fieldNameUnparsed = null; - var fieldName = null; - var fieldValue = null; + var fieldType = advancedSearchCriteria.rules[ruleKeys[idx]].type; + var fieldName = advancedSearchCriteria.rules[ruleKeys[idx]].name; + var fieldNameType = null; + var fieldValue = advancedSearchCriteria.rules[ruleKeys[idx]].value; - fieldType = advancedSearchCriteria.rules[ruleKeys[idx]].type; - fieldNameUnparsed = advancedSearchCriteria.rules[ruleKeys[idx]].name; - if (fieldNameUnparsed === undefined) { - fieldNameUnparsed = null; - } else if (fieldNameUnparsed.indexOf(".") != -1) { - fieldName = fieldNameUnparsed.substring(fieldNameUnparsed.indexOf(".") + 1, fieldNameUnparsed.length); + if(fieldName) { + var firstDotIndex = fieldName.indexOf("."); + fieldNameType = fieldName.substring(0, firstDotIndex); + fieldName = fieldName.substring(firstDotIndex + 1, fieldName.length); } - fieldValue = advancedSearchCriteria.rules[ruleKeys[idx]].value; - - //alert("fieldType is " + fieldType + " fieldName is " + fieldName + " fieldValue is " + fieldValue + " fieldNameUnparsed is " + fieldNameUnparsed); - //Case 1: fieldType = all - if(fieldType === "All") { - searchCriteria.withAnyField().thatEquals(fieldValue); + var setPropertyCriteria = function(criteria, propertyName, propertyValue) { + criteria.withProperty(propertyName).thatEquals(propertyValue); } - - //Case 2: fieldType = property - else if(fieldType === "Property") { - searchCriteria.withProperty(fieldName).thatEquals(fieldValue); - } - - //Case 3: fieldType = attribute - else if(fieldType === "Attribute"){ - switch(fieldName) { + + var setAttributeCriteria = function(criteria, attributeName, attributeValue) { + switch(attributeName) { case "CODE": - searchCriteria.withCode().thatEquals(fieldValue); + criteria.withCode().thatEquals(attributeValue); break; case "SAMPLE_TYPE": - searchCriteria.withType().withCode().thatEquals(fieldValue); + criteria.withType().withCode().thatEquals(attributeValue); break; case "PERM_ID": - searchCriteria.withPermId().thatEquals(fieldValue); + criteria.withPermId().thatEquals(attributeValue); break; case "SPACE": - searchCriteria.withSpace().withCode().thatEquals(fieldValue); - break; - case "PROJECT": - searchCriteria.withProject().withCode().thatEquals(fieldValue); - break; - case "PROJECT_PERM_ID": - searchCriteria.withProject().withPermId().thatEquals(fieldValue); + criteria.withSpace().withCode().thatEquals(attributeValue); break; case "METAPROJECT": - searchCriteria.withTag().withCode().thatEquals(fieldValue); + criteria.withTag().withCode().thatEquals(attributeValue); break; - case "REGISTRATION_DATE": //must be format 2009-08-18 - searchCriteria.withRegistrationDate().thatEquals(fieldValue); + case "REGISTRATION_DATE": //must be format 2009-08-18 ? + criteria.withRegistrationDate().thatEquals(new DateObjectEqualToValue(attributeValue)); break; - case "MODIFICATION_DATE": //must be format 2009-08-18 - searchCriteria.withModificationDate().thatEquals(fieldValue); + case "MODIFICATION_DATE": //must be format 2009-08-18 ? + criteria.withModificationDate().thatEquals(new DateObjectEqualToValue(attributeValue)); break; - default: - //Do Nothing } } - //Case 4: Parents - else if (fieldType === "Parent"){ - if(fieldNameUnparsed.indexOf("ATTR.") != -1){ - switch(fieldName) { - case "CODE": - searchCriteria.withParents().withCode().thatEquals(fieldValue); - break; - case "SAMPLE_TYPE": - searchCriteria.withParents().withType().withCode().thatEquals(fieldValue); - break; - case "PERM_ID": - searchCriteria.withParents().withPermId().thatEquals(fieldValue); - break; - case "SPACE": - searchCriteria.withParents().withSpace().withCode().thatEquals(fieldValue); - break; - case "PROJECT": - searchCriteria.withParents().withProject().withCode().thatEquals(fieldValue); - break; - case "PROJECT_PERM_ID": - searchCriteria.withParents().withProject().withPermId().thatEquals(fieldValue); - break; - case "METAPROJECT": - searchCriteria.withParents().withTag().withCode().thatEquals(fieldValue); - break; - case "REGISTRATION_DATE": //must be format 2009-08-18 - searchCriteria.withParents().withRegistrationDate().thatEquals(fieldValue); + switch(fieldType) { + case "All": + searchCriteria.withAnyField().thatEquals(fieldValue); + break; + case "Property": + setPropertyCriteria(searchCriteria, fieldName, fieldValue); + break; + case "Attribute": + setAttributeCriteria(searchCriteria, fieldName, fieldValue); + break; + case "Parent": + switch(fieldNameType) { + case "PROP": + setPropertyCriteria(searchCriteria.withParents(), fieldName, fieldValue); break; - case "MODIFICATION_DATE": //must be format 2009-08-18 - searchCriteria.withParents().withModificationDate().thatEquals(fieldValue); + case "ATTR": + setAttributeCriteria(searchCriteria.withParents(), fieldName, fieldValue); break; - default: - //Do Nothing - } - }else if(fieldNameUnparsed.indexOf("PROP.") != -1){ - searchCriteria.withParents().withProperty(fieldName).thatEquals(fieldValue); - } - }//end parent - - //Case 5: CHildren - else if (fieldType === "Children"){ - if(fieldNameUnparsed.indexOf("ATTR.") != -1){ - switch(fieldName) { - case "CODE": - searchCriteria.withChildren().withCode().thatEquals(fieldValue); - break; - case "SAMPLE_TYPE": - searchCriteria.withChildren().withType().withCode().thatEquals(fieldValue); - break; - case "PERM_ID": - searchCriteria.withChildren().withPermId().thatEquals(fieldValue); - break; - case "SPACE": - searchCriteria.withChildren().withSpace().withCode().thatEquals(fieldValue); - break; - case "PROJECT": - searchCriteria.withChildren().withProject().withCode().thatEquals(fieldValue); - break; - case "PROJECT_PERM_ID": - searchCriteria.withChildren().withProject().withPermId().thatEquals(fieldValue); - break; - case "METAPROJECT": - searchCriteria.withChildren().withTag().withCode().thatEquals(fieldValue); - break; - case "REGISTRATION_DATE": //must be format 2009-08-18 - searchCriteria.withChildren().withRegistrationDate().thatEquals(fieldValue); + } + break; + case "Children": + switch(fieldNameType) { + case "PROP": + setPropertyCriteria(searchCriteria.withChildren(), fieldName, fieldValue); break; - case "MODIFICATION_DATE": //must be format 2009-08-18 - searchCriteria.withChildren().withModificationDate().thatEquals(fieldValue); + case "ATTR": + setAttributeCriteria(searchCriteria.withChildren(), fieldName, fieldValue); break; - default: - //Do Nothing - } - } else if(fieldNameUnparsed.indexOf("PROP.") != -1){ - searchCriteria.withChildren().withProperty(fieldName).thatEquals(fieldValue); - } - } //end children - + } + break; + } } - //TO-DO Setting the fetchOptions given standard settings - var fetchOptions = new SampleFetchOptions(); - fetchOptions.withTags(); - fetchOptions.withType(); - fetchOptions.withSpace(); - fetchOptions.withExperiment(); - fetchOptions.withRegistrator(); - fetchOptions.withModifier(); - fetchOptions.withParents(); - fetchOptions.withProperties(); - - //to get all levels - //fetchOptions.withParentsWith(fetchOptions); - v3Api.searchSamples(searchCriteria, fetchOptions) .done(function(result) { callback(result); //this will call the method defined in the AdvancedSearchController which will display the table diff --git a/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/AdvancedSearch/AdvancedSearchView.js b/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/AdvancedSearch/AdvancedSearchView.js index 7390f4358ce..794a7e73143 100644 --- a/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/AdvancedSearch/AdvancedSearchView.js +++ b/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/AdvancedSearch/AdvancedSearchView.js @@ -148,7 +148,7 @@ function AdvancedSearchView(advancedSearchController, advancedSearchModel) { //how to make an on-select event?? this._getNewFieldTypeDropdownComponent = function($newFieldNameContainer) { var _this = this; - var fieldTypeOptions = [{value : "All", label : "All", selected : true }, {value : "Property", label : "Property"}, {value : "Attribute", label : "Attribute"}, {value : "Parent", label : "Parent"}, {value : "Children", label : "Children"}, {value : "Space", label : "Space"}]; + var fieldTypeOptions = [{value : "All", label : "All", selected : true }, {value : "Property", label : "Property"}, {value : "Attribute", label : "Attribute"}, {value : "Parent", label : "Parent"}, {value : "Children", label : "Children"}]; var $fieldTypeComponent = FormUtil.getDropdown(fieldTypeOptions, "Select Field Type"); $fieldTypeComponent.change(function() { var $thisComponent = $(this); @@ -227,6 +227,11 @@ function AdvancedSearchView(advancedSearchController, advancedSearchModel) { var prop = allProp[pIdx]; model.push({ value : "PROP." + prop.code, label : prop.label }); } + + model.sort(function(propertyA, propertyB) { + return propertyA.label.localeCompare(propertyB.label); + }); + return model; } @@ -265,8 +270,6 @@ function AdvancedSearchView(advancedSearchController, advancedSearchModel) { { value : "ATTR.SAMPLE_TYPE", label: "Sample Type" }, { value : "ATTR.PERM_ID", label: "Perm Id" }, { value : "ATTR.SPACE", label: "Space" }, - { value : "ATTR.PROJECT", label: "Project" }, - { value : "ATTR.PROJECT_PERM_ID", label: "Project Perm Id" }, { value : "ATTR.METAPROJECT", label: "Metaproject" }, { value : "ATTR.REGISTRATION_DATE", label: "Registration Date" }, { value : "ATTR.MODIFICATION_DATE", label: "Modification Date" }]; @@ -278,8 +281,6 @@ function AdvancedSearchView(advancedSearchController, advancedSearchModel) { { value : "ATTR.REGISTRATION_DATE", label : "Registration Date" }, { value : "ATTR.MODIFICATION_DATE", label : "Modification Date" }]; break; - default: - //Do Nothing } return model; } @@ -289,6 +290,7 @@ function AdvancedSearchView(advancedSearchController, advancedSearchModel) { var model = [{ value : 'EXPERIMENT', label : "Experiment" }, { value : 'SAMPLE', label : "Sample", selected : true }, { value : 'DATASET', label : "Dataset" }]; + this._advancedSearchModel.resetModel('SAMPLE'); var $dropdown = FormUtil.getDropdown(model, 'Select Entity Type to search for'); $dropdown.change(function() { diff --git a/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SideMenu/SideMenuWidgetController.js b/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SideMenu/SideMenuWidgetController.js index cf26457a044..21cc5e8e20d 100644 --- a/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SideMenu/SideMenuWidgetController.js +++ b/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SideMenu/SideMenuWidgetController.js @@ -386,6 +386,9 @@ function SideMenuWidgetController(mainController) { new SideMenuWidgetComponent(true, false, "STORAGE MANAGER", "STORAGE_MANAGER", utilities, null, "showStorageManager", null, "") ); } + utilities.newMenuIfSelected.children.push( + new SideMenuWidgetComponent(true, false, "ADVANCED SEARCH", "ADVANCED_SEARCH", utilities, null, "showAdvancedSearchPage", null, "") + ); utilities.newMenuIfSelected.children.push( new SideMenuWidgetComponent(true, false, "TRASHCAN", "TRASHCAN", utilities, null, "showTrashcanPage", null, "") ); -- GitLab