Skip to content

Commit

Permalink
Merge pull request #292 from schmunk42/feature/wedding-2023-04
Browse files Browse the repository at this point in the history
Feature/wedding 2023 04
  • Loading branch information
schmunk42 committed Apr 12, 2023
2 parents 4c021ca + 8ff455c commit eb31a95
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 59 deletions.
6 changes: 6 additions & 0 deletions src/commands/BatchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,11 @@ class BatchController extends Controller
*/
public $crudFixOutput = false;

/**
* @var integer number of grid columns in crud generator
*/
public $crudGridMaxColumns = 8;

/**
* @var string the namespace of the ActiveQuery class to be generated
*/
Expand Down Expand Up @@ -528,6 +533,7 @@ public function actionCruds()
'indexWidgetType' => $this->crudIndexWidgetType,
'indexGridClass' => $this->crudIndexGridClass,
'formLayout' => $this->crudFormLayout,
'gridMaxColumns' => $this->crudGridMaxColumns,
'generateAccessFilterMigrations' => $this->generateAccessFilterMigrations,
'actionButtonColumnPosition' => $this->crudActionButtonColumnPosition,
];
Expand Down
2 changes: 1 addition & 1 deletion src/generators/model/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ public function generateClassName($tableName, $useSchemaName = null)
$patterns[] = "/^{$db->tablePrefix}(.*?)$/";
$patterns[] = "/^(.*?){$db->tablePrefix}$/";

if (strpos($this->tableName, '*') !== false) {
if (strpos((string)$this->tableName, '*') !== false) {
$pattern = $this->tableName;
if (($pos = strrpos($pattern, '.')) !== false) {
$pattern = substr($pattern, $pos + 1);
Expand Down
35 changes: 34 additions & 1 deletion src/generators/module/default/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,45 @@

namespace <?= $generator->getControllerNamespace() ?>;

use dmstr\helpers\Metadata;
use rmrevin\yii\fontawesome\FA;
use yii\data\ArrayDataProvider;
use yii\web\Controller;

class DefaultController extends Controller
{
public function actionIndex()
{
return $this->render('index');
$controllers = Metadata::getModuleControllers($this->module->id);
$favourites = [];

$patterns = [
'^.*$' => ['color' => 'green', 'icon' => FA::_CUBE],
];

foreach ($patterns as $pattern => $options) {
foreach ($controllers as $c => $item) {
$controllers[$c]['label'] = $item['name'];
if ($item['name'] !== $this->id && preg_match("/$pattern/", $item['name'])) {
$favourites[$c] = $item;
$favourites[$c]['head'] = ucfirst(substr($item['name'], 0, 2));
$favourites[$c]['label'] = $item['name'];
$favourites[$c]['color'] = $options['color'];
$favourites[$c]['icon'] = $options['icon'] ?? null;
unset($controllers[$c]);
}
}
}

$dataProvider = new ArrayDataProvider([
'allModels' => $favourites,
'pagination' => [
'pageSize' => 100
]
]);

return $this->render('index', [
'dataProvider' => $dataProvider
]);
}
}
75 changes: 18 additions & 57 deletions src/generators/module/default/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,67 +5,28 @@

<?= '<?php' ?>

use rmrevin\yii\fontawesome\FA;
use yii\helpers\Inflector;

/*
* @var yii\web\View $this
/**
* @var ArrayDataProvider $dataProvider
*/
$controllers = \dmstr\helpers\Metadata::getModuleControllers($this->context->module->id);
$favourites = [];

$patterns = [
'^default$' => ['color' => 'gray', 'icon' => FA::_CUBE],
'^.*$' => ['color' => 'green', 'icon' => FA::_CUBE],
];

foreach ($patterns AS $pattern => $options) {
foreach ($controllers AS $c => $item) {
$controllers[$c]['label'] = $item['name'];
if (preg_match("/$pattern/", $item['name']) && $item['name'] !== 'default') {
$favourites[$c] = $item;
$favourites[$c]['head'] = ucfirst(substr($item['name'],0,2));
// ActiveRecord (model) counter
#$model = \Yii::createObject('app\\modules\\sakila\\models\\'.Inflector::id2camel($item['name']));
#$favourites[$c]['head'] .= ' <small class="label label-info pull-right">'.count($model->find()->all()).'</small>';
$favourites[$c]['label'] = $item['name'];
$favourites[$c]['color'] = $options['color'];
$favourites[$c]['icon'] = isset($options['icon']) ? $options['icon'] : null;
unset($controllers[$c]);
}
}
}

$dataProvider = new \yii\data\ArrayDataProvider(
[
'allModels' => $favourites,
'pagination' => [
'pageSize' => 100
]
]
);
use insolita\wgadminlte\SmallBox;
use yii\data\ArrayDataProvider;
use yii\widgets\ListView;

$listView = \yii\widgets\ListView::widget(
[
echo ListView::widget([
'dataProvider' => $dataProvider,
'layout' => "{items}\n{pager}",
'options' => ['class' => 'row'],
'itemOptions' => ['class' => 'col-xs-col-xs-6 col-sm-4 col-lg-3'],
'itemView' => function ($data) {
return '<div class="col-xs-6 col-sm-4 col-lg-3">'.insolita\wgadminlte\SmallBox::widget(
[
'head' => $data['head'],
'type' => $data['color'],
'text' => $data['label'],
'footer' => 'Manage',
'footer_link' => $data['route'],
'icon' => 'fa fa-' . $data['icon']
]
);
return SmallBox::widget([
'head' => $data['head'],
'type' => $data['color'],
'text' => $data['label'],
'footer' => <?php echo $generator->generateString('Manage') ?>,
'footer_link' => $data['route'],
'icon' => 'fa fa-' . $data['icon']
]);
},
]
).'</div>';
?>

<div class="row">
<?= '<?= $listView ?>' ?>
</div>

'emptyTextOptions' => ['class' => 'col-xs-12']
]);
2 changes: 2 additions & 0 deletions src/generators/module/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@
<?php
echo $form->field($generator, 'moduleClass');
echo $form->field($generator, 'moduleID');
echo $form->field($generator, 'enableI18N')->checkbox();
echo $form->field($generator, 'messageCategory');
?>
</div>

0 comments on commit eb31a95

Please sign in to comment.