Skip to content

Commit

Permalink
WIP awaiting the proxy methods now...
Browse files Browse the repository at this point in the history
  • Loading branch information
kinow committed Aug 18, 2024
1 parent e91b2be commit 4618620
Show file tree
Hide file tree
Showing 2 changed files with 153 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ var UnoChoice = UnoChoice || ($ => {
*
* @param avoidRecursion {boolean} flag to decide whether we want to permit self-reference parameters or not
*/
CascadeParameter.prototype.update = function(avoidRecursion) {
CascadeParameter.prototype.update = async function(avoidRecursion) {
let parametersString = this.getReferencedParametersAsText(); // gets the array parameters, joined by , (e.g. a,b,c,d)
console.log(`Values retrieved from Referenced Parameters: ${parametersString}`);
// Update the CascadeChoiceParameter Map of parameters
this.proxy.doUpdate(parametersString);
await this.proxy.doUpdate(parametersString);

let spinner, rootDiv;
if (this.getRandomName()) {
Expand All @@ -169,10 +169,9 @@ var UnoChoice = UnoChoice || ($ => {
// The inner function is called with the response provided by Stapler. Then we update the HTML elements.
let _self = this; // re-reference this to use within the inner function
console.log('Calling Java server code to update HTML elements...');
this.proxy.getChoicesForUI(t => {
let choices = t.responseObject();
console.log(`Values returned from server: ${choices}`);
let data = JSON.parse(choices);
await this.proxy.getChoicesForUI(t => {
let data = t.responseObject();
console.log(`Values returned from server: ${data}`);
let newValues = data[0];
let newKeys = data[1];
let selectedElements = [];
Expand Down Expand Up @@ -323,7 +322,7 @@ var UnoChoice = UnoChoice || ($ => {
let other = cascadeParameters[i];
if (this.referencesMe(other)) {
console.log(`Updating ${other.getParameterName()} from ${this.getParameterName()}`);
other.update(true);
await other.update(true);
}
}
}
Expand All @@ -342,7 +341,7 @@ var UnoChoice = UnoChoice || ($ => {
/**
* Returns <code>true</code> iff the given parameter is not null, and one of its
* reference parameters is the same parameter as <code>this</code>. In other words,
* it returns whether or not the given parameter references this parameter.
* it returns whether the given parameter references this parameter.
*
* @since 0.22
* @param cascadeParameter {CascadeParameter} a given parameter
Expand Down Expand Up @@ -386,8 +385,8 @@ var UnoChoice = UnoChoice || ($ => {
//_self.cascadeParameter.loading(true);
$(".behavior-loading").show();
// start updating in separate async function so browser will be able to repaint and show 'loading' animation , see JENKINS-34487
setTimeout(() => {
_self.cascadeParameter.update(false);
setTimeout(async () => {
await _self.cascadeParameter.update(false);
$(".behavior-loading").hide();
}, 0);
}
Expand Down Expand Up @@ -437,11 +436,11 @@ var UnoChoice = UnoChoice || ($ => {
*
* @param avoidRecursion {boolean} flag to decide whether we want to permit self-reference parameters or not
*/
DynamicReferenceParameter.prototype.update = function(avoidRecursion) {
DynamicReferenceParameter.prototype.update = async function(avoidRecursion) {
let parametersString = this.getReferencedParametersAsText(); // gets the array parameters, joined by , (e.g. a,b,c,d)
console.log(`Values retrieved from Referenced Parameters: ${parametersString}`);
// Update the Map of parameters
this.proxy.doUpdate(parametersString);
await this.proxy.doUpdate(parametersString);
let parameterElement = this.getParameterElement();

let spinner, rootDiv;
Expand All @@ -462,11 +461,10 @@ var UnoChoice = UnoChoice || ($ => {
// or maybe call a string to put as value in a INPUT.
if (parameterElement.tagName === 'OL') { // handle OL's
console.log('Calling Java server code to update HTML elements...');
this.proxy.getChoicesForUI(t => {
await this.proxy.getChoicesForUI(t => {
$(parameterElement).empty(); // remove all children elements
let choices = t.responseObject();
console.log(`Values returned from server: ${choices}`);
let data = JSON.parse(choices);
const data = t.responseObject();
console.log(`Values returned from server: ${data}`);
let newValues = data[0];
// let newKeys = data[1];
for (let i = 0; i < newValues.length; ++i) {
Expand All @@ -478,10 +476,9 @@ var UnoChoice = UnoChoice || ($ => {
} else if (parameterElement.tagName === 'UL') { // handle OL's
$(parameterElement).empty(); // remove all children elements
console.log('Calling Java server code to update HTML elements...');
this.proxy.getChoicesForUI(t => {
let choices = t.responseObject();
console.log(`Values returned from server: ${choices}`);
let data = JSON.parse(choices);
await this.proxy.getChoicesForUI(t => {
const data = t.responseObject();
console.log(`Values returned from server: ${data}`);
let newValues = data[0];
// let newKeys = data[1];
for (let i = 0; i < newValues.length; ++i) {
Expand All @@ -491,13 +488,12 @@ var UnoChoice = UnoChoice || ($ => {
}
});
} else if (parameterElement.id.indexOf('inputElement_') > -1) { // handle input text boxes
this.proxy.getChoicesAsStringForUI(t => {
parameterElement.value = t.responseObject();
await this.proxy.getChoicesAsStringForUI(t => {
parameterElement.value = JSON.stringify(t.responseObject());
});
} else if (parameterElement.id.indexOf('formattedHtml_') > -1) { // handle formatted HTML
this.proxy.getChoicesAsStringForUI(t => {
let options = t.responseObject();
parameterElement.innerHTML = JSON.parse(options);
await this.proxy.getChoicesAsStringForUI(t => {
parameterElement.innerHTML = t.responseObject();
});
}
// propagate change
Expand All @@ -510,7 +506,7 @@ var UnoChoice = UnoChoice || ($ => {
let other = cascadeParameters[i];
if (this.referencesMe(other)) {
console.log(`Updating ${other.getParameterName()} from ${this.getParameterName()}`);
other.update(true);
await other.update(true);
}
}
}
Expand Down Expand Up @@ -825,7 +821,7 @@ var UnoChoice = UnoChoice || ($ => {
let tail = args[args.length-1];
return (typeof(tail)=='function') ? tail : null;
})();
// 'arguments' is not an array so we convert it into an array
// 'arguments' is not an array, so we convert it into an array
let a = [];
for (let i=0; i<args.length-(callback!=null?1:0); i++)
a.push(args[i]);
Expand Down Expand Up @@ -906,7 +902,7 @@ var UnoChoice = UnoChoice || ($ => {
}
}

function renderCascadeChoiceParameter(parentDivRef, filterable, name, randomName, filterLength, paramName, referencedParameters, cascadeChoiceParameter) {
async function renderCascadeChoiceParameter(parentDivRef, filterable, name, randomName, filterLength, paramName, referencedParameters, cascadeChoiceParameter) {
// find the cascade parameter element
let parentDiv = jQuery(parentDivRef);
let parameterHtmlElement = parentDiv.find('DIV');
Expand Down Expand Up @@ -966,13 +962,13 @@ var UnoChoice = UnoChoice || ($ => {

// call update methods in Java passing the HTML values
console.log('Updating cascade of parameter [', name, '] ...');
cascadeParameter.update(false);
await cascadeParameter.update(false);
} else {
console.log('Parameter error: Missing parameter [', paramName, '] HTML element!');
}
}

function renderDynamicRenderParameter(parentDivRef, name, paramName, referencedParameters, dynamicReferenceParameter) {
async function renderDynamicRenderParameter(parentDivRef, name, paramName, referencedParameters, dynamicReferenceParameter) {
// find the cascade parameter element
let parentDiv = jQuery(parentDivRef);
// if the parameter class has been set to hidden, then we hide it now
Expand Down Expand Up @@ -1049,7 +1045,7 @@ var UnoChoice = UnoChoice || ($ => {

// call update methods in Java passing the HTML values
console.log('Updating cascade of parameter [', name, '] ...');
dynamicParameter.update(false);
await dynamicParameter.update(false);
} else {
console.log('Parameter error: Missing parameter [', paramName,'] HTML element!');
}
Expand Down
Loading

0 comments on commit 4618620

Please sign in to comment.