diff --git a/src/core/js/edit_mode.js b/src/core/js/edit_mode.js index 1e2557782274e888323384785144dbd7f1475f8f..2121a49aa48573d316e36da91da76049bbed6682 100644 --- a/src/core/js/edit_mode.js +++ b/src/core/js/edit_mode.js @@ -313,14 +313,66 @@ var edit_mode = new function() { } - this.get_datatype_str = function (atomic, refid, list) { - var result = atomic; - if (refid !== null && typeof refid !== "undefined") { - result = refid; + /** + * Pure converter from a datatype in string representation to a json + * objects. + * + * E.g. passing "LIST<Person>" results in + * { atomic_datatype: "REFERENCE", + * reference_scope: "Person", + * is_list: true + * } + * + * @param {str} datatype + * @returns {object} + */ + this.get_datatype_from_string = function (datatype) { + + var atomic = datatype; + const is_list = edit_mode.isListDatatype(datatype); + if (is_list) { + // unwrap the datatype from LIST<...> + atomic = edit_mode.unListDatatype(datatype); + } + + var ref = undefined; + if (edit_mode._known_atomic_datatypes.indexOf(atomic) == -1) { + // `atomic` not in `known_atomic_datatypes` (e.g. "Person") -> this + // is a reference and the `atomic` is actually the reference's + // scope entity. + reference = atomic; + atomic = "REFERENCE"; + } + + return { "atomic_datatype": atomic, "reference_scope": ref, "is_list": is_list}; + } + + /** + * Pure converter from a datatype json objects to a string representation + * of the datatype. + * + * E.g. passing + * { atomic_datatype: "REFERENCE", + * reference_scope: "Person", + * is_list: true + * } + * results in "LIST<Person>". + * + * @param {object} datatype + * @returns {str} + */ + this.get_datatype_str = function (datatype) { + var result = datatype["atomic_datatype"]; + + const ref = datatype["reference_scope"]; + if (ref !== null && typeof ref !== "undefined") { + result = ref; } - if (list === "on" || list === true) { + + if (is_list === "on" || is_list === true) { result = `LIST<${result}>`; } + return result; } @@ -350,10 +402,7 @@ var edit_mode = new function() { edit_mode.getProperties(ent_element), getParents(ent_element), true, - edit_mode.get_datatype_str( - obj.atomic_datatype, - obj.reference_target, - obj.is_list), + edit_mode.get_datatype_str(obj), getEntityDescription(ent_element), obj.unit, ); @@ -539,8 +588,8 @@ var edit_mode = new function() { roleElem.detach(); var parentsElem = $(header).find('.caosdb-f-parent-list'); parentsElem.detach(); - var temp = $('<div class="form-group"><label class="col-sm-2 control-label">parents</label><div class="col-sm-10"></div></div>'); - temp.find("div.col-sm-10").append(parentsElem); + const parentsSection = $('<div class="form-group"><label class="col-sm-2 control-label">parents</label><div class="col-sm-10"></div></div>'); + parentsSection.find("div.col-sm-10").append(parentsElem); header.attr("title", "Drop parents from the right panel here."); header.data("toggle", "tooltip"); @@ -548,18 +597,22 @@ var edit_mode = new function() { // create inputs var inputs = [ roleElem, - temp, + parentsSection, this.make_input("name", getEntityName(entity)), this.make_input("description", getEntityDescription(entity)), ]; if (getEntityRole(roleElem[0]) == "Property") { - // TODO seperate unit, list, datatype, refid factories and listeners - // TODO refactor getEntityUnit and use that - var unit = getEntityHeadingAttribute(entity, "unit"); - for (const input of this.make_datatype_input(getEntityDatatype(entity), unit)) { + const current_datatype = getEntityDatatype(entity); + for (const input of this.make_datatype_input(current_datatype)) { + // returns [`atomic_datatype`, `reference_scope`, `is_list`] inputs.push(input); } - temp.hide(); + + const current_unit = getEntityUnit(entity); + inputs.push(edit_mode.make_unit_input(current_unit)); + + // TODO currently no parents for properties. Why not? + parentsSection.hide(); } else if (getEntityRole(roleElem[0]) == "File") { inputs.push(this.make_input("path", getEntityPath(entity))); } @@ -568,7 +621,7 @@ var edit_mode = new function() { const form = $('<form class="form-horizontal"></form>').append(inputs); header.append(form); - edit_mode.make_dataype_input_logic(form[0]); + edit_mode.make_datatype_input_logic(form[0]); edit_mode.add_parent_delete_buttons(header[0]); } @@ -580,7 +633,7 @@ var edit_mode = new function() { return datatype.substring(5, datatype.length - 1); } - this.make_dataype_input_logic = function(form) { + this.make_datatype_input_logic = function(form) { const datatype = form_elements.get_fields(form, "atomic_datatype"); $(datatype).find("select").change(function () { @@ -597,9 +650,9 @@ var edit_mode = new function() { logger.trace('enter on_datatype_change', form, new_type); if (new_type === "REFERENCE") { - form_elements.enable_name(form, "reference_target"); + form_elements.enable_name(form, "reference_scope"); } else { - form_elements.disable_name(form, "reference_target"); + form_elements.disable_name(form, "reference_scope"); } if (new_type === "DOUBLE" || new_type === "INTEGER") { @@ -621,44 +674,38 @@ var edit_mode = new function() { return unit_input; } - /** - * { name: has_unit? } - */ - this._known_atomic_datatypes = { - "TEXT": false, - "DOUBLE": true, - "INTEGER": true, - "DATETIME": false, - "BOOLEAN": false, - "FILE": false, - "REFERENCE":false, - }; + this._known_atomic_datatypes = [ + "TEXT", + "DOUBLE", + "INTEGER", + "DATETIME", + "BOOLEAN", + "FILE", + "REFERENCE", + ]; /** + * Make three input elements which contain all necessary parts of a datatype. + * + * The three input elements are for the `atomic_datatype`, which is one of * @param {string} [datatype] - defaults to TEXT if undefined. - * @param {string} [unit] optional. */ - this.make_datatype_input = function(datatype, unit) { + this.make_datatype_input = function(datatype) { var _datatype = datatype || "TEXT"; - const is_list = edit_mode.isListDatatype(_datatype); - if (is_list) { - _datatype = edit_mode.unListDatatype(_datatype); - } - const known_atomic_datatypes = edit_mode._known_atomic_datatypes; + // split/convert datatype string into more practical variables. + const datatype_obj = edit_mode.get_datatype_from_string(_datatype); + const atomic_datatype = datatype_obj["atomic_datatype"]; + const reference_scope = datatype_obj["reference_scope"]; + const is_list = datatype_obj["is_list"]; - // is reference? - var reference = undefined; - if (typeof known_atomic_datatypes[_datatype] === "undefined") { - reference = _datatype; - _datatype = "REFERENCE"; - } - var select = $('<select name="atomic_datatype" class="form-control"></select>'); - for (const dt of Object.keys(known_atomic_datatypes)) { + // generate select input for the atomic_datatype + const select = $('<select name="atomic_datatype" class="form-control"></select>'); + for (const dt of known_atomic_datatypes) { select.append(`<option value="${dt}">${dt}</option>`); } - select.val(_datatype) + select.val(atomic_datatype) const datatype_config = { name: "atomic_datatype", @@ -669,17 +716,21 @@ var edit_mode = new function() { .append(form_elements._make_input_label_str(datatype_config)) .append($('<div class="col-sm-9"/>').append(select))[0]; + // generate select input for the RecordTypes which are the reference's + // scope. const reference_config = { - name: "reference_target", + name: "reference_scope", label: "reference to", - value: reference, + value: reference_scope, query: "SELECT name FROM RECORDTYPE", make_desc: getEntityName, make_value: getEntityName, }; - const refid_selector = form_elements + const ref_selector = form_elements .make_reference_drop_down(reference_config); + + // generate the checkbox ([ ] list) const list_checkbox_config = { name: "is_list", label: "list", @@ -688,8 +739,7 @@ var edit_mode = new function() { const list_checkbox = form_elements .make_checkbox_input(list_checkbox_config); - return [datatype_selector, refid_selector, list_checkbox, - edit_mode.make_unit_input(unit)]; + return [datatype_selector, ref_selector, list_checkbox]; } this.make_input = function(label, value) { @@ -1489,8 +1539,8 @@ var edit_mode = new function() { /** * Fill the reference drop down menu of an entity property with options. * - * The options are candidates for reference targets (i.e. values of - * reference properties). + * The options are the entities which are within the scope of the reference + * property. * * @param {HTMLElement} drop_down - A SELECT element which will be filled. * @param {HTMLElement[]} options - array of option elements, ready for diff --git a/src/core/js/sss_markdown.js b/src/core/js/sss_markdown.js new file mode 120000 index 0000000000000000000000000000000000000000..2e4b0b69e684a1b926faba5a9b75eb04e379c95a --- /dev/null +++ b/src/core/js/sss_markdown.js @@ -0,0 +1 @@ +/home/tf/indiscale/external/glaz_awi/server-profile/profile/custom/caosdb-server/caosdb-webui/src/ext/js/sss_markdown.js \ No newline at end of file