Browse Source

gii WIP

tags/2.0.0-beta
Qiang Xue 12 years ago
parent
commit
ef01a8cb79
  1. 21
      framework/yii/gii/ActiveField.php
  2. 6
      framework/yii/gii/Generator.php
  3. 9
      framework/yii/gii/assets/gii.js
  4. 1
      framework/yii/gii/controllers/DefaultController.php
  5. 13
      framework/yii/gii/generators/controller/Generator.php
  6. 15
      framework/yii/gii/generators/controller/views/form.php
  7. 9
      framework/yii/gii/views/default/_files.php
  8. 6
      framework/yii/gii/views/default/view.php

21
framework/yii/gii/ActiveField.php

@ -0,0 +1,21 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\gii;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class ActiveField extends \yii\widgets\ActiveField
{
public function sticky()
{
$this->options['class'] .= ' sticky';
return $this;
}
}

6
framework/yii/gii/Generator.php

@ -35,7 +35,7 @@ abstract class Generator extends Model
{ {
parent::init(); parent::init();
if (!isset($this->templates['default'])) { 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(); return array();
} }
public function getViewFile() public function formView()
{ {
$class = new ReflectionClass($this); $class = new ReflectionClass($this);
return dirname($class->getFileName()) . '/views/form.php'; return dirname($class->getFileName()) . '/views/form.php';
} }
public function getDefaultTemplate() public function defaultTemplate()
{ {
$class = new ReflectionClass($this); $class = new ReflectionClass($this);
return dirname($class->getFileName()) . '/templates'; return dirname($class->getFileName()) . '/templates';

9
framework/yii/gii/assets/gii.js

@ -10,6 +10,15 @@ yii.gii = (function ($) {
content: $hint.html() 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); })(jQuery);

1
framework/yii/gii/controllers/DefaultController.php

@ -43,6 +43,7 @@ class DefaultController extends Controller
$params['result'] = $generator->save($files, $_POST['answers']); $params['result'] = $generator->save($files, $_POST['answers']);
} else { } else {
$params['files'] = $files; $params['files'] = $files;
$params['answers'] = isset($_POST['answers']) ? $_POST['answers'] : null;
} }
} }
} }

13
framework/yii/gii/generators/controller/Generator.php

@ -20,6 +20,7 @@ class Generator extends \yii\gii\Generator
{ {
public $controller; public $controller;
public $baseClass = 'yii\web\Controller'; public $baseClass = 'yii\web\Controller';
public $ns = 'app\controllers';
public $actions = 'index'; public $actions = 'index';
public function getName() public function getName()
@ -36,12 +37,13 @@ class Generator extends \yii\gii\Generator
public function rules() public function rules()
{ {
return array_merge(parent::rules(), array( 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, baseClass', 'required'),
array('controller', 'match', 'pattern' => '/^[\w+\\/]*$/', 'message' => 'Only word characters and slashes are allowed.'), 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('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', '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', 'baseClass' => 'Base Class',
'controller' => 'Controller ID', 'controller' => 'Controller ID',
'actions' => 'Action IDs', 'actions' => 'Action IDs',
'ns' => 'Namespace',
); );
} }
@ -153,4 +156,10 @@ class Generator extends \yii\gii\Generator
} }
return $module->getControllerPath() . '/' . $id . 'Controller.php'; return $module->getControllerPath() . '/' . $id . 'Controller.php';
} }
public function getViewFile($action)
{
$module=$this->getModule();
return $module->getViewPath().'/'.$this->getControllerID().'/'.$action.'.php';
}
} }

15
framework/yii/gii/generators/controller/views/form.php

@ -1,8 +1,4 @@
<?php <?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/** /**
* @var yii\base\View $this * @var yii\base\View $this
* @var yii\widgets\ActiveForm $form * @var yii\widgets\ActiveForm $form
@ -17,11 +13,14 @@ use yii\widgets\ActiveForm;
<li><code>admin/user</code> generates <code>UserController.php</code> within the <code>admin</code> module.</li> <li><code>admin/user</code> generates <code>UserController.php</code> within the <code>admin</code> module.</li>
</ul> </ul>
'); ?> '); ?>
<?php echo $form->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.
'); ?>
<?php echo $form->field($generator, 'actions')->hint(' <?php echo $form->field($generator, 'actions')->hint('
Provide one or multiple action IDs to generate empty action method(s) in the controller. Provide one or multiple action IDs to generate empty action method(s) in the controller.
Separate multiple action IDs with commas or spaces. Separate multiple action IDs with commas or spaces.
'); ?> '); ?>
<?php echo $form->field($generator, 'ns')->sticky()->hint('
This is the namespace that the new controller class will should use.
'); ?>
<?php echo $form->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.
'); ?>

9
framework/yii/gii/views/default/_files.php

@ -8,6 +8,7 @@ use yii\gii\CodeFile;
* @var $this \yii\base\View * @var $this \yii\base\View
* @var $generator \yii\gii\Generator * @var $generator \yii\gii\Generator
* @var CodeFile[] $files * @var CodeFile[] $files
* @var array $answers
*/ */
?> ?>
<table class="table table-bordered table-striped table-condensed code-files"> <table class="table table-bordered table-striped table-condensed code-files">
@ -15,7 +16,7 @@ use yii\gii\CodeFile;
<tr> <tr>
<th class="file">Code File</th> <th class="file">Code File</th>
<th class="action">Action</th> <th class="action">Action</th>
<th class="check"> <th>
<?php <?php
$count = 0; $count = 0;
foreach ($files as $file) { foreach ($files as $file) {
@ -24,7 +25,7 @@ use yii\gii\CodeFile;
} }
} }
if ($count > 1) { if ($count > 1) {
echo '<input type="checkbox" name="checkAll" id="check-all" />'; echo '<input type="checkbox" id="check-all">';
} }
?> ?>
</th> </th>
@ -36,7 +37,7 @@ use yii\gii\CodeFile;
<td class="file"> <td class="file">
<?php echo Html::a(Html::encode($file->getRelativePath()), array('code', 'file' => $i), array('class' => 'view-code', 'rel' => $file->path)); ?> <?php echo Html::a(Html::encode($file->getRelativePath()), array('code', 'file' => $i), array('class' => 'view-code', 'rel' => $file->path)); ?>
<?php if ($file->operation === CodeFile::OP_OVERWRITE): ?> <?php if ($file->operation === CodeFile::OP_OVERWRITE): ?>
(<?php echo Html::a('diff', array('diff', 'file' => $i), array('class' => 'view-code', 'rel' => $file->path)); ?>) <?php echo Html::a('diff', array('diff', 'file' => $i), array('class' => 'view-code label label-warning', 'rel' => $file->path)); ?>
<?php endif; ?> <?php endif; ?>
</td> </td>
<td class="action"> <td class="action">
@ -54,7 +55,7 @@ use yii\gii\CodeFile;
echo '&nbsp;'; echo '&nbsp;';
} else { } else {
$key = md5($file->path); $key = md5($file->path);
echo Html::checkBox("answers[$key]"); echo Html::checkBox("answers[$key]", isset($answers) ? isset($answers[$key]) : ($file->operation === CodeFile::OP_NEW));
} }
?> ?>
</td> </td>

6
framework/yii/gii/views/default/view.php

@ -11,6 +11,7 @@ use yii\gii\CodeFile;
* @var yii\widgets\ActiveForm $form * @var yii\widgets\ActiveForm $form
* @var string $result * @var string $result
* @var CodeFile[] $files * @var CodeFile[] $files
* @var array $answers
*/ */
$this->title = $generator->getName(); $this->title = $generator->getName();
@ -24,10 +25,10 @@ foreach ($generator->templates as $name => $path) {
<p><?php echo $generator->getDescription(); ?></p> <p><?php echo $generator->getDescription(); ?></p>
<?php $form = ActiveForm::begin(); ?> <?php $form = ActiveForm::begin(array('fieldConfig' => array('class' => 'yii\gii\ActiveField'))); ?>
<div class="row"> <div class="row">
<div class="col-lg-6"> <div class="col-lg-6">
<?php echo $this->renderFile($generator->getViewFile(), array( <?php echo $this->renderFile($generator->formView(), array(
'generator' => $generator, 'generator' => $generator,
'form' => $form, 'form' => $form,
)); ?> )); ?>
@ -51,6 +52,7 @@ foreach ($generator->templates as $name => $path) {
echo $this->render('_files', array( echo $this->render('_files', array(
'generator' => $generator, 'generator' => $generator,
'files' => $files, 'files' => $files,
'answers' => $answers,
)); ));
} }
?> ?>

Loading…
Cancel
Save