Skip to content

Commit

Permalink
Updates to release v1.8.6 fix #187 fix #182 fix #180 fix #172
Browse files Browse the repository at this point in the history
  • Loading branch information
kartik-v committed Jan 11, 2022
1 parent cdeb72a commit 13992a8
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 74 deletions.
7 changes: 6 additions & 1 deletion CHANGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ Change Log: `yii2-detail-view`

## Version 1.8.6

**Date:** _under development_
**Date:** 11-Jan-2022

- Enhance & standardize php docs for new website https://docs.krajee.com.
- (bug #187): Fix BootstrapTrait usage.
- (enh #186): Correct alignments of BS3 controls in edit mode.
- (enh #185): New property `arrayValueToString` to control array values being printed via `print_r`.
- (enh #184): Add Slovak Translations and enhance model validation.
- (enh #182): Document `showErrorSummary` in docs.
- (enh #180): Accept array messages in flashes.
- (enh #172): Correct table condensed styles for child columns.

## Version 1.8.5

Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2014 - 2021, Kartik Visweswaran
Copyright (c) 2014 - 2022, Kartik Visweswaran
Krajee.com
All rights reserved.

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ Refer the [CHANGE LOG](https://github.com/kartik-v/yii2-detail-view/blob/master/

> NOTE: Bootstrap 5.x support is added since v1.8.4. The extension includes a BC Breaking change with v1.7.0. With this release, the `template` property of the yii core DetailView is not anymore supported. One can use `rowOptions`, `labelColOptions`, `valueColOptions` at the widget level or widget `attributes` level to configure advanced layout functionality.
### Demo
You can see detailed [documentation](http://demos.krajee.com/detail-view) and [demonstration](http://demos.krajee.com/detail-view-demo) on usage of the extension.
### Docs & Demo
You can see detailed [documentation](http://demos.krajee.com/detail-view), [demonstration](http://demos.krajee.com/detail-view-demo) and API [code documentation](https://docs.krajee.com/kartik-detail-detailview) on usage of the extension.

## Installation

Expand Down
112 changes: 54 additions & 58 deletions src/DetailView.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* @package yii2-detail-view
* @author Kartik Visweswaran <kartikv2@gmail.com>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2021
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2022
* @version 1.8.6
*/

Expand All @@ -12,6 +12,7 @@
use Closure;
use Exception;
use kartik\base\BootstrapInterface;
use kartik\base\BootstrapTrait;
use kartik\base\Config;
use kartik\base\TranslationTrait;
use kartik\base\WidgetTrait;
Expand Down Expand Up @@ -63,6 +64,7 @@
class DetailView extends YiiDetailView implements BootstrapInterface
{
use WidgetTrait;
use BootstrapTrait;
use TranslationTrait;

/**
Expand Down Expand Up @@ -400,7 +402,7 @@ class DetailView extends YiiDetailView implements BootstrapInterface
public $hideAlerts = false;

/**
* @var bool whether to show form error summery as an error alert. Defaults to `false`.
* @var bool whether to show form error summary as part of the error alert. Defaults to `false`.
*/
public $showErrorSummary = false;

Expand Down Expand Up @@ -519,53 +521,53 @@ class DetailView extends YiiDetailView implements BootstrapInterface
*
* An attribute can also be specified in terms of an array with the following elements.
*
* - attribute: string|Closure, the attribute name. This is required if either "label" or "value" is not specified.
* - label: string|Closure, the label associated with the attribute. If this is not specified, it will be generated
* - `attribute`: _string|Closure_, the attribute name. This is required if either "label" or "value" is not specified.
* - `label`: _string|Closure_, the label associated with the attribute. If this is not specified, it will be generated
* from the attribute name.
* - value: mixed|Closure, the value to be displayed. If this is not specified, it will be retrieved from [[model]]
* - `value`: _mixed|Closure_, the value to be displayed. If this is not specified, it will be retrieved from [[model]]
* using the attribute name by calling [[ArrayHelper::getValue()]]. Note that this value will be formatted into
* a displayable text according to the "format" option.
* - format: mixed|Closure, the type of the value that determines how the value would be formatted into a
* - `format`: _mixed|Closure_, the type of the value that determines how the value would be formatted into a
* displayable text. Please refer to [[Formatter]] for supported types.
* - visible: boolean|Closure, whether the attribute is visible. If set to `false`, the attribute will NOT be
* - `visible`: _boolean|Closure_, whether the attribute is visible. If set to `false`, the attribute will NOT be
* displayed.
*
* Additional special settings are:
* - viewModel: Model|Closure, the model to be used for this attribute in VIEW mode. This will override the `model`
* - `viewModel`: _Model|Closure_, the model to be used for this attribute in VIEW mode. This will override the `model`
* setting at the widget level. If not set, the widget `model` setting will be used.
* - editModel: Model|Closure, the model to be used for this attribute in EDIT mode. This will override the `model`
* - `editModel`: _Model|Closure_, the model to be used for this attribute in EDIT mode. This will override the `model`
* setting at the widget level. If not set, the widget `model` setting will be used.
* - rowOptions: array|Closure, HTML attributes for the row (if not set, this will be defaulted to the `rowOptions`
* - `rowOptions`: _array|Closure_, HTML attributes for the row (if not set, this will be defaulted to the `rowOptions`
* set at the widget level)
* - labelColOptions: array|Closure, HTML attributes for the label column (if not set, this will be defaulted to
* - `labelColOptions`: _array|Closure_, HTML attributes for the label column (if not set, this will be defaulted to
* the `labelColOptions` set at the widget level)
* - valueColOptions: array|Closure, HTML attributes for the value column (if not set, this will be defaulted to
* - `valueColOptions`: _array|Closure_, HTML attributes for the value column (if not set, this will be defaulted to
* `valueColOptions` set at the widget level)
* - group: boolean|Closure, whether to group the selection by merging the label and value into a single column.
* - groupOptions: array|Closure, HTML attributes for the grouped/merged column when `group` is set to `true`.
* - type: string|Closure, the input type for rendering the attribute in edit mode. Must be one of the
* - `group`: _boolean|Closure_, whether to group the selection by merging the label and value into a single column.
* - `groupOptions`: _array|Closure_, HTML attributes for the grouped/merged column when `group` is set to `true`.
* - `type`: _string|Closure_, the input type for rendering the attribute in edit mode. Must be one of the
* [[DetailView::::INPUT_]] constants.
* - displayOnly: boolean|Closure, if the input is to be set to as `display only` in edit mode.
* - widgetOptions: array|Closure, the widget options if you set `type` to [[DetailView::::INPUT_WIDGET]]. The
* - `displayOnly`: _boolean|Closure_, if the input is to be set to as `display only` in edit mode.
* - widgetOptions: array|Closure_, the widget options if you set `type` to [[DetailView::::INPUT_WIDGET]]. The
* following special options are recognized:
* - `class`: string the fully namespaced widget class.
* - items: array|Closure, the list of data items for dropDownList, listBox, checkboxList & radioList
* - inputType: string|Closure, the HTML 5 input type if `type` is set to [[DetailView::::INPUT_HTML 5]].
* - inputContainer: array|Closure, HTML attributes for the input container
* - inputWidth: string|Closure, the width of the container holding the input, should be appended along with the
* - `class`: _string the fully namespaced widget class.
* - `items`: _array|Closure_, the list of data items for dropDownList, listBox, checkboxList & radioList
* - `inputType`: _string|Closure_, the HTML 5 input type if `type` is set to [[DetailView::::INPUT_HTML 5]].
* - `inputContainer`: _array|Closure_, HTML attributes for the input container
* - `inputWidth`: _string|Closure_, the width of the container holding the input, should be appended along with the
* width unit (`px` or `%`) - this property is deprecated since v1.7.7
* - fieldConfig: array|Closure, optional, the Active field configuration.
* - options: array|Closure, optional, the HTML attributes for the input.
* - updateAttr: string|Closure, optional, the name of the attribute to be updated, when in edit mode. This will
* - `fieldConfig`: _array|Closure_, optional, the Active field configuration.
* - `options`: _array|Closure_, optional, the HTML attributes for the input.
* - `updateAttr`: _string|Closure_, optional, the name of the attribute to be updated, when in edit mode. This will
* default to the `attribute` setting.
* - updateMarkup: string|Closure, the raw markup to render in edit mode. If not set, this normally will be
* - `updateMarkup`: _string|Closure_, the raw markup to render in edit mode. If not set, this normally will be
* automatically generated based on `attribute` or `updateAttr` setting. If this is set it will override the
* default markup.
*
* Note that all of the attribute properties above can also be setup as a Closure callback with the signature
* `function($form, $widget)`, where:
* - `$form`: ActiveForm, is the current active form object in the detail view.
* - `$widget`: DetailView, is the current detail view widget instance.
* - `$form`: _ActiveForm_, is the current active form object in the detail view.
* - `$widget`: _DetailView_, is the current detail view widget instance.
*/
public $attributes;

Expand Down Expand Up @@ -775,11 +777,6 @@ class DetailView extends YiiDetailView implements BootstrapInterface
*/
protected $_form;

/**
* @var array HTML attributes for child tables
*/
protected $_childTableOptions = [];

/**
* @var array HTML attributes for table row
*/
Expand Down Expand Up @@ -815,9 +812,7 @@ protected function initWidget()
$this->pluginName = 'kvDetailView';
$this->initBsVersion();
$notBs3 = !$this->isBs(3);
if ($notBs3) {
Html::addCssClass($this->container, 'kv-container-bs4');
}
Html::addCssClass($this->container, 'kv-container-bs' . ($notBs3 ? 4 : 3));
if ($this->enableEditMode) {
/**
* @var string|ActiveForm $formClass
Expand All @@ -835,27 +830,26 @@ protected function initWidget()
}
if ($this->bootstrap) {
Html::addCssClass($this->options, 'table');
if ($this->condensed) {
$this->addCssClass($this->options, self::BS_TABLE_CONDENSED);
}
if ($this->hover) {
Html::addCssClass($this->options, 'table-hover');
}
if ($this->bordered) {
Html::addCssClass($this->options, 'table-bordered');
}
if ($this->condensed) {
$this->addCssClass($this->options, self::BS_TABLE_CONDENSED);
}
$this->_childTableOptions = $this->options;
if ($this->striped) {
Html::addCssClass($this->options, 'table-striped');
}
}
Html::addCssClass($this->_childTableOptions, 'kv-child-table');
Html::addCssClass($this->options, 'detail-view');
Html::addCssStyle($this->labelColOptions, "text-align:{$this->hAlign};vertical-align:{$this->vAlign};");
}

/**
* Prepares and runs the detail view widget
* Prepares and runs the detail view widget.
*
* @throws ReflectionException
* @throws Exception
*/
Expand Down Expand Up @@ -901,7 +895,8 @@ protected function runWidget()
}

/**
* Initializes and renders alert container block
* Initializes and renders alert container block.
*
* @throws Exception
*/
protected function renderAlertBlock()
Expand All @@ -920,15 +915,15 @@ protected function renderAlertBlock()
Html::addCssStyle($this->alertContainerOptions, 'display:none;');
}
$out = Html::beginTag('div', $this->alertContainerOptions);
$alertWidgetClass = !$this->isBs(3) ? 'yii\bootstrap4\Alert' : 'yii\bootstrap\Alert';
$alertWidgetClass = $this->getBSClass('Alert');
foreach ($flashes as $type => $message) {
if (!isset($this->alertMessageSettings[$type])) {
continue;
}
$opts = $this->alertWidgetOptions;
$options = ArrayHelper::getValue($opts, 'options', []);
Html::addCssClass($options, $this->alertMessageSettings[$type]);
$opts['body'] = $message;
$opts['body'] = is_array($message) ? implode('<br>', $message) : $message;
$opts['options'] = $options;
/** @noinspection PhpUndefinedMethodInspection */
$out .= "\n" . $alertWidgetClass::widget($opts);
Expand All @@ -939,7 +934,7 @@ protected function renderAlertBlock()
}

/**
* Check if model has editing errors
* Check if model has editing errors.
*
* @return boolean
*/
Expand All @@ -963,8 +958,7 @@ protected function hasEditErrors()
}

/**
* Validates the display of correct attributes and buttons
* at initialization based on mode
* Validates the display of correct attributes and buttons at initialization based on mode.
*
* @return void
*/
Expand All @@ -986,7 +980,7 @@ protected function validateDisplay()
}

/**
* Renders the main detail view widget
* Renders the main detail view widget.
*
* @return string the detail view content
* @throws InvalidConfigException
Expand Down Expand Up @@ -1082,7 +1076,7 @@ protected function renderAttributeItem($attribute)
}

/**
* Checks if a bootstrap grid column class has been added to the container
* Checks if a bootstrap grid column class has been added to the container.
*
* @param array $container
*
Expand All @@ -1109,7 +1103,7 @@ protected static function hasGridCol($container = [])
}

/**
* Renders each form attribute
* Renders each form attribute.
*
* @param array $config the attribute config
*
Expand Down Expand Up @@ -1183,7 +1177,7 @@ protected function renderFormAttribute($config)
}

/**
* Sets a default css class within `options` if not set
* Sets a default css class within `options` if not set.
*
* @param array $options the HTML options
* @param string|array $css the CSS class to test and append
Expand All @@ -1197,6 +1191,7 @@ protected static function initCss(&$options, $css)

/**
* Sets the grid panel layout based on the [[template]] and [[panel]] settings.
*
* @param string $items
* @return string
* @throws InvalidConfigException|Exception
Expand Down Expand Up @@ -1266,7 +1261,7 @@ protected function renderPanel($items)
}

/**
* Renders the buttons for a specific mode
* Renders the buttons for a specific mode.
*
* @param integer $mode
*
Expand All @@ -1289,7 +1284,7 @@ protected function renderButtons($mode = 1)
}

/**
* Renders a button
* Renders a button.
*
* @param string $type the button type
*
Expand Down Expand Up @@ -1318,7 +1313,7 @@ protected function renderButton($type)
}

/**
* Gets the default button
* Gets the default button.
*
* @param string $type the button type
* @param string $iconBs3 the bootstrap 3 icon suffix name
Expand Down Expand Up @@ -1357,7 +1352,8 @@ protected function getDefaultButton($type, $iconBs3, $iconNotBs3, $title)
}

/**
* Register assets
* Register client assets for the [[DetailView]] widget.
*
* @throws Exception
*/
protected function registerAssets()
Expand Down Expand Up @@ -1431,7 +1427,7 @@ protected function normalizeAttributes()
}

/**
* Parses and returns the attribute
* Parses and returns the attribute.
*
* @param string|array $attribute the attribute item configuration
*
Expand Down Expand Up @@ -1527,4 +1523,4 @@ protected function parseAttributeProp($setting)
*/
return $setting instanceof Closure ? $setting($this->_form, $this) : $setting;
}
}
}
2 changes: 1 addition & 1 deletion src/DetailViewAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* @package yii2-detail-view
* @author Kartik Visweswaran <kartikv2@gmail.com>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2021
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2022
* @version 1.8.6
*/

Expand Down
8 changes: 4 additions & 4 deletions src/assets/css/kv-detail-view.css
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*!
* @package yii2-detail-view
* @author Kartik Visweswaran <kartikv2@gmail.com>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2021
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2022
* @version 1.8.6
*
* Styles for yii2-detail-view extension
*
* Author: Kartik Visweswaran
* Copyright: 2014 - 2021, Kartik Visweswaran, Krajee.com
* Copyright: 2014 - 2022, Kartik Visweswaran, Krajee.com
* For more JQuery plugins visit http://plugins.krajee.com
* For more Yii related demos visit http://demos.krajee.com
*/
Expand Down Expand Up @@ -105,11 +105,11 @@

}

.table .kv-child-table > tbody > tr > td, .table .kv-child-table > tbody > tr > th {
.kv-container-bs3 .table .kv-child-table > tbody > tr > td, .kv-container-bs3 .table .kv-child-table > tbody > tr > th {
padding: 8px;
}

.table-condensed .kv-child-table > tbody > tr > td, .table-condensed .kv-child-table > tbody > tr > th {
.kv-container-bs3 .table-condensed .kv-child-table > tbody > tr > td, .kv-container-bs3 .table-condensed .kv-child-table > tbody > tr > th {
padding: 5px;
}

Expand Down
Loading

0 comments on commit 13992a8

Please sign in to comment.