diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/controllers/MainController.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/controllers/MainController.js index 5574f1a6367c8dfb8c5208ad79014ec071f0200c..555d7b7b94f3fd1c8654310c11d6f8f356d48bd7 100644 --- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/controllers/MainController.js +++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/controllers/MainController.js @@ -662,7 +662,7 @@ function MainController(profile) { var newView = null; if(freeText) { - newView = new AdvancedSearchController(this, "*" + freeText + "*"); + newView = new AdvancedSearchController(this, freeText); } else { newView = new AdvancedSearchController(this); } 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 1a28646dc6a000ff6e138ba0bb036208e98fd3cb..19332cee035bb45a65cdee1acc14634a324ab7c8 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 @@ -1445,7 +1445,7 @@ function ServerFacade(openbisServer) { // // Global Search // - this.searchGlobally = function(freeText, callbackFunction) + this.searchGlobally = function(freeText, advancedFetchOptions, callbackFunction) { var _this = this; require(['openbis', 'as/dto/global/search/GlobalSearchCriteria', @@ -1458,8 +1458,11 @@ function ServerFacade(openbisServer) { var v3api = new openbis(url + "/openbis/openbis/rmi-application-server-v3.json"); v3api._private.sessionToken = mainController.serverFacade.getSession(); var searchCriteria = new GlobalSearchCriteria(); - searchCriteria.withWildCards(); - searchCriteria.withText().thatContains(freeText); +// searchCriteria.withWildCards(); + + searchCriteria.withText().thatContains(freeText.toLowerCase().trim()); + searchCriteria.withOperator("AND"); + var fetchOptions = new GlobalSearchObjectFetchOptions(); var sampleFetchOptions = fetchOptions.withSample(); sampleFetchOptions.withSpace(); @@ -1481,6 +1484,30 @@ function ServerFacade(openbisServer) { dataSetFetchOptions.withModifier(); dataSetFetchOptions.withProperties(); + if(advancedFetchOptions && advancedFetchOptions.cache) { + fetchOptions.cacheMode(advancedFetchOptions.cache); + } + + if(advancedFetchOptions && + advancedFetchOptions.count != null && + advancedFetchOptions.count != undefined && + advancedFetchOptions.from != null && + advancedFetchOptions.from != undefined) { + fetchOptions.from(advancedFetchOptions.from); + fetchOptions.count(advancedFetchOptions.count); + } + +// if(advancedFetchOptions && advancedFetchOptions.sort) { +// switch(advancedFetchOptions.sort.type) { +// case "Attribute": +// fetchOptions.sortBy()[advancedFetchOptions.sort.name]()[advancedFetchOptions.sort.direction](); +// break; +// case "Property": +// fetchOptions.sortBy().property(advancedFetchOptions.sort.name)[advancedFetchOptions.sort.direction](); +// break; +// } +// } + v3api.searchGlobally(searchCriteria, fetchOptions).done(function(results) { callbackFunction(results); }).fail(function(error) { diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/AdvancedSearch/AdvancedSearchController.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/AdvancedSearch/AdvancedSearchController.js index 336b0567e6a0f8914517057b714bf73251ce72cb..17dc51417e637b4471306f7365d4f431bafc6d08 100644 --- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/AdvancedSearch/AdvancedSearchController.js +++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/AdvancedSearch/AdvancedSearchController.js @@ -25,34 +25,141 @@ function AdvancedSearchController(mainController, forceFreeTextSearch) { } this.search = function() { - var _this = this; - var model = this._advancedSearchModel.criteria; - - Util.blockUI(); - var callbackFunction = function(results) { - _this._advancedSearchView.renderResults(results); - Util.unblockUI(); - }; - - switch(this._advancedSearchModel.criteria.entityKind) { - case "ALL": - var freeText = ""; - for(var ruleId in model.rules) { - if(model.rules[ruleId].value) { - freeText += " " + model.rules[ruleId].value; + this._advancedSearchView.renderResults(this._advancedSearchModel.criteria); + } + + this.searchWithPagination = function(criteria, isGlobalSearch) { + return function(callback, options) { + var callbackForSearch = function(results) { + var dataList = []; + for(var rIdx = 0; rIdx < results.objects.length; rIdx++) { + var entity = results.objects[rIdx]; + + var rowData = {}; + if(isGlobalSearch) { + rowData.matched = entity.match; + rowData.score = entity.score; + + switch(entity.objectKind) { + case "SAMPLE": + entity = entity.sample; + break; + case "EXPERIMENT": + entity = entity.experiment; + break; + case "DATA_SET": + entity = entity.dataSet; + break; + case "MATERIAL": + continue; //Skip materials, they are not supported on the ELN + break; + } + } + + //properties + rowData.entityKind = entity["@type"].substring(entity["@type"].lastIndexOf(".") + 1, entity["@type"].length); + + if(entity.experiment) { + rowData.experiment = entity.experiment.code; + } + + rowData.entityType = entity.type.code; + rowData.code = entity.code; + rowData.permId = entity.permId.permId; + rowData.registrationDate = (entity.registrator && entity.registrator.registrationDate)?Util.getFormatedDate(new Date(entity.registrator.registrationDate)):null; + rowData.modificationDate = (entity.modifier && entity.modifier.registrationDate)?Util.getFormatedDate(new Date(entity.modifier.registrationDate)):null; + rowData.entityObject = entity; + + if(entity.identifier) { + rowData.identifier = entity.identifier.identifier; } + + for(var propertyCode in entity.properties) { + rowData[propertyCode] = entity.properties[propertyCode]; + } + + //Add the row data + dataList.push(rowData); + } + + callback({ + objects : dataList, + totalCount : results.totalCount + }); + } + + var fetchOptions = {}; + + if(options) { + fetchOptions.count = options.pageSize; + fetchOptions.from = options.pageIndex * options.pageSize; + } + + if(!criteria.cached) { + fetchOptions.cache = "RELOAD_AND_CACHE"; + criteria.cached = true; + } else { + fetchOptions.cache = "CACHE"; + } + + var criteriaToSend = $.extend(true, {}, criteria); + + if(options.search) { + var filter = options.search.toLowerCase().split(/[ ,]+/); //Split by regular space or comma + for(var fIdx = 0; fIdx < filter.length; fIdx++) { + var fKeyword = filter[fIdx]; + criteriaToSend.rules[Util.guid()] = { type : "All", name : "", value : fKeyword }; + } + } + + if(options.sortProperty && options.sortDirection) { + fetchOptions.sort = { + type : null, + name : null, + direction : options.sortDirection } - mainController.serverFacade.searchGlobally(freeText, callbackFunction); - break; - case "SAMPLE": - mainController.serverFacade.searchForSamplesAdvanced(model, null, callbackFunction); - break; - case "EXPERIMENT": - mainController.serverFacade.searchForExperimentsAdvanced(model, null, callbackFunction); - break; - case "DATASET": - mainController.serverFacade.searchForDataSetsAdvanced(model, null, callbackFunction); - break; + switch(options.sortProperty) { + case "code": + fetchOptions.sort.type = "Attribute"; + fetchOptions.sort.name = "code"; + break; + case "registrationDate": + fetchOptions.sort.type = "Attribute"; + fetchOptions.sort.name = "registrationDate" + + break; + case "modificationDate": + fetchOptions.sort.type = "Attribute"; + fetchOptions.sort.name = "modificationDate"; + break; + default: //Properties + fetchOptions.sort.type = "Property"; + fetchOptions.sort.name = options.sortProperty; + break; + } + } + + switch(criteriaToSend.entityKind) { + case "ALL": + $(".repeater-search").empty(); + var freeText = ""; + for(var ruleId in criteriaToSend.rules) { + if(criteriaToSend.rules[ruleId].value) { + freeText += " " + criteriaToSend.rules[ruleId].value; + } + } + mainController.serverFacade.searchGlobally(freeText, fetchOptions, callbackForSearch); + break; + case "SAMPLE": + mainController.serverFacade.searchForSamplesAdvanced(criteriaToSend, fetchOptions, callbackForSearch); + break; + case "EXPERIMENT": + mainController.serverFacade.searchForExperimentsAdvanced(criteriaToSend, fetchOptions, callbackForSearch); + break; + case "DATASET": + mainController.serverFacade.searchForDataSetsAdvanced(criteriaToSend, fetchOptions, callbackForSearch); + break; + } } } } \ No newline at end of file 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 bdcae6853e605f50035b19e0033261f92b659723..41e622ac0e8d77c52b9abcb8ff840f6f6076fba2 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 @@ -17,6 +17,7 @@ function AdvancedSearchView(advancedSearchController, advancedSearchModel) { this._advancedSearchController = advancedSearchController; this._advancedSearchModel = advancedSearchModel; + this._$andOrDropdownComponent = null; this._$menuPanelContainer = null; this._$searchCriteriaPanelContainer = null; this._$tbody = null; @@ -73,12 +74,12 @@ function AdvancedSearchView(advancedSearchController, advancedSearchModel) { $menuPanelContainer.append(FormUtil.getFieldForComponentWithLabel($entityTypeDropdown, "Search For", null, true)); var andOrOptions = [{value : "AND", label : "AND", selected : true}, {value : "OR", label : "OR"}]; - var $andOrDropdownComponent = FormUtil.getDropdown(andOrOptions, "Select logical operator"); + this._$andOrDropdownComponent = FormUtil.getDropdown(andOrOptions, "Select logical operator"); var _this = this; - $andOrDropdownComponent.change(function() { + this._$andOrDropdownComponent.change(function() { _this._advancedSearchModel.criteria.logicalOperator = $(this).val(); }); - $menuPanelContainer.append(FormUtil.getFieldForComponentWithLabel($andOrDropdownComponent, "Using", null, true)); + $menuPanelContainer.append(FormUtil.getFieldForComponentWithLabel(this._$andOrDropdownComponent, "Using", null, true)); var $submitButton = FormUtil.getButtonWithIcon('glyphicon-search', function() { _this._advancedSearchController.search(); @@ -154,11 +155,19 @@ function AdvancedSearchView(advancedSearchController, advancedSearchModel) { //should make new objects every time. otherwise, using the same object will produce odd results! //how to make an on-select event?? this._getNewFieldTypeDropdownComponent = function($newFieldNameContainer, entityKind, uuid) { + //Update dropdown component + this._$andOrDropdownComponent.val("AND"); + this._advancedSearchModel.criteria.logicalOperator = "AND"; + this._$andOrDropdownComponent.removeAttr("disabled"); + // var _this = this; var fieldTypeOptions = null; switch(entityKind) { case "ALL": fieldTypeOptions = [{value : "All", label : "All", selected : true }]; + this._$andOrDropdownComponent.val("OR"); + this._advancedSearchModel.criteria.logicalOperator = "OR"; + this._$andOrDropdownComponent.attr("disabled", ""); break; case "SAMPLE": fieldTypeOptions = [{value : "All", label : "All", selected : true }, @@ -402,13 +411,13 @@ function AdvancedSearchView(advancedSearchController, advancedSearchModel) { return $minusButton; } - this.renderResults = function(results) { + this.renderResults = function(criteria) { var isGlobalSearch = this._advancedSearchModel.criteria.entityKind === "ALL"; - var dataGridController = this._getGridForResults(results, isGlobalSearch); + var dataGridController = this._getGridForResults(criteria, isGlobalSearch); dataGridController.init(this._$dataGridContainer); } - this._getGridForResults = function(results, isGlobalSearch) { + this._getGridForResults = function(criteria, isGlobalSearch) { var getLinkOnClick = function(code, data) { switch(data.entityKind) { @@ -425,7 +434,7 @@ function AdvancedSearchView(advancedSearchController, advancedSearchModel) { label : 'Entity Kind', property : 'entityKind', isExportable: true, - sortable : true, + sortable : false, render : function(data) { if(data.entityKind === "Sample") { return ELNDictionary.Sample; @@ -439,12 +448,12 @@ function AdvancedSearchView(advancedSearchController, advancedSearchModel) { label : 'Entity Type', property : 'entityType', isExportable: true, - sortable : true + sortable : false }, { label : 'Name', property : 'NAME', isExportable: true, - sortable : true, + sortable : !isGlobalSearch, render : function(data) { return getLinkOnClick(data.NAME, data); } @@ -452,7 +461,7 @@ function AdvancedSearchView(advancedSearchController, advancedSearchModel) { label : 'Code', property : 'code', isExportable: true, - sortable : true, + sortable : !isGlobalSearch, render : function(data) { return getLinkOnClick(data.code, data); } @@ -460,7 +469,7 @@ function AdvancedSearchView(advancedSearchController, advancedSearchModel) { label : 'Identifier', property : 'identifier', isExportable: true, - sortable : true, + sortable : false, render : function(data) { return getLinkOnClick(data.identifier, data); } @@ -468,7 +477,7 @@ function AdvancedSearchView(advancedSearchController, advancedSearchModel) { label : ELNDictionary.ExperimentELN + '/' + ELNDictionary.ExperimentInventory, property : 'experiment', isExportable: false, - sortable : true + sortable : false }]; if(isGlobalSearch) { @@ -476,14 +485,14 @@ function AdvancedSearchView(advancedSearchController, advancedSearchModel) { label : 'Matched', property : 'matched', isExportable: true, - sortable : true + sortable : false }); columns.push({ label : 'Score', property : 'score', isExportable: true, - sortable : true + sortable : false }); } @@ -495,131 +504,81 @@ function AdvancedSearchView(advancedSearchController, advancedSearchModel) { }); //Add properties as columns dynamically depending on the results - - //1. Get properties with actual data - var foundPropertyCodes = {}; - for(var rIdx = 0; rIdx < results.objects.length; rIdx++) { - var entity = results.objects[rIdx]; - if(isGlobalSearch) { - switch(entity.objectKind) { - case "SAMPLE": - entity = entity.sample; - break; - case "EXPERIMENT": - entity = entity.experiment; - break; - case "DATA_SET": - entity = entity.dataSet; - break; + var dynamicColumnsFunc = function(entities) { + //1. Get properties with actual data + var foundPropertyCodes = {}; + for(var rIdx = 0; rIdx < entities.length; rIdx++) { + var entity = entities[rIdx].entityObject; + if(isGlobalSearch) { + switch(entity.objectKind) { + case "SAMPLE": + entity = entity.sample; + break; + case "EXPERIMENT": + entity = entity.experiment; + break; + case "DATA_SET": + entity = entity.dataSet; + break; + } + } + + for(var propertyCode in entity.properties) { + if(entity.properties[propertyCode]) { + foundPropertyCodes[propertyCode] = true; + } } } - for(var propertyCode in entity.properties) { - if(entity.properties[propertyCode]) { - foundPropertyCodes[propertyCode] = true; + //2. Get columns + var propertyColumnsToSort = []; + for(var propertyCode in foundPropertyCodes) { + var propertiesToSkip = ["NAME", "XMLCOMMENTS", "ANNOTATIONS_STATE"]; + if($.inArray(propertyCode, propertiesToSkip) !== -1) { + continue; } - } - } - - //2. Get columns - var propertyColumnsToSort = []; - for(var propertyCode in foundPropertyCodes) { - var propertiesToSkip = ["NAME", "XMLCOMMENTS", "ANNOTATIONS_STATE"]; - if($.inArray(propertyCode, propertiesToSkip) !== -1) { - continue; + + propertyColumnsToSort.push({ + label : profile.getPropertyType(propertyCode).label, + property : propertyCode, + sortable : !isGlobalSearch + }); } - propertyColumnsToSort.push({ - label : profile.getPropertyType(propertyCode).label, - property : propertyCode, - sortable : true + //3. Sort column properties by label + propertyColumnsToSort.sort(function(propertyA, propertyB) { + return propertyA.label.localeCompare(propertyB.label); }); + + return propertyColumnsToSort; } - //3. Sort column properties by label - propertyColumnsToSort.sort(function(propertyA, propertyB) { - return propertyA.label.localeCompare(propertyB.label); - }); - columns = columns.concat(propertyColumnsToSort); - + var columnsLast = []; //4. Add registration/modification date columns - columns.push({ + columnsLast.push({ label : '---------------', property : null, isExportable: false, sortable : false }); - columns.push({ + columnsLast.push({ label : 'Registration Date', property : 'registrationDate', isExportable: true, - sortable : true + sortable : !isGlobalSearch }); - columns.push({ + columnsLast.push({ label : 'Modification Date', property : 'modificationDate', isExportable: true, - sortable : true + sortable : !isGlobalSearch }); - var getDataRows = function(callback) { - var rows = []; - for(var rIdx = 0; rIdx < results.objects.length; rIdx++) { - var entity = results.objects[rIdx]; - - var rowData = {}; - - if(isGlobalSearch) { - rowData.matched = entity.match; - rowData.score = entity.score; - - switch(entity.objectKind) { - case "SAMPLE": - entity = entity.sample; - break; - case "EXPERIMENT": - entity = entity.experiment; - break; - case "DATA_SET": - entity = entity.dataSet; - break; - case "MATERIAL": - continue; //Skip materials, they are not supported on the ELN - break; - } - } - - //properties - rowData.entityKind = entity["@type"].substring(entity["@type"].lastIndexOf(".") + 1, entity["@type"].length); - - if(entity.experiment) { - rowData.experiment = entity.experiment.code; - } - - rowData.entityType = entity.type.code; - rowData.code = entity.code; - rowData.permId = entity.permId.permId; - rowData.registrationDate = (entity.registrator && entity.registrator.registrationDate)?Util.getFormatedDate(new Date(entity.registrator.registrationDate)):null; - rowData.modificationDate = (entity.modifier && entity.modifier.registrationDate)?Util.getFormatedDate(new Date(entity.modifier.registrationDate)):null; - rowData.entityObject = entity; - - if(entity.identifier) { - rowData.identifier = entity.identifier.identifier; - } - - for(var propertyCode in entity.properties) { - rowData[propertyCode] = entity.properties[propertyCode]; - } - - //Add the row data - rows.push(rowData); - } - callback(rows); - }; + var getDataRows = this._advancedSearchController.searchWithPagination(criteria, isGlobalSearch); - var dataGrid = new DataGridController("Search Results", columns, [], null, getDataRows, null, false, "ADVANCED_SEARCH_OPENBIS_" + this._advancedSearchModel.criteria.entityKind); + var dataGrid = new DataGridController("Search Results", columns, columnsLast, dynamicColumnsFunc, getDataRows, null, false, "ADVANCED_SEARCH_OPENBIS_" + this._advancedSearchModel.criteria.entityKind); return dataGrid; }