Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis committed Apr 29, 2024
1 parent 53ca43d commit d69bb7c
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 44 deletions.
19 changes: 7 additions & 12 deletions app/src/View/Helper/AlertHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,14 @@
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 {
/**
* Map Alert Type to Icon
*
* @param string $type
*
* @return string
*/
public function getAlertIcon(string $type): string
{
return match($type) {
Expand Down
52 changes: 24 additions & 28 deletions app/src/View/Helper/FieeldHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,15 +291,19 @@ public function formField(string $fieldName,
$fieldArgs = $fieldOptions ?? [];
$fieldArgs['label'] = $fieldOptions['label'] ?? false;
$fieldArgs['readonly'] = !$this->editable
|| \boolval($fieldOptions['readonly'])
|| (isset($fieldOptions['readonly']) && $fieldOptions['readonly'])
|| ($fieldName == 'plugin' && $this->action == 'edit');

// Selects, Checkboxes, and Radio Buttons use "disabled"
$fieldArgs['disabled'] = $fieldArgs['readonly'];
$fieldArgs['required'] = $this->isReqField($fieldName) ?? boolval($fieldOptions['required']);
$fieldArgs['required'] = $this->isReqField($fieldName)
|| (isset($fieldOptions['required']) && $fieldOptions['required']);

// Get the field type from the map of fields (e.g. 'boolean', 'string', 'timestamp')
$fieldType = $fieldType ?? $this->getFieldType($fieldName);
// Cause any select (except status) to render with a blank option, even
// if the field is required. This makes it clear when a value needs to be set.
// Note this will be ignored for non-select controls.
$fieldArgs['empty'] = !\in_array($fieldName, ['status', 'sync_status_on_delete'], true)
|| (isset($fieldOptions['empty']) && $fieldOptions['empty']);

// Remove prefix from field value
if(!empty($fieldPrefix) && !empty($this->getEntity()->$fieldName)) {
Expand All @@ -310,31 +314,23 @@ public function formField(string $fieldName,
$this->getView()->set('vv_obj', $vv_obj);
}

// Cause any select (except status) to render with a blank option, even
// if the field is required. This makes it clear when a value needs to be set.
// Note this will be ignored for non-select controls.
if(\in_array($fieldName, ['status', 'sync_status_on_delete'], true)) {
$fieldArgs['empty'] = false;
} elseif(isset($fieldOptions['empty'])) {
$fieldArgs['empty'] = $fieldOptions['empty'];
} else {
$fieldArgs['empty'] = true;
}

// A boolean field is a checkbox. Set the label and class to improve rendering
// and accessibility.
if($fieldType === 'boolean') {
$fieldArgs['label'] = $fieldLabel;
$fieldArgs['class'] = 'form-check-input';
} elseif($fieldType === 'date') {
return $this->dateField($fieldName, DateTypeEnum::DateOnly);
} elseif($fieldType == 'datetime' || $fieldType == 'timestamp') {
return $this->dateField($fieldName);
}

// Get the field type from the map of fields (e.g. 'boolean', 'string', 'timestamp')
$fieldType = $fieldType ?? $this->getFieldType($fieldName);
// Generate the form control or pass along the markup generated in a wrapper function
return $this->Form->control($fieldName, $fieldArgs);

return match($fieldType) {
// A boolean field is a checkbox. Set the label and class to improve rendering
// and accessibility.
'boolean' => $this->Form->control($fieldName, [
// First import and then overwrite
...$fieldArgs,
'label' => $fieldLabel,
'class' => 'form-check-input',
]),
'date' => $this->dateField($fieldName, DateTypeEnum::DateOnly),
'datetime',
'timestamp' => $this->dateField($fieldName),
default => $this->Form->control($fieldName, $fieldArgs)
};
}

/**
Expand Down
10 changes: 8 additions & 2 deletions app/templates/element/form/listItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,25 @@
$this->set('fieldName', $arguments['fieldName']);
$this->set('vv_field_arguments', $arguments);

// Additional classes calculation
// Class calculation by field Type
$classes = match ($this->Fieeld->getFieldType($arguments['fieldName'])) {
'date',
'datetime',
'timestamp' => 'fields-datepicker ',
default => ''
};

// Class calculation by field name
$classes .= match ($arguments['fieldName']) {
'source_record' => 'source-record ',
'retry_interval',
'login' => 'subfield ',
default => ''
};

// Class calculation by type of Info Div
if(isset($arguments['autocomplete'])) {
$classes = 'fields-people-autocomplete ';
$classes .= 'fields-people-autocomplete ';
}

?>
Expand Down
3 changes: 2 additions & 1 deletion app/templates/element/form/nameDiv.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@

// Override the default required behavior is the field has the required
// option set
$optionsRequired = boolval($vv_field_arguments['fieldOptions']['required']);
$optionsRequired = isset($vv_field_arguments['fieldOptions']['required'])
&& $vv_field_arguments['fieldOptions']['required'];

// Extra class required for the grouped controls elements
if(isset($groupedControls)) {
Expand Down
1 change: 1 addition & 0 deletions app/templates/element/notify/alert.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

$alertClass = "alert-{$type}";
$showButton = false;

if(isset($dismissible) && $dismissible) {
$alertClass .= ' alert-dismissible';
$showButton = true;
Expand Down
2 changes: 1 addition & 1 deletion app/webroot/js/comanage/comanage.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function showFields(fields, isPageLoad) {
$('#' + field).closest('li').addClass('collapse show');
} else {
$('#' + field).closest('li').collapse('show');
}
}
}
}

Expand Down

0 comments on commit d69bb7c

Please sign in to comment.