diff --git a/CHANGELOG.md b/CHANGELOG.md index d731af586c4bef459141e0834df8d0add95a8c14..a546c66c34d82a3f804a3fc9e216c2786c0670c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [caosdb-webui#226](https://gitlab.com/caosdb/caosdb-webui/-/issues/226) * Fixed broken download of referenced files in the export of select statements. https://gitlab.com/linkahead/linkahead-webui/-/issues/238 +* Do not send unpaged queries during Edit Mode usage. Fixes + [caosdb-webui#217](https://gitlab.com/linkahead/linkahead-webui/-/issues/217) ### Security ### diff --git a/src/core/js/edit_mode.js b/src/core/js/edit_mode.js index d9c5d1937f0fd6f94f167c2364fe1f800d823fe3..5cde9729e69da8a3f7b31103ff817035ec950b3f 100644 --- a/src/core/js/edit_mode.js +++ b/src/core/js/edit_mode.js @@ -1013,9 +1013,39 @@ var edit_mode = new function () { const select = $('<select data-container="body" data-virtual-scroll="100" data-window-padding="15" data-live-search="true" class="selectpicker form-control caosdb-list-' + property.datatype + '" data-resolved="false"><option value=""></option></select>'); options.then((_options) => { + // The options might not include all entites (if there are + // many). Include the property value if it is missing. + if (-1==_options.map((e)=>{return e.value}).indexOf(property.value)){ + _options = _options.concat([$(`<option value="${property.value}">ID: ${property.value}</option>`)[0]]) + } edit_mode.fill_reference_drop_down(select[0], _options, property.value); result.empty(); result.append(select); + if(_options[0].getAttribute('value') == "NA") { + // Add input for manual ID insertion + idinput = $("<input type='number' value=''></input>") + idinput.hide() + // When Enter is pressed, the insertion is completed + idinput.on('keyup', function(e){ + if (e.key === 'Enter' || e.keyCode === 13) { + idinput.hide(); + var sel_id = idinput[0].value + select.append(`<option value="${sel_id}">ID: ${sel_id}</option>`); + // workaround for selectpicker bug (options are + // doubled otherwise) + select.selectpicker('destroy'); + select.selectpicker('val', `${sel_id}`); + $(result).find('.dropdown').show(); + } + }); + result.append(idinput); + var manualInsertButton = $('<button title="Insert Entity Id manually." class="btn btn-link caosdb-update-entity-button caosdb-f-list-item-button"><i class="bi-pencil"></i></button>'); + $(manualInsertButton ).click(function () { + $(result).find('.dropdown').hide(); + $(result).find('input').show(); + }); + result.parent().append(manualInsertButton); + } edit_mode._init_select(select); }); } @@ -1838,8 +1868,12 @@ var edit_mode = new function () { */ this.retrieve_datatype_list = async function (datatype) { var find_entity = ["FILE", "REFERENCE"].includes(datatype) ? "" : `"${datatype}"`; - var entities = datatype !== "FILE" ? edit_mode.query(`FIND Record ${find_entity}`, true) : []; - var files = edit_mode.query(`FIND File ${find_entity}`, true); + const max_options = 25; + // TODO cache this? + var n_entities = datatype !== "FILE" ? $(await connection.get(`Entity/?query=COUNT RECORD ${find_entity}`)).find('Query').attr('results') : 0; + var n_files =$(await connection.get(`Entity/?query=COUNT FILE ${find_entity}`)).find('Query').attr('results'); + var entities = datatype !== "FILE" ? edit_mode.query(`FIND Record ${find_entity}&P=0L${max_options}`, true) : []; + var files = edit_mode.query(`FIND File ${find_entity}&P=0L${max_options}`, true); await Promise.all([entities, files]) @@ -1848,8 +1882,11 @@ var edit_mode = new function () { .concat(edit_mode ._create_reference_options(await files)); + if (n_entities > max_options || n_files > max_options) { + // add notification that not all entities are shown + options=[$(`<option disabled=true value="NA"/>`).text('Dropdown only shows selection of possible entities!')[0]].concat(options); + } return options; - } this.highlight = function (entity) {