Skip to content

Commit

Permalink
Block generate uses the luya\admin\base\TypesInterface. closes #1136
Browse files Browse the repository at this point in the history
  • Loading branch information
nadar committed Jan 6, 2017
1 parent c8c5d19 commit 2e85aff
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The changelog contains informations about bug fixes, new features or bc breaking

### Added

- [#1136](https://github.com/luyadev/luya/issues/1136) Block generate uses the luya\admin\base\TypesInterface.
- [#1134](https://github.com/luyadev/luya/issues/1134) ToggleStatus plugin ables to toggle the status from the crud list overview.
- [#1133](https://github.com/luyadev/luya/issues/1133) Added callable $labelField and getter access for ngrest plugin luya\admin\ngrest\plugins\SelectModel.
- [#1121](https://github.com/luyadev/luya/issues/1121) Ukrain language added.
Expand Down
29 changes: 28 additions & 1 deletion core/console/commands/BlockController.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ private function getVariableTypes()
'textarea' => 'Textarea multi rows input',
'password' => 'Passwort input field (hides the signs)',
'number' => 'Numbers allowed only',
'decimal' => 'Decimal Number Float',
'wysiwyg' => 'What you see is what you get Editor',
'select' => 'Dropdown Select',
'date' => 'Date Selector',
Expand All @@ -133,9 +134,35 @@ private function getVariableTypes()
'image-array-upload' => 'creates an asrray with image id an caption string',
'list-array' => 'Creates an array with a key variable value',
'table' => 'User can dynamic create tables (jsons)',
'link' => 'Generats a linkable internal or external resource (use Link Injector!)',
'cms-page' => 'Returns CMS page selection tree (only when cms is registered).',
];
}

private function getVariableTypeInterfaceMap()
{
return [
'text' => 'self::TYPE_TEXT',
'textarea' => 'self::TYPE_TEXTAREA',
'password' => 'self::TYPE_PASSWORD',
'number' => 'self::TYPE_NUMBER',
'decimal' => 'self::TYPE_DECIMAL',
'wysiwyg' => 'self::TYPE_WYSIWYG',
'select' => 'self::TYPE_SELECT',
'date' => 'self::TYPE_DATE',
'datetime' => 'self::TYPE_DATETIME',
'checkbox' => 'self::TYPE_CHECKBOX',
'checkbox-array' => 'self::TYPE_CHECKBOX_ARRAY',
'file-upload' => 'self::TYPE_FILEUPLOAD',
'file-array-upload' => 'self::TYPE_FILEUPLOAD_ARRAY',
'image-upload' => 'self::TYPE_IMAGEUPLOAD',
'image-array-upload' => 'self::TYPE_IMAGEUPLOAD_ARRAY',
'list-array' => 'self::TYPE_LIST_ARRAY',
'table' => 'self::TYPE_TABLE',
'link' => 'self::TYPE_LINK',
'cms-page' => 'self::TYPE_CMS_PAGE',
];
}

private function getVariableTypesOptions()
{
Expand Down Expand Up @@ -219,7 +246,7 @@ private function varCreator($prefix, $typeCast)
$v = [
'var' => Inflector::variablize($name),
'label' => $label,
'type' => 'zaa-'.$type,
'type' => $this->getVariableTypeInterfaceMap()[$type],
];

if ($this->hasVariableTypeOption($type)) {
Expand Down
4 changes: 2 additions & 2 deletions core/console/commands/views/block/create_block.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ public function config()
<?php if (!empty($config['vars'])): ?>
'vars' => [
<?php foreach ($config['vars'] as $var): ?>
['var' => '<?= $var['var']; ?>', 'label' => '<?= $var['label']; ?>', 'type' => '<?= $var['type']; ?>'<?php if (isset($var['options'])): ?>, 'options' => <?= $var['options']; ?><?php endif; ?>],
['var' => '<?= $var['var']; ?>', 'label' => '<?= $var['label']; ?>', 'type' => <?= $var['type']; ?><?php if (isset($var['options'])): ?>, 'options' => <?= $var['options']; ?><?php endif; ?>],
<?php endforeach; ?>
],
<?php endif; ?>
<?php if (!empty($config['cfgs'])): ?>
'cfgs' => [
<?php foreach ($config['cfgs'] as $var): ?>
['var' => '<?= $var['var']; ?>', 'label' => '<?= $var['label']; ?>', 'type' => '<?= $var['type']; ?>'<?php if (isset($var['options'])): ?>, 'options' => <?= $var['options']; ?><?php endif; ?>],
['var' => '<?= $var['var']; ?>', 'label' => '<?= $var['label']; ?>', 'type' => <?= $var['type']; ?><?php if (isset($var['options'])): ?>, 'options' => <?= $var['options']; ?><?php endif; ?>],
<?php endforeach; ?>
],
<?php endif; ?>
Expand Down
12 changes: 11 additions & 1 deletion modules/admin/src/base/TypesInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,20 @@ interface TypesInterface
/**
* @var string
*/
const TYPE_IAGEUPLOAD_ARRAY = 'zaa-image-upload-array';
const TYPE_IMAGEUPLOAD_ARRAY = 'zaa-image-upload-array';

/**
* @var string
*/
const TYPE_LIST_ARRAY = 'zaa-list-array';

/**
* @var string Generates a table view similar to a json input.
*/
const TYPE_TABLE = 'zaa-table';

/**
* @var string Generates a selection of all cms page, works only if cms module is present.
*/
const TYPE_CMS_PAGE = 'zaa-cms-page';
}
32 changes: 16 additions & 16 deletions tests/core/console/commands/BlockControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ public function config()
{
return [
'vars' => [
['var' => 'foo', 'label' => 'Foo', 'type' => 'zaa-text'],
['var' => 'bar', 'label' => 'Bar', 'type' => 'zaa-image', 'options' => OPTIONS!],
['var' => 'foo', 'label' => 'Foo', 'type' => self::TYPE_TEXT],
['var' => 'bar', 'label' => 'Bar', 'type' => self::TYPE_IMAGEUPLOAD, 'options' => OPTIONS!],
],
'cfgs' => [
['var' => 'foo', 'label' => 'Foo', 'type' => 'zaa-text'],
['var' => 'bar', 'label' => 'Bar', 'type' => 'zaa-image', 'options' => OPTIONS!],
['var' => 'foo', 'label' => 'Foo', 'type' => self::TYPE_TEXT],
['var' => 'bar', 'label' => 'Bar', 'type' => self::TYPE_IMAGEUPLOAD, 'options' => OPTIONS!],
],
'placeholders' => [
['var' => 'foo', 'label' => 'Foo'],
Expand Down Expand Up @@ -124,12 +124,12 @@ public function admin()
$ctrl->type = BlockController::TYPE_APP;
$ctrl->config = [
'vars' => [
['var' => 'foo', 'type' => 'zaa-text', 'label' => 'Foo'],
['var' => 'bar', 'type' => 'zaa-image', 'label' => 'Bar', 'options'=> 'OPTIONS!'],
['var' => 'foo', 'type' => 'self::TYPE_TEXT', 'label' => 'Foo'],
['var' => 'bar', 'type' => 'self::TYPE_IMAGEUPLOAD', 'label' => 'Bar', 'options'=> 'OPTIONS!'],
],
'cfgs' => [
['var' => 'foo', 'type' => 'zaa-text', 'label' => 'Foo'],
['var' => 'bar', 'type' => 'zaa-image', 'label' => 'Bar', 'options'=> 'OPTIONS!'],
['var' => 'foo', 'type' => 'self::TYPE_TEXT', 'label' => 'Foo'],
['var' => 'bar', 'type' => 'self::TYPE_IMAGEUPLOAD', 'label' => 'Bar', 'options'=> 'OPTIONS!'],
],
'placeholders' => [
['var' => 'foo', 'label' => 'Foo'],
Expand Down Expand Up @@ -214,12 +214,12 @@ public function config()
{
return [
'vars' => [
['var' => 'foo', 'label' => 'Foo', 'type' => 'zaa-text'],
['var' => 'bar', 'label' => 'Bar', 'type' => 'zaa-image', 'options' => OPTIONS!],
['var' => 'foo', 'label' => 'Foo', 'type' => self::TYPE_TEXT],
['var' => 'bar', 'label' => 'Bar', 'type' => self::TYPE_IMAGEUPLOAD, 'options' => OPTIONS!],
],
'cfgs' => [
['var' => 'foo', 'label' => 'Foo', 'type' => 'zaa-text'],
['var' => 'bar', 'label' => 'Bar', 'type' => 'zaa-image', 'options' => OPTIONS!],
['var' => 'foo', 'label' => 'Foo', 'type' => self::TYPE_TEXT],
['var' => 'bar', 'label' => 'Bar', 'type' => self::TYPE_IMAGEUPLOAD, 'options' => OPTIONS!],
],
'placeholders' => [
['var' => 'foo', 'label' => 'Foo'],
Expand Down Expand Up @@ -257,12 +257,12 @@ public function admin()
$ctrl->type = BlockController::TYPE_MODULE;
$ctrl->config = [
'vars' => [
['var' => 'foo', 'type' => 'zaa-text', 'label' => 'Foo'],
['var' => 'bar', 'type' => 'zaa-image', 'label' => 'Bar', 'options'=> 'OPTIONS!'],
['var' => 'foo', 'type' => 'self::TYPE_TEXT', 'label' => 'Foo'],
['var' => 'bar', 'type' => 'self::TYPE_IMAGEUPLOAD', 'label' => 'Bar', 'options'=> 'OPTIONS!'],
],
'cfgs' => [
['var' => 'foo', 'type' => 'zaa-text', 'label' => 'Foo'],
['var' => 'bar', 'type' => 'zaa-image', 'label' => 'Bar', 'options'=> 'OPTIONS!'],
['var' => 'foo', 'type' => 'self::TYPE_TEXT', 'label' => 'Foo'],
['var' => 'bar', 'type' => 'self::TYPE_IMAGEUPLOAD', 'label' => 'Bar', 'options'=> 'OPTIONS!'],
],
'placeholders' => [
['var' => 'foo', 'label' => 'Foo'],
Expand Down

0 comments on commit 2e85aff

Please sign in to comment.