Closed alanruttenberg closed 9 years ago
Ah, good to see the other issues are resolved. About the first one: there is a public yasqe command (not documented I see), which initializes the autocompleter. You'd probably get away with simply re-initializing the autocompleter when the endpoint changes:
yasqe.autocompleters.init('customPrefixCompleter',customPrefixCompleter);
(this command is already automatically set to execute when you open a new tab)
I also suggest to remove the returnObj.persistent = ...
line, considering yasqe instances won't share the same autocompletions.
As a result, on page load, the autocompleter always executes the get request (contrary to fetching it from localstorage if they're stored there).
I took your advice and used the custom autocompleter example (code below). Now I can complete the sesame prefixes in the PREFIX section.
There are a some issues I could use some help on still.
I could have sworn there was some version of YASQE where if I typed a prefix in the query the prefix definition was added to the PREFIX section automatically. This is not happening.doneI would like to complete prefixes used in the query. So I type "?foo a too" and it offers "tooth:" (and if I accept adds it to the prefixes section).doneBest, Alan
` javascript
YASGUI.YASQE.defaults.sparql.callbacks.success = function(data){console.log("success", data);};/ Adapted from https://gist.github.com/LaurensRietveld/3549c02f5727346ae89c#file-init-js to get prefixes from a sesame endpoint /
/**
var getAutocompletionsArrayFromSesameCsv = function(csvString) { var completionsArray = []; csvString.split("\n").splice(1).forEach(function(url) {//remove first line, as this one contains the projection variable url=url.replace("\r",""); headerprefix = url.split(",") completestring= headerprefix[0] + ": <" + headerprefix[1] + ">"; completionsArray.push(completestring); }); sorted=completionsArray.sort(); minusfirst=sorted.splice(1); return minusfirst; }
var customPrefixCompleter = function(yasqe) { //we use several functions from the regular prefix autocompleter (this way, we don't have to re-define code such as determining whether we are in a valid autocompletion position) yasqe.on("change", function() { YASGUI.YASQE.Autocompleters.prefixes.appendPrefixIfNeeded(yasqe, 'customPrefixCompleter'); }); var returnObj = { // we don't complete unless we've typed at least 3 characters, // are not in the middle of a token, are not immediately after // a token which has invalid characters for a prefix or we're // in whitespace. isValidCompletionPosition: function(){var token = yasqe.getCompleteToken(); return(token.string.length > 2 && !(token.type == "ws")&& !(yasqe.getCursor().ch < token.end) && token.string.match(/^[0-9A-Za-z_]+$/) )}, // token.state.queryType lets us know whether we are in the // query body or before it. If before we do the usual // otherwise don't show or include the URI in the completion. postProcessToken: function(token,suggestedString) { if (token.state.queryType) return(suggestedString.replace(/:.*/,":")) else return(suggestedString) }, preProcessToken: function(token) {return YASGUI.YASQE.Autocompleters.prefixes.preprocessPrefixTokenForCompletion(yasqe, token)}, appendPrefixIfNeeded: function(yasqe, completerName) {return YASGUI.YASQE.Autocompleters.prefixes.appendPrefixIfNeeded(yasqe,completerName)} }
}
//now register our new autocompleter YASGUI.YASQE.registerAutocompleter('customPrefixCompleter', customPrefixCompleter); YASGUI.YASQE.defaults.autocompleters=['customPrefixCompleter']