N°2677 - Add style definition for enums (refactor & fix CI)

This commit is contained in:
Eric
2020-12-31 16:34:59 +01:00
parent 640b6a7288
commit d77f374918
3 changed files with 39 additions and 28 deletions

View File

@@ -863,7 +863,7 @@ EOF
if ($oAttDef->IsWritable()) {
if (($sStateAttCode === $sAttCode) && (MetaModel::HasLifecycle($sClass))) {
// State attribute is always read-only from the UI
$sHTMLValue = $this->GetStateLabel();
$sHTMLValue = $this->GetAsHTML($sAttCode);
$val = array(
'label' => '<label>'.$oAttDef->GetLabel().'</label>',
'value' => $sHTMLValue,
@@ -3227,28 +3227,20 @@ HTML;
// Then prepare the value
// - The field is visible in the current state of the object
if ($oAttDef->GetEditClass() == 'Document')
{
if ($oAttDef->GetEditClass() == 'Document') {
$oDocument = $this->Get($sAttCode);
if (!$oDocument->IsEmpty())
{
if (!$oDocument->IsEmpty()) {
$sDisplayValue = $this->GetAsHTML($sAttCode);
$sDisplayValue .= "<br/>".Dict::Format('UI:OpenDocumentInNewWindow_',
$oDocument->GetDisplayLink(get_class($this), $this->GetKey(), $sAttCode)).", \n";
$sDisplayValue .= "<br/>".Dict::Format('UI:DownloadDocument_',
$oDocument->GetDownloadLink(get_class($this), $this->GetKey(), $sAttCode)).", \n";
} else {
$sDisplayValue = '';
}
else
{
$sDisplayValue ='';
}
}
elseif ($oAttDef instanceof AttributeDashboard)
{
} elseif ($oAttDef instanceof AttributeDashboard) {
$sDisplayValue = '';
}
else
{
} else {
$sDisplayValue = $this->GetAsHTML($sAttCode);
}
$sValueAsHtml = $sDisplayValue;

View File

@@ -1582,7 +1582,8 @@ abstract class DBObject implements iDisplay
}
/**
* Get the label of the current state
* Get the label (raw text) of the current state
* helper for MetaModel::GetStateLabel()
*
* @api
*

View File

@@ -786,16 +786,21 @@ EOF
/**
* @param $oNode
* @param $sTag
* @param bool $bAddQuotes
*
* @return string
* @throws \DOMFormatException
*/
protected function GetMandatoryPropString($oNode, $sTag)
protected function GetMandatoryPropString($oNode, $sTag, $bAddQuotes = true)
{
$val = $oNode->GetChildText($sTag);
if (!is_null($val) && ($val !== ''))
{
return "'".$val."'";
if ($bAddQuotes) {
return "'".$val."'";
} else {
return $val;
}
}
else
{
@@ -1343,13 +1348,15 @@ EOF
foreach($oValueNodes as $oValue)
{
// New in 3.0 the format of values changed
$sCode = $this->GetMandatoryPropString($oValue, 'enum_code');
$oStyleNode = $oValue->getElementsByTagName('style')->item(0);
$sMainColor = $this->GetMandatoryPropString($oStyleNode, 'main_color');
$sComplementaryColor = $this->GetMandatoryPropString($oStyleNode, 'complementary_color');
$sDecorationClasses = $this->GetPropString($oStyleNode, 'decoration_classes', '');
$aValues[] = self::RemoveSurroundingQuotes($sCode);
$aStyledValues[] = "$sCode => new ormStyle($sMainColor, $sComplementaryColor, $sDecorationClasses)";
$sCode = $this->GetMandatoryPropString($oValue, 'enum_code', false);
$aValues[] = $sCode;
$oStyleNode = $oValue->GetOptionalElement('style');
if ($oStyleNode) {
$sMainColor = $this->GetMandatoryPropString($oStyleNode, 'main_color');
$sComplementaryColor = $this->GetMandatoryPropString($oStyleNode, 'complementary_color');
$sDecorationClasses = $this->GetPropString($oStyleNode, 'decoration_classes', '');
$aStyledValues[] = "'$sCode' => new ormStyle($sMainColor, $sComplementaryColor, $sDecorationClasses)";
}
}
$sValues = '"'.implode(',', $aValues).'"';
$aParameters['allowed_values'] = "new ValueSetEnum($sValues)";
@@ -1365,14 +1372,25 @@ EOF
{
$oValues = $oField->GetUniqueElement('values');
$oValueNodes = $oValues->getElementsByTagName('value');
$aValues = array();
$aValues = [];
$aStyledValues = [];
foreach($oValueNodes as $oValue)
{
// new style... $aValues[] = self::QuoteForPHP($oValue->textContent);
$aValues[] = $oValue->textContent;
// New in 3.0 the format of values changed
$sCode = $this->GetMandatoryPropString($oValue, 'enum_code', false);
$aValues[] = $sCode;
$oStyleNode = $oValue->GetOptionalElement('style');
if ($oStyleNode) {
$sMainColor = $this->GetMandatoryPropString($oStyleNode, 'main_color');
$sComplementaryColor = $this->GetMandatoryPropString($oStyleNode, 'complementary_color');
$sDecorationClasses = $this->GetPropString($oStyleNode, 'decoration_classes', '');
$aStyledValues[] = "'$sCode' => new ormStyle($sMainColor, $sComplementaryColor, $sDecorationClasses)";
}
}
// new style... $sValues = 'array('.implode(', ', $aValues).')';
$sValues = '"'.implode(',', $aValues).'"';
$sStyledValues = "[".implode(',', $aStyledValues)."]";
$aParameters['styled_values'] = "$sStyledValues";
$aParameters['allowed_values'] = "new ValueSetEnum($sValues)";
$aParameters['sql'] = $this->GetMandatoryPropString($oField, 'sql');
$aParameters['default_value'] = $this->GetPropString($oField, 'default_value', '');