mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-18 06:48:50 +02:00
N°8772 - compilation of choices from inputs
This commit is contained in:
@@ -1250,7 +1250,7 @@
|
||||
</node>
|
||||
<node id="order_by" xsi:type="Combodo-Property">
|
||||
<label>UI:DashletGroupBy:Prop-OrderField</label>
|
||||
<value-type xsi:type="Combodo-ValueTypeChoice">
|
||||
<value-type xsi:type="Combodo-ValueTypeChoiceFromInput">
|
||||
<values>
|
||||
<value id="attribute">
|
||||
<label>{{aggregation_attribute.label}}</label>
|
||||
|
||||
@@ -561,6 +561,7 @@ return array(
|
||||
'Combodo\\iTop\\PropertyTree\\ValueType\\AbstractValueType' => $baseDir . '/sources/PropertyTree/ValueType/AbstractValueType.php',
|
||||
'Combodo\\iTop\\PropertyTree\\ValueType\\ValueTypeAggregateFunction' => $baseDir . '/sources/PropertyTree/ValueType/ValueTypeAggregateFunction.php',
|
||||
'Combodo\\iTop\\PropertyTree\\ValueType\\ValueTypeChoice' => $baseDir . '/sources/PropertyTree/ValueType/ValueTypeChoice.php',
|
||||
'Combodo\\iTop\\PropertyTree\\ValueType\\ValueTypeChoiceFromInput' => $baseDir . '/sources/PropertyTree/ValueType/ValueTypeChoiceFromInput.php',
|
||||
'Combodo\\iTop\\PropertyTree\\ValueType\\ValueTypeClass' => $baseDir . '/sources/PropertyTree/ValueType/ValueTypeClass.php',
|
||||
'Combodo\\iTop\\PropertyTree\\ValueType\\ValueTypeClassAttribute' => $baseDir . '/sources/PropertyTree/ValueType/ValueTypeClassAttribute.php',
|
||||
'Combodo\\iTop\\PropertyTree\\ValueType\\ValueTypeClassAttributeGroupBy' => $baseDir . '/sources/PropertyTree/ValueType/ValueTypeClassAttributeGroupBy.php',
|
||||
|
||||
@@ -947,6 +947,7 @@ class ComposerStaticInit7f81b4a2a468a061c306af5e447a9a9f
|
||||
'Combodo\\iTop\\PropertyTree\\ValueType\\AbstractValueType' => __DIR__ . '/../..' . '/sources/PropertyTree/ValueType/AbstractValueType.php',
|
||||
'Combodo\\iTop\\PropertyTree\\ValueType\\ValueTypeAggregateFunction' => __DIR__ . '/../..' . '/sources/PropertyTree/ValueType/ValueTypeAggregateFunction.php',
|
||||
'Combodo\\iTop\\PropertyTree\\ValueType\\ValueTypeChoice' => __DIR__ . '/../..' . '/sources/PropertyTree/ValueType/ValueTypeChoice.php',
|
||||
'Combodo\\iTop\\PropertyTree\\ValueType\\ValueTypeChoiceFromInput' => __DIR__ . '/../..' . '/sources/PropertyTree/ValueType/ValueTypeChoiceFromInput.php',
|
||||
'Combodo\\iTop\\PropertyTree\\ValueType\\ValueTypeClass' => __DIR__ . '/../..' . '/sources/PropertyTree/ValueType/ValueTypeClass.php',
|
||||
'Combodo\\iTop\\PropertyTree\\ValueType\\ValueTypeClassAttribute' => __DIR__ . '/../..' . '/sources/PropertyTree/ValueType/ValueTypeClassAttribute.php',
|
||||
'Combodo\\iTop\\PropertyTree\\ValueType\\ValueTypeClassAttributeGroupBy' => __DIR__ . '/../..' . '/sources/PropertyTree/ValueType/ValueTypeClassAttributeGroupBy.php',
|
||||
|
||||
@@ -64,6 +64,10 @@ class Property extends AbstractProperty
|
||||
$this->GenerateInputs($sInputName, $sValue, $sPrerequisiteExpressions, $sInputs);
|
||||
}
|
||||
|
||||
foreach ($this->oValueType->GetDynamicInputValues() as $sInputName => $sValue) {
|
||||
$this->GenerateInputs($sInputName, $sValue, $sPrerequisiteExpressions, $sInputs, true);
|
||||
}
|
||||
|
||||
$sLabel = utils::QuoteForPHP($this->sLabel);
|
||||
$aOptions = [
|
||||
'label' => $sLabel,
|
||||
@@ -80,10 +84,11 @@ $sOptions\t\t]){$sInputs};
|
||||
PHP;
|
||||
}
|
||||
|
||||
private function GenerateInputs(string $sInputName, string $sValue, string &$sPrerequisiteExpressions, string &$sInputs): void
|
||||
private function GenerateInputs(string $sInputName, string $sValue, string &$sPrerequisiteExpressions, string &$sInputs, bool $bIsDynamic = false): void
|
||||
{
|
||||
if (preg_match('/^{{(?<node>\w+)\.(?<output>\w+)}}$/', $sValue, $aMatches) === 1) {
|
||||
$sInputs .= "\n ->InputDependsOn('$sInputName', '{$aMatches['node']}', '{$aMatches['output']}')";
|
||||
$sVerb = $bIsDynamic ? 'AddInputDependsOn' : 'InputDependsOn';
|
||||
$sInputs .= "\n ->$sVerb('$sInputName', '{$aMatches['node']}', '{$aMatches['output']}')";
|
||||
} elseif (preg_match('/^{{(?<expression>.*)}}$/', $sValue, $aMatches) === 1) {
|
||||
$sExpression = $aMatches['expression'];
|
||||
$sBindings = '';
|
||||
@@ -125,8 +130,8 @@ PHP;
|
||||
|
||||
|
||||
PHP;
|
||||
|
||||
$sInputs .= "\n ->InputDependsOn('$sInputName', '{$this->sId}_{$sInputName}_expression', 'result')";
|
||||
$sVerb = $bIsDynamic ? 'AddInputDependsOn' : 'InputDependsOn';
|
||||
$sInputs .= "\n ->$sVerb('$sInputName', '{$this->sId}_{$sInputName}_expression', 'result')";
|
||||
} else {
|
||||
$sInputs .= "\n ->SetInputValue('$sInputName', ".utils::QuoteForPHP($sValue).")";
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ abstract class AbstractValueType
|
||||
protected array $aInputs = [];
|
||||
protected array $aOutputs = [];
|
||||
protected array $aInputValues = [];
|
||||
protected array $aDynamicInputValues = [];
|
||||
protected array $aFormBlockOptionsForPHP = [];
|
||||
|
||||
public function InitFromDomNode(DesignElement $oDomNode): void
|
||||
@@ -56,6 +57,11 @@ abstract class AbstractValueType
|
||||
return $this->aInputs[$sInputName]->GetDataType();
|
||||
}
|
||||
|
||||
public function GetDynamicInputValues(): array
|
||||
{
|
||||
return $this->aDynamicInputValues;
|
||||
}
|
||||
|
||||
public function GetOutputs(): array
|
||||
{
|
||||
return $this->aOutputs;
|
||||
|
||||
33
sources/PropertyTree/ValueType/ValueTypeChoiceFromInput.php
Normal file
33
sources/PropertyTree/ValueType/ValueTypeChoiceFromInput.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2025 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\PropertyTree\ValueType;
|
||||
|
||||
use Combodo\iTop\DesignElement;
|
||||
use Combodo\iTop\Forms\Block\Base\ChoiceFromInputsBlock;
|
||||
use Combodo\iTop\PropertyTree\ValueType\AbstractValueType;
|
||||
use utils;
|
||||
|
||||
class ValueTypeChoiceFromInput extends AbstractValueType
|
||||
{
|
||||
public function GetFormBlockClass(): string
|
||||
{
|
||||
return ChoiceFromInputsBlock::class;
|
||||
}
|
||||
|
||||
public function InitFromDomNode(DesignElement $oDomNode): void
|
||||
{
|
||||
parent::InitFromDomNode($oDomNode);
|
||||
|
||||
foreach ($oDomNode->GetNodes('values/value') as $oValueNode) {
|
||||
/** @var DesignElement $oValueNode */
|
||||
$sValue = $oValueNode->GetAttribute('id');
|
||||
$sLabel = $oValueNode->GetChildText('label');
|
||||
$this->aDynamicInputValues[$sValue] = $sLabel;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -104,6 +104,7 @@ class_alias(\Combodo\iTop\PropertyTree\CollectionOfTrees::class, 'Combodo-Collec
|
||||
|
||||
class_alias(\Combodo\iTop\PropertyTree\ValueType\ValueTypeAggregateFunction::class, 'Combodo-ValueTypeAggregateFunction');
|
||||
class_alias(\Combodo\iTop\PropertyTree\ValueType\ValueTypeChoice::class, 'Combodo-ValueTypeChoice');
|
||||
class_alias(\Combodo\iTop\PropertyTree\ValueType\ValueTypeChoiceFromInput::class, 'Combodo-ValueTypeChoiceFromInput');
|
||||
class_alias(\Combodo\iTop\PropertyTree\ValueType\ValueTypeClass::class, 'Combodo-ValueTypeClass');
|
||||
class_alias(\Combodo\iTop\PropertyTree\ValueType\ValueTypeClassAttribute::class, 'Combodo-ValueTypeClassAttribute');
|
||||
class_alias(\Combodo\iTop\PropertyTree\ValueType\ValueTypeClassAttributeGroupBy::class, 'Combodo-ValueTypeClassAttributeGroupBy');
|
||||
|
||||
@@ -5,8 +5,10 @@
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
use Combodo\iTop\Forms\Block\Base\ChoiceFromInputsBlock;
|
||||
use Combodo\iTop\Forms\Compiler\FormsCompiler;
|
||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
use Symfony\Component\Validator\Constraints\NotNull;
|
||||
|
||||
class FormsCompilerTest extends ItopDataTestCase
|
||||
{
|
||||
@@ -166,6 +168,19 @@ PHP,
|
||||
<value-type xsi:type="Combodo-ValueTypeString">
|
||||
</value-type>
|
||||
</node>
|
||||
<node id="choice_from_input" xsi:type="Combodo-Property">
|
||||
<label>UI:ChoiceFromInput</label>
|
||||
<value-type xsi:type="Combodo-ValueTypeChoiceFromInput">
|
||||
<values>
|
||||
<value id="value_a">
|
||||
<label>{{class_attribute_property.label}}</label>
|
||||
</value>
|
||||
<value id="value_b">
|
||||
<label>{{class_attribute_group_by_property.label}}</label>
|
||||
</value>
|
||||
</values>
|
||||
</value-type>
|
||||
</node>
|
||||
</nodes>
|
||||
</node>
|
||||
XML,
|
||||
@@ -217,6 +232,12 @@ class FormFor__AllValueTypesTest extends Combodo\iTop\Forms\Block\Base\FormBlock
|
||||
\$this->Add('string_property', 'Combodo\iTop\Forms\Block\Base\TextFormBlock', [
|
||||
'label' => 'UI:String',
|
||||
]);
|
||||
|
||||
\$this->Add('choice_from_input', 'Combodo\iTop\Forms\Block\Base\ChoiceFromInputsBlock', [
|
||||
'label' => 'UI:ChoiceFromInput',
|
||||
])
|
||||
->AddInputDependsOn('value_a', 'class_attribute_property', 'label')
|
||||
->AddInputDependsOn('value_b', 'class_attribute_group_by_property', 'label');
|
||||
}
|
||||
}
|
||||
PHP,
|
||||
|
||||
Reference in New Issue
Block a user