diff --git a/datamodels/2.x/itop-core-update/view/SelectUpdateFile.html.twig b/datamodels/2.x/itop-core-update/view/SelectUpdateFile.html.twig index c9a250385..666f0c77e 100644 --- a/datamodels/2.x/itop-core-update/view/SelectUpdateFile.html.twig +++ b/datamodels/2.x/itop-core-update/view/SelectUpdateFile.html.twig @@ -3,9 +3,9 @@ {% apply spaceless %} {% UIContentBlock "" "ibo-update-core" %} -{% UIHtml %} - -{% EndUIHtml %} + +{% UITitle ForPage {'title':'iTopUpdate:UI:PageTitle'|dict_s} %} + {% UIHtml %}
 
{% EndUIHtml %} @@ -13,13 +13,9 @@ {% UIContentBlock "" "display_block display-files" %} {% UIFieldSet {'legend':'iTopUpdate:UI:Status'|dict_s} %} -{% UIHtml %} -
-
- {{ 'iTopUpdate:UI:CanCoreUpdate:Loading'|dict_s }} -
-
-{% EndUIHtml %} +{% UIAlert ForInformation {'title':'', 'id':'header-requirements'} %} + {{ 'iTopUpdate:UI:CanCoreUpdate:Loading'|dict_s }} +{% EndUIAlert %} {% set sVersion = 'UI:iTopVersion:Long'|dict_format(constant('ITOP_APPLICATION'), constant('ITOP_VERSION'), constant('ITOP_REVISION'), constant('ITOP_BUILD_DATE')) %} diff --git a/lib/composer/autoload_classmap.php b/lib/composer/autoload_classmap.php index 782017a67..433f83602 100644 --- a/lib/composer/autoload_classmap.php +++ b/lib/composer/autoload_classmap.php @@ -151,6 +151,8 @@ return array( 'Combodo\\iTop\\Application\\TwigBase\\Controller\\PageNotFoundException' => $baseDir . '/sources/application/TwigBase/Controller/Controller.php', 'Combodo\\iTop\\Application\\TwigBase\\Twig\\Extension' => $baseDir . '/sources/application/TwigBase/Twig/Extension.php', 'Combodo\\iTop\\Application\\TwigBase\\Twig\\TwigHelper' => $baseDir . '/sources/application/TwigBase/Twig/TwigHelper.php', + 'Combodo\\iTop\\Application\\TwigBase\\UI\\Component\\UIAlertNode' => $baseDir . '/sources/application/TwigBase/UI/Component/Alert/UIAlertNode.php', + 'Combodo\\iTop\\Application\\TwigBase\\UI\\Component\\UIAlertParser' => $baseDir . '/sources/application/TwigBase/UI/Component/Alert/UIAlertParser.php', 'Combodo\\iTop\\Application\\TwigBase\\UI\\Component\\UIContentBlockNode' => $baseDir . '/sources/application/TwigBase/UI/Layout/UIContentBlockNode.php', 'Combodo\\iTop\\Application\\TwigBase\\UI\\Component\\UIContentBlockParser' => $baseDir . '/sources/application/TwigBase/UI/Layout/UIContentBlockParser.php', 'Combodo\\iTop\\Application\\TwigBase\\UI\\Component\\UIFieldNode' => $baseDir . '/sources/application/TwigBase/UI/Component/Field/UIFieldNode.php', @@ -159,6 +161,8 @@ return array( 'Combodo\\iTop\\Application\\TwigBase\\UI\\Component\\UIFieldSetParser' => $baseDir . '/sources/application/TwigBase/UI/Component/FieldSet/UIFieldSetParser.php', 'Combodo\\iTop\\Application\\TwigBase\\UI\\Component\\UIHtmlNode' => $baseDir . '/sources/application/TwigBase/UI/Component/Html/UIHtmlNode.php', 'Combodo\\iTop\\Application\\TwigBase\\UI\\Component\\UIHtmlParser' => $baseDir . '/sources/application/TwigBase/UI/Component/Html/UIHtmlParser.php', + 'Combodo\\iTop\\Application\\TwigBase\\UI\\Component\\UITitleNode' => $baseDir . '/sources/application/TwigBase/UI/Component/Title/UITitleNode.php', + 'Combodo\\iTop\\Application\\TwigBase\\UI\\Component\\UITitleParser' => $baseDir . '/sources/application/TwigBase/UI/Component/Title/UITitleParser.php', 'Combodo\\iTop\\Application\\TwigBase\\UI\\UIBlockExtension' => $baseDir . '/sources/application/TwigBase/UI/UIBlockExtension.php', 'Combodo\\iTop\\Application\\TwigBase\\UI\\UIBlockHelper' => $baseDir . '/sources/application/TwigBase/UI/UIBlockHelper.php', 'Combodo\\iTop\\Application\\UI\\Base\\Component\\Alert\\Alert' => $baseDir . '/sources/application/UI/Base/Component/Alert/Alert.php', diff --git a/lib/composer/autoload_static.php b/lib/composer/autoload_static.php index 8416f1343..9d3f8c2cb 100644 --- a/lib/composer/autoload_static.php +++ b/lib/composer/autoload_static.php @@ -381,6 +381,8 @@ class ComposerStaticInit0018331147de7601e7552f7da8e3bb8b 'Combodo\\iTop\\Application\\TwigBase\\Controller\\PageNotFoundException' => __DIR__ . '/../..' . '/sources/application/TwigBase/Controller/Controller.php', 'Combodo\\iTop\\Application\\TwigBase\\Twig\\Extension' => __DIR__ . '/../..' . '/sources/application/TwigBase/Twig/Extension.php', 'Combodo\\iTop\\Application\\TwigBase\\Twig\\TwigHelper' => __DIR__ . '/../..' . '/sources/application/TwigBase/Twig/TwigHelper.php', + 'Combodo\\iTop\\Application\\TwigBase\\UI\\Component\\UIAlertNode' => __DIR__ . '/../..' . '/sources/application/TwigBase/UI/Component/Alert/UIAlertNode.php', + 'Combodo\\iTop\\Application\\TwigBase\\UI\\Component\\UIAlertParser' => __DIR__ . '/../..' . '/sources/application/TwigBase/UI/Component/Alert/UIAlertParser.php', 'Combodo\\iTop\\Application\\TwigBase\\UI\\Component\\UIContentBlockNode' => __DIR__ . '/../..' . '/sources/application/TwigBase/UI/Layout/UIContentBlockNode.php', 'Combodo\\iTop\\Application\\TwigBase\\UI\\Component\\UIContentBlockParser' => __DIR__ . '/../..' . '/sources/application/TwigBase/UI/Layout/UIContentBlockParser.php', 'Combodo\\iTop\\Application\\TwigBase\\UI\\Component\\UIFieldNode' => __DIR__ . '/../..' . '/sources/application/TwigBase/UI/Component/Field/UIFieldNode.php', @@ -389,6 +391,8 @@ class ComposerStaticInit0018331147de7601e7552f7da8e3bb8b 'Combodo\\iTop\\Application\\TwigBase\\UI\\Component\\UIFieldSetParser' => __DIR__ . '/../..' . '/sources/application/TwigBase/UI/Component/FieldSet/UIFieldSetParser.php', 'Combodo\\iTop\\Application\\TwigBase\\UI\\Component\\UIHtmlNode' => __DIR__ . '/../..' . '/sources/application/TwigBase/UI/Component/Html/UIHtmlNode.php', 'Combodo\\iTop\\Application\\TwigBase\\UI\\Component\\UIHtmlParser' => __DIR__ . '/../..' . '/sources/application/TwigBase/UI/Component/Html/UIHtmlParser.php', + 'Combodo\\iTop\\Application\\TwigBase\\UI\\Component\\UITitleNode' => __DIR__ . '/../..' . '/sources/application/TwigBase/UI/Component/Title/UITitleNode.php', + 'Combodo\\iTop\\Application\\TwigBase\\UI\\Component\\UITitleParser' => __DIR__ . '/../..' . '/sources/application/TwigBase/UI/Component/Title/UITitleParser.php', 'Combodo\\iTop\\Application\\TwigBase\\UI\\UIBlockExtension' => __DIR__ . '/../..' . '/sources/application/TwigBase/UI/UIBlockExtension.php', 'Combodo\\iTop\\Application\\TwigBase\\UI\\UIBlockHelper' => __DIR__ . '/../..' . '/sources/application/TwigBase/UI/UIBlockHelper.php', 'Combodo\\iTop\\Application\\UI\\Base\\Component\\Alert\\Alert' => __DIR__ . '/../..' . '/sources/application/UI/Base/Component/Alert/Alert.php', diff --git a/sources/application/TwigBase/UI/Component/Alert/UIAlertNode.php b/sources/application/TwigBase/UI/Component/Alert/UIAlertNode.php new file mode 100644 index 000000000..5aec163ca --- /dev/null +++ b/sources/application/TwigBase/UI/Component/Alert/UIAlertNode.php @@ -0,0 +1,61 @@ + $oBody], ['type' => $sType, 'params' => $oParams], $lineno, $tag); + } + + public function compile(Compiler $compiler) + { + $sBlockVar = UIBlockHelper::GetBlockVarName('oFieldSet'); + $oParams = $this->getAttribute('params'); + $compiler + ->addDebugInfo($this) + ->write("\$aParams = ") + ->subcompile($oParams) + ->raw(";\n") + ->write("\$sTitle = \$aParams['title'] ?? '';\n") + ->write("\$sId = \$aParams['id'] ?? null;\n") + ->write("ob_start();\n") + ->subcompile($this->getNode('body')) + ->write("\$sContent = ob_get_contents();\n") + ->write("ob_end_clean();\n"); + + $sType = $this->getAttribute('type'); + switch ($sType) { + case 'ForInformation': + case 'Neutral': + case 'ForSuccess': + case 'ForWarning': + case 'ForDanger': + case 'ForFailure': + case 'WithBrandingPrimaryColor': + case 'WithBrandingSecondaryColor': + $compiler + ->write("\${$sBlockVar} = Combodo\\iTop\\Application\\UI\\Base\\Component\\Alert\\AlertFactory::Make{$sType}(\$sTitle, \$sContent, \$sId);\n"); + break; + // TODO 3.0 add other Factory methods + + default: + throw new SyntaxError(sprintf('%s: Bad type "%s" for %s at line %d', $this->getTemplateName(), $sType, $this->tag, $this->lineno), $this->lineno, $this->getSourceContext()); + + } + $compiler->write(UIBlockHelper::AddToParentBlock($sBlockVar)); + + } +} diff --git a/sources/application/TwigBase/UI/Component/Alert/UIAlertParser.php b/sources/application/TwigBase/UI/Component/Alert/UIAlertParser.php new file mode 100644 index 000000000..b2fed3bf1 --- /dev/null +++ b/sources/application/TwigBase/UI/Component/Alert/UIAlertParser.php @@ -0,0 +1,50 @@ +getLine(); + $oStream = $this->parser->getStream(); + + $sType = $oStream->expect(Token::NAME_TYPE)->getValue(); + + $oParams = $this->parser->getExpressionParser()->parseExpression(); + + $oStream->expect(Token::BLOCK_END_TYPE); + + $oBody = $this->parser->subparse([$this, 'decideForEnd'], true); + $oStream->expect(Token::BLOCK_END_TYPE); + + + return new UIAlertNode($sType, $oParams, $oBody, $iLineno, $this->getTag()); + } + + /** + * @inheritDoc + */ + public function getTag() + { + return 'UIAlert'; + } + + public function decideForEnd(Token $token) + { + return $token->test('EndUIAlert'); + } +} \ No newline at end of file diff --git a/sources/application/TwigBase/UI/Component/Field/UIFieldNode.php b/sources/application/TwigBase/UI/Component/Field/UIFieldNode.php index 0775cf1d0..c1dbb2a3b 100644 --- a/sources/application/TwigBase/UI/Component/Field/UIFieldNode.php +++ b/sources/application/TwigBase/UI/Component/Field/UIFieldNode.php @@ -44,7 +44,7 @@ class UIFieldNode extends Node ->write("\${$sBlockVar} = Combodo\\iTop\\Application\\UI\\Base\\Component\\Field\\FieldFactory::Make{$sType}(\$sLabel, \$sValue);\n") ->write("\${$sBlockVar}->SetValueId(\$sValueId);\n"); break; - // TODO 3.0 add other FieldFactory methods + // TODO 3.0 add other Factory methods default: throw new SyntaxError(sprintf('%s: Bad type "%s" for %s at line %d', $this->getTemplateName(), $sType, $this->tag, $this->lineno), $this->lineno, $this->getSourceContext()); diff --git a/sources/application/TwigBase/UI/Component/Title/UITitleNode.php b/sources/application/TwigBase/UI/Component/Title/UITitleNode.php new file mode 100644 index 000000000..1b52afb19 --- /dev/null +++ b/sources/application/TwigBase/UI/Component/Title/UITitleNode.php @@ -0,0 +1,50 @@ + $sType, 'params' => $oParams], $lineno, $tag); + } + + public function compile(Compiler $compiler) + { + $sBlockVar = UIBlockHelper::GetBlockVarName('oFieldSet'); + $oParams = $this->getAttribute('params'); + $compiler + ->addDebugInfo($this) + ->write("\$aParams = ") + ->subcompile($oParams) + ->raw(";\n"); + + $sType = $this->getAttribute('type'); + switch ($sType) { + case 'ForPage': + $compiler + ->write("\$sTitle = \$aParams['title'] ?? '';\n") + ->write("\$sId = \$aParams['id'] ?? null;\n") + ->write("\${$sBlockVar} = Combodo\\iTop\\Application\\UI\\Base\\Component\\Title\\TitleFactory::Make{$sType}(\$sTitle, \$sId);\n"); + break; + // TODO 3.0 add other Factory methods + + default: + throw new SyntaxError(sprintf('%s: Bad type "%s" for %s at line %d', $this->getTemplateName(), $sType, $this->tag, $this->lineno), $this->lineno, $this->getSourceContext()); + + } + $compiler->write(UIBlockHelper::AddToParentBlock($sBlockVar)); + + } +} diff --git a/sources/application/TwigBase/UI/Component/Title/UITitleParser.php b/sources/application/TwigBase/UI/Component/Title/UITitleParser.php new file mode 100644 index 000000000..921cd59c7 --- /dev/null +++ b/sources/application/TwigBase/UI/Component/Title/UITitleParser.php @@ -0,0 +1,41 @@ +getLine(); + $oStream = $this->parser->getStream(); + + $sType = $oStream->expect(Token::NAME_TYPE)->getValue(); + + $oParams = $this->parser->getExpressionParser()->parseExpression(); + + $oStream->expect(Token::BLOCK_END_TYPE); + + return new UITitleNode($sType, $oParams, $iLineno, $this->getTag()); + } + + /** + * @inheritDoc + */ + public function getTag() + { + return 'UITitle'; + } +} \ No newline at end of file diff --git a/sources/application/TwigBase/UI/UIBlockExtension.php b/sources/application/TwigBase/UI/UIBlockExtension.php index a654f164d..af0923c9b 100644 --- a/sources/application/TwigBase/UI/UIBlockExtension.php +++ b/sources/application/TwigBase/UI/UIBlockExtension.php @@ -8,10 +8,12 @@ namespace Combodo\iTop\Application\TwigBase\UI; +use Combodo\iTop\Application\TwigBase\UI\Component\UIAlertParser; use Combodo\iTop\Application\TwigBase\UI\Component\UIContentBlockParser; use Combodo\iTop\Application\TwigBase\UI\Component\UIFieldParser; use Combodo\iTop\Application\TwigBase\UI\Component\UIFieldSetParser; use Combodo\iTop\Application\TwigBase\UI\Component\UIHtmlParser; +use Combodo\iTop\Application\TwigBase\UI\Component\UITitleParser; use Twig\Extension\AbstractExtension; class UIBlockExtension extends AbstractExtension @@ -23,6 +25,8 @@ class UIBlockExtension extends AbstractExtension new UIContentBlockParser(), new UIFieldSetParser(), new UIFieldParser(), + new UIAlertParser(), + new UITitleParser(), ]; } } \ No newline at end of file diff --git a/sources/application/UI/Base/Component/Alert/AlertFactory.php b/sources/application/UI/Base/Component/Alert/AlertFactory.php index 1c0e95f6b..25eeece29 100644 --- a/sources/application/UI/Base/Component/Alert/AlertFactory.php +++ b/sources/application/UI/Base/Component/Alert/AlertFactory.php @@ -35,12 +35,13 @@ class AlertFactory * * @param string $sTitle * @param string $sContent The raw HTML content, must be already sanitized + * @param string|null $sId * * @return \Combodo\iTop\Application\UI\Base\Component\Alert\Alert */ - public static function MakeNeutral(string $sTitle, string $sContent) + public static function MakeNeutral(string $sTitle, string $sContent, ?string $sId = null) { - return new Alert($sTitle, $sContent, Alert::ENUM_COLOR_NEUTRAL); + return new Alert($sTitle, $sContent, Alert::ENUM_COLOR_NEUTRAL, $sId); } /** @@ -63,12 +64,13 @@ class AlertFactory * * @param string $sTitle * @param string $sContent The raw HTML content, must be already sanitized + * @param string|null $sId * * @return \Combodo\iTop\Application\UI\Base\Component\Alert\Alert */ - public static function MakeForSuccess(string $sTitle, string $sContent) + public static function MakeForSuccess(string $sTitle, string $sContent, ?string $sId = null) { - return new Alert($sTitle, $sContent, Alert::ENUM_COLOR_SUCCESS); + return new Alert($sTitle, $sContent, Alert::ENUM_COLOR_SUCCESS, $sId); } /** @@ -76,12 +78,13 @@ class AlertFactory * * @param string $sTitle * @param string $sContent The raw HTML content, must be already sanitized + * @param string|null $sId * * @return \Combodo\iTop\Application\UI\Base\Component\Alert\Alert */ - public static function MakeForWarning(string $sTitle, string $sContent) + public static function MakeForWarning(string $sTitle, string $sContent, ?string $sId = null) { - return new Alert($sTitle, $sContent, Alert::ENUM_COLOR_WARNING); + return new Alert($sTitle, $sContent, Alert::ENUM_COLOR_WARNING, $sId); } /** @@ -89,12 +92,13 @@ class AlertFactory * * @param string $sTitle * @param string $sContent The raw HTML content, must be already sanitized + * @param string|null $sId * * @return \Combodo\iTop\Application\UI\Base\Component\Alert\Alert */ - public static function MakeForDanger(string $sTitle, string $sContent) + public static function MakeForDanger(string $sTitle, string $sContent, ?string $sId = null) { - return new Alert($sTitle, $sContent, Alert::ENUM_COLOR_DANGER); + return new Alert($sTitle, $sContent, Alert::ENUM_COLOR_DANGER, $sId); } /** @@ -102,12 +106,13 @@ class AlertFactory * * @param string $sTitle * @param string $sContent The raw HTML content, must be already sanitized + * @param string|null $sId * * @return \Combodo\iTop\Application\UI\Base\Component\Alert\Alert */ - public static function MakeForFailure(string $sTitle, string $sContent) + public static function MakeForFailure(string $sTitle, string $sContent, ?string $sId = null) { - return new Alert($sTitle, $sContent, Alert::ENUM_COLOR_FAILURE); + return new Alert($sTitle, $sContent, Alert::ENUM_COLOR_FAILURE, $sId); } /** @@ -115,12 +120,13 @@ class AlertFactory * * @param string $sTitle * @param string $sContent The raw HTML content, must be already sanitized + * @param string|null $sId * * @return \Combodo\iTop\Application\UI\Base\Component\Alert\Alert */ - public static function MakeWithBrandingPrimaryColor(string $sTitle, string $sContent) + public static function MakeWithBrandingPrimaryColor(string $sTitle, string $sContent, ?string $sId = null) { - return new Alert($sTitle, $sContent, Alert::ENUM_COLOR_PRIMARY); + return new Alert($sTitle, $sContent, Alert::ENUM_COLOR_PRIMARY, $sId); } /** @@ -128,11 +134,12 @@ class AlertFactory * * @param string $sTitle * @param string $sContent The raw HTML content, must be already sanitized + * @param string|null $sId * * @return \Combodo\iTop\Application\UI\Base\Component\Alert\Alert */ - public static function MakeWithBrandingSecondaryColor(string $sTitle, string $sContent) + public static function MakeWithBrandingSecondaryColor(string $sTitle, string $sContent, ?string $sId = null) { - return new Alert($sTitle, $sContent, Alert::ENUM_COLOR_SECONDARY); + return new Alert($sTitle, $sContent, Alert::ENUM_COLOR_SECONDARY, $sId); } } \ No newline at end of file