N°2657 - MTP : Progress Bar has disappeared (support any code length)

This commit is contained in:
Eric
2020-01-29 17:44:47 +01:00
parent aa3e284af3
commit 7f9e4385ac
5 changed files with 57 additions and 26 deletions

View File

@@ -9705,21 +9705,6 @@ abstract class AttributeSet extends AttributeDBFieldVoid
return array_merge(parent::ListExpectedParams(), array('is_null_allowed', 'max_items'));
}
/**
* Allowed values are mandatory for this attribute to be modified
*
* @param array $aArgs
* @param string $sContains
*
* @return array|null
* @throws \CoreException
* @throws \OQLException
*/
public function GetAllowedValues($aArgs = array(), $sContains = '')
{
return parent::GetAllowedValues($aArgs, $sContains);
}
/**
* Allowed different values for the set values are mandatory for this attribute to be modified
*
@@ -10142,8 +10127,27 @@ class AttributeEnumSet extends AttributeSet
return array_merge(parent::ListExpectedParams(), array('possible_values', 'is_null_allowed', 'max_items'));
}
public function GetMaxSize()
{
$aRawValues = $this->GetRawPossibleValues();
$iMaxItems = $this->GetMaxItems();
$aLengths = array();
foreach (array_keys($aRawValues) as $sKey)
{
$aLengths[] = strlen($sKey);
}
rsort($aLengths, SORT_NUMERIC);
$iMaxSize = 2;
for ($i = 0; $i < min($iMaxItems, count($aLengths)); $i++)
{
$iMaxSize += $aLengths[$i] + 1;
}
return max(255, $iMaxSize);
}
private function GetRawPossibleValues($aArgs = array(), $sContains = '')
{
/** @var ValueSetEnumPadded $oValSetDef */
$oValSetDef = $this->Get('possible_values');
if (!$oValSetDef)
{
@@ -10184,9 +10188,14 @@ class AttributeEnumSet extends AttributeSet
$sLabel = $this->SearchLabel('/Attribute:'.$this->m_sCode.'/Value:'.$sValue, null, true /*user lang*/);
if (is_null($sLabel))
{
$sDefault = str_replace('_', ' ', $sValue);
// Browse the hierarchy again, accepting default (english) translations
$sLabel = $this->SearchLabel('/Attribute:'.$this->m_sCode.'/Value:'.$sValue, $sDefault, false);
$sLabel = $this->SearchLabel('/Attribute:'.$this->m_sCode.'/Value:'.$sValue, null, false);
if (is_null($sLabel))
{
$sDefault = trim(str_replace('_', ' ', $sValue));
// Browse the hierarchy again, accepting default (english) translations
$sLabel = $this->SearchLabel('/Attribute:'.$this->m_sCode.'/Value:'.$sDefault, $sDefault, false);
}
}
}

View File

@@ -111,7 +111,7 @@ class ormSet
/**
*
* @param array $aItems
* @param string[] $aItems
*
* @throws \CoreException
* @throws \CoreUnexpectedValue when a code is invalid
@@ -126,7 +126,7 @@ class ormSet
$aValues = array();
$iCount = 0;
$bError = false;
foreach($aItems as $oItem)
foreach($aItems as $sItem)
{
$iCount++;
if (($this->iLimit != 0) && ($iCount > $this->iLimit))
@@ -134,7 +134,7 @@ class ormSet
$bError = true;
continue;
}
$aValues[] = $oItem;
$aValues[] = $sItem;
}
$this->aPreserved = &$aValues;

View File

@@ -57,7 +57,7 @@ abstract class Trigger extends cmdbAbstractObject
MetaModel::Init_AddAttribute(new AttributeString("description", array("allowed_values" => null, "sql" => "description", "default_value" => null, "is_null_allowed" => false, "depends_on" => array())));
MetaModel::Init_AddAttribute(new AttributeLinkedSetIndirect("action_list", array("linked_class" => "lnkTriggerAction", "ext_key_to_me" => "trigger_id", "ext_key_to_remote" => "action_id", "allowed_values" => null, "count_min" => 1, "count_max" => 0, "depends_on" => array())));
$aTags = ContextTag::GetTags();
MetaModel::Init_AddAttribute( new AttributeEnumSet("context", array("allowed_values" => null, "possible_values" => new ValueSetEnum($aTags), "sql" => "context", "depends_on" => array(), "is_null_allowed" => true, "max_items" => 12)));
MetaModel::Init_AddAttribute( new AttributeEnumSet("context", array("allowed_values" => null, "possible_values" => new ValueSetEnumPadded($aTags), "sql" => "context", "depends_on" => array(), "is_null_allowed" => true, "max_items" => 12)));
// Display lists
MetaModel::Init_SetZListItems('details', array('finalclass', 'description', 'context', 'action_list')); // Attributes to be displayed for the complete details

View File

@@ -350,10 +350,10 @@ class ValueSetEnum extends ValueSetDefinition
$this->m_values = $Values;
}
// Helper to export the datat model
// Helper to export the data model
public function GetValueList()
{
$this->LoadValues($aArgs = array());
$this->LoadValues(null);
return $this->m_aValues;
}
@@ -382,6 +382,29 @@ class ValueSetEnum extends ValueSetDefinition
}
}
class ValueSetEnumPadded extends ValueSetEnum
{
public function __construct($Values)
{
parent::__construct($Values);
if (is_string($Values))
{
$this->LoadValues(null);
}
else
{
$this->m_aValues = $Values;
}
$aPaddedValues = array();
foreach ($this->m_aValues as $sKey => $sVal)
{
$sKey = str_pad($sKey, 3, '_', STR_PAD_LEFT);
$aPaddedValues[$sKey] = $sKey;
}
$this->m_values = $aPaddedValues;
}
}
/**
* Fixed set values, defined as a range: 0..59 (with an optional increment)
*

View File

@@ -1537,12 +1537,11 @@ EOF
$aValues = array();
foreach($oValueNodes as $oValue)
{
// new style... $aValues[] = self::QuoteForPHP($oValue->textContent);
$aValues[] = $oValue->textContent;
}
// new style... $sValues = 'array('.implode(', ', $aValues).')';
$sValues = '"'.implode(',', $aValues).'"';
$aParameters['allowed_values'] = "new ValueSetEnum($sValues)";
$aParameters['allowed_values'] = 'null';
$aParameters['possible_values'] = "new ValueSetEnumPadded($sValues)";
$aParameters['sql'] = $this->GetMandatoryPropString($oField, 'sql');
$aParameters['is_null_allowed'] = $this->GetPropBoolean($oField, 'is_null_allowed', false);
$aParameters['depends_on'] = $sDependencies;