From a7619f2820f33dc850e3d78553a3f401b0635a67 Mon Sep 17 00:00:00 2001 From: Molkobain Date: Mon, 27 Jan 2020 16:58:13 +0100 Subject: [PATCH] =?UTF-8?q?N=C2=B02313=20-=20Markup=20extensibility:=20Add?= =?UTF-8?q?=20metadata=20on=20admin.=20console=20object=20lists?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/cmdbabstract.class.inc.php | 4 +- application/datatable.class.inc.php | 70 +++++++++++++++++++++++--- application/webpage.class.inc.php | 28 ++++++++++- 3 files changed, 92 insertions(+), 10 deletions(-) diff --git a/application/cmdbabstract.class.inc.php b/application/cmdbabstract.class.inc.php index b8a7dfebd..ddfe4a816 100644 --- a/application/cmdbabstract.class.inc.php +++ b/application/cmdbabstract.class.inc.php @@ -5126,8 +5126,10 @@ EOF * * @return array * @since 2.7.0 + * + * @internal Do NOT use, this is experimental and most likely to be moved elsewhere when we find its rightful place. */ - protected static function GetAttDefClassesToExcludeFromMarkupMetadataRawValue(){ + public static function GetAttDefClassesToExcludeFromMarkupMetadataRawValue(){ return array( 'AttributeBlob', 'AttributeCustomFields', diff --git a/application/datatable.class.inc.php b/application/datatable.class.inc.php index 7f5bbfcdb..b37cf8deb 100644 --- a/application/datatable.class.inc.php +++ b/application/datatable.class.inc.php @@ -456,11 +456,15 @@ EOF; $aAttribs = array(); if ($sSelectMode == 'multiple') { - $aAttribs['form::select'] = array('label' => "iListId}:not(:disabled)', this.checked);\" class=\"checkAll\">", 'description' => Dict::S('UI:SelectAllToggle+')); + $aAttribs['form::select'] = array( + 'label' => "iListId}:not(:disabled)', this.checked);\" class=\"checkAll\">", + 'description' => Dict::S('UI:SelectAllToggle+'), + 'metadata' => array(), + ); } else if ($sSelectMode == 'single') { - $aAttribs['form::select'] = array('label' => "", 'description' => ''); + $aAttribs['form::select'] = array('label' => '', 'description' => '', 'metadata' => array()); } foreach($this->aClassAliases as $sAlias => $sClassName) @@ -471,12 +475,33 @@ EOF; { if ($sAttCode == '_key_') { - $aAttribs['key_'.$sAlias] = array('label' => MetaModel::GetName($sClassName), 'description' => ''); + $sAttLabel = MetaModel::GetName($sClassName); + + $aAttribs['key_'.$sAlias] = array( + 'label' => $sAttLabel, + 'description' => '', + 'metadata' => array( + 'object_class' => $sClassName, + 'attribute_label' => $sAttLabel, + ), + ); } else { $oAttDef = MetaModel::GetAttributeDef($sClassName, $sAttCode); - $aAttribs[$sAttCode.'_'.$sAlias] = array('label' => MetaModel::GetLabel($sClassName, $sAttCode), 'description' => $oAttDef->GetOrderByHint()); + $sAttDefClass = get_class($oAttDef); + $sAttLabel = MetaModel::GetLabel($sClassName, $sAttCode); + + $aAttribs[$sAttCode.'_'.$sAlias] = array( + 'label' => $sAttLabel, + 'description' => $oAttDef->GetOrderByHint(), + 'metadata' => array( + 'object_class' => $sClassName, + 'attribute_code' => $sAttCode, + 'attribute_type' => $sAttDefClass, + 'attribute_label' => $sAttLabel, + ), + ); } } } @@ -507,6 +532,7 @@ EOF; } $aValues = array(); + $aAttDefsCache = array(); $this->oSet->Seek(0); $iMaxObjects = $iPageSize; while (($aObjects = $this->oSet->FetchAssoc()) && ($iMaxObjects != 0)) @@ -547,11 +573,41 @@ EOF; { if ($sAttCode == '_key_') { - $aRow['key_'.$sAlias] = $aObjects[$sAlias]->GetHyperLink(); + $aRow['key_'.$sAlias] = array( + 'value_raw' => $aObjects[$sAlias]->GetKey(), + 'value_html' => $aObjects[$sAlias]->GetHyperLink(), + ); } else { - $aRow[$sAttCode.'_'.$sAlias] = $aObjects[$sAlias]->GetAsHTML($sAttCode, $bLocalize); + // Prepare att. def. classes cache to avoid retrieving AttDef for each row + if(!isset($aAttDefsCache[$sClassName][$sAttCode])) + { + $aAttDefClassesCache[$sClassName][$sAttCode] = get_class(MetaModel::GetAttributeDef($sClassName, $sAttCode)); + } + + // Only retrieve raw (stored) value for simple fields + $bExcludeRawValue = false; + foreach (cmdbAbstractObject::GetAttDefClassesToExcludeFromMarkupMetadataRawValue() as $sAttDefClassToExclude) + { + if (is_a($aAttDefClassesCache[$sClassName][$sAttCode], $sAttDefClassToExclude, true)) + { + $bExcludeRawValue = true; + break; + } + } + + if($bExcludeRawValue) + { + $aRow[$sAttCode.'_'.$sAlias] = $aObjects[$sAlias]->GetAsHTML($sAttCode, $bLocalize); + } + else + { + $aRow[$sAttCode.'_'.$sAlias] = array( + 'value_raw' => $aObjects[$sAlias]->Get($sAttCode), + 'value_html' => $aObjects[$sAlias]->GetAsHTML($sAttCode, $bLocalize), + ); + } } } } @@ -609,7 +665,7 @@ EOF; $aValues = $this->GetHTMLTableValues($aColumns, $sSelectMode, $iPageSize, $bViewLink, $aExtraParams); - $sHtml = ''; + $sHtml = '
'; foreach($this->oSet->GetFilter()->GetInternalParams() as $sName => $sValue) { diff --git a/application/webpage.class.inc.php b/application/webpage.class.inc.php index 324a1bdaa..c99659448 100644 --- a/application/webpage.class.inc.php +++ b/application/webpage.class.inc.php @@ -296,8 +296,32 @@ class WebPage implements Page foreach ($aConfig as $sName => $aAttribs) { $sClass = isset($aAttribs['class']) ? 'class="'.$aAttribs['class'].'"' : ''; - $sValue = ($aRow[$sName] === '') ? ' ' : $aRow[$sName]; - $sHtml .= ""; + + // Prepare metadata + // - From table config. + $sMetadata = ''; + if(isset($aAttribs['metadata'])) + { + foreach($aAttribs['metadata'] as $sMetadataProp => $sMetadataValue) + { + $sMetadataPropSanitized = str_replace('_', '-', $sMetadataProp); + $sMetadataValueSanitized = utils::HtmlEntities($sMetadataValue); + $sMetadata .= 'data-'.$sMetadataPropSanitized.'="'.$sMetadataValueSanitized.'" '; + } + } + + // Prepare value + if(is_array($aRow[$sName])) + { + $sValueHtml = ($aRow[$sName]['value_html'] === '') ? ' ' : $aRow[$sName]['value_html']; + $sMetadata .= 'data-value-raw="'.utils::HtmlEntities($aRow[$sName]['value_raw']).'" '; + } + else + { + $sValueHtml = ($aRow[$sName] === '') ? ' ' : $aRow[$sName]; + } + + $sHtml .= ""; } $sHtml .= "";
$sValue$sValueHtml