Skip to content

Commit

Permalink
Merge pull request #278 from uldisn/master
Browse files Browse the repository at this point in the history
For "updated gii JSON form config path creates two bugs #277"
  • Loading branch information
schmunk42 committed Feb 3, 2021
2 parents 7d27dd4 + 0c2e711 commit 7ab6a28
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/generators/crud/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use schmunk42\giiant\helpers\SaveForm;

/*
/**
* @var yii\web\View
* @var yii\bootstrap\ActiveForm $form
* @var schmunk42\giiant\generators\crud\Generator $generator
Expand All @@ -13,10 +13,10 @@
* on chenging listbox, form fill with selected saved forma data
* currently work with input text, input checkbox and select form fields
*/
$this->registerJs(SaveForm::getSavedFormsJs($generator->getName()), yii\web\View::POS_END);
$this->registerJs(SaveForm::getSavedFormsJs($generator->getName(), $generator->giiInfoPath), yii\web\View::POS_END);
$this->registerJs(SaveForm::jsFillForm(), yii\web\View::POS_END);
echo $form->field($generator, 'savedForm')->dropDownList(
SaveForm::getSavedFormsListbox($generator->getName()), ['onchange' => 'fillForm(this.value)']
SaveForm::getSavedFormsListbox($generator->getName(), $generator->giiInfoPath), ['onchange' => 'fillForm(this.value)']
);

echo $form->field($generator, 'modelClass');
Expand Down
4 changes: 2 additions & 2 deletions src/generators/model/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
* on chenging listbox, form fill with selected saved forma data
* currently work with input text, input checkbox and select form fields
*/
$this->registerJs(SaveForm::getSavedFormsJs($generator->getName()), yii\web\View::POS_END);
$this->registerJs(SaveForm::getSavedFormsJs($generator->getName(), $generator->giiInfoPath), yii\web\View::POS_END);
$this->registerJs(SaveForm::jsFillForm(), yii\web\View::POS_END);
echo $form->field($generator, 'savedForm')->dropDownList(
SaveForm::getSavedFormsListbox($generator->getName()), ['onchange' => 'fillForm(this.value)']
SaveForm::getSavedFormsListbox($generator->getName() , $generator->giiInfoPath), ['onchange' => 'fillForm(this.value)']
);

echo $form->field($generator, 'tableName');
Expand Down
19 changes: 10 additions & 9 deletions src/helpers/SaveForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace schmunk42\giiant\helpers;

use yii\helpers\Json;
use yii\helpers\StringHelper;

class SaveForm
Expand Down Expand Up @@ -36,7 +37,7 @@ public static function getFormAttributesValues($generator, $attributes)
* @return array|bool
* @throws \ReflectionException
*/
public static function loadSavedForms($generatorName)
public static function loadSavedForms($generatorName, $giiInfoPath)
{
$suffix = str_replace(' ', '', $generatorName);

Expand All @@ -48,8 +49,8 @@ public static function loadSavedForms($generatorName)
* get all possible gii directories with out validation on existing
*/
$forms = [];
self::buildJson(\Yii::getAlias('@app/gii'), $forms, $suffix, 'app');
if ($commonGiiDir = \Yii::getAlias('@common/gii', false)) {
self::buildJson(\Yii::getAlias('@app/' . $giiInfoPath), $forms, $suffix, 'app');
if ($commonGiiDir = \Yii::getAlias('@common/' . $giiInfoPath, false)) {
self::buildJson($commonGiiDir, $forms, $suffix, 'common');
}
foreach (\Yii::$app->modules as $moduleId => $module) {
Expand All @@ -66,7 +67,7 @@ public static function loadSavedForms($generatorName)
$reflector = new \ReflectionClass($module['class']);
$basePath = StringHelper::dirname($reflector->getFileName());
}
$basePath .= '/gii';
$basePath .= '/' . $giiInfoPath;

self::buildJson($basePath, $forms, $suffix, $moduleId);
}
Expand Down Expand Up @@ -109,10 +110,10 @@ protected static function buildJson($path, &$forms, $suffix, $moduleId = NULL)
*
* @return array
*/
public static function getSavedFormsListbox($generatorName)
public static function getSavedFormsListbox($generatorName, $giiInfoPath)
{
$r = ['0' => ' - '];
foreach (self::loadSavedForms($generatorName) as $k => $row) {
foreach (self::loadSavedForms($generatorName, $giiInfoPath) as $k => $row) {
$r[$k] = $row['label'];
}

Expand All @@ -124,12 +125,12 @@ public static function getSavedFormsListbox($generatorName)
*
* @return string
*/
public static function getSavedFormsJs($generatorName)
public static function getSavedFormsJs($generatorName, $giiInfoPath)
{
$js = [];

foreach (self::loadSavedForms($generatorName) as $k => $row) {
$js[] = $k.":'".$row['jsonData']."'";
foreach (self::loadSavedForms($generatorName, $giiInfoPath) as $k => $row) {
$js[] = $k.":'".Json::encode(Json::decode($row['jsonData']))."'";
}

return 'var savedForms = {'.str_replace('\\', '\\\\', implode(',', $js)).'};';
Expand Down

0 comments on commit 7ab6a28

Please sign in to comment.