mirror of https://github.com/jenkinsci/jenkins.git
Merge pull request #9959 from timja/JENKINS-37241/autocomplete-improvements
[JENKINS-37241] Support for query parameters in autocomplete
This commit is contained in:
commit
3beaec617b
|
|
@ -474,6 +474,12 @@ public abstract class Descriptor<T extends Describable<T>> implements Loadable,
|
|||
if (method == null)
|
||||
return; // no auto-completion
|
||||
|
||||
// build query parameter line by figuring out what should be submitted
|
||||
List<String> depends = buildFillDependencies(method, new ArrayList<>());
|
||||
if (!depends.isEmpty()) {
|
||||
attributes.put("fillDependsOn", String.join(" ", depends));
|
||||
}
|
||||
|
||||
attributes.put("autoCompleteUrl", String.format("%s/%s/autoComplete%s", getCurrentDescriptorByNameUrl(), getDescriptorUrl(), capitalizedFieldName));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ module.exports = [
|
|||
object: "readonly",
|
||||
objectToUrlFormEncoded: "readonly",
|
||||
onSetupWizardInitialized: "readonly",
|
||||
qs: "readonly",
|
||||
refillOnChange: "readonly",
|
||||
refreshPart: "readonly",
|
||||
registerSortableDragDrop: "readonly",
|
||||
|
|
@ -72,6 +73,7 @@ module.exports = [
|
|||
shortenName: "readonly",
|
||||
Sortable: "readonly",
|
||||
toQueryString: "readonly",
|
||||
TryEach: "readonly",
|
||||
ts_refresh: "readonly",
|
||||
updateOptionalBlock: "readonly",
|
||||
Utilities: "readonly",
|
||||
|
|
|
|||
|
|
@ -59,9 +59,30 @@ function init() {
|
|||
}
|
||||
return;
|
||||
}
|
||||
const url =
|
||||
e.getAttribute("autoCompleteUrl") + "?value=" + encodeURIComponent(word);
|
||||
fetch(url)
|
||||
|
||||
const url = e.getAttribute("autoCompleteUrl");
|
||||
|
||||
const depends = e.getAttribute("fillDependsOn");
|
||||
const q = qs(e).addThis();
|
||||
if (depends && depends.length > 0) {
|
||||
depends.split(" ").forEach(
|
||||
TryEach(function (n) {
|
||||
q.nearBy(n);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
const queryString = q.toString();
|
||||
const idx = queryString.indexOf("?");
|
||||
const parameters = queryString.substring(idx + 1);
|
||||
|
||||
fetch(url, {
|
||||
method: "post",
|
||||
headers: crumb.wrap({
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
}),
|
||||
body: parameters,
|
||||
})
|
||||
.then((rsp) => (rsp.ok ? rsp.json() : {}))
|
||||
.then((response) => createAndShowDropdown(e, response.suggestions || []));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue