Add UIBlocks to twig (changed UIContentBlock params)

This commit is contained in:
Eric
2021-01-14 09:29:12 +01:00
parent bffb7b5eab
commit e51fd028fa
5 changed files with 95 additions and 19 deletions

View File

@@ -2,7 +2,7 @@
{# @license http://opensource.org/licenses/AGPL-3.0 #}
{% apply spaceless %}
{% UIContentBlock "" "ibo-update-core" %}
{% UIContentBlock {'container_class':'ibo-update-core'} %}
{% UITitle ForPage {'title':'iTopUpdate:UI:PageTitle'|dict_s} %}
@@ -10,7 +10,7 @@
<div class="ibo-v-spacer">&nbsp;</div>
{% EndUIHtml %}
{% UIContentBlock "" "display_block display-files" %}
{% UIContentBlock {'container_class':'display_block display-files'} %}
{% UIFieldSet {'legend':'iTopUpdate:UI:Status'|dict_s} %}
{% UIAlert ForInformation {'title':'', 'id':'header-requirements'} %}
@@ -38,6 +38,83 @@
{% EndUIFieldSet %}
{% EndUIContentBlock %}
{% UIContentBlock {'container_class':'display_block display-files'} %}
{% UIFieldSet {'legend':'iTopUpdate:UI:SelectUpdateFile'|dict_s} %}
{# <form enctype="multipart/form-data" method="post"> #}
{# <input type="hidden" name="operation" value="ConfirmUpdate"/> #}
{# <input type="hidden" name="transaction_id" value="{{ sTransactionId }}"> #}
{# <div id="header-file-size" class="header_message message_error" style="display: none"> #}
{# <div> #}
{# <span>{{ 'iTopUpdate:Error:FileUploadMaxSizeTooSmall'|dict_s }}</span> #}
{# </div> #}
{# <div> #}
{# <span>{{ 'iTopUpdate:UI:PostMaxSize'|dict_format(sPostMaxSize) }}</span> #}
{# </div> #}
{# <div> #}
{# <span>{{ 'iTopUpdate:UI:UploadMaxFileSize'|dict_format(sUploadMaxSize) }}</span> #}
{# </div> #}
{# </div> #}
{# <div class="field_container field_large"> #}
{# <div class="field_data"> #}
{# <div class="upload_container"> #}
{# <input type="file" id="file" name="file"/> #}
{# </div> #}
{# </div> #}
{# <div id="dobackup-warning" class="header_message message_info" style="display: none">{{ 'iTopUpdate:UI:DoBackup:Warning'|dict_s }}</div> #}
{# <div class="field_data"> #}
{# <label id="dobackup-label" for="doBackup">{{ 'iTopUpdate:UI:DoBackup:Label'|dict_s }}</label> #}
{# <input type="checkbox" id="doBackup" name="doBackup" checked="checked" value="1"/> #}
{# </div> #}
{# <div class="field_data"> #}
{# <label id="dofilesarchive-label" for="doFilesArchive">{{ 'iTopUpdate:UI:DoFilesArchive'|dict_s }}</label> #}
{# <input type="checkbox" id="doFilesArchive" name="doFilesArchive" checked="checked" value="1"/> #}
{# </div> #}
{# </div> #}
{# <p><input id="check-update" type="submit" value="{{ 'iTopUpdate:UI:CheckUpdate'|dict_s }}" disabled="disabled"/> <i id="submit-wait" style="display: none" class="fas fa-spinner fa-spin" aria-hidden="true"></i></p> #}
{# </form> #}
{% EndUIFieldSet %}
{% EndUIContentBlock %}
{% UIContentBlock {'container_class':'display_block display-files'} %}
{% UIFieldSet {'legend':'iTopUpdate:UI:History'|dict_s} %}
{# <div class="details"> #}
{# {% for aInstall in aPreviousInstall %} #}
{# {% if loop.first %} #}
{# <table class="listResults ibo-datatable"> #}
{# <tr> #}
{# <th>{{ 'Class:ModuleInstallation/Attribute:name'|dict_s }}</th> #}
{# <th>{{ 'Class:ModuleInstallation/Attribute:version'|dict_s }}</th> #}
{# <th>{{ 'Class:ModuleInstallation/Attribute:installed'|dict_s }}</th> #}
{# <th>{{ 'Class:ModuleInstallation/Attribute:comment'|dict_s }}</th> #}
{# </tr> #}
{# {% endif %} #}
{# {% if (loop.index0 % 2) == 0 %} #}
{# {% set sRowClass = "odd" %} #}
{# {% else %} #}
{# {% set sRowClass = "even" %} #}
{# {% endif %} #}
{# <tr class="{{ sRowClass }}"> #}
{# <td>{{ aInstall.name }}</td> #}
{# <td>{{ aInstall.version }}</td> #}
{# <td>{{ aInstall.installed }}</td> #}
{# <td>{{ aInstall.comment }}</td> #}
{# </tr> #}
{# {% if loop.last %} #}
{# </table> #}
{# {% endif %} #}
{# {% endfor %} #}
{# </div> #}
{% EndUIFieldSet %}
{% EndUIContentBlock %}
{% EndUIContentBlock %}
{# <div class="page_header"><h1 class="ibo-title--text title is-size-3">{{ 'iTopUpdate:UI:PageTitle'|dict_s }}</h1></div> #}

View File

@@ -29,8 +29,8 @@ class UIFieldSetNode extends Node
->subcompile($oParams)
->raw(";\n")
->write("\$sLegend = \$aParams['legend'] ?? '';\n")
->write("\$sName = \$aParams['value'] ?? null;\n")
->write("\${$sBlockVar} = new Combodo\\iTop\\Application\\UI\\Base\\Component\\FieldSet\\FieldSet(\$sLegend, \$sName);\n")
->write("\$sId = \$aParams['id'] ?? null;\n")
->write("\${$sBlockVar} = new Combodo\\iTop\\Application\\UI\\Base\\Component\\FieldSet\\FieldSet(\$sLegend, \$sId);\n")
->write(UIBlockHelper::AddToParentBlock($sBlockVar))
->write(UIBlockHelper::PushParentBlock($sBlockVar))
->subcompile($this->getNode('body'))

View File

@@ -14,19 +14,24 @@ use Twig\Node\Node;
class UIContentBlockNode extends Node
{
public function __construct($sName, $sContainerClass, $oBody, $lineno = 0, $tag = null)
public function __construct($oParams, $oBody, $lineno = 0, $tag = null)
{
parent::__construct(['body' => $oBody], ['name' => $sName, 'container_class' => $sContainerClass], $lineno, $tag);
parent::__construct(['body' => $oBody], ['params' => $oParams], $lineno, $tag);
}
public function compile(Compiler $compiler)
{
$sBlockVar = UIBlockHelper::GetBlockVarName('oContentBlock');
$sName = empty($this->getAttribute('name')) ? 'null' : "'".$this->getAttribute('name')."'";
$sContainerClass = $this->getAttribute('container_class');
$oParams = $this->getAttribute('params');
$compiler
->addDebugInfo($this)
->write("\${$sBlockVar} = new Combodo\\iTop\\Application\\UI\\Base\\Layout\\UIContentBlock({$sName}, '{$sContainerClass}');\n")
->write("\$aParams = ")
->subcompile($oParams)
->raw(";\n")
->write("\$sId = \$aParams['id'] ?? null;\n")
->write("\$sContainerClass = \$aParams['container_class'] ?? '';\n")
->write("\${$sBlockVar} = new Combodo\\iTop\\Application\\UI\\Base\\Layout\\UIContentBlock(\$sId, \$sContainerClass);\n")
->write(UIBlockHelper::AddToParentBlock($sBlockVar))
->write(UIBlockHelper::PushParentBlock($sBlockVar))
->subcompile($this->getNode('body'))

View File

@@ -22,20 +22,14 @@ class UIContentBlockParser extends AbstractTokenParser
$iLineno = $token->getLine();
$oStream = $this->parser->getStream();
$sName = null;
if ($oStream->test(Token::STRING_TYPE)) {
$sName = $oStream->expect(Token::STRING_TYPE)->getValue();
}
$sContainerClass = '';
if ($oStream->test(Token::STRING_TYPE)) {
$sContainerClass = $oStream->expect(Token::STRING_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 UIContentBlockNode($sName, $sContainerClass, $oBody, $iLineno, $this->getTag());
return new UIContentBlockNode($oParams, $oBody, $iLineno, $this->getTag());
}
/**

View File

@@ -12,7 +12,7 @@ class UIBlockHelper
{
public static function PushParentBlock($sBlockVarName)
{
return "\$context['UIBlockParent'][] = \${$sBlockVarName};\n";
return "array_push(\$context['UIBlockParent'], \${$sBlockVarName});\n";
}
public static function PopParentBlock()