Skip to content

Commit

Permalink
fix: autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
StephaneBour committed Jan 15, 2024
1 parent ac0f042 commit 5985f51
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@


function hideAutoComplete(editor) {
if (MODE != MODE_VISIBLE) return;
if (MODE !== MODE_VISIBLE) return;
editor = editor || sense.editor;
editor.commands.removeCommands(visibleMenuAceCMDS);
editor.commands.addCommands(_cached_cmds_to_restore);
Expand Down
15 changes: 9 additions & 6 deletions src/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ function resetToValues(server, content) {
function constructESUrl(server, url) {
if (url.indexOf("://") >= 0) return url;
if (server.indexOf("://") < 0) server = "http://" + server;
if (server.substr(-1) == "/") {
server = server.substr(0, server.length - 1);
if (server.substring(-1) === "/") {
server = server.substring(0, server.length - 1);
}
if (url.charAt(0) === "/") url = url.substr(1);
if (url.charAt(0) === "/") url = url.substring(1);

return server + "/" + url;
}
Expand All @@ -62,13 +62,13 @@ function callES(server, url, method, data, successCallback, completeCallback) {
var password = url_parts[3];
url = url_parts[1] + url_parts[4];
console.log("Calling " + url + " (uname: " + uname + " pwd: " + password + ")");
if (data && method == "GET") method = "POST";
if (data && method === "GET") method = "POST";

$.ajax({
url: url,
data: method == "GET" ? null : data,
data: method === "GET" ? null : data,
contentType: 'application/json',
headers: method == "GET" ? null : { "Content-Type": "application/json" },
headers: method === "GET" ? null : { "Content-Type": "application/json" },
// xhrFields: {
// withCredentials: true
// },
Expand Down Expand Up @@ -465,6 +465,9 @@ function checkVersion() {
document.getElementById('new_version').style.display = 'block';
}
});
})
.catch(rejected => {
console.log(rejected);
});
}

Expand Down
47 changes: 24 additions & 23 deletions src/mappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,31 +138,32 @@
return [field_name];
}

function getFieldNamesFromTypeMapping(type_mapping) {
var properties;

if(typeof type_mapping['properties'] == 'undefined')
properties = type_mapping[Object.keys(type_mapping)[0]]['properties'];
else
properties = type_mapping['properties'];

if(typeof properties == 'undefined') {
return null;
function extractConcatenatedKeys(json) {
let keys = [];

function extractKeys(obj, prefix) {
for (let key in obj) {
// Construire le chemin complet de la clé
let fullPath = prefix ? prefix + "." + key : key;

if (obj.hasOwnProperty(key)) {
// Si c'est un objet avec des propriétés, on explore récursivement
if (obj[key] && typeof obj[key] === 'object' && obj[key].hasOwnProperty('properties')) {
extractKeys(obj[key].properties, fullPath);
} else {
// Sinon, on ajoute simplement la clé complète
keys.push(fullPath);
}
}
}
}

extractKeys(json);
return keys;
}

var field_list =
$.map(properties, function (field_mapping, field_name) {
return getFieldNamesFromFieldMapping(field_name, field_mapping);
});

// deduping
var last = undefined;
field_list.sort();
return $.map(field_list, function (f) {
var r = (f === last) ? null : f;
last = f;
return r;
});
function getFieldNamesFromTypeMapping(type_mapping, debug = false) {
return extractConcatenatedKeys(type_mapping);
}

function loadMappings(mappings) {
Expand Down

0 comments on commit 5985f51

Please sign in to comment.