Add UIBlocks to twig (DataTable, Form, Input)

This commit is contained in:
Eric
2021-01-14 13:14:05 +01:00
parent e51fd028fa
commit d8316a090a
21 changed files with 434 additions and 212 deletions

View File

@@ -9,6 +9,8 @@ namespace Combodo\iTop\CoreUpdate\Controller;
use Combodo\iTop\Application\TwigBase\Controller\Controller;
use Combodo\iTop\CoreUpdate\Service\CoreUpdater;
use Combodo\iTop\DBTools\Service\DBToolsUtils;
use DBObjectSearch;
use DBObjectSet;
use Dict;
use Exception;
use SetupUtils;
@@ -16,21 +18,24 @@ use utils;
class UpdateController extends Controller
{
public function OperationSelectUpdateFile()
public function OperationSelectUpdateFile()
{
$sTransactionId = utils::GetNewTransactionId();
$aParams = array();
$aParams = [];
$aParams['sTransactionId'] = $sTransactionId;
$aParams['aPreviousInstall'] = $this->GetPreviousInstallations();
$aParams['sAjaxURL'] = utils::GetAbsoluteUrlModulePage('itop-core-update', 'ajax.php', array('maintenance' => 'true'));
$aParams['iDiskFreeSpace'] = disk_free_space(APPROOT);
$aParams['sDiskFreeSpace'] = utils::BytesToFriendlyFormat($aParams['iDiskFreeSpace']);
//$aParams['aPreviousInstall'] = $this->GetPreviousInstallations();
$aParams['sAjaxURL'] = utils::GetAbsoluteUrlModulePage('itop-core-update', 'ajax.php', array('maintenance' => 'true'));
$aParams['iDiskFreeSpace'] = disk_free_space(APPROOT);
$aParams['sDiskFreeSpace'] = utils::BytesToFriendlyFormat($aParams['iDiskFreeSpace']);
$aParams['iFileUploadMaxSize'] = $this->GetFileUploadMaxSize();
$aParams['sFileUploadMaxSize'] = utils::BytesToFriendlyFormat($aParams['iFileUploadMaxSize']);
$aParams['sPostMaxSize'] = ini_get('post_max_size');
$aParams['sUploadMaxSize'] = ini_get('upload_max_filesize');
$oFilter = DBObjectSearch::FromOQL('SELECT ModuleInstallation WHERE parent_id=0 AND name!="datamodel"');
$oSet = new DBObjectSet($oFilter, ['installed' => false]); // Most recent first
$aParams['oSet'] = $oSet;
$this->DisplayPage($aParams);
$this->DisplayPage($aParams);
}
/**

View File

@@ -36,203 +36,54 @@
{% EndUIField %}
{% 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 }}"> #}
{% UIForm {} %}
{% UIInput ForHidden {'name':'operation', 'value':'ConfirmUpdate'} %}
{% UIInput ForHidden {'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> #}
{% UIHtml %}
<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>
{% EndUIHtml %}
{# <div class="field_container field_large"> #}
{# <div class="field_data"> #}
{# <div class="upload_container"> #}
{# <input type="file" id="file" name="file"/> #}
{# </div> #}
{# </div> #}
{% UIContentBlock {'container_class':'upload_container'} %}
{% UIInput WithLabel {'type':'file', 'id':'file', 'name':'file'} %}
{% EndUIContentBlock %}
{% UIHtml %}
<div id="dobackup-warning" class="header_message message_info" style="display: none">{{ 'iTopUpdate:UI:DoBackup:Warning'|dict_s }}</div>
{% EndUIHtml %}
{% UIField Large {'label':'iTopUpdate:UI:DoBackup:Label'|dict_s} %}
{% UIInput Standard {'type':'checkbox', 'id':'doBackup', 'name':'doBackup', 'value':'1', 'checked':true} %}
{% EndUIField %}
{% UIField Large {'label':'iTopUpdate:UI:DoFilesArchive'|dict_s} %}
{% UIInput Standard {'type':'checkbox', 'id':'doFilesArchive', 'name':'doFilesArchive', 'value':'1', 'checked':true} %}
{% EndUIField %}
{# <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> #}
{% EndUIForm %}
{% 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> #}
{% UIDataTable ForResult {'list_id':'iboupdatehistory', 'object_set':oSet} %}
{% EndUIFieldSet %}
{% EndUIContentBlock %}
{% EndUIContentBlock %}
{# <div class="page_header"><h1 class="ibo-title--text title is-size-3">{{ 'iTopUpdate:UI:PageTitle'|dict_s }}</h1></div> #}
{# <div class="ibo-v-spacer">&nbsp;</div> #}
{# <div class="display_block display-files"> #}
{# <fieldset class="ibo-fieldset"> #}
{# <legend class="ibo-fieldset-legend">{{ 'iTopUpdate:UI:Status'|dict_s }}</legend> #}
{# <div id="header-requirements" class="ibo-alert ibo-is-information ibo-is-opened"> #}
{# <div class="ibo-alert--body"> #}
{# <span id="can-core-update">{{ 'iTopUpdate:UI:CanCoreUpdate:Loading'|dict_s }} <i class="ajax-spin fas fa-spinner fa-spin" aria-hidden="true"></i></span> #}
{# </div> #}
{# </div> #}
{# {{ include('DisplayCurrentVersion.html.twig') }} #}
{# <div class="ibo-field ibo-field-small" data-role="ibo-field"> #}
{# <div class="ibo-field--label"><span title="">{{ 'iTopUpdate:UI:DiskFreeSpace'|dict_s }}</span></div> #}
{# <div class="ibo-field--value"> #}
{# <div class="field_value">{{ sDiskFreeSpace }}</div> #}
{# </div> #}
{# </div> #}
{# <div class="ibo-field ibo-field-small" data-role="ibo-field"> #}
{# <div class="ibo-field--label"><span title="">{{ 'iTopUpdate:UI:ItopDiskSpace'|dict_s }}</span></div> #}
{# <div class="ibo-field--value"> #}
{# <div id="itop-disk-space" class="field_value"><i class="ajax-spin fas fa-spinner fa-spin" aria-hidden="true"></i></div> #}
{# </div> #}
{# </div> #}
{# <div class="ibo-field ibo-field-small" data-role="ibo-field"> #}
{# <div class="ibo-field--label"><span title="">{{ 'iTopUpdate:UI:DBDiskSpace'|dict_s }}</span></div> #}
{# <div id="db-disk-space" class="ibo-field--value"><i class="ajax-spin fas fa-spinner fa-spin" aria-hidden="true"></i></div> #}
{# </div> #}
{# <div class="ibo-field ibo-field-small" data-role="ibo-field"> #}
{# <div class="ibo-field--label"><span title="">{{ 'iTopUpdate:UI:FileUploadMaxSize'|dict_s }}</span></div> #}
{# <div class="ibo-field--value">{{ sFileUploadMaxSize }}</div> #}
{# </div> #}
{# </fieldset> #}
{# <fieldset class="ibo-fieldset"> #}
{# <legend class="ibo-fieldset-legend">{{ 'iTopUpdate:UI:SelectUpdateFile'|dict_s }}</legend> #}
{# <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> #}
{# </fieldset> #}
{# <fieldset class="ibo-fieldset"> #}
{# <legend class="ibo-fieldset-legend">{{ 'iTopUpdate:UI:History'|dict_s }}</legend> #}
{# <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> #}
{# </fieldset> #}
{# </div> #}
{% endapply %}

View File

@@ -155,12 +155,18 @@ return array(
'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\\UIDataTableNode' => $baseDir . '/sources/application/TwigBase/UI/Component/DataTable/UIDataTableNode.php',
'Combodo\\iTop\\Application\\TwigBase\\UI\\Component\\UIDataTableParser' => $baseDir . '/sources/application/TwigBase/UI/Component/DataTable/UIDataTableParser.php',
'Combodo\\iTop\\Application\\TwigBase\\UI\\Component\\UIFieldNode' => $baseDir . '/sources/application/TwigBase/UI/Component/Field/UIFieldNode.php',
'Combodo\\iTop\\Application\\TwigBase\\UI\\Component\\UIFieldParser' => $baseDir . '/sources/application/TwigBase/UI/Component/Field/UIFieldParser.php',
'Combodo\\iTop\\Application\\TwigBase\\UI\\Component\\UIFieldSetNode' => $baseDir . '/sources/application/TwigBase/UI/Component/FieldSet/UIFieldSetNode.php',
'Combodo\\iTop\\Application\\TwigBase\\UI\\Component\\UIFieldSetParser' => $baseDir . '/sources/application/TwigBase/UI/Component/FieldSet/UIFieldSetParser.php',
'Combodo\\iTop\\Application\\TwigBase\\UI\\Component\\UIFormNode' => $baseDir . '/sources/application/TwigBase/UI/Component/Form/UIFormNode.php',
'Combodo\\iTop\\Application\\TwigBase\\UI\\Component\\UIFormParser' => $baseDir . '/sources/application/TwigBase/UI/Component/Form/UIFormParser.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\\UIInputNode' => $baseDir . '/sources/application/TwigBase/UI/Component/Input/UIInputNode.php',
'Combodo\\iTop\\Application\\TwigBase\\UI\\Component\\UIInputParser' => $baseDir . '/sources/application/TwigBase/UI/Component/Input/UIInputParser.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',

View File

@@ -385,12 +385,18 @@ class ComposerStaticInit0018331147de7601e7552f7da8e3bb8b
'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\\UIDataTableNode' => __DIR__ . '/../..' . '/sources/application/TwigBase/UI/Component/DataTable/UIDataTableNode.php',
'Combodo\\iTop\\Application\\TwigBase\\UI\\Component\\UIDataTableParser' => __DIR__ . '/../..' . '/sources/application/TwigBase/UI/Component/DataTable/UIDataTableParser.php',
'Combodo\\iTop\\Application\\TwigBase\\UI\\Component\\UIFieldNode' => __DIR__ . '/../..' . '/sources/application/TwigBase/UI/Component/Field/UIFieldNode.php',
'Combodo\\iTop\\Application\\TwigBase\\UI\\Component\\UIFieldParser' => __DIR__ . '/../..' . '/sources/application/TwigBase/UI/Component/Field/UIFieldParser.php',
'Combodo\\iTop\\Application\\TwigBase\\UI\\Component\\UIFieldSetNode' => __DIR__ . '/../..' . '/sources/application/TwigBase/UI/Component/FieldSet/UIFieldSetNode.php',
'Combodo\\iTop\\Application\\TwigBase\\UI\\Component\\UIFieldSetParser' => __DIR__ . '/../..' . '/sources/application/TwigBase/UI/Component/FieldSet/UIFieldSetParser.php',
'Combodo\\iTop\\Application\\TwigBase\\UI\\Component\\UIFormNode' => __DIR__ . '/../..' . '/sources/application/TwigBase/UI/Component/Form/UIFormNode.php',
'Combodo\\iTop\\Application\\TwigBase\\UI\\Component\\UIFormParser' => __DIR__ . '/../..' . '/sources/application/TwigBase/UI/Component/Form/UIFormParser.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\\UIInputNode' => __DIR__ . '/../..' . '/sources/application/TwigBase/UI/Component/Input/UIInputNode.php',
'Combodo\\iTop\\Application\\TwigBase\\UI\\Component\\UIInputParser' => __DIR__ . '/../..' . '/sources/application/TwigBase/UI/Component/Input/UIInputParser.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',

View File

@@ -42,16 +42,16 @@ class ModuleInstallation extends cmdbAbstractObject
);
MetaModel::Init_Params($aParams);
//MetaModel::Init_InheritAttributes();
MetaModel::Init_AddAttribute(new AttributeString("name", array("allowed_values"=>null, "sql"=>"name", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
MetaModel::Init_AddAttribute(new AttributeString("version", array("allowed_values"=>null, "sql"=>"version", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
MetaModel::Init_AddAttribute(new AttributeDateTime("installed", array("allowed_values"=>null, "sql"=>"installed", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
MetaModel::Init_AddAttribute(new AttributeText("comment", array("allowed_values"=>null, "sql"=>"comment", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
MetaModel::Init_AddAttribute(new AttributeExternalKey("parent_id", array("targetclass"=>"ModuleInstallation", "jointype"=> "", "allowed_values"=>null, "sql"=>"parent_id", "is_null_allowed"=>true, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array())));
MetaModel::Init_AddAttribute(new AttributeString("name", array("allowed_values" => null, "sql" => "name", "default_value" => null, "is_null_allowed" => false, "depends_on" => array())));
MetaModel::Init_AddAttribute(new AttributeString("version", array("allowed_values" => null, "sql" => "version", "default_value" => null, "is_null_allowed" => true, "depends_on" => array())));
MetaModel::Init_AddAttribute(new AttributeDateTime("installed", array("allowed_values" => null, "sql" => "installed", "default_value" => null, "is_null_allowed" => true, "depends_on" => array())));
MetaModel::Init_AddAttribute(new AttributeText("comment", array("allowed_values" => null, "sql" => "comment", "default_value" => null, "is_null_allowed" => true, "depends_on" => array())));
MetaModel::Init_AddAttribute(new AttributeExternalKey("parent_id", array("targetclass" => "ModuleInstallation", "jointype" => "", "allowed_values" => null, "sql" => "parent_id", "is_null_allowed" => true, "on_target_delete" => DEL_MANUAL, "depends_on" => array())));
// Display lists
MetaModel::Init_SetZListItems('details', array('name', 'version', 'installed', 'comment', 'parent_id')); // Attributes to be displayed for the complete details
MetaModel::Init_SetZListItems('list', array('name', 'version', 'installed', 'parent_id')); // Attributes to be displayed for a list
MetaModel::Init_SetZListItems('list', array('name', 'version', 'installed', 'comment')); // Attributes to be displayed for a list
// Search criteria
// MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
// MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form

View File

@@ -22,7 +22,7 @@ class UIAlertNode extends Node
public function compile(Compiler $compiler)
{
$sBlockVar = UIBlockHelper::GetBlockVarName('oFieldSet');
$sBlockVar = UIBlockHelper::GetBlockVarName('oAlert');
$oParams = $this->getAttribute('params');
$compiler
->addDebugInfo($this)

View File

@@ -0,0 +1,48 @@
<?php
/**
* @copyright Copyright (C) 2010-2021 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\TwigBase\UI\Component;
use Combodo\iTop\Application\TwigBase\UI\UIBlockHelper;
use Twig\Compiler;
use Twig\Error\SyntaxError;
use Twig\Node\Node;
class UIDataTableNode extends Node
{
public function __construct($sType, $oParams, $lineno = 0, $tag = null)
{
parent::__construct([], ['type' => $sType, 'params' => $oParams], $lineno, $tag);
}
public function compile(Compiler $compiler)
{
$sBlockVar = UIBlockHelper::GetBlockVarName('oDataTable');
$oParams = $this->getAttribute('params');
$sType = $this->getAttribute('type');
$compiler
->addDebugInfo($this)
->write("\$aParams = ")
->subcompile($oParams)
->raw(";\n");
switch ($sType) {
case 'ForResult':
$compiler
->write("\$sListId = \$aParams['list_id'] ?? '';\n")
->write("\$oSet = \$aParams['object_set'] ?? null;\n")
->write("\${$sBlockVar} = Combodo\\iTop\\Application\\UI\\Base\\Component\\DataTable\\DataTableFactory::Make{$sType}(\$context['UIBlockParent'][0], \$sListId, \$oSet);\n")
->write(UIBlockHelper::AddToParentBlock($sBlockVar));
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());
}
}
}

View File

@@ -0,0 +1,41 @@
<?php
/**
* @copyright Copyright (C) 2010-2021 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\TwigBase\UI\Component;
use Twig\Token;
use Twig\TokenParser\AbstractTokenParser;
class UIDataTableParser extends AbstractTokenParser
{
/**
* @inheritDoc
*/
public function parse(Token $token)
{
$iLineno = $token->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 UIDataTableNode($sType, $oParams, $iLineno, $this->getTag());
}
/**
* @inheritDoc
*/
public function getTag()
{
return 'UIDataTable';
}
}

View File

@@ -22,7 +22,7 @@ class UIFieldNode extends Node
public function compile(Compiler $compiler)
{
$sBlockVar = UIBlockHelper::GetBlockVarName('oFieldSet');
$sBlockVar = UIBlockHelper::GetBlockVarName('oField');
$oParams = $this->getAttribute('params');
$compiler
->addDebugInfo($this)

View File

@@ -0,0 +1,39 @@
<?php
/**
* @copyright Copyright (C) 2010-2021 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\TwigBase\UI\Component;
use Combodo\iTop\Application\TwigBase\UI\UIBlockHelper;
use Twig\Compiler;
use Twig\Node\Node;
class UIFormNode extends Node
{
public function __construct($oParams, $oBody, $lineno = 0, $tag = null)
{
parent::__construct(['body' => $oBody], ['params' => $oParams], $lineno, $tag);
}
public function compile(Compiler $compiler)
{
$sBlockVar = UIBlockHelper::GetBlockVarName('oForm');
$oParams = $this->getAttribute('params');
$compiler
->addDebugInfo($this)
->write("\$aParams = ")
->subcompile($oParams)
->raw(";\n")
->write("\$sId = \$aParams['id'] ?? null;\n")
->write("\${$sBlockVar} = new Combodo\\iTop\\Application\\UI\\Base\\Component\\Form\\Form(\$sId);\n")
->write(UIBlockHelper::AddToParentBlock($sBlockVar))
->write(UIBlockHelper::PushParentBlock($sBlockVar))
->subcompile($this->getNode('body'))
->write(UIBlockHelper::PopParentBlock());
}
}

View File

@@ -0,0 +1,47 @@
<?php
/**
* @copyright Copyright (C) 2010-2021 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\TwigBase\UI\Component;
use Twig\Token;
use Twig\TokenParser\AbstractTokenParser;
class UIFormParser extends AbstractTokenParser
{
/**
* @inheritDoc
*/
public function parse(Token $token)
{
$iLineno = $token->getLine();
$oStream = $this->parser->getStream();
$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 UIFormNode($oParams, $oBody, $iLineno, $this->getTag());
}
/**
* @inheritDoc
*/
public function getTag()
{
return 'UIForm';
}
public function decideForEnd(Token $token)
{
return $token->test('EndUIForm');
}
}

View File

@@ -0,0 +1,79 @@
<?php
/**
* @copyright Copyright (C) 2010-2021 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\TwigBase\UI\Component;
use Combodo\iTop\Application\TwigBase\UI\UIBlockHelper;
use Twig\Compiler;
use Twig\Error\SyntaxError;
use Twig\Node\Node;
class UIInputNode extends Node
{
public function __construct($sType, $oParams, $lineno = 0, $tag = null)
{
parent::__construct([], ['type' => $sType, 'params' => $oParams], $lineno, $tag);
}
public function compile(Compiler $compiler)
{
$sBlockVar = UIBlockHelper::GetBlockVarName('oInput');
$oParams = $this->getAttribute('params');
$compiler
->addDebugInfo($this)
->write("\$aParams = ")
->subcompile($oParams)
->raw(";\n");
$sFactoryType = $this->getAttribute('type');
switch ($sFactoryType) {
case 'ForHidden':
$compiler
->write("\$sName = \$aParams['name'] ?? '';\n")
->write("\$sValue = \$aParams['value'] ?? '';\n")
->write("\$sId = \$aParams['id'] ?? null;\n")
->write("\${$sBlockVar} = Combodo\\iTop\\Application\\UI\\Base\\Component\\Input\\InputFactory::Make{$sFactoryType}(\$sName, \$sValue, \$sId);\n");
break;
case 'Standard':
$compiler
->write("\$sType = \$aParams['type'] ?? '';\n")
->write("\$sName = \$aParams['name'] ?? '';\n")
->write("\$sValue = \$aParams['value'] ?? '';\n")
->write("\$sId = \$aParams['id'] ?? null;\n")
->write("\${$sBlockVar} = Combodo\\iTop\\Application\\UI\\Base\\Component\\Input\\InputFactory::Make{$sFactoryType}(\$sType, \$sName, \$sValue, \$sId);\n")
->write("if (\$aParams['checked'] ?? false) {\n")
->indent()
->write("\${$sBlockVar}->SetChecked(true);\n")
->outdent()
->write("}\n");
break;
case 'WithLabel':
$compiler
->write("\$sLabel = \$aParams['label'] ?? '';\n")
->write("\$sType = \$aParams['type'] ?? '';\n")
->write("\$sName = \$aParams['name'] ?? '';\n")
->write("\$sValue = \$aParams['value'] ?? '';\n")
->write("\$sId = \$aParams['id'] ?? null;\n")
->write("\${$sBlockVar} = Combodo\\iTop\\Application\\UI\\Base\\Component\\Input\\InputFactory::Make{$sFactoryType}(\$sType, \$sLabel, \$sName, \$sValue, \$sId);\n")
->write("if (\$aParams['checked'] ?? false) {\n")
->indent()
->write("\${$sBlockVar}->GetInput()->SetChecked(true);\n")
->outdent()
->write("}\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(), $sFactoryType, $this->tag, $this->lineno), $this->lineno, $this->getSourceContext());
}
$compiler->write(UIBlockHelper::AddToParentBlock($sBlockVar));
}
}

View File

@@ -0,0 +1,43 @@
<?php
/**
* @copyright Copyright (C) 2010-2021 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\TwigBase\UI\Component;
use Twig\Token;
use Twig\TokenParser\AbstractTokenParser;
class UIInputParser extends AbstractTokenParser
{
/**
* @inheritDoc
*/
public function parse(Token $token)
{
$iLineno = $token->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 UIInputNode($sType, $oParams, $iLineno, $this->getTag());
}
/**
* @inheritDoc
*/
public function getTag()
{
return 'UIInput';
}
}

View File

@@ -22,7 +22,7 @@ class UITitleNode extends Node
public function compile(Compiler $compiler)
{
$sBlockVar = UIBlockHelper::GetBlockVarName('oFieldSet');
$sBlockVar = UIBlockHelper::GetBlockVarName('oTitle');
$oParams = $this->getAttribute('params');
$compiler
->addDebugInfo($this)

View File

@@ -10,9 +10,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\UIDataTableParser;
use Combodo\iTop\Application\TwigBase\UI\Component\UIFieldParser;
use Combodo\iTop\Application\TwigBase\UI\Component\UIFieldSetParser;
use Combodo\iTop\Application\TwigBase\UI\Component\UIFormParser;
use Combodo\iTop\Application\TwigBase\UI\Component\UIHtmlParser;
use Combodo\iTop\Application\TwigBase\UI\Component\UIInputParser;
use Combodo\iTop\Application\TwigBase\UI\Component\UITitleParser;
use Twig\Extension\AbstractExtension;
@@ -27,6 +30,9 @@ class UIBlockExtension extends AbstractExtension
new UIFieldParser(),
new UIAlertParser(),
new UITitleParser(),
new UIDataTableParser(),
new UIFormParser(),
new UIInputParser(),
];
}
}

View File

@@ -7,12 +7,13 @@
namespace Combodo\iTop\Application\UI\Base\Component\Field;
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
use Combodo\iTop\Application\UI\Base\UIBlock;
/**
* @since 3.0.0
*/
class Field extends UIBlock
class Field extends UIContentBlock
{
/** @inheritdoc */
public const BLOCK_CODE = 'ibo-field';
@@ -48,21 +49,18 @@ class Field extends UIBlock
protected $sLabel;
/** @var string */
protected $sValueId;
/**
* Could be Input, but we have legacy code that needs to set raw HTML !
*
* @var UIBlock
*/
protected $oValue;
/** @var string */
protected $sComments;
public function __construct(string $sLabel, UIBlock $oValue, ?string $sId = null)
public function __construct(string $sLabel, UIBlock $oValue = null, ?string $sId = null)
{
parent::__construct($sId);
$this->sLabel = $sLabel;
$this->oValue = $oValue;
$this->sValueId = null;
if (!is_null($oValue)) {
$this->AddSubBlock($oValue);
}
}
/**

View File

@@ -8,7 +8,7 @@ namespace Combodo\iTop\Application\UI\Base\Component\Field;
use Combodo\iTop\Application\UI\Base\Component\Html\Html;
use Combodo\iTop\Application\UI\Base\Component\Input\AbstractInput;
use Combodo\iTop\Application\UI\Base\UIBlock;
/**
* @since 3.0.0
@@ -61,7 +61,7 @@ class FieldFactory
$oField->$sMethodName((($iParamsFlags & $iConstant) === $iConstant));
}
public static function MakeFromObject(string $sLabel, AbstractInput $oInput, ?string $sLayout = null)
public static function MakeFromObject(string $sLabel, UIBlock $oInput, ?string $sLayout = null)
{
$oField = new Field($sLabel, $oInput);

View File

@@ -20,6 +20,8 @@ class Input extends AbstractInput
public const INPUT_HIDDEN = 'hidden';
protected $bChecked = false;
/** @var string */
protected $sType;
@@ -39,4 +41,23 @@ class Input extends AbstractInput
return $this;
}
/**
* @param $bChecked
*
* @return $this
*/
public function SetChecked($bChecked)
{
$this->bChecked = $bChecked;
return $this;
}
/**
* @return bool
*/
public function IsChecked()
{
return $this->bChecked;
}
}

View File

@@ -26,6 +26,32 @@ class InputFactory
return $oInput;
}
public static function MakeStandard(string $sType, string $sName, string $sValue, ?string $sId = null): Input
{
$oInput = new Input($sId);
$oInput->SetType($sType)
->SetName($sName)
->SetValue($sValue);
return $oInput;
}
public static function MakeWithLabel(string $sType, string $sLabel, string $sName, string $sValue, ?string $sId = null): InputWithLabel
{
$oInput = new Input($sId);
$oInput->SetType($sType)
->SetName($sName)
->SetValue($sValue);
if (is_null($sId)) {
$sId = $oInput->GetId();
}
return new InputWithLabel($sLabel, $oInput, $sId);
}
/**
* @see Field component that is better adapter when dealing with a standard iTop form
*

View File

@@ -16,7 +16,11 @@
data-value-raw="{{ aParams.value_raw }}"
>
<div class="ibo-field--label">{{ oUIBlock.GetLabel()|raw }}</div>
<div class="ibo-field--value" {% if oUIBlock.GetValueId() %}id="{{ oUIBlock.GetValueId() }}"{% endif %}>{{ render_block(oUIBlock.GetValue()) }}</div>
<div class="ibo-field--value" {% if oUIBlock.GetValueId() %}id="{{ oUIBlock.GetValueId() }}"{% endif %}>
{% for oSubBlock in oUIBlock.GetSubBlocks() %}
{{ render_block(oSubBlock, {aPage: aPage}) }}
{% endfor %}
</div>
{% if (oUIBlock.GetComments() is not null) %}
{{ oUIBlock.GetComments() }}
{% endif %}

View File

@@ -1,5 +1,7 @@
{% block iboInputLabel %}
{% endblock %}
{% block iboInput %}
<input type="{{ oUIBlock.GetType() }}" id="{{ oUIBlock.GetId() }}" name="{{ oUIBlock.GetName() }}" value="{{ oUIBlock.GetValue()|raw }}">
<input type="{{ oUIBlock.GetType() }}" id="{{ oUIBlock.GetId() }}" name="{{ oUIBlock.GetName() }}" value="{{ oUIBlock.GetValue()|raw }}"
{% if oUIBlock.IsChecked() %}checked="checked"{% endif %}
>
{% endblock %}