diff --git a/app/availableplugins/ApiConnector/src/Model/Table/ApiSourcesTable.php b/app/availableplugins/ApiConnector/src/Model/Table/ApiSourcesTable.php index fd4b255e4..cf4fd5866 100644 --- a/app/availableplugins/ApiConnector/src/Model/Table/ApiSourcesTable.php +++ b/app/availableplugins/ApiConnector/src/Model/Table/ApiSourcesTable.php @@ -189,7 +189,7 @@ protected function mapApiToRegistry(string $model, array $attributes): array { */ public function remove( - \App\Model\Entity\ExternalIdentitySource $source, + \App\Model\Entity\ExternalIdentitySource $source, string $sorId ): array { // We call this remove() so as not to interfere with the default table::delete(). @@ -293,7 +293,7 @@ protected function resultToEntityData(array $result): array { */ public function retrieve( - \App\Model\Entity\ExternalIdentitySource $source, + \App\Model\Entity\ExternalIdentitySource $source, string $source_key ): array { $ret = [ @@ -328,7 +328,7 @@ public function retrieve( */ public function search( - \App\Model\Entity\ExternalIdentitySource $source, + \App\Model\Entity\ExternalIdentitySource $source, array $searchAttrs ): array { $ret = []; diff --git a/app/availableplugins/ApiConnector/templates/ApiSources/fields.inc b/app/availableplugins/ApiConnector/templates/ApiSources/fields.inc index 6eb871263..8bd3e6ec6 100644 --- a/app/availableplugins/ApiConnector/templates/ApiSources/fields.inc +++ b/app/availableplugins/ApiConnector/templates/ApiSources/fields.inc @@ -30,8 +30,15 @@ if($vv_action == 'add' || $vv_action == 'edit') { print '
  • ' . __d('api_connector', 'field.ApiSources.push_mode') . '

  • '; - print $this->Field->banner(__d('api_connector', 'information.endpoint.push', [$vv_push_endpoint])); + print $this->element('banner', [ + 'info' => __d('api_connector', 'information.endpoint.push', [$vv_push_endpoint]) + ]); - print $this->Field->control('api_user_id'); + + print $this->element('form/listItem', [ + 'arguments' => [ + 'fieldName' => 'api_user_id', + ] + ]); } diff --git a/app/availableplugins/FileConnector/src/Model/Table/FileSourcesTable.php b/app/availableplugins/FileConnector/src/Model/Table/FileSourcesTable.php index c170e3ebb..82be14a59 100644 --- a/app/availableplugins/FileConnector/src/Model/Table/FileSourcesTable.php +++ b/app/availableplugins/FileConnector/src/Model/Table/FileSourcesTable.php @@ -349,7 +349,7 @@ protected function resultToEntityData(array $result): array { */ public function retrieve( - \App\Model\Entity\ExternalIdentitySource $source, + \App\Model\Entity\ExternalIdentitySource $source, string $source_key ): array { // Read the field configuration (for resultToEntity) @@ -423,7 +423,7 @@ public function ruleIsFileReadable($entity, array $options): string|bool { */ public function search( - \App\Model\Entity\ExternalIdentitySource $source, + \App\Model\Entity\ExternalIdentitySource $source, array $searchAttrs ): array { // Read the field configuration (for resultToEntity) diff --git a/app/availableplugins/FileConnector/templates/FileProvisioners/fields.inc b/app/availableplugins/FileConnector/templates/FileProvisioners/fields.inc index 4980a687a..d5e5c8353 100644 --- a/app/availableplugins/FileConnector/templates/FileProvisioners/fields.inc +++ b/app/availableplugins/FileConnector/templates/FileProvisioners/fields.inc @@ -27,5 +27,9 @@ // This view does currently not support read-only if($vv_action == 'add' || $vv_action == 'edit') { - print $this->Field->control('filename'); + print $this->element('form/listItem', [ + 'arguments' => [ + 'fieldName' => 'filename', + ] + ]); } diff --git a/app/availableplugins/FileConnector/templates/FileSources/fields.inc b/app/availableplugins/FileConnector/templates/FileSources/fields.inc index 2380fe7bb..e9e7ae621 100644 --- a/app/availableplugins/FileConnector/templates/FileSources/fields.inc +++ b/app/availableplugins/FileConnector/templates/FileSources/fields.inc @@ -27,13 +27,17 @@ // This view does currently not support read-only if($vv_action == 'add' || $vv_action == 'edit') { - print $this->Field->control('filename'); - - print $this->Field->control('format'); - - print $this->Field->control('archivedir'); - - print $this->Field->control('threshold_warn'); - - print $this->Field->control('threshold_override'); + foreach([ + 'filename', + 'format', + 'archivedir', + 'threshold_warn', + 'threshold_override', + ] as $field) { + print $this->element('form/listItem', [ + 'arguments' => [ + 'fieldName' => $field, + ] + ]); + } } diff --git a/app/availableplugins/SqlConnector/templates/SqlProvisioners/fields.inc b/app/availableplugins/SqlConnector/templates/SqlProvisioners/fields.inc index 2b23c2634..ff3da2816 100644 --- a/app/availableplugins/SqlConnector/templates/SqlProvisioners/fields.inc +++ b/app/availableplugins/SqlConnector/templates/SqlProvisioners/fields.inc @@ -27,7 +27,18 @@ // This view does currently not support read-only if($vv_action == 'add' || $vv_action == 'edit') { - print $this->Field->control('server_id'); - - print $this->Field->control('table_prefix', ['default' => 'sp_']); + print $this->element('form/listItem', [ + 'arguments' => [ + 'fieldName' => 'server_id', + ] + ]); + + print $this->element('form/listItem', [ + 'arguments' => [ + 'fieldName' => 'table_prefix', + 'options' => [ + 'default' => 'sp_' + ] + ] + ]); } diff --git a/app/config/.env.example b/app/config/.env.example index 15060f7be..f5ac424ce 100644 --- a/app/config/.env.example +++ b/app/config/.env.example @@ -25,6 +25,8 @@ export SECURITY_SALT="__SALT__" #export CACHE_DEFAULT_URL="file://tmp/cache/?prefix=${APP_NAME}_default&duration=${CACHE_DURATION}" #export CACHE_CAKECORE_URL="file://tmp/cache/persistent?prefix=${APP_NAME}_cake_core&serialize=true&duration=${CACHE_DURATION}" #export CACHE_CAKEMODEL_URL="file://tmp/cache/models?prefix=${APP_NAME}_cake_model&serialize=true&duration=${CACHE_DURATION}" +#export CACHE_CAKEROUTE_URL="file://tmp/cache/routes?prefix=${APP_NAME}_cake_routes&serialize=true&duration=${CACHE_DURATION}" +#export CACHE_HTMLELEMENT_URL="file://tmp/cache/elements?prefix=${APP_NAME}_html_elements&serialize=true&duration=${CACHE_DURATION}" # Uncomment these to define email transport configuration via environment variables. #export EMAIL_TRANSPORT_DEFAULT_URL="" diff --git a/app/config/app.php b/app/config/app.php index 8917343bd..58739ebd2 100644 --- a/app/config/app.php +++ b/app/config/app.php @@ -171,6 +171,17 @@ 'duration' => '+1 years', 'url' => env('CACHE_CAKEROUTES_URL', null), ], + /** + * Configure the cache for html elements. + * Duration will be set to '+2 seconds' in bootstrap.php when debug = true + */ + '_html_elements' => [ + 'className' => 'Cake\Cache\Engine\FileEngine', + 'prefix' => 'myapp_cake_elements_', + 'duration' => '+1 week', + 'probability' => 100, + 'url' => env('CACHE_HTMLELEMENT_URL', null), + ] ], /** diff --git a/app/plugins/CoreAssigner/templates/FormatAssigners/fields.inc b/app/plugins/CoreAssigner/templates/FormatAssigners/fields.inc index f382bc570..b6d06487a 100644 --- a/app/plugins/CoreAssigner/templates/FormatAssigners/fields.inc +++ b/app/plugins/CoreAssigner/templates/FormatAssigners/fields.inc @@ -47,18 +47,30 @@ Field->control('format'); - - print $this->Field->control( - fieldName: 'collision_mode', - options: [ - 'onChange' => 'updateGadgets()' + print $this->element('form/listItem', [ + 'arguments' => [ + 'fieldName' => 'format' ] - ); - - print $this->Field->control('permitted_characters'); + ]); - print $this->Field->control('minimum'); + print $this->element('form/listItem', [ + 'arguments' => [ + 'fieldName' => 'collision_mode', + 'options' => [ + 'onChange' => 'updateGadgets()' + ] + ] + ]); - print $this->Field->control('maximum'); + foreach([ + 'permitted_characters', + 'minimum', + 'maximum', + ] as $field) { + print $this->element('form/listItem', [ + 'arguments' => [ + 'fieldName' => $field, + ] + ]); + } } diff --git a/app/plugins/CoreAssigner/templates/SqlAssigners/fields.inc b/app/plugins/CoreAssigner/templates/SqlAssigners/fields.inc index d0b2f5942..d2ede3a3d 100644 --- a/app/plugins/CoreAssigner/templates/SqlAssigners/fields.inc +++ b/app/plugins/CoreAssigner/templates/SqlAssigners/fields.inc @@ -27,9 +27,15 @@ // This view does currently not support read-only, and add is not used if($vv_action == 'edit') { - print $this->Field->control('server_id'); - - print $this->Field->control('source_table'); - - print $this->Field->control('type_id'); + foreach([ + 'server_id', + 'source_table', + 'type_id', + ] as $field) { + print $this->element('form/listItem', [ + 'arguments' => [ + 'fieldName' => $field, + ] + ]); + } } diff --git a/app/plugins/CoreServer/templates/SmtpServers/fields.inc b/app/plugins/CoreServer/templates/SmtpServers/fields.inc index b77ac9220..bac623cdc 100644 --- a/app/plugins/CoreServer/templates/SmtpServers/fields.inc +++ b/app/plugins/CoreServer/templates/SmtpServers/fields.inc @@ -27,19 +27,48 @@ // This view does currently not support read-only, and add is not used if($vv_action == 'edit') { - print $this->Field->control('hostname'); + print $this->element('form/listItem', [ + 'arguments' => [ + 'fieldName' => 'hostname', + ] + ]); - print $this->Field->control('port', ['default' => 587]); + print $this->element('form/listItem', [ + 'arguments' => [ + 'fieldName' => 'port', + 'fieldOptions' => [ + 'default' => 587 + ] + ]]); - print $this->Field->control('username'); + print $this->element('form/listItem', [ + 'arguments' => [ + 'fieldName' => 'username', + ] + ]); - print $this->Field->control('password'); + print $this->element('form/listItem', [ + 'arguments' => [ + 'fieldName' => 'password', + ] + ]); - print $this->Field->control('use_tls', ['default' => true]); + print $this->element('form/listItem', [ + 'arguments' => [ + 'fieldName' => 'use_tls', + 'fieldOptions' => [ + 'default' => true + ] + ]]); - print $this->Field->control('default_from'); - - print $this->Field->control('default_reply_to'); - - print $this->Field->control('override_to'); + foreach ([ + 'default_from', + 'default_reply_to', + 'override_to', + ] as $field) { + print $this->element('form/listItem', [ + 'arguments' => [ + 'fieldName' => $field + ]]); + } } diff --git a/app/plugins/CoreServer/templates/SqlServers/fields.inc b/app/plugins/CoreServer/templates/SqlServers/fields.inc index 0d0a13d04..a15d291f9 100644 --- a/app/plugins/CoreServer/templates/SqlServers/fields.inc +++ b/app/plugins/CoreServer/templates/SqlServers/fields.inc @@ -27,15 +27,18 @@ // This view does currently not support read-only, and add is not used if($vv_action == 'edit') { - print $this->Field->control('type'); - - print $this->Field->control('hostname'); - - print $this->Field->control('port'); - - print $this->Field->control('databas'); - - print $this->Field->control('username'); - - print $this->Field->control('password'); + foreach([ + 'type', + 'hostname', + 'port', + 'databas', + 'username', + 'password', + ] as $field) { + print $this->element('form/listItem', [ + 'arguments' => [ + 'fieldName' => $field, + ] + ]); + } } diff --git a/app/src/Controller/ApiUsersController.php b/app/src/Controller/ApiUsersController.php index 25a690757..aa871b09b 100644 --- a/app/src/Controller/ApiUsersController.php +++ b/app/src/Controller/ApiUsersController.php @@ -62,7 +62,8 @@ public function generate(string $id) { 'api.key', $this->request->getParam('action')); $this->set('vv_title', $title); - + + // Let the view render $this->render('/Standard/add-edit-view'); } } \ No newline at end of file diff --git a/app/src/Controller/StandardController.php b/app/src/Controller/StandardController.php index b1ee0a7d6..79085fed4 100644 --- a/app/src/Controller/StandardController.php +++ b/app/src/Controller/StandardController.php @@ -423,7 +423,7 @@ public function edit(string $id) { $this->set('vv_title', $title); $this->set('vv_supertitle', $supertitle); $this->set('vv_subtitle', $subtitle); - + // Let the view render $this->render('/Standard/add-edit-view'); } @@ -870,7 +870,7 @@ public function view($id = null) { $this->set('vv_title', $title); $this->set('vv_supertitle', $supertitle); $this->set('vv_subtitle', $subtitle); - + // Let the view render $this->render('/Standard/add-edit-view'); } diff --git a/app/src/Model/Table/AdHocAttributesTable.php b/app/src/Model/Table/AdHocAttributesTable.php index 3bdb8a142..7822a3e0f 100644 --- a/app/src/Model/Table/AdHocAttributesTable.php +++ b/app/src/Model/Table/AdHocAttributesTable.php @@ -43,7 +43,8 @@ class AdHocAttributesTable extends Table { use \App\Lib\Traits\ValidationTrait; use \App\Lib\Traits\SearchFilterTrait; use \App\Lib\Traits\QueryModificationTrait; - + use \App\Lib\Traits\AutoViewVarsTrait; + /** * Provide the default layout * diff --git a/app/src/Model/Table/HistoryRecordsTable.php b/app/src/Model/Table/HistoryRecordsTable.php index e3917a7d0..d37567c0f 100644 --- a/app/src/Model/Table/HistoryRecordsTable.php +++ b/app/src/Model/Table/HistoryRecordsTable.php @@ -41,7 +41,8 @@ class HistoryRecordsTable extends Table { use \App\Lib\Traits\TableMetaTrait; use \App\Lib\Traits\ValidationTrait; use \App\Lib\Traits\SearchFilterTrait; - + use \App\Lib\Traits\AutoViewVarsTrait; + /** * Perform Cake Model initialization. * diff --git a/app/src/View/Helper/AlertHelper.php b/app/src/View/Helper/AlertHelper.php index d653759df..0c3d1ef68 100644 --- a/app/src/View/Helper/AlertHelper.php +++ b/app/src/View/Helper/AlertHelper.php @@ -32,65 +32,21 @@ use \Cake\View\Helper; use phpDocumentor\Reflection\Types\Boolean; -/** - * Helper which will produce Bootstrap based alert - * - * @param string $message Alert message - * @param string $type Define the type of Alert. The value should be one of - * [success,warning,danger,info]. Defaults to 'warning' - * @param boolean $dismissable Can the Alert be dismissed? Defaults to false. - * @param string|null $title Title to display (typically "Success", "Error", or "Warning"). Defaults to null. - * @param boolean $dis_text_dark Disable dark-text fonts for light|info color mode. - * @return mixed - a constructed HTML block - * @since COmanage Registry v5.0.0 - */ class AlertHelper extends Helper { - - public $helpers = ['Html']; - - public function alert( - string $message, - string $type = 'warning', - bool $dismissable = false, - string $title = null ) { - - $closeButton = ''; - $dismissableClass = ''; - if($dismissable) { - $closeButton = ' - - - - '; - $dismissableClass = ' alert-dismissible'; - } - - $titleMarkup = ''; - if(!empty($title)) { - $titleMarkup = '' . $title . ''; - } - - return ' - - '; - } - - public function getAlertIcon(string $type) { - switch($type) { - case('success'): return 'check_circle'; - case('information'): return 'info'; - default: return 'report_problem'; - } + /** + * Map Alert Type to Icon + * + * @param string $type + * + * @return string + */ + public function getAlertIcon(string $type): string + { + return match($type) { + 'success' => 'check_circle', + 'information' => 'info', + default => 'report_problem' + }; } } \ No newline at end of file diff --git a/app/src/View/Helper/FieldHelper.php b/app/src/View/Helper/FieldHelper.php index 1b26ac583..60355b63c 100644 --- a/app/src/View/Helper/FieldHelper.php +++ b/app/src/View/Helper/FieldHelper.php @@ -25,7 +25,6 @@ * @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0) */ -// XXX can we merge this with Match so we only maintain one file? declare(strict_types = 1); namespace App\View\Helper; @@ -37,173 +36,155 @@ use App\Lib\Util\StringUtilities; class FieldHelper extends Helper { - public $helpers = ['Form', 'Html', 'Url', 'Alert']; - + public $helpers = ['Form', 'Html']; + // Is this read-only or read-write? - protected $editable = true; + protected bool $editable = true; // Our current model name - protected $modelName = null; + protected ?string $modelName = null; // The plugin we are rendering within, if set - protected $pluginName = null; - + protected ?string $pluginName = null; + // The list of required fields - protected $reqFields = []; - + protected array $reqFields = []; + + // The field types + protected array $fieldTypes = []; + // The current entity, if edit or view - protected $entity = null; + protected ?object $entity = null; // The current action - protected $action = null; + protected ?string $action = null; + /** - * Emit an informational banner. + * Constructor hook method. + * + * @param array $config The configuration settings provided to this helper. * - * @since COmanage Registry v6.0.0 - * @param string $info Information string - * @return string HTML for banner + * @return void */ - - public function banner(string $info): string { - return '
  • ' . - $this->Alert->alert($info, 'warning') - . '
  • '; + public function initialize(array $config): void + { + parent::initialize($config); + + $this->reqFields = $this->getView()->get('vv_required_fields'); + $this->modelName = $this->getView()->getName(); + $this->action = $this->getView()->get('vv_action'); + $this->editable = \in_array($this->action, ['add', 'edit']); + $this->pluginName = $this->getView()->getPlugin(); + $this->entity = $this->getView()->get('vv_obj'); + $this->fieldTypes = $this->getView()->get('vv_field_types'); } /** - * Emit a form control. + * We autogenerate field labels and descriptions from the field name. * - * @param string $fieldName Form field - * @param array $options FormHelper control options - * @param string|null $labelText Label text (fieldName language key used by default) - * @param string|null $ctrlCode Control code passed in from wrapper functions - * @param string $cssClass Start li css class passed in from wrapper functions - * @param string $beforeField Markup to be placed before/above the field - * @param string $afterField Markup to be placed after/below the field - * @param string $prefix Field prefix - used for API Usernames - * @param bool $labelIsTextOnly For fields that should not include