From 26d994c3584f770bdb9147b368489eeb7f281dbc Mon Sep 17 00:00:00 2001 From: Mariia Pukhliakova <mariia.pukhliakova@id.ethz.ch> Date: Fri, 28 Feb 2020 16:20:49 +0100 Subject: [PATCH] SSDM-9324 26. Search --- .../eln-lims/html/js/test/UserTests.js | 50 ++++++++++++++++++- .../eln-lims/html/js/util/EventUtil.js | 48 ++++++++++++++++++ .../AdvancedSearch/AdvancedSearchView.js | 24 +++++---- .../widgets/AdvancedEntitySearchDropdown.js | 1 + .../eln-lims/html/lib/grid/js/Grid.html | 2 +- .../webapps/eln-lims/html/lib/grid/js/Grid.js | 10 ++++ 6 files changed, 121 insertions(+), 14 deletions(-) diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/test/UserTests.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/test/UserTests.js index d03b6714c7f..1fc3a681305 100644 --- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/test/UserTests.js +++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/test/UserTests.js @@ -30,8 +30,10 @@ var UserTests = new function() { //23. Experiment Step Form - Dataset Uploader and Viewer .then(() => this.datasetUploader()) //24. Experiment Step Form - Children Generator (not exist) - //24. Project Form - Show in project overview + //25. Project Form - Show in project overview .then(() => this.showInProjectOverview()) + //26. Search + .then(() => this.search()) .catch(error => { console.log(error) }); } @@ -474,7 +476,7 @@ var UserTests = new function() { this.showInProjectOverview = function() { return new Promise(function executor(resolve, reject) { var e = EventUtil; - // go to project 101 + Promise.resolve().then(() => e.waitForId("PATH_TESTID_PROJECT_101")) .then(() => e.click("PATH_TESTID_PROJECT_101")) // click "Show Experiments" @@ -498,4 +500,48 @@ var UserTests = new function() { .then(() => resolve()); }); } + + this.search = function() { + return new Promise(function executor(resolve, reject) { + var e = EventUtil; + + Promise.resolve().then(() => e.waitForId("search")) + // start global search + .then(() => e.click("search")) + .then(() => e.change("search", "BAC5", false)) + .then(() => e.keypress("search", 13, false)) + .then(() => e.waitForId("save-btn")) + // check searching results + .then(() => e.waitForId("columns-dropdown-id")) + .then(() => e.click("columns-dropdown-id")) + .then(() => e.waitForId("code-cln")) + .then(() => e.checked("code-cln", true)) + // todo should be modified after test 10. and BAC5_BAC4 will be available + .then(() => e.waitForId("bac5-id")) + // save query + .then(() => e.waitForId("save-btn")) + .then(() => e.click("save-btn")) + .then(() => e.waitForId("Name")) + .then(() => e.write("Name", "Search for BAC5", false)) + .then(() => e.waitForId("advanced-entity-search-dropdown-id")) + .then(() => e.triggerSearchSelect2("advanced-entity-search-dropdown-id", "ba", false)) + .then(() => e.waitForId("search-query-save-btn")) + .then(() => e.click("search-query-save-btn")) + // wait for saving + .then(() => e.sleep(3000)) + // Click on BAC5 + .then(() => e.waitForId("bac5-id")) + .then(() => e.click("bac5-id")) + .then(() => e.waitForId("edit-btn")) + // Click on Advanced Search + .then(() => e.waitForId("ADVANCED_SEARCH")) + .then(() => e.click("ADVANCED_SEARCH")) + .then(() => e.waitForId("saved-search-dropdown-id")) + .then(() => e.triggerSelectSelect2("saved-search-dropdown-id", 0, false)) + .then(() => e.waitForId("search-btn")) + .then(() => e.click("search-btn")) + .then(() => e.waitForId("bac5-id")) + .then(() => resolve()); + }); + } } \ No newline at end of file diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/util/EventUtil.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/util/EventUtil.js index 7499b9cdd9d..84520f191dd 100644 --- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/util/EventUtil.js +++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/util/EventUtil.js @@ -44,6 +44,39 @@ var EventUtil = new function() { }); }; + this.triggerSelectSelect2 = function(elementId, value, ignoreError) { + return new Promise(function executor(resolve, reject) { + try { + var element = EventUtil.getElement(elementId, ignoreError, resolve); + element.focus(); + element.val(value); + element.select2().trigger('select2:select'); + resolve(); + } catch(error) { + reject(error); + } + }); + }; + + this.triggerSearchSelect2 = function(elementId, value, ignoreError) { + return new Promise(function executor(resolve, reject) { + try { + var element = EventUtil.getElement(elementId, ignoreError, resolve); + element.select2('open'); + + var $search = element.data('select2').dropdown.$search || element.data('select2').selection.$search; + $search.val(value); + $search.trigger('input'); + setTimeout(function() { + $('.select2-results__option').trigger("mouseup"); + resolve(); + }, 2000); + } catch(error) { + reject(error); + } + }); + }; + this.checked = function(elementId, value, ignoreError) { return new Promise(function executor(resolve, reject) { try { @@ -90,6 +123,21 @@ var EventUtil = new function() { }); }; + this.keypress = function(elementId, key, ignoreError) { + return new Promise(function executor(resolve, reject) { + try { + var element = EventUtil.getElement(elementId, ignoreError, resolve); + element.focus(); + var e = $.Event('keypress'); + e.which = key; + $(element).trigger(e); + resolve(); + } catch(error) { + reject(error); + } + }); + } + this.verifyExistence = function(elementId, isExist, ignoreError) { return new Promise(function executor(resolve, reject) { var elementExistence = $("#" + elementId).length > 0; 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 a32c9c1bcc8..262b93a35f2 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 @@ -125,7 +125,7 @@ function AdvancedSearchView(advancedSearchController, advancedSearchModel) { Â Â Â Â }); } - Â Â Â Â var $btnSave = $('<input>', { 'type': 'submit', 'class' : 'btn btn-primary', 'value' : 'Save' }); + Â Â Â Â var $btnSave = $('<input>', { 'type': 'submit', 'class' : 'btn btn-primary', 'value' : 'Save', 'id' : 'search-query-save-btn' }); Â Â Â Â var $btnCancel = $('<a>', { 'class' : 'btn btn-default' }).append('Cancel'); Â Â Â Â $btnCancel.click(function() { Â Â Â Â Â Â Util.unblockUI(); @@ -190,10 +190,11 @@ function AdvancedSearchView(advancedSearchController, advancedSearchModel) { }); } this._$savedSearchesDropdown = FormUtil.getPlainDropdown(savedSearchOptions); - this._$savedSearchesDropdown.change(function(change) { - var i = _this._$savedSearchesDropdown.val(); - _this._advancedSearchController.selectSavedSearch(i); - }); + this._$savedSearchesDropdown.attr("id", "saved-search-dropdown-id"); + this._$savedSearchesDropdown.on("select2:select", function () { + var i = _this._$savedSearchesDropdown.val(); + _this._advancedSearchController.selectSavedSearch(i); + }); $container.append(this._$savedSearchesDropdown); this._$savedSearchesDropdown.select2({ width: '400px', @@ -209,7 +210,7 @@ function AdvancedSearchView(advancedSearchController, advancedSearchModel) { var $buttonSave = FormUtil.getButtonWithIcon('glyphicon-floppy-disk', function() { _this._save(); - }, 'Save'); + }, 'Save', null, "save-btn"); $buttonSave.css({ 'margin-left': '8px'}); $container.append($buttonSave); @@ -243,7 +244,7 @@ function AdvancedSearchView(advancedSearchController, advancedSearchModel) { var $submitButton = FormUtil.getButtonWithIcon('glyphicon-search', function() { _this._advancedSearchController.search(); - }); + }, null, null, "search-btn"); $submitButton.css("margin-top", "22px"); var $submitButtonGroup = FormUtil.getFieldForComponentWithLabel($submitButton, "", null, true); @@ -743,7 +744,8 @@ function AdvancedSearchView(advancedSearchController, advancedSearchModel) { } } } - return _this._getLinkOnClick(data.code, data, paginationInfo); + var id = data.code.toLowerCase() + "-id"; + return _this._getLinkOnClick(data.code, data, paginationInfo, id); } }, { label : 'Identifier', @@ -901,16 +903,16 @@ function AdvancedSearchView(advancedSearchController, advancedSearchModel) { return dataGrid; } - this._getLinkOnClick = function(code, data, paginationInfo) { + this._getLinkOnClick = function(code, data, paginationInfo, id) { if(data.entityKind !== "Sample") { paginationInfo = null; // TODO - Only supported for samples for now } switch(data.entityKind) { case "Experiment": - return FormUtil.getFormLink(code, data.entityKind, data.identifier, paginationInfo); + return FormUtil.getFormLink(code, data.entityKind, data.identifier, paginationInfo, id); break; default: - return FormUtil.getFormLink(code, data.entityKind, data.permId, paginationInfo); + return FormUtil.getFormLink(code, data.entityKind, data.permId, paginationInfo, id); break; } } diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/widgets/AdvancedEntitySearchDropdown.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/widgets/AdvancedEntitySearchDropdown.js index 6e8671454d9..53f93071e53 100644 --- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/widgets/AdvancedEntitySearchDropdown.js +++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/widgets/AdvancedEntitySearchDropdown.js @@ -233,6 +233,7 @@ function AdvancedEntitySearchDropdown(isMultiple, // this.init = function($container) { $select.attr("multiple", "multiple"); + $select.attr("id", "advanced-entity-search-dropdown-id"); if(isRequired) { $select.attr("required", "required"); diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/lib/grid/js/Grid.html b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/lib/grid/js/Grid.html index 085d860a497..bf2b5ec2387 100644 --- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/lib/grid/js/Grid.html +++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/lib/grid/js/Grid.html @@ -60,7 +60,7 @@ </div> <div class="dropdown columnDropdown" style = "display: inline; padding-left: 10px;"> - <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown"> + <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" id="columns-dropdown-id"> Columns <span class="caret"></span> </button> <ul style="max-height:500px; overflow:scroll; overflow-x: hidden;" class="dropdown-menu" role="menu"></ul> diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/lib/grid/js/Grid.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/lib/grid/js/Grid.js index e08983f693b..56c9306db25 100644 --- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/lib/grid/js/Grid.js +++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/lib/grid/js/Grid.js @@ -175,10 +175,20 @@ $.extend(Grid.prototype, { columnsForDropdown.forEach(function(column, columnIndex) { if(!column.showByDefault && !column.hide) { + var checkbox = $("<input>") .attr("type", "checkbox") .attr("value", column.property) .attr("style", "margin-left: 5px;"); + + if (column.property != null) { + var id = column.property.split(" ").join("-") + "-cln"; + if (id[0] === '$') { + id = id.substring(1, id.length - 1); + } + id = id.toLowerCase(); + checkbox.attr("id", id) + } if(thisGrid.tableSettings && thisGrid.tableSettings.columns && Object.keys(thisGrid.tableSettings.columns).length !== 0) { if((thisGrid.tableSettings.columns[column.property] === true)) { //If settings are present -- GitLab