Skip to content

Commit

Permalink
Custom date format in date plugin for list rendering. (#270)
Browse files Browse the repository at this point in the history
* Block Preview styling

* Tooltip preview fix #246

* Date plugin with custom format

* Changelog for #270

* Refactored namespace using
  • Loading branch information
boehsermoe authored and nadar committed Mar 5, 2019
1 parent 8820619 commit 54c6527
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,26 @@ In order to read more about upgrading and BC breaks have a look at the [UPGRADE

This release contains new migrations and requires to run the `migrate` command after updating. Check the [UPGRADE Document](UPGRADE.md).

## Changed
### Changed

+ [#268](https://github.com/luyadev/luya-module-admin/issues/268) Deprecated classes, methods and properties has been removed.
+ [#261](https://github.com/luyadev/luya-module-admin/issues/261) Add ngRestFind() for none $is_api_user Users.
+ [#210](https://github.com/luyadev/luya-module-admin/issues/210) New tag translation option.
+ [#140](https://github.com/luyadev/luya-module-admin/issues/140) Generic Scheduler with Yii Queue integration.

## Fixed
### Fixed

+ [#258](https://github.com/luyadev/luya-module-admin/issues/258) NgRest Crud search with pagination problem fixed.
+ [#226](https://github.com/luyadev/luya-module-admin/issues/226) Fixed search indicator
+ [#267](https://github.com/luyadev/luya-module-admin/pull/267) I18n::decodeFindActive returned empty value for explicitly selected lang

## Added
### Added

+ [#205](https://github.com/luyadev/luya-module-admin/issues/205) CRUD search works now in filters and relation calls, sorting and pagination works in searching.
+ [#216](https://github.com/luyadev/luya-module-admin/issues/216) File manager file detail view provides option to tag files.
+ [#259](https://github.com/luyadev/luya-module-admin/pull/259) SelectRelationActiveQuery supports related i18n label fields
+ [#253](https://github.com/luyadev/luya-module-admin/pull/253) Added command action to reset password for users via cli.
+ [#270](https://github.com/luyadev/luya-module-admin/pull/270) Custom date format for date plugin in listing.

## 1.2.3 (21. November 2018)

Expand Down
11 changes: 10 additions & 1 deletion src/ngrest/plugins/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace luya\admin\ngrest\plugins;

use luya\admin\ngrest\base\Plugin;
use Yii;

/**
* Data input field
Expand All @@ -27,13 +28,21 @@ class Date extends Plugin
*/
public $emptyMessage = '-';

/**
* @var string Use custom datetime format by [date filter](https://docs.angularjs.org/api/ng/filter/date). Default is 'shortDate'. Use false to take \yii\i18n\Formatter::$dateFormat as fallback.
* @since 2.0.0
*/
public $format = 'shortDate';

/**
* @inheritdoc
*/
public function renderList($id, $ngModel)
{
$format = $this->format ?? Yii::$app->formatter->dateFormat;

return [
$this->createTag('span', null, ['ng-show' => $ngModel, 'ng-bind' => $ngModel.'*1000 | date : \'shortDate\'']),
$this->createTag('span', null, ['ng-show' => $ngModel, 'ng-bind' => $ngModel."*1000 | date : '$format'"]),
$this->createTag('span', $this->emptyMessage, ['ng-show' => '!'.$ngModel]),
];
}
Expand Down
19 changes: 14 additions & 5 deletions src/ngrest/plugins/Datetime.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace luya\admin\ngrest\plugins;

use luya\admin\ngrest\base\Plugin;
use Yii;

/**
* Date and Time input field
Expand All @@ -13,7 +14,7 @@
* Example empty Date configuration
*
* ```
* ['timestamp', ['Datetime', 'emptyMessage' => 'No Date']],
* ['timestamp', ['Datetime', 'emptyMessage' => 'No Date', 'format' => 'dd.MM.yyyy']],
* ```
*
* @author Basil Suter <basil@nadar.io>
Expand All @@ -22,30 +23,38 @@
class Datetime extends Plugin
{
/**
* @var string This text will be displayed in the list overview when no date has been slected
* @var string This text will be displayed in the list overview when no date has been selected
* or date is null/empty.
*/
public $emptyMessage = '-';

/**
* @var string Use custom datetime format by [date filter](https://docs.angularjs.org/api/ng/filter/date). Default is 'short'. Use false to take \yii\i18n\Formatter::$datetimeFormat as fallback.
* @since 2.0.0
*/
public $format = 'short';

/**
* @inheritdoc
*/
public function renderList($id, $ngModel)
{
$format = $this->format ?? Yii::$app->formatter->datetimeFormat;

return [
$this->createTag('span', null, ['ng-show' => $ngModel, 'ng-bind' => $ngModel.'*1000 | date : \'short\'']),
$this->createTag('span', null, ['ng-show' => $ngModel, 'ng-bind' => $ngModel."*1000 | date : '$format'"]),
$this->createTag('span', $this->emptyMessage, ['ng-show' => '!'.$ngModel]),
];
}

/**
* @inheritdoc
*/
public function renderCreate($id, $ngModel)
{
return $this->createFormTag('zaa-datetime', $id, $ngModel);
}

/**
* @inheritdoc
*/
Expand Down

0 comments on commit 54c6527

Please sign in to comment.