view.php 1.78 KB
Newer Older
Qiang Xue committed
1 2 3
<?php

use yii\helpers\Html;
Qiang Xue committed
4
use yii\widgets\ActiveForm;
Qiang Xue committed
5
use yii\gii\components\ActiveField;
Qiang Xue committed
6
use yii\gii\CodeFile;
Qiang Xue committed
7 8

/**
Alexander Makarov committed
9
 * @var yii\web\View $this
Qiang Xue committed
10
 * @var yii\gii\Generator $generator
11
 * @var string $id
Qiang Xue committed
12
 * @var yii\widgets\ActiveForm $form
Qiang Xue committed
13 14
 * @var string $results
 * @var boolean $hasError
Qiang Xue committed
15
 * @var CodeFile[] $files
Qiang Xue committed
16
 * @var array $answers
Qiang Xue committed
17 18 19
 */

$this->title = $generator->getName();
Alexander Makarov committed
20
$templates = [];
Qiang Xue committed
21 22 23
foreach ($generator->templates as $name => $path) {
	$templates[$name] = "$name ($path)";
}
Qiang Xue committed
24 25
?>
<div class="default-view">
Alexander Makarov committed
26
	<h1><?= Html::encode($this->title) ?></h1>
Qiang Xue committed
27

Alexander Makarov committed
28
	<p><?= $generator->getDescription() ?></p>
Qiang Xue committed
29

Alexander Makarov committed
30
	<?php $form = ActiveForm::begin([
31
		'id' => "$id-generator",
Qiang Xue committed
32
		'successCssClass' => '',
Alexander Makarov committed
33 34
		'fieldConfig' => ['class' => ActiveField::className()],
	]); ?>
Qiang Xue committed
35
		<div class="row">
Qiang Xue committed
36
			<div class="col-lg-8">
37
				<?= $this->renderFile($generator->formView(), [
Qiang Xue committed
38 39
					'generator' => $generator,
					'form' => $form,
40 41
				]) ?>
				<?= $form->field($generator, 'template')->sticky()
Qiang Xue committed
42
					->label('Code Template')
Qiang Xue committed
43 44
					->dropDownList($templates)->hint('
						Please select which set of the templates should be used to generated the code.
45
				') ?>
Qiang Xue committed
46
				<div class="form-group">
Alexander Makarov committed
47
					<?= Html::submitButton('Preview', ['name' => 'preview', 'class' => 'btn btn-primary']) ?>
Qiang Xue committed
48

49
					<?php if (isset($files)): ?>
Alexander Makarov committed
50
						<?= Html::submitButton('Generate', ['name' => 'generate', 'class' => 'btn btn-success']) ?>
Qiang Xue committed
51 52
					<?php endif; ?>
				</div>
Qiang Xue committed
53 54
			</div>
		</div>
Qiang Xue committed
55

Qiang Xue committed
56 57
		<?php
		if (isset($results)) {
Alexander Makarov committed
58
			echo $this->render('view/results', [
Qiang Xue committed
59 60 61
				'generator' => $generator,
				'results' => $results,
				'hasError' => $hasError,
Alexander Makarov committed
62
			]);
Qiang Xue committed
63
		} elseif (isset($files)) {
Alexander Makarov committed
64
			echo $this->render('view/files', [
Qiang Xue committed
65 66 67
				'generator' => $generator,
				'files' => $files,
				'answers' => $answers,
Alexander Makarov committed
68
			]);
Qiang Xue committed
69 70
		}
		?>
Qiang Xue committed
71
	<?php ActiveForm::end(); ?>
Qiang Xue committed
72
</div>