From aed71a63358b5dd3a7f1acdd1baf783e86768296 Mon Sep 17 00:00:00 2001 From: Anne-Catherine <57360138+accognet@users.noreply.github.com> Date: Wed, 24 Jul 2024 17:20:13 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B07146=20-=20Fix=20style=20not=20applied?= =?UTF-8?q?=20in=20list=20in=20the=20end-users=20portal=20in=20iTop=203.0+?= =?UTF-8?q?=20(#635)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * N°7146 - Fix style not applied in list in the end-users portal in iTop 3.0+ - Add Markup in search list in order to use style * N°7146 - Fix style not applied in list in the end-users portal in iTop 3.0+ * WIP * Fix link on external Key * Add new markup * Update datamodels/2.x/itop-portal-base/portal/src/Controller/ObjectController.php Co-authored-by: Thomas Casteleyn --------- Co-authored-by: Thomas Casteleyn --- .../src/Controller/ObjectController.php | 39 +++++++--- .../object/mode_search_regular.html.twig | 28 +++++-- .../BsLinkedSetFieldRenderer.php | 74 ++++++++++++++----- 3 files changed, 105 insertions(+), 36 deletions(-) diff --git a/datamodels/2.x/itop-portal-base/portal/src/Controller/ObjectController.php b/datamodels/2.x/itop-portal-base/portal/src/Controller/ObjectController.php index 88f5f6dcd..9dd64cfbb 100644 --- a/datamodels/2.x/itop-portal-base/portal/src/Controller/ObjectController.php +++ b/datamodels/2.x/itop-portal-base/portal/src/Controller/ObjectController.php @@ -1408,14 +1408,14 @@ class ObjectController extends BrickController protected function PrepareObjectInformation(DBObject $oObject, $aAttCodes = array()) { $sObjectClass = get_class($oObject); - $aObjectData = array( + $aObjectData = [ 'id' => $oObject->GetKey(), 'name' => $oObject->GetName(), - 'attributes' => array(), - ); + 'attributes' => [], + ]; // Retrieving attributes definitions - $aAttDefs = array(); + $aAttDefs = []; foreach ($aAttCodes as $sAttCode) { if ($sAttCode === 'id') @@ -1429,13 +1429,30 @@ class ObjectController extends BrickController // Preparing attribute data foreach ($aAttDefs as $oAttDef) { - $aAttData = array( - 'att_code' => $oAttDef->GetCode(), - ); + $aAttData = [ + 'object_class' => $sObjectClass, + 'object_id' => $oObject->GetKey(), + 'attribute_code' => $oAttDef->GetCode(), + 'attribute_type' => get_class($oAttDef), + ]; + + // - Value raw + // For simple fields, we get the raw (stored) value as well + $bExcludeRawValue = false; + foreach (ApplicationHelper::GetAttDefClassesToExcludeFromMarkupMetadataRawValue() as $sAttDefClassToExclude) + { + if (is_a($oAttDef, $sAttDefClassToExclude, true)) + { + $bExcludeRawValue = true; + break; + } + } + $aAttData['value_raw'] = ($bExcludeRawValue === false) ? $oObject->Get($oAttDef->GetCode()) : null; + if ($oAttDef->IsExternalKey()) { - $aAttData['value'] = $oObject->GetAsHTML($oAttDef->GetCode().'_friendlyname'); + $aAttData['value_html'] = $oObject->GetAsHTML($oAttDef->GetCode().'_friendlyname'); // Checking if user can access object's external key if ($this->oSecurityHelper->IsActionAllowed(UR_ACTION_READ, $oAttDef->GetTargetClass())) @@ -1467,14 +1484,14 @@ class ObjectController extends BrickController { $sUrl = $oAttDef->Get('default_image'); } - $aAttData['value'] = ''; + $aAttData['value_html'] = ''; } elseif ($oAttDef instanceof AttributeEnum) { - $aAttData['value'] = $oAttDef->GetAsPlainText($oObject->Get($oAttDef->GetCode())); + $aAttData['value_html'] = $oAttDef->GetAsPlainText($oObject->Get($oAttDef->GetCode())); } else { - $aAttData['value'] = $oAttDef->GetAsHTML($oObject->Get($oAttDef->GetCode())); + $aAttData['value_html'] = $oAttDef->GetAsHTML($oObject->Get($oAttDef->GetCode())); if ($oAttDef instanceof AttributeFriendlyName) { diff --git a/datamodels/2.x/itop-portal-base/portal/templates/bricks/object/mode_search_regular.html.twig b/datamodels/2.x/itop-portal-base/portal/templates/bricks/object/mode_search_regular.html.twig index b0dda5793..f42884158 100644 --- a/datamodels/2.x/itop-portal-base/portal/templates/bricks/object/mode_search_regular.html.twig +++ b/datamodels/2.x/itop-portal-base/portal/templates/bricks/object/mode_search_regular.html.twig @@ -9,7 +9,7 @@
{#
#}
- +
@@ -66,22 +66,35 @@ "title": oColumnProperties[sKey].title, "defaultContent": "", "type": "html", - "data": "attributes."+sKey+".att_code", - "render": function(data, type, row){ + "data": "attributes."+sKey+".attribute_code", + "render": function(attribute_code, type, row){ var cellElem; + var metadataNames = ['object_class', 'object_id', 'attribute_code', 'attribute_type', 'value_raw']; // Preparing the cell data - if(row.attributes[data].url !== undefined) + if(row.attributes[attribute_code].url !== undefined) { cellElem = $(''); - cellElem.attr('target', '_blank').attr('href', row.attributes[data].url); + cellElem.attr('target', '_blank').attr('href', row.attributes[attribute_code].url); } else { cellElem = $(''); } - cellElem.attr('data-object-id', row.id).html('' + row.attributes[data].value + ''); - + //Add markup + for(var sPropName in row.attributes[attribute_code]) + { + var propValue = row.attributes[attribute_code][sPropName]; + if(sPropName === 'value_html') + { + cellElem.html(propValue); + } + else if(metadataNames.indexOf(sPropName) > -1) + { + cellElem.attr('data-'+sPropName.replace('_', '-'), propValue) + } + } + return cellElem.prop('outerHTML'); }, }); @@ -92,7 +105,6 @@ $(document).ready(function(){ showTableLoader(); - // Note : Those options should be externalized in an library so we can use them on any DataTables for the portal. // We would just have to override / complete the necessary elements oTable = $('#{{ sTableId }}').DataTable({ diff --git a/sources/Renderer/Bootstrap/FieldRenderer/BsLinkedSetFieldRenderer.php b/sources/Renderer/Bootstrap/FieldRenderer/BsLinkedSetFieldRenderer.php index b91bc8f5c..df9cf6b5d 100644 --- a/sources/Renderer/Bootstrap/FieldRenderer/BsLinkedSetFieldRenderer.php +++ b/sources/Renderer/Bootstrap/FieldRenderer/BsLinkedSetFieldRenderer.php @@ -24,6 +24,7 @@ use ApplicationContext; use AttributeFriendlyName; use Combodo\iTop\Form\Field\DateTimeField; use Combodo\iTop\Form\Field\Field; +use Combodo\iTop\Portal\Helper\ApplicationHelper; use Combodo\iTop\Renderer\Bootstrap\BsFieldRendererMappings; use Combodo\iTop\Renderer\FieldRenderer; use Combodo\iTop\Renderer\RenderingOutput; @@ -192,7 +193,7 @@ EOF "render": function(data, type, row) { var oCheckboxElem = $('{$sSelectionInputHtml}'); - if(row.limited_access) + if(row.limited_access) { oCheckboxElem.html('-'); } @@ -221,7 +222,8 @@ EOF "className": {$sIsEditable} && aColumnProperties.mandatory ? 'mandatory' : '', "render": function(data, type, row){ var cellElem; - + var metadataNames = ['object_class', 'object_id', 'attribute_code', 'attribute_type', 'value_raw']; + // Preparing the cell data if(data.url !== undefined) { @@ -232,8 +234,19 @@ EOF { cellElem = $(''); } - cellElem.html('' + data.value + ''); - + for(var sPropName in row.attributes[data.prefix+data.attribute_code]) + { + var propValue = row.attributes[data.prefix+data.attribute_code][sPropName]; + if(sPropName === 'value_html') + { + cellElem.html(propValue); + } + else if(metadataNames.indexOf(sPropName) > -1) + { + cellElem.attr('data-'+sPropName.replace('_', '-'), propValue) + } + } + return cellElem.prop('outerHTML'); }, }); @@ -242,7 +255,6 @@ EOF for(sKey in oColumnProperties_{$this->oField->GetGlobalId()}) { aColumnProperties = oColumnProperties_{$this->oField->GetGlobalId()}[sKey]; - // Level main column aColumnsDefinition.push({ "width": "auto", @@ -254,7 +266,8 @@ EOF "data": "attributes." + sKey, "className": aColumnProperties.mandatory ? 'mandatory' : '', "render": function(data, type, row){ - var cellElem; + var cellElem; + var metadataNames = ['object_class', 'object_id', 'attribute_code', 'attribute_type', 'value_raw']; // Preparing the cell data if(data.url !== undefined) @@ -266,7 +279,19 @@ EOF { cellElem = $(''); } - cellElem.html('' + data.value + ''); + + for(var sPropName in row.attributes[data.attribute_code]) + { + var propValue = row.attributes[data.attribute_code][sPropName]; + if(sPropName === 'value_html') + { + cellElem.html(propValue); + } + else if(metadataNames.indexOf(sPropName) > -1) + { + cellElem.attr('data-'+sPropName.replace('_', '-'), propValue) + } + } return cellElem.prop('outerHTML'); }, @@ -799,7 +824,6 @@ JS static::TransferFieldRendererGlobalOutput($oFieldOutput, $oOutput); } } - } /** @@ -821,14 +845,30 @@ JS if ($sAttCode !== 'id') { - // Prepare attribute properties - $aAttProperties = array( - 'att_code' => $sAttCode, - ); - // Retrieve attribute definition $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode); + // Prepare attribute properties + $aAttProperties = [ + 'prefix'=> $sAttribueKeyPrefix, + 'object_class' => $sClass, + 'object_id' => $oItem->GetKey(), + 'attribute_code' => $sAttCode, + 'attribute_type' => get_class($oAttDef), + ]; + // - Value raw + // For simple fields, we get the raw (stored) value as well + $bExcludeRawValue = false; + foreach (ApplicationHelper::GetAttDefClassesToExcludeFromMarkupMetadataRawValue() as $sAttDefClassToExclude) + { + if (is_a($oAttDef, $sAttDefClassToExclude, true)) + { + $bExcludeRawValue = true; + break; + } + } + $aAttProperties['value_raw'] = ($bExcludeRawValue === false) ? $oItem->Get($sAttCode) : null; + // External key specific if ($bIsEditable) { @@ -847,23 +887,23 @@ JS $oFieldOutput = $oFieldRenderer->Render(); $aAttProperties['js_inline'] = $oFieldOutput->GetJs(); $aAttProperties['css_inline'] = $oFieldOutput->GetCss(); - $aAttProperties['value'] = $oFieldOutput->GetHtml(); + $aAttProperties['value_html'] = $oFieldOutput->GetHtml(); } } else if ($oAttDef->IsExternalKey()) { /** @var \AttributeExternalKey $oAttDef */ - $aAttProperties['value'] = $oItem->Get($sAttCode.'_friendlyname'); + $aAttProperties['value_html'] = $oItem->Get($sAttCode.'_friendlyname'); // Checking if user can access object's external key - $sObjectUrl = ApplicationContext::MakeObjectUrl($sClass, $oItem->Get($sAttCode)); + $sObjectUrl = ApplicationContext::MakeObjectUrl($oAttDef->GetTargetClass(), $oItem->Get($sAttCode)); if (!empty($sObjectUrl)) { $aAttProperties['url'] = $sObjectUrl; } } else { // Others attributes - $aAttProperties['value'] = $oAttDef->GetAsHTML($oItem->Get($sAttCode)); + $aAttProperties['value_html'] = $oAttDef->GetAsHTML($oItem->Get($sAttCode)); if ($oAttDef instanceof AttributeFriendlyName) { // Checking if user can access object