diff --git a/src/migrations/m220523_110031_add_hide_template_flag.php b/src/migrations/m220523_110031_add_hide_template_flag.php new file mode 100644 index 0000000..60320b0 --- /dev/null +++ b/src/migrations/m220523_110031_add_hide_template_flag.php @@ -0,0 +1,26 @@ +addColumn('{{%hrzg_widget_template}}', 'hide_in_list_selection', + $this->boolean()->notNull()->defaultValue(0)->after('twig_template')); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropColumn('{{%hrzg_widget_template}}', 'hide_in_list_selection'); + } +} diff --git a/src/models/crud/WidgetTemplate.php b/src/models/crud/WidgetTemplate.php index 1edc633..0ea9f75 100644 --- a/src/models/crud/WidgetTemplate.php +++ b/src/models/crud/WidgetTemplate.php @@ -17,6 +17,10 @@ */ class WidgetTemplate extends BaseWidgetTemplate { + + public const IS_VISIBLE_IN_LIST = 0; + public const IS_HIDDEN_IN_LIST = 1; + /** * @inheritdoc */ @@ -58,7 +62,11 @@ function ($attribute, $params) { } }, ], - + [ + 'hide_in_list_selection', + 'in', + 'range' => [self::IS_HIDDEN_IN_LIST, self::IS_VISIBLE_IN_LIST] + ] ] ); } diff --git a/src/models/crud/base/WidgetTemplate.php b/src/models/crud/base/WidgetTemplate.php index e0a7848..11a01ed 100644 --- a/src/models/crud/base/WidgetTemplate.php +++ b/src/models/crud/base/WidgetTemplate.php @@ -13,6 +13,7 @@ * @property string $name * @property string $json_schema * @property string $twig_template + * @property bool $hide_in_list_selection */ abstract class WidgetTemplate extends \yii\db\ActiveRecord { @@ -55,7 +56,8 @@ public function getAliasModel($plural = false) public function rules() { return [ - [['name', 'php_class', 'json_schema'], 'required'], + [['name', 'php_class', 'json_schema','hide_in_list_selection'], 'required'], + [['hide_in_list_selection'], 'boolean'], [['json_schema', 'twig_template'], 'string'], [['created_at', 'updated_at'], 'safe'], [['name'], 'string', 'max' => 255], @@ -72,6 +74,7 @@ public function attributeLabels() 'name' => Yii::t('widgets', 'Name'), 'json_schema' => Yii::t('widgets', 'Json Schema'), 'twig_template' => Yii::t('widgets', 'Twig Template'), + 'hide_in_list_selection' => Yii::t('widgets', 'Hide In List Selection'), 'created_at' => Yii::t('widgets', 'Created At'), 'updated_at' => Yii::t('widgets', 'Updated At'), ]; diff --git a/src/models/crud/search/WidgetTemplate.php b/src/models/crud/search/WidgetTemplate.php index 5a35af1..0383ffc 100644 --- a/src/models/crud/search/WidgetTemplate.php +++ b/src/models/crud/search/WidgetTemplate.php @@ -19,7 +19,7 @@ public function rules() { return [ [['id'], 'integer'], - [['name', 'json_schema', 'twig_template', 'created_at', 'updated_at'], 'safe'], + [['name', 'json_schema', 'twig_template', 'created_at', 'updated_at', 'php_class', 'hide_in_list_selection'], 'safe'], ]; } @@ -63,7 +63,9 @@ public function search($params) $query->andFilterWhere(['like', 'name', $this->name]) ->andFilterWhere(['like', 'json_schema', $this->json_schema]) - ->andFilterWhere(['like', 'twig_template', $this->twig_template]); + ->andFilterWhere(['like', 'twig_template', $this->twig_template]) + ->andFilterWhere(['like', 'php_class', $this->php_class]) + ->andFilterWhere(['like', 'hide_in_list_selection', $this->hide_in_list_selection]); $query->orderBy('name'); diff --git a/src/views/crud/widget-template/_form.php b/src/views/crud/widget-template/_form.php index 10c5e09..1674b09 100644 --- a/src/views/crud/widget-template/_form.php +++ b/src/views/crud/widget-template/_form.php @@ -55,6 +55,8 @@ ['mode' => 'twig', 'containerOptions' => ['style' => 'height: 800px;']] ) ?> endBlock() ?> + + field($model,'hide_in_list_selection')->checkbox() ?>

endBlock(); ?> blocks['main'] ?> diff --git a/src/views/crud/widget-template/index.php b/src/views/crud/widget-template/index.php index 9bfc4a9..4bd4f2b 100644 --- a/src/views/crud/widget-template/index.php +++ b/src/views/crud/widget-template/index.php @@ -1,4 +1,5 @@ 'widget-template-main', + 'id' => 'widget-template-main', 'enableReplaceState' => false, - 'linkSelector' => '#pjax-main ul.pagination a, th a', + 'linkSelector' => '#pjax-main ul.pagination a, th a', ] ) ?>

@@ -30,7 +31,7 @@

- '.\Yii::t('widgets', 'New'), ['create'], + ' . \Yii::t('widgets', 'New'), ['create'], ['class' => 'btn btn-success']) ?>
@@ -52,15 +53,28 @@ 'template' => '{view} {update} {delete}', 'urlCreator' => function ($action, $model, $key, $index) { // using the column name as key, not mapping to 'id' like the standard generator - $params = is_array($key) ? $key : [$model->primaryKey()[0] => (string) $key]; - $params[0] = \Yii::$app->controller->id ? \Yii::$app->controller->id.'/'.$action : $action; + $params = is_array($key) ? $key : [$model->primaryKey()[0] => (string)$key]; + $params[0] = \Yii::$app->controller->id ? \Yii::$app->controller->id . '/' . $action : $action; return Url::toRoute($params); }, 'contentOptions' => ['nowrap' => 'nowrap'], ], 'name', - 'php_class', + [ + 'attribute' => 'php_class', + 'filter' => $searchModel->optPhpClass() + ], + [ + 'attribute' => 'hide_in_list_selection', + 'filter' => [ + WidgetTemplate::IS_VISIBLE_IN_LIST => Yii::t('widgets', 'Visible'), + WidgetTemplate::IS_HIDDEN_IN_LIST => Yii::t('widgets', 'Hidden'), + ], + 'value' => function ($model) { + return $model->hide_in_list_selection === WidgetTemplate::IS_VISIBLE_IN_LIST ? Yii::t('widgets', 'Visible') : Yii::t('widgets', 'Hidden'); + } + ] ], ]); ?> diff --git a/src/views/crud/widget-template/view.php b/src/views/crud/widget-template/view.php index cec8548..612bf4b 100644 --- a/src/views/crud/widget-template/view.php +++ b/src/views/crud/widget-template/view.php @@ -4,6 +4,7 @@ * @var hrzg\widget\models\crud\WidgetTemplate $model */ use dmstr\bootstrap\Tabs; +use hrzg\widget\models\crud\WidgetTemplate; use insolita\wgadminlte\Box; use yii\helpers\Html; use yii\widgets\DetailView; @@ -79,6 +80,12 @@ 'format' => 'html', 'value' => '
' . Html::encode($model->twig_template) . '
' ], + [ + 'attribute' => 'hide_in_list_selection', + 'value' => function ($model) { + return $model->hide_in_list_selection === WidgetTemplate::IS_VISIBLE_IN_LIST ? Yii::t('widgets', 'Visible') : Yii::t('widgets', 'Hidden'); + } + ], 'created_at', 'updated_at', ], diff --git a/src/widgets/Cell.php b/src/widgets/Cell.php index 229434d..61cc3a1 100644 --- a/src/widgets/Cell.php +++ b/src/widgets/Cell.php @@ -135,7 +135,7 @@ public function getMenuItems() $linkTarget = \Yii::$app->params['backend.iframe.name'] ?? '_self'; return [ [ - 'label' => ' ' . $this->id . ' Cell', + 'label' => ' ' . $this->id . ' ' . \Yii::t('widgets', 'Cell') . '', 'items' => [[ 'label' => FA::icon(FA::_PLUS), 'url' => [ @@ -302,7 +302,12 @@ private function generateCellControls() ['label' => $this->id] ]; - foreach (WidgetTemplate::find()->where(['php_class' => TwigTemplate::class])->orderBy('name')->all() as $template) { + $templates = WidgetTemplate::find() + ->where(['php_class' => TwigTemplate::class]) + ->andWhere(['hide_in_list_selection' => WidgetTemplate::IS_VISIBLE_IN_LIST]) + ->orderBy('name') + ->all(); + foreach ($templates as $template) { $items[] = [ 'label' => $template->name, 'url' => [