N°3537 run_query : fix cannot set query arguments values

This commit is contained in:
Pierre Goiffon
2021-01-14 15:26:23 +01:00
parent f1b972dde8
commit a41229b223
2 changed files with 54 additions and 14 deletions

View File

@@ -23,7 +23,9 @@ use Combodo\iTop\Application\UI\Base\Component\CollapsibleSection\CollapsibleSec
use Combodo\iTop\Application\UI\Base\Component\FieldSet\FieldSet;
use Combodo\iTop\Application\UI\Base\Component\Form\Form;
use Combodo\iTop\Application\UI\Base\Component\Html\Html;
use Combodo\iTop\Application\UI\Base\Component\Input\InputFactory;
use Combodo\iTop\Application\UI\Base\Component\Input\TextArea;
use Combodo\iTop\Application\UI\Base\Component\Panel\PanelFactory;
require_once('../approot.inc.php');
require_once(APPROOT.'/application/application.inc.php');
@@ -172,20 +174,13 @@ try
$oHiddenParams = new Html($oAppContext->GetForForm());
$oQueryForm->AddSubBlock($oHiddenParams);
//--- Query textarea
$oQueryTitle = new Html('<h2>'.Dict::S('UI:RunQuery:ExpressionToEvaluate').'</h2>');
$oQueryForm->AddSubBlock($oQueryTitle);
$oQueryTextArea = new TextArea(utils::EscapeHtml($sExpression), 'expression', 120, 8);
$oQueryTextArea->SetName('expression');
$oQueryForm->AddSubBlock($oQueryTextArea);
$oQuerySubmit = ButtonFactory::MakeForPrimaryAction(
Dict::S('UI:Button:Evaluate'),
null,
null,
true
);
$oQueryForm->AddSubBlock($oQuerySubmit);
$oP->add_linked_script(utils::GetAbsoluteUrlAppRoot()."/js/jquery.hotkeys.js");
$oP->add_ready_script(<<<EOF
$("#expression").select();
@@ -196,15 +191,31 @@ EOF
);
if (count($aArgs) > 0) {
$oP->add("<div class=\"wizContainer\">\n");
$oP->add("<h2>Query arguments</h2>\n");
//--- Query arguments
$oQueryArgsContainer = PanelFactory::MakeForInformation('Query arguments')
->SetCSSClasses('wizContainer');
$oQueryForm->AddSubBlock($oQueryArgsContainer);
foreach ($aArgs as $sParam => $sValue) {
$oP->p("$sParam: <input type=\"string\" name=\"arg_$sParam\" value=\"$sValue\">\n");
$oArgInput = InputFactory::MakeForInputWithLabel(
$sParam,
'arg_'.$sParam,
$sValue
);
$oQueryArgsContainer->AddSubBlock($oArgInput);
}
$oP->add("</div>\n");
}
$oQuerySubmit = ButtonFactory::MakeForPrimaryAction(
Dict::S('UI:Button:Evaluate'),
null,
null,
true
);
$oQueryForm->AddSubBlock($oQuerySubmit);
if ($oFilter) {
//--- Query filter
$oP->add("<h2>Query results</h2>\n");
$oResultBlock = new DisplayBlock($oFilter, 'list', false);
@@ -230,6 +241,7 @@ EOF
iTopWebPage::ENUM_BREADCRUMB_ENTRY_ICON_TYPE_CSS_CLASSES);
//--- More info
$aMoreInfoBlocks = [];
$oDevelopedQuerySet = new FieldSet(Dict::S('UI:RunQuery:DevelopedQuery'));

View File

@@ -26,6 +26,29 @@ class InputFactory
return $oInput;
}
/**
* @see Field component that is better adapter when dealing with a standard iTop form
*
* @param string $sLabel
* @param string $sInputName
* @param string|null $sInputValue
* @param string|null $sInputId
* @param string $sInputType
*
* @return \Combodo\iTop\Application\UI\Base\Component\Input\InputWithLabel
*/
public static function MakeForInputWithLabel(
string $sLabel, string $sInputName, ?string $sInputValue = null,
?string $sInputId = null, string $sInputType = 'type'
): InputWithLabel
{
$oInput = new Input($sInputId);
$oInput->SetType($sInputType);
$oInput->SetValue($sInputValue);
return static::MakeInputWithLabel($sInputName, $sLabel, $oInput, $sInputId);
}
/**
* If you need to have a real field with a label, you might use a {@link Field} component instead
*
@@ -38,14 +61,19 @@ class InputFactory
public static function MakeForSelectWithLabel(string $sName, string $sLabel, ?string $sId = null): InputWithLabel
{
$oInput = new Select($sId);
return static::MakeInputWithLabel($sName, $sLabel, $oInput, $sId);
}
private static function MakeInputWithLabel(string $sName, string $sLabel, Input $oInput, ?string $sId = null)
{
$oInput->SetName($sName);
if (is_null($sId)) {
$sId = $oInput->GetId();
}
$oInputWithLabel = new InputWithLabel($sLabel, $oInput, $sId);
return $oInputWithLabel;
return new InputWithLabel($sLabel, $oInput, $sId);
}
public static function MakeForSelect(string $sName, ?string $sId = null): Select