From ef01a8cb79b19a9b5685d18bc519c22e1514a348 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Fri, 16 Aug 2013 08:45:53 -0400 Subject: [PATCH] gii WIP --- framework/yii/gii/ActiveField.php | 21 +++++++++++++++++++++ framework/yii/gii/Generator.php | 6 +++--- framework/yii/gii/assets/gii.js | 9 +++++++++ framework/yii/gii/controllers/DefaultController.php | 1 + .../yii/gii/generators/controller/Generator.php | 13 +++++++++++-- .../yii/gii/generators/controller/views/form.php | 15 +++++++-------- framework/yii/gii/views/default/_files.php | 9 +++++---- framework/yii/gii/views/default/view.php | 6 ++++-- 8 files changed, 61 insertions(+), 19 deletions(-) create mode 100644 framework/yii/gii/ActiveField.php diff --git a/framework/yii/gii/ActiveField.php b/framework/yii/gii/ActiveField.php new file mode 100644 index 0000000..9a03987 --- /dev/null +++ b/framework/yii/gii/ActiveField.php @@ -0,0 +1,21 @@ + + * @since 2.0 + */ +class ActiveField extends \yii\widgets\ActiveField +{ + public function sticky() + { + $this->options['class'] .= ' sticky'; + return $this; + } +} diff --git a/framework/yii/gii/Generator.php b/framework/yii/gii/Generator.php index 13b7c54..40588d9 100644 --- a/framework/yii/gii/Generator.php +++ b/framework/yii/gii/Generator.php @@ -35,7 +35,7 @@ abstract class Generator extends Model { parent::init(); if (!isset($this->templates['default'])) { - $this->templates['default'] = $this->getDefaultTemplate(); + $this->templates['default'] = $this->defaultTemplate(); } } @@ -60,13 +60,13 @@ abstract class Generator extends Model return array(); } - public function getViewFile() + public function formView() { $class = new ReflectionClass($this); return dirname($class->getFileName()) . '/views/form.php'; } - public function getDefaultTemplate() + public function defaultTemplate() { $class = new ReflectionClass($this); return dirname($class->getFileName()) . '/templates'; diff --git a/framework/yii/gii/assets/gii.js b/framework/yii/gii/assets/gii.js index 1ff3f4a..58c50cb 100644 --- a/framework/yii/gii/assets/gii.js +++ b/framework/yii/gii/assets/gii.js @@ -10,6 +10,15 @@ yii.gii = (function ($) { content: $hint.html() }); }); + + var $checkAll = $('#check-all'); + $checkAll.click(function() { + $('.code-files .check input').prop('checked', this.checked); + }); + $('.code-files .check input').click(function() { + $checkAll.prop('checked', !$('.code-files .check input:not(:checked)').length); + }); + $checkAll.prop('checked', !$('.code-files .check input:not(:checked)').length); } }; })(jQuery); diff --git a/framework/yii/gii/controllers/DefaultController.php b/framework/yii/gii/controllers/DefaultController.php index f206c61..619df2c 100644 --- a/framework/yii/gii/controllers/DefaultController.php +++ b/framework/yii/gii/controllers/DefaultController.php @@ -43,6 +43,7 @@ class DefaultController extends Controller $params['result'] = $generator->save($files, $_POST['answers']); } else { $params['files'] = $files; + $params['answers'] = isset($_POST['answers']) ? $_POST['answers'] : null; } } } diff --git a/framework/yii/gii/generators/controller/Generator.php b/framework/yii/gii/generators/controller/Generator.php index 04fee04..56b8f6d 100644 --- a/framework/yii/gii/generators/controller/Generator.php +++ b/framework/yii/gii/generators/controller/Generator.php @@ -20,6 +20,7 @@ class Generator extends \yii\gii\Generator { public $controller; public $baseClass = 'yii\web\Controller'; + public $ns = 'app\controllers'; public $actions = 'index'; public function getName() @@ -36,12 +37,13 @@ class Generator extends \yii\gii\Generator public function rules() { return array_merge(parent::rules(), array( - array('controller, actions, baseClass', 'filter', 'filter' => 'trim'), + array('controller, actions, baseClass, ns', 'filter', 'filter' => 'trim'), array('controller, baseClass', 'required'), array('controller', 'match', 'pattern' => '/^[\w+\\/]*$/', 'message' => 'Only word characters and slashes are allowed.'), array('actions', 'match', 'pattern' => '/^\w+[\w\s,]*$/', 'message' => 'Only word characters, spaces and commas are allowed.'), array('baseClass', 'match', 'pattern' => '/^[a-zA-Z_][\w\\\\]*$/', 'message' => 'Only word characters and backslashes are allowed.'), - array('baseClass', 'validateReservedWord', 'skipOnError' => true), + array('baseClass', 'validateReservedWord'), + array('ns', 'match', 'pattern' => '/^[a-zA-Z_][\w\\\\]*$/', 'message' => 'Only word characters and backslashes are allowed.'), )); } @@ -51,6 +53,7 @@ class Generator extends \yii\gii\Generator 'baseClass' => 'Base Class', 'controller' => 'Controller ID', 'actions' => 'Action IDs', + 'ns' => 'Namespace', ); } @@ -153,4 +156,10 @@ class Generator extends \yii\gii\Generator } return $module->getControllerPath() . '/' . $id . 'Controller.php'; } + + public function getViewFile($action) + { + $module=$this->getModule(); + return $module->getViewPath().'/'.$this->getControllerID().'/'.$action.'.php'; + } } diff --git a/framework/yii/gii/generators/controller/views/form.php b/framework/yii/gii/generators/controller/views/form.php index b08c3c3..2e48889 100644 --- a/framework/yii/gii/generators/controller/views/form.php +++ b/framework/yii/gii/generators/controller/views/form.php @@ -1,8 +1,4 @@ admin/user generates UserController.php within the admin module. '); ?> -field($generator, 'baseClass')->hint(' - This is the class that the new controller class will extend from. - Please make sure the class exists and can be autoloaded. -'); ?> field($generator, 'actions')->hint(' Provide one or multiple action IDs to generate empty action method(s) in the controller. Separate multiple action IDs with commas or spaces. '); ?> +field($generator, 'ns')->sticky()->hint(' + This is the namespace that the new controller class will should use. +'); ?> +field($generator, 'baseClass')->sticky()->hint(' + This is the class that the new controller class will extend from. + Please make sure the class exists and can be autoloaded. +'); ?> diff --git a/framework/yii/gii/views/default/_files.php b/framework/yii/gii/views/default/_files.php index 05c8ee5..3fe1048 100644 --- a/framework/yii/gii/views/default/_files.php +++ b/framework/yii/gii/views/default/_files.php @@ -8,6 +8,7 @@ use yii\gii\CodeFile; * @var $this \yii\base\View * @var $generator \yii\gii\Generator * @var CodeFile[] $files + * @var array $answers */ ?> @@ -15,7 +16,7 @@ use yii\gii\CodeFile; - @@ -36,7 +37,7 @@ use yii\gii\CodeFile; diff --git a/framework/yii/gii/views/default/view.php b/framework/yii/gii/views/default/view.php index d0738aa..541ae26 100644 --- a/framework/yii/gii/views/default/view.php +++ b/framework/yii/gii/views/default/view.php @@ -11,6 +11,7 @@ use yii\gii\CodeFile; * @var yii\widgets\ActiveForm $form * @var string $result * @var CodeFile[] $files + * @var array $answers */ $this->title = $generator->getName(); @@ -24,10 +25,10 @@ foreach ($generator->templates as $name => $path) {

getDescription(); ?>

- + array('class' => 'yii\gii\ActiveField'))); ?>
- renderFile($generator->getViewFile(), array( + renderFile($generator->formView(), array( 'generator' => $generator, 'form' => $form, )); ?> @@ -51,6 +52,7 @@ foreach ($generator->templates as $name => $path) { echo $this->render('_files', array( 'generator' => $generator, 'files' => $files, + 'answers' => $answers, )); } ?>
Code File Action + 1) { - echo ''; + echo ''; } ?> getRelativePath()), array('code', 'file' => $i), array('class' => 'view-code', 'rel' => $file->path)); ?> operation === CodeFile::OP_OVERWRITE): ?> - ( $i), array('class' => 'view-code', 'rel' => $file->path)); ?>) + $i), array('class' => 'view-code label label-warning', 'rel' => $file->path)); ?> @@ -54,7 +55,7 @@ use yii\gii\CodeFile; echo ' '; } else { $key = md5($file->path); - echo Html::checkBox("answers[$key]"); + echo Html::checkBox("answers[$key]", isset($answers) ? isset($answers[$key]) : ($file->operation === CodeFile::OP_NEW)); } ?>