From 9bc2cd0a3847e47a79bde401f59f26d45d0da36b Mon Sep 17 00:00:00 2001 From: Timmy38 Date: Tue, 12 May 2026 12:01:41 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B09167=20Use=20ExtensionDetails=20UIBlocks?= =?UTF-8?q?=20instead=20of=20table?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../layout/extension/_extension-details.scss | 13 ++++++- .../templates/AnalysisResult.html.twig | 19 +++++++--- .../templates/Features.html.twig | 18 ++++++++-- setup/extensionsmap.class.inc.php | 18 +--------- .../DryRemovalRuntimeEnvironment.php | 6 ++-- setup/itopextension.class.inc.php | 13 +++++++ .../Layout/Extension/ExtensionDetails.php | 36 +++++++++++-------- .../ExtensionDetailsUIBlockFactory.php | 30 ++++++++++++++-- .../components/input/input-toggler.html.twig | 3 +- .../input/input-toggler.ready.js.twig | 2 ++ .../Backoffice/RenderAllUiBlocks.php | 3 ++ 11 files changed, 115 insertions(+), 46 deletions(-) diff --git a/css/backoffice/layout/extension/_extension-details.scss b/css/backoffice/layout/extension/_extension-details.scss index 0c39e8ba6b..3fd5e51c92 100644 --- a/css/backoffice/layout/extension/_extension-details.scss +++ b/css/backoffice/layout/extension/_extension-details.scss @@ -62,4 +62,15 @@ $ibo-extension-details--actions--button--padding-x: $ibo-button--padding-x !defa .ibo-extension-details--actions:has(.toggler-install:not(:disabled)) .ibo-popover-menu--section a[data-resource-id="force_uninstall"] { display: none; -} \ No newline at end of file +} + +.ibo-extension-details .ibo-popover-menu ~ .ibo-button{ + visibility: hidden; +} +.ibo-extension-details .ibo-popover-menu:has(.ibo-popover-menu--item) ~ .ibo-button{ + visibility: visible; +} + +.ibo-extension-details .ibo-toggler--wrapper:has(.ibo-toggler.ibo-is-hidden){ + visibility: hidden; +} diff --git a/datamodels/2.x/combodo-data-feature-removal/templates/AnalysisResult.html.twig b/datamodels/2.x/combodo-data-feature-removal/templates/AnalysisResult.html.twig index e585003983..2ce1f409f1 100644 --- a/datamodels/2.x/combodo-data-feature-removal/templates/AnalysisResult.html.twig +++ b/datamodels/2.x/combodo-data-feature-removal/templates/AnalysisResult.html.twig @@ -4,10 +4,21 @@ {% UIPanel ForInformation { sTitle:'DataFeatureRemoval:Analysis:Title'|dict_s} %} - - {% UIFieldSet Standard {sLegend:'DataFeatureRemoval:Features:Title'|dict_s} %} - {% UIDataTable ForForm { sRef:'aExtensions', aColumns:aExtensions.Columns, aData:aExtensions.Data} %}{% EndUIDataTable %} - {% EndUIFieldSet %} + {% UIPanel Neutral { sTitle:'DataFeatureRemoval:Features:Title'|dict_s, sSubTitle: '' } %} + {% UIMultiColumn Standard {} %} + {% for iColumnIndex in 0..iColumnCount-1 %} + {% UIColumn Standard {} %} + {% for aExtension in aAvailableExtensions[iColumnIndex] %} + {% if aExtension['installed'] %} + {% UIExtensionDetails Installed { sCode : aExtension['code'], sLabel : aExtension['label'], sDescription : aExtension['description'], aMetaData : [aExtension['version'], aExtension['source']], aExtraFlags : aExtension['extra_flags']} %}{% EndUIExtensionDetails %} + {% else %} + {% UIExtensionDetails NotInstalled { sCode : aExtension['code'], sLabel : aExtension['label'], sDescription : aExtension['description'], aMetaData : [aExtension['version'], aExtension['source']], aExtraFlags : aExtension['extra_flags']} %}{% EndUIExtensionDetails %} + {% endif %} + {% endfor %} + {% EndUIColumn %} + {% endfor %} + {% EndUIMultiColumn %} + {% EndUIPanel %} {% if bDeletionNeeded %} {% UIFieldSet Standard {sLegend:'DataFeatureRemoval:DeletionPlan:Title'|dict_s} %} diff --git a/datamodels/2.x/combodo-data-feature-removal/templates/Features.html.twig b/datamodels/2.x/combodo-data-feature-removal/templates/Features.html.twig index 26c3f15a10..71b06b6b64 100644 --- a/datamodels/2.x/combodo-data-feature-removal/templates/Features.html.twig +++ b/datamodels/2.x/combodo-data-feature-removal/templates/Features.html.twig @@ -6,9 +6,21 @@ {% UIInput ForHidden {sName:'operation', sValue:'Analyze'} %} {% UIInput ForHidden {sName:'transaction_id', sValue:sTransactionId} %} - {% UIFieldSet Standard {sLegend:'DataFeatureRemoval:Features:Title'|dict_s} %} - {% UIDataTable ForForm { sRef:'aExtensions', aColumns:aExtensions.Columns, aData:aExtensions.Data} %}{% EndUIDataTable %} - {% EndUIFieldSet %} + {% UIPanel Neutral { sTitle:'DataFeatureRemoval:Features:Title'|dict_s, sSubTitle: '' } %} + {% UIMultiColumn Standard {} %} + {% for iColumnIndex in 0..iColumnCount-1 %} + {% UIColumn Standard {} %} + {% for aExtension in aAvailableExtensions[iColumnIndex] %} + {% if aExtension['installed'] %} + {% UIExtensionDetails Installed { sCode : aExtension['code'], sLabel : aExtension['label'], sDescription : aExtension['description'], aMetaData : [aExtension['version'], aExtension['source']], aExtraFlags : aExtension['extra_flags']} %}{% EndUIExtensionDetails %} + {% else %} + {% UIExtensionDetails NotInstalled { sCode : aExtension['code'], sLabel : aExtension['label'], sDescription : aExtension['description'], aMetaData : [aExtension['version'], aExtension['source']], aExtraFlags : aExtension['extra_flags']} %}{% EndUIExtensionDetails %} + {% endif %} + {% endfor %} + {% EndUIColumn %} + {% endfor %} + {% EndUIMultiColumn %} + {% EndUIPanel %} {% UIToolbar ForButton {} %} {% UIButton ForPrimaryAction {sLabel:'UI:Button:Analyze'|dict_s, sName:'btn_apply', sId:'btn_apply', bIsSubmit:true} %} diff --git a/setup/extensionsmap.class.inc.php b/setup/extensionsmap.class.inc.php index 11dc6e063a..233c8e3bd9 100644 --- a/setup/extensionsmap.class.inc.php +++ b/setup/extensionsmap.class.inc.php @@ -486,7 +486,7 @@ class iTopExtensionsMap 'default' => true, // by default offer to install all modules 'modules' => $oExtension->aModules, 'mandatory' => $oExtension->bMandatory, - 'source_label' => $this->GetExtensionSourceLabel($oExtension->sSource), + 'source_label' => $oExtension->GetExtensionSourceLabel(), 'uninstallable' => $oExtension->CanBeUninstalled(), 'missing' => $oExtension->bRemovedFromDisk, 'version' => $oExtension->sVersion, @@ -496,22 +496,6 @@ class iTopExtensionsMap return $aRes; } - protected function GetExtensionSourceLabel($sSource) - { - $sResult = ''; - switch ($sSource) { - case iTopExtension::SOURCE_MANUAL: - $sResult = 'Local extensions folder'; - break; - - case iTopExtension::SOURCE_REMOTE: - $sResult = (ITOP_APPLICATION == 'iTop') ? 'iTop Hub' : 'ITSM Designer'; - break; - - } - return $sResult; - } - /** * Mark the given extension as chosen * @param string $sExtensionCode The code of the extension (code without version number) diff --git a/setup/feature_removal/DryRemovalRuntimeEnvironment.php b/setup/feature_removal/DryRemovalRuntimeEnvironment.php index ed86e87e2b..4cb8d1d42f 100644 --- a/setup/feature_removal/DryRemovalRuntimeEnvironment.php +++ b/setup/feature_removal/DryRemovalRuntimeEnvironment.php @@ -8,7 +8,7 @@ use SetupUtils; class DryRemovalRuntimeEnvironment extends RunTimeEnvironment { - protected array $aExtensionsByCode; + protected array $aExtensionsToRemoveByCode; /** * Toolset for building a run-time environment @@ -18,7 +18,7 @@ class DryRemovalRuntimeEnvironment extends RunTimeEnvironment public function __construct($sSourceEnv = 'production', array $aExtensionCodesToRemove = []) { parent::__construct($sSourceEnv, false); - $this->aExtensionsByCode = $aExtensionCodesToRemove; + $this->aExtensionsToRemoveByCode = $aExtensionCodesToRemove; $this->Prepare($sSourceEnv, $this->sBuildEnv); } @@ -34,7 +34,7 @@ class DryRemovalRuntimeEnvironment extends RunTimeEnvironment SetupUtils::copydir(APPROOT."/data/$sSourceEnv-modules", APPROOT."/data/$sBuildEnv-modules"); SetupUtils::copydir(APPROOT."/conf/$sSourceEnv", APPROOT."/conf/$sBuildEnv"); - $this->DeclareExtensionAsRemoved($this->aExtensionsByCode); + $this->DeclareExtensionAsRemoved($this->aExtensionsToRemoveByCode); } private function DeclareExtensionAsRemoved(array $aExtensionCodes): void diff --git a/setup/itopextension.class.inc.php b/setup/itopextension.class.inc.php index b40a64d74a..238ae76e39 100644 --- a/setup/itopextension.class.inc.php +++ b/setup/itopextension.class.inc.php @@ -169,4 +169,17 @@ class iTopExtension return json_encode($this->__serialize(), JSON_PRETTY_PRINT); } + public function GetExtensionSourceLabel(): string + { + return match ($this->sSource) { + self::SOURCE_MANUAL => 'Local extensions folder', + self::SOURCE_REMOTE => (ITOP_APPLICATION == 'iTop') ? 'iTop Hub' : 'ITSM Designer', + default => '', + }; + } + + public function IsRemote(): string + { + return $this->sSource === self::SOURCE_REMOTE; + } } diff --git a/sources/Application/UI/Base/Layout/Extension/ExtensionDetails.php b/sources/Application/UI/Base/Layout/Extension/ExtensionDetails.php index 0d03ebd6c7..bf82433b74 100644 --- a/sources/Application/UI/Base/Layout/Extension/ExtensionDetails.php +++ b/sources/Application/UI/Base/Layout/Extension/ExtensionDetails.php @@ -179,32 +179,37 @@ class ExtensionDetails extends UIContentBlock protected function InitializeToggler() { + $sName = 'aSelectedExtensions['.$this->GetCode().']'; $this->oToggler = new Toggler(); - $this->oToggler->SetName('ExtensionToggler'); + $this->oToggler->SetName($sName); $this->oToggler->AddCSSClass('toggler-install'); } protected function InitializePopoverMenu() { - $sModalLabel = Dict::Format('UI:Layout:ExtensionsDetails:MenuAboutTitle', $this->sLabel); - $sModalText = $this->sAbout; - $oModifyButton = new JSButtonItem( - 'extension_details', - Dict::S('UI:Layout:ExtensionsDetails:MenuAbout'), - <<oPopoverMenu = new PopoverMenu(); - $this->oPopoverMenu->AddItem('more-actions', PopoverMenuItemFactory::MakeFromApplicationPopupMenuItem($oModifyButton)); $oPopoverOpenButton = ButtonUIBlockFactory::MakeIconAction('fas fa-ellipsis-v', 'Show more actions'); $this->oPopoverMenu->SetTogglerFromBlock($oPopoverOpenButton); $this->oMoreActions = new UIContentBlock(); $this->oMoreActions->AddSubBlock($this->oPopoverMenu); $this->oMoreActions->AddSubBlock($oPopoverOpenButton); + + if (mb_strlen($this->sAbout) > 0) { + $sModalLabel = Dict::Format('UI:Layout:ExtensionsDetails:MenuAboutTitle', $this->sLabel); + $sModalText = $this->sAbout; + $oModifyButton = new JSButtonItem( + 'extension_details', + Dict::S('UI:Layout:ExtensionsDetails:MenuAbout'), + <<oPopoverMenu->AddItem('more-actions', PopoverMenuItemFactory::MakeFromApplicationPopupMenuItem($oModifyButton)); + } + } public function AllowForceUninstall() @@ -213,7 +218,8 @@ JS, 'force_uninstall', Dict::S('UI:Layout:ExtensionsDetails:MenuForce'), <<oPopoverMenu->AddItem('more-actions', PopoverMenuItemFactory::MakeFromApplicationPopupMenuItem($oForceUninstallButton)); diff --git a/sources/Application/UI/Base/Layout/Extension/ExtensionDetailsUIBlockFactory.php b/sources/Application/UI/Base/Layout/Extension/ExtensionDetailsUIBlockFactory.php index 7ec0db7b26..7ab01cd07a 100644 --- a/sources/Application/UI/Base/Layout/Extension/ExtensionDetailsUIBlockFactory.php +++ b/sources/Application/UI/Base/Layout/Extension/ExtensionDetailsUIBlockFactory.php @@ -18,6 +18,9 @@ class ExtensionDetailsUIBlockFactory extends AbstractUIBlockFactory $aBadges = []; $bUninstallable = $aExtraFlags['uninstallable'] ?? true; $bMissingFromDisk = $aExtraFlags['missing'] ?? false; + $bSelected = $aExtraFlags['selected'] ?? true; + $bDisabled = $aExtraFlags['disabled'] ?? false; + $bRemote = $aExtraFlags['remote'] ?? false; self::AddExtraBadges($aBadges, $bUninstallable, $bMissingFromDisk); $oBadgeInstalled = BadgeUIBlockFactory::MakeGreen(Dict::S('UI:Layout:ExtensionsDetails:BadgeInstalled')); $oBadgeInstalled->AddCSSClass('checked'); @@ -28,10 +31,22 @@ class ExtensionDetailsUIBlockFactory extends AbstractUIBlockFactory $oExtensionDetails = new ExtensionDetails($sCode, $sLabel, $sDescription, $aMetaData, $aBadges, $sAbout); $oExtensionDetails->GetToggler()->SetIsToggled(true); - if (!$bUninstallable) { + if ($bMissingFromDisk) { + $oExtensionDetails->GetToggler()->SetIsToggled(false); + $oExtensionDetails->GetToggler()->SetIsDisabled(true); + } elseif (!$bUninstallable || $bRemote) { $oExtensionDetails->AllowForceUninstall(); $oExtensionDetails->GetToggler()->SetIsDisabled(true); } + + if (!$bSelected) { + $oExtensionDetails->GetToggler()->SetIsToggled(false); + } + if ($bDisabled) { + $oExtensionDetails->GetToggler()->SetIsDisabled(true); + $oExtensionDetails->GetToggler()->AddCSSClass('ibo-is-hidden'); + } + return $oExtensionDetails; } @@ -39,6 +54,8 @@ class ExtensionDetailsUIBlockFactory extends AbstractUIBlockFactory { $aBadges = []; $bUninstallable = $aExtraFlags['uninstallable'] ?? true; + $bSelected = $aExtraFlags['selected'] ?? false; + $bDisabled = $aExtraFlags['disabled'] ?? false; self::AddExtraBadges($aBadges, $bUninstallable, false); $oBadgeInstalled = BadgeUIBlockFactory::MakeGrey(Dict::S('UI:Layout:ExtensionsDetails:BadgeNotInstalled')); $oBadgeInstalled->AddCSSClass('unchecked'); @@ -46,8 +63,17 @@ class ExtensionDetailsUIBlockFactory extends AbstractUIBlockFactory $oBadgeToBeUninstalled = BadgeUIBlockFactory::MakeCyan(Dict::S('UI:Layout:ExtensionsDetails:BadgeToBeInstalled')); $oBadgeToBeUninstalled->AddCSSClass('checked'); $aBadges[] = $oBadgeToBeUninstalled; + $oExtensionDetails = new ExtensionDetails($sCode, $sLabel, $sDescription, $aMetaData, $aBadges, $sAbout); - return new ExtensionDetails($sCode, $sLabel, $sDescription, $aMetaData, $aBadges, $sAbout); + if ($bSelected) { + $oExtensionDetails->GetToggler()->SetIsToggled(true); + } + if ($bDisabled) { + $oExtensionDetails->GetToggler()->SetIsDisabled(true); + $oExtensionDetails->GetToggler()->AddCSSClass('ibo-is-hidden'); + } + + return $oExtensionDetails; } private static function AddExtraBadges(array &$aBadges, bool $bUninstallable, bool $bMissingFromDisk) diff --git a/templates/base/components/input/input-toggler.html.twig b/templates/base/components/input/input-toggler.html.twig index f9bd74c6b5..1674d06cb9 100644 --- a/templates/base/components/input/input-toggler.html.twig +++ b/templates/base/components/input/input-toggler.html.twig @@ -1,7 +1,8 @@ {% extends "base/components/input/layout.html.twig" %} {% block iboInput %} - {{ parent() }} + {{ parent() }} + {% endblock %} diff --git a/templates/base/components/input/input-toggler.ready.js.twig b/templates/base/components/input/input-toggler.ready.js.twig index ec3e102fbc..703c0c5ad9 100644 --- a/templates/base/components/input/input-toggler.ready.js.twig +++ b/templates/base/components/input/input-toggler.ready.js.twig @@ -1,8 +1,10 @@ $('#{{ oUIBlock.GetId() }}').parent().on('click', function() { let oInput = $(this).find('.ibo-toggler'); + let oHiddenInput = $(this).find('.ibo-toggler--hidden'); if (!oInput.prop('disabled')) { oInput.prop('checked', !oInput.prop('checked')); + oHiddenInput.val(oInput.prop('checked') ? 'on' : 'off'); oInput.trigger('change'); } }); \ No newline at end of file diff --git a/tests/manual-visual-tests/Backoffice/RenderAllUiBlocks.php b/tests/manual-visual-tests/Backoffice/RenderAllUiBlocks.php index 2aac9ef2f0..a1bb135d05 100644 --- a/tests/manual-visual-tests/Backoffice/RenderAllUiBlocks.php +++ b/tests/manual-visual-tests/Backoffice/RenderAllUiBlocks.php @@ -639,6 +639,9 @@ $oPage->AddUiBlock($oMultiCol); $oExtensionDetailInstalledFromFactory = ExtensionDetailsUIBlockFactory::MakeInstalled('itop-sample', 'My extension v2', 'This is for test only', ['v1.1.1', 'Designer', '12/12/2012'], ['uninstallable' => false,'missing' => true]); $oColumnLeft->AddSubBlock($oExtensionDetailInstalledFromFactory); +$oExtensionDetailInstalledFromFactory = ExtensionDetailsUIBlockFactory::MakeInstalled('itop-not-uninstallable', 'You cannot uninstall me', 'Click force uninstall to uninstall me', ['v9.9.9', 'Void', '12/12/2012'], ['uninstallable' => false,'missing' => false]); +$oColumnLeft->AddSubBlock($oExtensionDetailInstalledFromFactory); + $oExtensionDetailInstalledWithLongTitle = ExtensionDetailsUIBlockFactory::MakeNotInstalled('itop-sample', 'My extension with a very long title', 'This is for test only', ['v1.1.1', 'Designer', '12/12/2012'], ['uninstallable' => false]); $oColumnRight->AddSubBlock($oExtensionDetailInstalledWithLongTitle); $oPage->add('
');