Merge remote-tracking branch 'origin/support/2.7' into support/3.0

N°5741 - remove use of get_config_parameter and get_module_setting in Twig

# Conflicts:
#	application/twigextension.class.inc.php
#	datamodels/2.x/itop-portal-base/portal/src/Twig/AppExtension.php
#	sources/application/TwigBase/Twig/Extension.php
This commit is contained in:
Eric Espie
2022-11-23 17:38:27 +01:00
13 changed files with 155 additions and 77 deletions

View File

@@ -6,7 +6,6 @@ use AttributeDate;
use AttributeDateTime;
use Dict;
use Exception;
use MetaModel;
use Twig_Environment;
use Twig_SimpleFilter;
use Twig_SimpleFunction;
@@ -111,22 +110,6 @@ class TwigExtension
return utils::IsDevelopmentEnvironment();
}));
// Function to get configuration parameter
// Usage in twig: {{ get_config_parameter('foo') }}
$oTwigEnv->addFunction(new Twig_SimpleFunction('get_config_parameter', function($sParamName)
{
$oConfig = MetaModel::GetConfig();
return $oConfig->Get($sParamName);
}));
// Function to get a module setting
// Usage in twig: {{ get_module_setting(<MODULE_CODE>, <PROPERTY_CODE> [, <DEFAULT_VALUE>]) }}
// since 3.0.0, but see N°4034 for upcoming evolutions in the 3.1
$oTwigEnv->addFunction(new Twig_SimpleFunction('get_module_setting', function (string $sModuleCode, string $sPropertyCode, $defaultValue = null) {
$oConfig = MetaModel::GetConfig();
return $oConfig->GetModuleSetting($sModuleCode, $sPropertyCode, $defaultValue);
}));
// Function to get the URL of a static page in a module
// Usage in twig: {{ get_static_page_module_url('itop-my-module', 'path-to-my-page') }}
$oTwigEnv->addFunction(new Twig_SimpleFunction('get_static_page_module_url', function($sModuleName, $sPage)

View File

@@ -157,6 +157,7 @@ if (!defined('PORTAL_ID'))
// Env. vars to be used in templates and others
$_ENV['COMBODO_CURRENT_ENVIRONMENT'] = utils::GetCurrentEnvironment();
$_ENV['COMBODO_ABSOLUTE_URL'] = utils::GetAbsoluteUrlAppRoot();
$_ENV['COMBODO_CONF_APP_ICON_URL'] = MetaModel::GetConfig()->Get('app_icon_url');
$_ENV['COMBODO_MODULES_ABSOLUTE_URL'] = utils::GetAbsoluteUrlModulesRoot();
$_ENV['COMBODO_PORTAL_BASE_ABSOLUTE_URL'] = utils::GetAbsoluteUrlModulesRoot().'itop-portal-base/portal/public/';
$_ENV['COMBODO_PORTAL_BASE_ABSOLUTE_PATH'] = MODULESROOT.'/itop-portal-base/portal/public/';

View File

@@ -30,6 +30,7 @@ parameters:
# Used in templates
combodo.current_environment: '%env(string:COMBODO_CURRENT_ENVIRONMENT)%'
combodo.absolute_url: '%env(string:COMBODO_ABSOLUTE_URL)%'
combodo.conf.app_icon_url: '%env(string:COMBODO_CONF_APP_ICON_URL)%'
combodo.modules.absolute_url: '%env(string:COMBODO_MODULES_ABSOLUTE_URL)%'
combodo.modules.absolute_path: !php/const MODULESROOT
combodo.portal.base.absolute_url: '%env(string:COMBODO_PORTAL_BASE_ABSOLUTE_URL)%'

View File

@@ -20,15 +20,13 @@
namespace Combodo\iTop\Portal\Twig;
use AttributeDate;
use Twig\Extension\AbstractExtension;
use AttributeDateTime;
use AttributeText;
use Dict;
use Twig\Extension\AbstractExtension;
use Twig_SimpleFilter;
use Twig_SimpleFunction;
use utils;
use Dict;
use MetaModel;
/**
* Class AppExtension
@@ -186,28 +184,6 @@ class AppExtension extends AbstractExtension
return utils::IsDevelopmentEnvironment();
});
// Function to get configuration parameter
// Usage in twig: {{ get_config_parameter('foo') }}
$functions[] = new Twig_SimpleFunction('get_config_parameter', function ($sParamName) {
$oConfig = MetaModel::GetConfig();
return $oConfig->Get($sParamName);
});
/**
* Function to get a module setting
* Usage in twig: {{ get_module_setting(<MODULE_CODE>, <PROPERTY_CODE> [, <DEFAULT_VALUE>]) }}
*
* @uses Config::GetModuleSetting()
* @since 3.0.0
*/
$functions[] = new Twig_SimpleFunction('get_module_setting',
function (string $sModuleCode, string $sPropertyCode, $defaultValue = null) {
$oConfig = MetaModel::GetConfig();
return $oConfig->GetModuleSetting($sModuleCode, $sPropertyCode, $defaultValue);
});
/**
* Function to get iTop's app root absolute URL (eg. https://aaa.bbb.ccc/xxx/yyy/)
* Usage in twig: {{ get_absolute_url_app_root() }}

View File

@@ -186,7 +186,7 @@
<span class="icon-bar"></span>
</button>
{% block pNavigationTopMenuLogo %}
<a class="navbar-brand pull-right" href="{{ get_config_parameter('app_icon_url') }}">
<a class="navbar-brand pull-right" href="{{ app['combodo.conf.app_icon_url'] }}">
{% if app['combodo.portal.instance.conf'].properties.logo is not null %}
<img src="{{ app['combodo.portal.instance.conf'].properties.logo }}" alt="{{ app['combodo.portal.instance.conf'].properties.name|dict_s }}" />
{% else %}
@@ -314,7 +314,7 @@
{% if app['kernel'].debug == true %}
<div style="position: fixed; bottom: 0px; left: 0px; z-index: 9999;">Debug : Taille <span class="hidden-sm hidden-md hidden-lg">XS</span><span class="hidden-xs hidden-md hidden-lg">SM</span><span class="hidden-xs hidden-sm hidden-lg">MD</span><span class="hidden-xs hidden-sm hidden-md">LG</span></div>
{% endif %}
<a href="{{ get_config_parameter('app_icon_url') }}" title="{{ app['combodo.portal.instance.conf'].properties.name|dict_s }}">
<a href="{{ app['combodo.conf.app_icon_url'] }}" title="{{ app['combodo.portal.instance.conf'].properties.name|dict_s }}">
<img src="{{ app['combodo.portal.instance.conf'].properties.logo }}" alt="{{ app['combodo.portal.instance.conf'].properties.name|dict_s }}" />
</a>
{% endblock %}

View File

@@ -14,7 +14,6 @@ use Combodo\iTop\Application\UI\Base\iUIBlock;
use Combodo\iTop\Renderer\BlockRenderer;
use Dict;
use Exception;
use MetaModel;
use Twig_Environment;
use Twig_SimpleFilter;
use Twig_SimpleFunction;
@@ -143,28 +142,6 @@ class Extension
return utils::IsDevelopmentEnvironment();
}));
// Function to get configuration parameter
// Usage in twig: {{ get_config_parameter('foo') }}
$oTwigEnv->addFunction(new Twig_SimpleFunction('get_config_parameter', function ($sParamName) {
$oConfig = MetaModel::GetConfig();
return $oConfig->Get($sParamName);
}));
/**
* Function to get a module setting
* Usage in twig: {{ get_module_setting(<MODULE_CODE>, <PROPERTY_CODE> [, <DEFAULT_VALUE>]) }}
*
* @uses Config::GetModuleSetting()
* @since 3.0.0
*/
$oTwigEnv->addFunction(new Twig_SimpleFunction('get_module_setting',
function (string $sModuleCode, string $sPropertyCode, $defaultValue = null) {
$oConfig = MetaModel::GetConfig();
return $oConfig->GetModuleSetting($sModuleCode, $sPropertyCode, $defaultValue);
}));
// Function to get iTop's app root absolute URL (eg. https://aaa.bbb.ccc/xxx/yyy/)
// Usage in twig: {{ get_absolute_url_app_root() }}
/** @since 3.0.0 */

View File

@@ -24,6 +24,7 @@ use AttributeDateTime;
use Combodo\iTop\Application\UI\Base\UIBlock;
use Combodo\iTop\Core\CMDBChange\CMDBChangeOrigin;
use DateTime;
use MetaModel;
use UserRights;
use utils;
@@ -74,6 +75,8 @@ class ActivityEntry extends UIBlock
*/
protected $sOrigin;
protected $bShowAuthorNameBelowEntries;
/**
* ActivityEntry constructor.
*
@@ -94,6 +97,7 @@ class ActivityEntry extends UIBlock
$this->SetDateTime($oDateTime);
$this->SetAuthor($sAuthorLogin);
$this->SetOrigin(static::DEFAULT_ORIGIN);
$this->SetShowAuthorNameBelowEntries(MetaModel::GetConfig()->Get('activity_panel.show_author_name_below_entries'));
}
/**
@@ -306,6 +310,22 @@ class ActivityEntry extends UIBlock
return $this->sOrigin;
}
/**
* @return mixed
*/
public function ShowAuthorNameBelowEntries(): bool
{
return $this->bShowAuthorNameBelowEntries;
}
/**
* @param bool $bShowAuthorNameBelowEntries
*/
public function SetShowAuthorNameBelowEntries($bShowAuthorNameBelowEntries): void
{
$this->bShowAuthorNameBelowEntries = $bShowAuthorNameBelowEntries;
}
/**
* @return string|null The CSS decoration classes for the origin of the entry
* @see \CMDBChangeOrigin

View File

@@ -90,6 +90,17 @@ class ActivityPanel extends UIBlock
protected $oComposeMenu;
/** @var bool Whether a confirmation dialog should be prompt when multiple entries are about to be submitted at once */
protected $bShowMultipleEntriesSubmitConfirmation;
/** @var int */
protected $iDatetimesReformatLimit;
/** @var int */
protected $iLockWatcherPeriod;
/** @var bool */
protected $bPrefilterOnlyCurrentLog;
/** @var bool */
protected $bPrefilterStateChangesOnLogs;
/** @var bool */
protected $bPrefilterEditsOnLogs;
/**
* ActivityPanel constructor.
@@ -105,12 +116,18 @@ class ActivityPanel extends UIBlock
{
parent::__construct($sId);
$oConfig = MetaModel::GetConfig();
$this->InitializeCaseLogTabs();
$this->InitializeCaseLogTabsEntryForms();
$this->InitializeComposeMenu();
$this->SetObjectMode(cmdbAbstractObject::DEFAULT_DISPLAY_MODE);
$this->SetObject($oObject);
$this->SetEntries($aEntries);
$this->SetDatetimesReformatLimit($oConfig->Get('activity_panel.datetimes_reformat_limit'));
$this->SetLockWatcherPeriod($oConfig->Get('activity_panel.lock_watcher_period'));
$this->SetPrefilterOnlyCurrentLog($oConfig->Get('activity_panel.prefilter_only_current_log'));
$this->SetPrefilterStateChangesOnLogs($oConfig->Get('activity_panel.prefilter_state_changes_on_logs'));
$this->SetPrefilterEditsOnLogs($oConfig->Get('activity_panel.prefilter_edits_on_logs'));
$this->bAreEntriesSorted = false;
$this->bHasMoreEntriesToLoad = false;
$this->aLastLoadedEntriesIds = [];
@@ -846,6 +863,86 @@ class ActivityPanel extends UIBlock
return utils::GetAbsoluteUrlAppRoot().'pages/ajax.render.php';
}
/**
* @return int
*/
public function GetDatetimesReformatLimit(): int
{
return $this->iDatetimesReformatLimit;
}
/**
* @param int $iDatetimesReformatLimit
*/
public function SetDatetimesReformatLimit(int $iDatetimesReformatLimit): void
{
$this->iDatetimesReformatLimit = $iDatetimesReformatLimit;
}
/**
* @return int
*/
public function GetLockWatcherPeriod(): int
{
return $this->iLockWatcherPeriod;
}
/**
* @param int $iLockWatcherPeriod
*/
public function SetLockWatcherPeriod(int $iLockWatcherPeriod): void
{
$this->iLockWatcherPeriod = $iLockWatcherPeriod;
}
/**
* @return bool
*/
public function GetPrefilterOnlyCurrentLog(): bool
{
return $this->bPrefilterOnlyCurrentLog;
}
/**
* @param bool $bPrefilterOnlyCurrentLog
*/
public function SetPrefilterOnlyCurrentLog(bool $bPrefilterOnlyCurrentLog): void
{
$this->bPrefilterOnlyCurrentLog = $bPrefilterOnlyCurrentLog;
}
/**
* @return bool
*/
public function GetPrefilterStateChangesOnLogs(): bool
{
return $this->bPrefilterStateChangesOnLogs;
}
/**
* @param bool $bPrefilterStateChangesOnLogs
*/
public function SetPrefilterStateChangesOnLogs(bool $bPrefilterStateChangesOnLogs): void
{
$this->bPrefilterStateChangesOnLogs = $bPrefilterStateChangesOnLogs;
}
/**
* @return bool
*/
public function GetPrefilterEditsOnLogs(): bool
{
return $this->bPrefilterEditsOnLogs;
}
/**
* @param bool $bPrefilterEditsOnLogs
*/
public function SetPrefilterEditsOnLogs(bool $bPrefilterEditsOnLogs): void
{
$this->bPrefilterEditsOnLogs = $bPrefilterEditsOnLogs;
}
/**
* @inheritdoc
*/

View File

@@ -86,6 +86,9 @@ class NavigationMenu extends UIBlock implements iKeyboardShortcut
protected $bIsExpanded;
/** @var bool Whether the hint on how the menu filter works shoudl be displayed or not */
protected $bShowMenuFilterHint;
/** @var bool */
protected $bShowMenusCount;
/**
* NavigationMenu constructor.
@@ -106,10 +109,13 @@ class NavigationMenu extends UIBlock implements iKeyboardShortcut
) {
parent::__construct($sId);
$oConfig = MetaModel::GetConfig();
$this->sAppRevisionNumber = utils::GetAppRevisionNumber();
$this->sAppSquareIconUrl = Branding::GetCompactMainLogoAbsoluteUrl();
$this->sAppFullIconUrl = Branding::GetFullMainLogoAbsoluteUrl();
$this->sAppIconLink = MetaModel::GetConfig()->Get('app_icon_url');
$this->sAppIconLink = $oConfig->Get('app_icon_url');
$this->SetShowMenusCount($oConfig->Get('navigation_menu.show_menus_count'));
$this->aSiloSelection = array();
$this->aMenuGroups = ApplicationMenu::GetMenuGroups($oAppContext->GetAsHash());
$this->oUserMenu = $oUserMenu;
@@ -479,4 +485,21 @@ JS;
{
return "[data-role='".static::BLOCK_CODE."']";
}
/**
* @return bool
*/
public function GetShowMenusCount(): bool
{
return $this->bShowMenusCount;
}
/**
* @param bool $bShowMenusCount
*/
public function SetShowMenusCount(bool $bShowMenusCount): void
{
$this->bShowMenusCount = $bShowMenusCount;
}
}

View File

@@ -39,7 +39,7 @@
<span class="{{ oUIBlock.GetOriginDecorationClasses() }}"></span>
</span>
{% endif %}
{% if get_config_parameter('activity_panel.show_author_name_below_entries') %}
{% if oUIBlock.ShowAuthorNameBelowEntries() %}
<span class="ibo-activity-entry--author-name ibo-is-hidden" data-role="ibo-activity-entry--author-name">{{ oUIBlock.GetAuthorFriendlyname() }}</span>
{% endif %}
<span class="ibo-activity-entry--datetime" data-role="ibo-activity-entry--datetime"

View File

@@ -1,9 +1,9 @@
$('#{{ oUIBlock.GetId() }}').activity_panel({
datetime_format: {{ oUIBlock.GetDateTimeFormatForJSWidget()|json_encode|raw }},
datetimes_reformat_limit: {{ get_config_parameter('activity_panel.datetimes_reformat_limit') }},
datetimes_reformat_limit: {{ oUIBlock.GetDatetimesReformatLimit() }},
{% if oUIBlock.HasTransactionId() %}transaction_id: {{ oUIBlock.GetTransactionId()|var_export }},{% endif %}
lock_enabled: {{ oUIBlock.IsLockEnabled()|var_export }},
lock_watcher_period: {{ get_config_parameter('activity_panel.lock_watcher_period') }},
lock_watcher_period: {{ oUIBlock.GetLockWatcherPeriod() }},
lock_endpoint: {{ oUIBlock.GetLockEndpoint()|var_export|raw }},
show_multiple_entries_submit_confirmation: {{ oUIBlock.GetShowMultipleEntriesSubmitConfirmation()|var_export }},
save_state_endpoint: {{ oUIBlock.GetSaveStateEndpoint()|var_export|raw }},

View File

@@ -28,7 +28,7 @@
<label class="ibo-activity-panel--tab-toolbar-action" data-role="ibo-activity-panel--tab-toolbar-action"
data-tooltip-content="{{ 'UI:Layout:ActivityPanel:Tab:Toolbar:Filter:Logs:Tooltip'|dict_s }}">
<input type="checkbox" name="caselogs" data-role="ibo-activity-panel--filter" data-target-entry-types="caselog"
{% if (aFilteredCaseLogsAttCodes is not defined) or (aFilteredCaseLogsAttCodes is empty) or (get_config_parameter('activity_panel.prefilter_only_current_log') == false) %}checked{% endif %}>
{% if (aFilteredCaseLogsAttCodes is not defined) or (aFilteredCaseLogsAttCodes is empty) or (oUIBlock.GetPrefilterOnlyCurrentLog() == false) %}checked{% endif %}>
{{ 'UI:Layout:ActivityPanel:Tab:Toolbar:Filter:Logs:Title'|dict_s }}
{% if oUIBlock.GetCaseLogTabs()|length > 0 %}
<a class="ibo-activity-panel--filter-options-toggler ibo-is-closed" href="#"
@@ -43,7 +43,7 @@
<input type="checkbox" name="caselog" value="{{ sCaseLogAttCode }}"
class="ibo-activity-panel--filter-option-input"
data-role="ibo-activity-panel--filter-option-input"
{% if (aFilteredCaseLogsAttCodes is not defined) or (sCaseLogAttCode in aFilteredCaseLogsAttCodes) or (get_config_parameter('activity_panel.prefilter_only_current_log') == false) %}checked{% endif %}>
{% if (aFilteredCaseLogsAttCodes is not defined) or (sCaseLogAttCode in aFilteredCaseLogsAttCodes) or (oUIBlock.GetPrefilterOnlyCurrentLog() == false) %}checked{% endif %}>
{{ aCaseLogData['title'] }}
</label>
{% endfor %}
@@ -55,13 +55,13 @@
<label class="ibo-activity-panel--tab-toolbar-action"
data-tooltip-content="{{ 'UI:Layout:ActivityPanel:Tab:Toolbar:Filter:Transitions:Tooltip'|dict_s }}">
<input type="checkbox" name="transitions" data-role="ibo-activity-panel--filter"
data-target-entry-types="transition" {% if (bPrefilterStateChanges is defined and bPrefilterStateChanges == true) or (get_config_parameter('activity_panel.prefilter_state_changes_on_logs') == true) %}checked{% endif %}>
data-target-entry-types="transition" {% if (bPrefilterStateChanges is defined and bPrefilterStateChanges == true) or (oUIBlock.GetPrefilterStateChangesOnLogs() == true) %}checked{% endif %}>
{{ 'UI:Layout:ActivityPanel:Tab:Toolbar:Filter:Transitions:Title'|dict_s }}
</label>
{% endif %}
<label class="ibo-activity-panel--tab-toolbar-action"
data-tooltip-content="{{ 'UI:Layout:ActivityPanel:Tab:Toolbar:Filter:Edits:Tooltip'|dict_s }}">
<input type="checkbox" name="edits" data-role="ibo-activity-panel--filter" data-target-entry-types="edits" {% if (bPrefilterEdits is defined and bPrefilterEdits == true) or (get_config_parameter('activity_panel.prefilter_edits_on_logs') == true) %}checked{% endif %}>
<input type="checkbox" name="edits" data-role="ibo-activity-panel--filter" data-target-entry-types="edits" {% if (bPrefilterEdits is defined and bPrefilterEdits == true) or (oUIBlock.GetPrefilterEditsOnLogs() == true) %}checked{% endif %}>
{{ 'UI:Layout:ActivityPanel:Tab:Toolbar:Filter:Edits:Title'|dict_s }}
</label>
</div>

View File

@@ -1,5 +1,5 @@
$('#{{ oUIBlock.GetId() }}').navigation_menu({
display_counts: {% if get_config_parameter('navigation_menu.show_menus_count') %} true {% else %} false {% endif %},
display_counts: {% if oUIBlock.GetShowMenusCount() %} true {% else %} false {% endif %},
org_id: '{{ oUIBlock.GetOrgId() }}'
});