From bec5e250a586c15ab477f65e09dbd61109b9b0df Mon Sep 17 00:00:00 2001 From: Pierre Goiffon Date: Wed, 14 Feb 2024 10:07:24 +0100 Subject: [PATCH] =?UTF-8?q?N=C2=B05472=20Notification=20Action=20objects?= =?UTF-8?q?=20:=20add=20a=20last=20executions=20tab=20(#549)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This tab is an ajax tab (deferred on demand loading) The tab will display the last EventNotification for this action. Number of objects displayed is based on the new `notifications.last_executions_days` config parameter (default to 61 days, can be set to 0 for no limit) --- core/action.class.inc.php | 57 +++++++++++++++++++ core/config.class.inc.php | 8 +++ dictionaries/en.dictionary.itop.core.php | 4 ++ lib/composer/autoload_classmap.php | 1 + lib/composer/autoload_static.php | 1 + .../Notifications/ActionController.php | 48 ++++++++++++++++ 6 files changed, 119 insertions(+) create mode 100644 sources/Controller/Notifications/ActionController.php diff --git a/core/action.class.inc.php b/core/action.class.inc.php index 10660003a..29f9ca771 100644 --- a/core/action.class.inc.php +++ b/core/action.class.inc.php @@ -17,7 +17,9 @@ // along with iTop. If not, see use Combodo\iTop\Application\TwigBase\Twig\TwigHelper; +use Combodo\iTop\Application\UI\Base\Component\DataTable\DataTableUIBlockFactory; use Combodo\iTop\Application\WebPage\WebPage; +use Combodo\iTop\Service\Router\Router; /** * Persistent classes (internal): user defined actions @@ -168,6 +170,61 @@ abstract class Action extends cmdbAbstractObject $this->m_aCheckWarnings[] = Dict::S('Action:WarningNoTriggerLinked'); } } + + /** + * @since 3.2.0 N°5472 method creation + */ + public function DisplayBareRelations(WebPage $oPage, $bEditMode = false) + { + parent::DisplayBareRelations($oPage, false); + + if ($oPage instanceof iTopWebPage) { + $this->GenerateLastExecutionsTab($oPage, $bEditMode); + } + } + + /** + * @since 3.2.0 N°5472 method creation + */ + protected function GenerateLastExecutionsTab(iTopWebPage $oPage, $bEditMode) + { + $oRouter = Router::GetInstance(); + $sActionLastExecutionsPageUrl = $oRouter->GenerateUrl('notifications.action.last_executions_tab', ['action_id' => $this->GetKey()]); + $oPage->AddAjaxTab('action_errors', $sActionLastExecutionsPageUrl, false, Dict::S('Action:last_executions_tab')); + } + + /** + * @throws InvalidConfigParamException + * @since 3.2.0 N°5472 method creation + */ + public function GetLastExecutionsTabContent(WebPage $oPage): void + { + $oConfig = utils::GetConfig(); + $sLastExecutionDaysConfigParamName = 'notifications.last_executions_days'; + $iLastExecutionDays = $oConfig->Get($sLastExecutionDaysConfigParamName); + + if ($iLastExecutionDays < 0) { + throw new InvalidConfigParamException("Invalid value for {$sLastExecutionDaysConfigParamName} config parameter. Param desc: " . $oConfig->GetDescription($sLastExecutionDaysConfigParamName)); + } + + $sActionQueryOql = 'SELECT EventNotification WHERE action_id = :action_id'; + $aActionQueryParams = ['action_id' => $this->GetKey()]; + if ($iLastExecutionDays > 0) { + $sActionQueryOql .= ' AND date > DATE_SUB(NOW(), INTERVAL :days DAY)'; + $aActionQueryParams['days'] = $iLastExecutionDays; + $sActionQueryLimit = Dict::Format('Action:last_executions_tab_limit_days', $iLastExecutionDays); + } else { + $sActionQueryLimit = Dict::S('Action:last_executions_tab_limit_none'); + } + + $oActionFilter = DBObjectSearch::FromOQL($sActionQueryOql, $aActionQueryParams); + $oSet = new DBObjectSet($oActionFilter, ['date' => false]); + + $sPanelTitle = Dict::Format('Action:last_executions_tab_panel_title', $sActionQueryLimit); + $oExecutionsListBlock = DataTableUIBlockFactory::MakeForResult($oPage, 'action_executions_list', $oSet, ['panel_title' => $sPanelTitle]); + + $oPage->AddUiBlock($oExecutionsListBlock); + } } /** diff --git a/core/config.class.inc.php b/core/config.class.inc.php index 8f1a295a9..4b1ad7e4c 100644 --- a/core/config.class.inc.php +++ b/core/config.class.inc.php @@ -1619,6 +1619,14 @@ class Config 'source_of_value' => '', 'show_in_conf_sample' => false, ], + 'notifications.last_executions_days' => [ + 'type' => 'integer', + 'description' => 'Number of days to display in the Action\'s last executions tab (0 means no limit)', + 'default' => 30 + 31, // 2 months + 'value' => 61, + 'source_of_value' => '', + 'show_in_conf_sample' => false, + ], 'regenerate_session_id_enabled' => [ 'type' => 'bool', 'description' => 'If true then session id will be regenerated on each login, to prevent session fixation.', diff --git a/dictionaries/en.dictionary.itop.core.php b/dictionaries/en.dictionary.itop.core.php index 505a9e699..bc88471c4 100644 --- a/dictionaries/en.dictionary.itop.core.php +++ b/dictionaries/en.dictionary.itop.core.php @@ -539,6 +539,10 @@ Dict::Add('EN US', 'English', 'English', array( 'Class:Action/Attribute:finalclass' => 'Action sub-class', 'Class:Action/Attribute:finalclass+' => 'Name of the final class', 'Action:WarningNoTriggerLinked' => 'Warning, no trigger is linked to the action. It will not be active until it has at least 1.', + 'Action:last_executions_tab' => 'Last executions', + 'Action:last_executions_tab_panel_title' => 'Executions of this action (%1$s)', + 'Action:last_executions_tab_limit_days' => 'past %1$s days', + 'Action:last_executions_tab_limit_none' => 'no limit', )); // diff --git a/lib/composer/autoload_classmap.php b/lib/composer/autoload_classmap.php index 0566bd64b..12549749d 100644 --- a/lib/composer/autoload_classmap.php +++ b/lib/composer/autoload_classmap.php @@ -394,6 +394,7 @@ return array( 'Combodo\\iTop\\Controller\\Base\\Layout\\ObjectController' => $baseDir . '/sources/Controller/Base/Layout/ObjectController.php', 'Combodo\\iTop\\Controller\\Links\\LinkSetController' => $baseDir . '/sources/Controller/Links/LinkSetController.php', 'Combodo\\iTop\\Controller\\Newsroom\\iTopNewsroomController' => $baseDir . '/sources/Controller/Newsroom/iTopNewsroomController.php', + 'Combodo\\iTop\\Controller\\Notifications\\ActionController' => $baseDir . '/sources/Controller/Notifications/ActionController.php', 'Combodo\\iTop\\Controller\\OAuth\\OAuthLandingController' => $baseDir . '/sources/Controller/OAuth/OAuthLandingController.php', 'Combodo\\iTop\\Controller\\PreferencesController' => $baseDir . '/sources/Controller/PreferencesController.php', 'Combodo\\iTop\\Controller\\TemporaryObjects\\TemporaryObjectController' => $baseDir . '/sources/Controller/TemporaryObjects/TemporaryObjectController.php', diff --git a/lib/composer/autoload_static.php b/lib/composer/autoload_static.php index 029ad0205..fc5240244 100644 --- a/lib/composer/autoload_static.php +++ b/lib/composer/autoload_static.php @@ -769,6 +769,7 @@ class ComposerStaticInit7f81b4a2a468a061c306af5e447a9a9f 'Combodo\\iTop\\Controller\\Base\\Layout\\ObjectController' => __DIR__ . '/../..' . '/sources/Controller/Base/Layout/ObjectController.php', 'Combodo\\iTop\\Controller\\Links\\LinkSetController' => __DIR__ . '/../..' . '/sources/Controller/Links/LinkSetController.php', 'Combodo\\iTop\\Controller\\Newsroom\\iTopNewsroomController' => __DIR__ . '/../..' . '/sources/Controller/Newsroom/iTopNewsroomController.php', + 'Combodo\\iTop\\Controller\\Notifications\\ActionController' => __DIR__ . '/../..' . '/sources/Controller/Notifications/ActionController.php', 'Combodo\\iTop\\Controller\\OAuth\\OAuthLandingController' => __DIR__ . '/../..' . '/sources/Controller/OAuth/OAuthLandingController.php', 'Combodo\\iTop\\Controller\\PreferencesController' => __DIR__ . '/../..' . '/sources/Controller/PreferencesController.php', 'Combodo\\iTop\\Controller\\TemporaryObjects\\TemporaryObjectController' => __DIR__ . '/../..' . '/sources/Controller/TemporaryObjects/TemporaryObjectController.php', diff --git a/sources/Controller/Notifications/ActionController.php b/sources/Controller/Notifications/ActionController.php new file mode 100644 index 000000000..d42d9e760 --- /dev/null +++ b/sources/Controller/Notifications/ActionController.php @@ -0,0 +1,48 @@ +GetLastExecutionsTabContent($oPage); + + return $oPage; + } +} \ No newline at end of file