From d850be89877cff3802287150e8ae22a9c9935a27 Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Sun, 28 Apr 2024 09:33:11 +0300 Subject: [PATCH] Available plugins.Alert to element. --- .../src/Model/Table/ApiSourcesTable.php | 6 +- .../templates/ApiSources/fields.inc | 11 +++- .../templates/FileProvisioners/fields.inc | 6 +- .../templates/FileSources/fields.inc | 22 ++++--- .../templates/SqlProvisioners/fields.inc | 17 ++++- app/src/View/Helper/AlertHelper.php | 53 ++------------- app/src/View/Helper/FieeldHelper.php | 34 +++++----- app/templates/ApiUsers/fields.inc | 2 +- app/templates/Cos/select.php | 2 +- app/templates/Dashboards/configuration.php | 6 +- app/templates/Dashboards/search.php | 4 +- .../ExtIdentitySourceRecords/fields.inc | 5 +- app/templates/ExternalIdentities/fields.inc | 8 ++- .../ExternalIdentitySources/retrieve.php | 3 +- .../ExternalIdentitySources/search.php | 5 +- app/templates/ProvisioningTargets/status.php | 4 +- .../element/filter/dateTimeFilters.php | 4 +- app/templates/element/flash.php | 4 +- app/templates/element/flash/default.php | 2 +- app/templates/element/flash/error.php | 6 +- app/templates/element/flash/information.php | 6 +- app/templates/element/flash/success.php | 6 +- .../element/form/infoDiv/autocomplete.php | 2 +- app/templates/element/menuPanel.php | 6 +- app/templates/element/notify/alert.php | 65 +++++++++++++++++++ app/templates/element/{ => notify}/banner.php | 2 +- app/templates/element/notify/closeButton.php | 35 ++++++++++ 27 files changed, 221 insertions(+), 105 deletions(-) create mode 100644 app/templates/element/notify/alert.php rename app/templates/element/{ => notify}/banner.php (95%) create mode 100644 app/templates/element/notify/closeButton.php 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/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/src/View/Helper/AlertHelper.php b/app/src/View/Helper/AlertHelper.php index d653759df..b4b083af5 100644 --- a/app/src/View/Helper/AlertHelper.php +++ b/app/src/View/Helper/AlertHelper.php @@ -45,52 +45,13 @@ * @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'; - } + 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/FieeldHelper.php b/app/src/View/Helper/FieeldHelper.php index 21e69ed2e..29acdff70 100644 --- a/app/src/View/Helper/FieeldHelper.php +++ b/app/src/View/Helper/FieeldHelper.php @@ -273,39 +273,39 @@ public function dateField(string $fieldName, /** * Create the actual Form element * - * @param string $fieldName Form field - * @param array|null $options FormHelper control options - * @param string|null $labelText - * @param string $prefix Field prefix - used for API Usernames - * @param string|null $fieldType + * @param string $fieldName Form field + * @param array|null $fieldOptions The second parameter of the Form->control helper. List of element options + * @param string|null $fieldLabel Custom label thext + * @param string $fieldPrefix If the field has a specil prefix provide the value + * @param string|null $fieldType Field type to override the one calculated from the schema * * @return string HTML element * @since COmanage Registry v5.0.0 */ public function formField(string $fieldName, - array $options = null, - string $labelText = null, - string $prefix = '', // api user + array $fieldOptions = null, + string $fieldLabel = null, + string $fieldPrefix = '', string $fieldType = null): string { - $fieldArgs = $options ?? []; - $fieldArgs['label'] = $options['label'] ?? false; + $fieldArgs = $fieldOptions ?? []; + $fieldArgs['label'] = $fieldOptions['label'] ?? false; $fieldArgs['readonly'] = !$this->editable - || (isset($options['readonly']) && $options['readonly']) + || (isset($fieldOptions['readonly']) && $fieldOptions['readonly']) || ($fieldName == 'plugin' && $this->action == 'edit'); // Selects, Checkboxes, and Radio Buttons use "disabled" $fieldArgs['disabled'] = $fieldArgs['readonly']; - $fieldArgs['required'] = (bool)$this->isReqField($fieldName); + $fieldArgs['required'] = $this->isReqField($fieldName); // Get the field type from the map of fields (e.g. 'boolean', 'string', 'timestamp') $fieldType = $fieldType ?? $this->getFieldType($fieldName); // Remove prefix from field value - if(!empty($prefix) && !empty($this->getEntity()->$fieldName)) { + if(!empty($fieldPrefix) && !empty($this->getEntity()->$fieldName)) { $vv_obj = $this->getView()->get('vv_obj'); $fieldValue = $vv_obj->$fieldName; - $fieldValueTemp = str_replace($prefix, '', $fieldValue); + $fieldValueTemp = str_replace($fieldPrefix, '', $fieldValue); $vv_obj->$fieldName = $fieldValueTemp; $this->getView()->set('vv_obj', $vv_obj); } @@ -315,8 +315,8 @@ public function formField(string $fieldName, // Note this will be ignored for non-select controls. if(\in_array($fieldName, ['status', 'sync_status_on_delete'], true)) { $fieldArgs['empty'] = false; - } elseif(isset($options['empty'])) { - $fieldArgs['empty'] = $options['empty']; + } elseif(isset($fieldOptions['empty'])) { + $fieldArgs['empty'] = $fieldOptions['empty']; } else { $fieldArgs['empty'] = true; } @@ -324,7 +324,7 @@ public function formField(string $fieldName, // A boolean field is a checkbox. Set the label and class to improve rendering // and accessibility. if($fieldType === 'boolean') { - $fieldArgs['label'] = $labelText; + $fieldArgs['label'] = $fieldLabel; $fieldArgs['class'] = 'form-check-input'; } elseif($fieldType === 'date') { return $this->dateField($fieldName, DateTypeEnum::DateOnly); diff --git a/app/templates/ApiUsers/fields.inc b/app/templates/ApiUsers/fields.inc index 349916d8a..e8cba5cac 100644 --- a/app/templates/ApiUsers/fields.inc +++ b/app/templates/ApiUsers/fields.inc @@ -28,7 +28,7 @@ // This view does not support read-only if($vv_action == 'add' || $vv_action == 'edit') { if($vv_cur_co->id == 1) { - print $this->element('banner', __d('information', 'api.cmp')); + print $this->element('banner', ['info' => __d('information', 'api.cmp')]); } // AR-ApiUser-3 For namespacing purposes, API Users are named with a prefix consisting of the string "co_#.". diff --git a/app/templates/Cos/select.php b/app/templates/Cos/select.php index b62bb20a5..b18e1833b 100644 --- a/app/templates/Cos/select.php +++ b/app/templates/Cos/select.php @@ -35,7 +35,7 @@ - Alert->alert(__d('information','cos.none'), 'warning') ?> + element('notify/alert', ['message' => __d('information','cos.none')]) ?>

    diff --git a/app/templates/Dashboards/configuration.php b/app/templates/Dashboards/configuration.php index 10c307cb7..1ecc290c9 100644 --- a/app/templates/Dashboards/configuration.php +++ b/app/templates/Dashboards/configuration.php @@ -145,6 +145,10 @@ ]; ?>
    - Alert->alert(__d('information','cmp.config.notice', $noticeUrls), 'information', true) ?> + element('notify/alert', [ + 'message' => __d('information','cmp.config.notice', $noticeUrls), + 'type' => 'information', + 'dismissible' => true + ]) ?>
    \ No newline at end of file diff --git a/app/templates/Dashboards/search.php b/app/templates/Dashboards/search.php index 3481f9fd2..e39f29d6b 100644 --- a/app/templates/Dashboards/search.php +++ b/app/templates/Dashboards/search.php @@ -59,13 +59,13 @@ - Alert->alert($b, 'warning') ?> + element('notify/alert', ['message' => $b]) ?> - Alert->alert($b, 'warning') ?> + element('notify/alert', ['message' => $b]) ?>
    diff --git a/app/templates/ExtIdentitySourceRecords/fields.inc b/app/templates/ExtIdentitySourceRecords/fields.inc index b1eb8aa5f..47df19b92 100644 --- a/app/templates/ExtIdentitySourceRecords/fields.inc +++ b/app/templates/ExtIdentitySourceRecords/fields.inc @@ -42,7 +42,10 @@ $noticeText = __d( ] ); -print $this->Alert->alert($noticeText, 'information', false); +print $this->element('notify/alert', [ + 'message' => $noticeText, + 'type' => 'information' +]); // This view does not support add or edit if($vv_action == 'view') { diff --git a/app/templates/ExternalIdentities/fields.inc b/app/templates/ExternalIdentities/fields.inc index 8741f75ad..4f5eeaff2 100644 --- a/app/templates/ExternalIdentities/fields.inc +++ b/app/templates/ExternalIdentities/fields.inc @@ -43,8 +43,12 @@ if($vv_action == 'add' || $vv_action == 'edit' || $vv_action == 'view') { ) ] ); - - print $this->Alert->alert($noticeText, 'information', false); + + $this->element('notify/alert', [ + 'message' => $noticeText, + 'type' => 'information' + ]); + } print $this->element('form/listItem', [ diff --git a/app/templates/ExternalIdentitySources/retrieve.php b/app/templates/ExternalIdentitySources/retrieve.php index b50364847..f0925635d 100644 --- a/app/templates/ExternalIdentitySources/retrieve.php +++ b/app/templates/ExternalIdentitySources/retrieve.php @@ -105,8 +105,7 @@ ); } ?> -Alert->alert($noticeText, 'information', false) ?> - +element('notify/alert', ['message' => $noticeText,'type' => 'information']) ?>

    diff --git a/app/templates/ExternalIdentitySources/search.php b/app/templates/ExternalIdentitySources/search.php index a7b841cec..65c166613 100644 --- a/app/templates/ExternalIdentitySources/search.php +++ b/app/templates/ExternalIdentitySources/search.php @@ -42,7 +42,10 @@
    - Alert->alert(__d('information', 'ExternalIdentitySources.search.attrs.none'), 'information', false) ?> + element('notify/alert', [ + 'message' => __d('information', 'ExternalIdentitySources.search.attrs.none'), + 'type' => 'information' + ]) ?> - Alert->alert($b, 'warning') ?> + element('notify/alert', ['message' => $b]) ?> - Alert->alert($b, 'warning') ?> + element('notify/alert', ['message' => $b]) ?>
    diff --git a/app/templates/element/filter/dateTimeFilters.php b/app/templates/element/filter/dateTimeFilters.php index 4c7440dba..a3ad78d2f 100644 --- a/app/templates/element/filter/dateTimeFilters.php +++ b/app/templates/element/filter/dateTimeFilters.php @@ -42,7 +42,7 @@ Form->label("{$key}_starts_at", __d('field', 'starts_at'), ['class' => 'filter-datepicker-lbl']); - print $this->Field->dateField("{$key}_starts_at", DateTypeEnum::DateOnly, $query)['controlCode']; + print $this->Fieeld->dateField("{$key}_starts_at", DateTypeEnum::DateOnly, $query); ?> @@ -50,7 +50,7 @@ Form->label("{$key}_ends_at", __d('field','ends_at'), ['class' => 'filter-datepicker-lbl']); - print $this->Field->dateField("{$key}_ends_at", DateTypeEnum::DateOnly, $query)['controlCode']; + print $this->Fieeld->dateField("{$key}_ends_at", DateTypeEnum::DateOnly, $query); ?> diff --git a/app/templates/element/flash.php b/app/templates/element/flash.php index 5c6a91f26..3809206e3 100644 --- a/app/templates/element/flash.php +++ b/app/templates/element/flash.php @@ -32,13 +32,13 @@ - Alert->alert($b, 'warning') ?> + element('notify/alert', ['message' => $b]) ?> - Alert->alert($b, 'warning') ?> + element('notify/alert', ['message' => $b]) ?> \ No newline at end of file diff --git a/app/templates/element/flash/default.php b/app/templates/element/flash/default.php index 325e35513..7484ee14a 100644 --- a/app/templates/element/flash/default.php +++ b/app/templates/element/flash/default.php @@ -8,6 +8,6 @@ - Alert->alert($message, 'warning', true) ?> + element('notify/alert', ['message' => $message]) ?> diff --git a/app/templates/element/flash/error.php b/app/templates/element/flash/error.php index 8069a15da..c77a0eac9 100644 --- a/app/templates/element/flash/error.php +++ b/app/templates/element/flash/error.php @@ -8,5 +8,9 @@ - Alert->alert($message, 'danger', true) ?> + element('notify/alert', [ + 'message' => $message, + 'type' => 'danger', + 'dismissible' => true + ]) ?> diff --git a/app/templates/element/flash/information.php b/app/templates/element/flash/information.php index 26dc52329..c7b7b83b1 100644 --- a/app/templates/element/flash/information.php +++ b/app/templates/element/flash/information.php @@ -8,5 +8,9 @@ - Alert->alert($message, 'information', true) ?> + element('notify/alert', [ + 'message' => $message, + 'type' => 'information', + 'dismissible' => true + ]) ?> \ No newline at end of file diff --git a/app/templates/element/flash/success.php b/app/templates/element/flash/success.php index 6f0671bb0..17c7469d5 100644 --- a/app/templates/element/flash/success.php +++ b/app/templates/element/flash/success.php @@ -8,5 +8,9 @@ - Alert->alert($message, 'success', true) ?> + element('notify/alert', [ + 'message' => $message, + 'type' => 'success', + 'dismissible' => true + ]) ?> \ No newline at end of file diff --git a/app/templates/element/form/infoDiv/autocomplete.php b/app/templates/element/form/infoDiv/autocomplete.php index 02477afab..787a54c1a 100644 --- a/app/templates/element/form/infoDiv/autocomplete.php +++ b/app/templates/element/form/infoDiv/autocomplete.php @@ -51,7 +51,7 @@ Form->hidden($fieldName, $vv_field_arguments['options']) . $this->element('peopleAutocomplete', $autocompleteArgs); + print $this->Form->hidden($fieldName, $vv_field_arguments['fieldOptions']) . $this->element('peopleAutocomplete', $autocompleteArgs); ?>
    info diff --git a/app/templates/element/menuPanel.php b/app/templates/element/menuPanel.php index d4065b255..8790380c3 100644 --- a/app/templates/element/menuPanel.php +++ b/app/templates/element/menuPanel.php @@ -485,7 +485,11 @@ ]; ?>
    - Alert->alert(__d('information','cmp.config.notice', $noticeUrls), 'information', true) ?> + element('notify/alert', [ + 'message' => __d('information','cmp.config.notice', $noticeUrls), + 'type' => 'information', + 'dismissible' => true + ]) ?>
    diff --git a/app/templates/element/notify/alert.php b/app/templates/element/notify/alert.php new file mode 100644 index 000000000..2d316f8ea --- /dev/null +++ b/app/templates/element/notify/alert.php @@ -0,0 +1,65 @@ + + + diff --git a/app/templates/element/banner.php b/app/templates/element/notify/banner.php similarity index 95% rename from app/templates/element/banner.php rename to app/templates/element/notify/banner.php index c0393c6c1..27bfdfbaa 100644 --- a/app/templates/element/banner.php +++ b/app/templates/element/notify/banner.php @@ -35,5 +35,5 @@
  • - Alert->alert($info, 'warning') ?> + element('notify/alert', ['message' => $info]) ?>
  • diff --git a/app/templates/element/notify/closeButton.php b/app/templates/element/notify/closeButton.php new file mode 100644 index 000000000..b7f5efa99 --- /dev/null +++ b/app/templates/element/notify/closeButton.php @@ -0,0 +1,35 @@ + + + + + \ No newline at end of file