diff --git a/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/controllers/MainController.js b/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/controllers/MainController.js index 7e6f81960ea653a2ba44086289f741be7a3c1e90..39f12f7cf98f8bca1ef7788be73d1947ac3b5241 100644 --- a/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/controllers/MainController.js +++ b/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/controllers/MainController.js @@ -605,7 +605,7 @@ function MainController(profile) { $("#search").addClass("search-query-searching"); if(!searchDomain || searchDomain === profile.getSearchDomains()[0].name) { //Global Search - localReference.serverFacade.searchWithText(value, function(data) { + localReference.serverFacade.searchGlobally(value, function(data) { $("#search").removeClass("search-query-searching"); var columns = [ { 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 149cd830a1a5db6142cba772f15a4e2ea4399de0..9ae84add8f0f7664e48f2445b0ac27f55c730683 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 @@ -604,7 +604,7 @@ function ServerFacade(openbisServer) { var fetchOptionsClass = 'as/dto/sample/fetchoptions/SampleFetchOptions'; var searchMethodName = 'searchSamples'; this.searchForEntityAdvanced(advancedSearchCriteria, callback, criteriaClass, fetchOptionsClass, searchMethodName); - } + } this.searchForEntityAdvanced = function(advancedSearchCriteria, callback, criteriaClass, fetchOptionsClass, searchMethodName) { require(['openbis', @@ -1257,32 +1257,44 @@ function ServerFacade(openbisServer) { } // - // Free Text Search + // Globale Search // - this.searchWithText = function(freeText, callbackFunction) + this.searchGlobally = function(freeText, callbackFunction) { var _this = this; - var regEx = /\d{4}-\d{2}-\d{2}/g; - var match = freeText.match(regEx); - - if(match && match.length === 1) { //Search With Date Mode, we merge results with dates found on registration and modification fields what is slow for large number of entities - this.searchSamples(this._getCriteriaWithDate(freeText, true, false), function(samples1) { - _this.searchSamples(_this._getCriteriaWithDate(freeText, false, true), function(samples2) { - _this.searchSamples(_this._getCriteriaWithDate(freeText, false, false), function(samples3) { - var results = samples1.concat(samples2).concat(samples3).uniqueOBISEntity(); - callbackFunction(results); - }); - }); - }); - } else if(match && match.length > 1) { - Util.showError("Search only supports one date at a time!"); - callbackFunction([]); - } else { //Normal Search - this.searchSamples(this._getCriteriaWithDate(freeText, false, false), function(samples) { - callbackFunction(samples); + require(['openbis', 'as/dto/global/search/GlobalSearchCriteria', + 'as/dto/global/fetchoptions/GlobalSearchObjectFetchOptions'], + function(openbis, GlobalSearchCriteria, GlobalSearchObjectFetchOptions){ + var protocol = window.location.protocol; + var host = window.location.hostname; + var port = window.location.port; + var url = protocol + "//" + host + ":" + port; + var v3api = new openbis(url + "/openbis/openbis/rmi-application-server-v3.json"); + v3api._private.sessionToken = mainController.serverFacade.getSession(); + var searchCriteria = new GlobalSearchCriteria(); + searchCriteria.withText().thatContains(freeText); + var fetchOptions = new GlobalSearchObjectFetchOptions(); + var sampleFetchOptions = fetchOptions.withSample(); + sampleFetchOptions.withSpace(); + sampleFetchOptions.withType(); + sampleFetchOptions.withRegistrator(); + sampleFetchOptions.withModifier(); + sampleFetchOptions.withExperiment(); + v3api.searchGlobally(searchCriteria, fetchOptions).done(function(results) { + var v1Samples = []; + var objects = results.getObjects(); + for (var i = 0; i < objects.length; i++) { + var sample = objects[i].getSample(); + if (sample) { + v1Samples.push(_this.getV3SampleAsV1(sample)); + } + } + callbackFunction(v1Samples); + }).fail(function(error) { + Util.showError("Call failed to server: " + JSON.stringify(error)); + Util.unblockUI(); }); - callbackFunction([]); - } + }); } this._getCriteriaWithDate = function(freeText, isRegistrationDate, isModificationDate) { diff --git a/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/lib/openbis/js/v3/openbis.js b/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/lib/openbis/js/v3/openbis.js index 051e7f3173e051c5392a4a8c6ac52753ae458d11..800858443e601c3cbf1b017d63bcf2de68e34bf2 100644 --- a/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/lib/openbis/js/v3/openbis.js +++ b/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/lib/openbis/js/v3/openbis.js @@ -1,4 +1,4 @@ -define(['util/Json'], function(stjsUtil) { +define([ 'util/Json' ], function(stjsUtil) { var __private = function() { @@ -458,6 +458,18 @@ define(['util/Json'], function(stjsUtil) { }); } + this.searchGlobally = function(criteria, fetchOptions) { + var thisFacade = this; + return thisFacade._private.ajaxRequest({ + url : openbisUrl, + data : { + "method" : "searchGlobally", + "params" : [ thisFacade._private.sessionToken, criteria, fetchOptions ] + }, + returnType : "SearchResult" + }); + } + this.deleteSpaces = function(ids, deletionOptions) { var thisFacade = this; return thisFacade._private.ajaxRequest({