Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Y
yii2-giiant
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
dmstr
yii2-giiant
Commits
d94cc56c
Commit
d94cc56c
authored
Oct 05, 2016
by
Fredy Nurman Saleh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tidy up. put newlines in saveral part.
parent
4ffd2832
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
91 additions
and
72 deletions
+91
-72
_form.php
src/generators/crud/default/views/_form.php
+5
-3
create.php
src/generators/crud/default/views/create.php
+2
-2
index.php
src/generators/crud/default/views/index.php
+13
-15
update.php
src/generators/crud/default/views/update.php
+2
-2
view.php
src/generators/crud/default/views/view.php
+59
-46
RelationProvider.php
src/generators/crud/providers/core/RelationProvider.php
+10
-4
No files found.
src/generators/crud/default/views/_form.php
View file @
d94cc56c
...
...
@@ -82,7 +82,7 @@ use yii\helpers\StringHelper;
$items
=
<<<EOS
[
'label' => Yii::t('$generator->modelMessageCategory',
StringHelper::basename('{$model::className()}')
),
'label' => Yii::t('$generator->modelMessageCategory',
'$label'
),
'content' => \$this->blocks['main'],
'active' => true,
],
...
...
@@ -93,8 +93,10 @@ EOS;
"<?=
Tabs::widget(
[
'encodeLabels' => false,
'items' => [
$items
]
'encodeLabels' => false,
'items' => [
$items
]
]
);
?>"
;
...
...
src/generators/crud/default/views/create.php
View file @
d94cc56c
...
...
@@ -31,10 +31,10 @@ $this->params['breadcrumbs'][] = $this->title;
<div
class=
"giiant-crud
<?=
Inflector
::
camel2id
(
StringHelper
::
basename
(
$generator
->
modelClass
),
'-'
,
true
)
?>
-create"
>
<h1>
<?=
"<?= Yii::t('
{
$generator
->
modelMessageCategory
}
', '
{
$modelName
}
') ?>"
?>
<?=
"<?= Yii::t('
{
$generator
->
modelMessageCategory
}
', '
{
$modelName
}
') ?>
\n
"
?>
<small>
<?php
$label
=
StringHelper
::
basename
(
$generator
->
modelClass
);
?>
<?=
'<?= $model->'
.
$generator
->
getModelNameAttribute
(
$generator
->
modelClass
)
.
' ?>'
?>
<?=
'<?= $model->'
.
$generator
->
getModelNameAttribute
(
$generator
->
modelClass
)
.
" ?>
\n
"
?>
</small>
</h1>
...
...
src/generators/crud/default/views/index.php
View file @
d94cc56c
...
...
@@ -42,10 +42,8 @@ use <?= $generator->indexWidgetType === 'grid' ? $generator->indexGridClass : 'y
<?php
endif
;
?>
*/
<?php
$this
->
title
=
Yii
::
t
(
$generator
->
modelMessageCategory
,
$modelName
);
$this->title = Yii::t(
<?=
"'
{
$generator
->
modelMessageCategory
}
', '
{
$modelName
}
'"
?>
);
$this->params['breadcrumbs'][] = $this->title;
?>
<?php
if
(
$generator
->
accessFilter
)
:
...
...
@@ -84,7 +82,7 @@ echo '?>';
<div
class=
"giiant-crud
<?=
Inflector
::
camel2id
(
StringHelper
::
basename
(
$generator
->
modelClass
),
'-'
,
true
)
?>
-index"
>
<?=
'<?php '
.
(
$generator
->
indexWidgetType
===
'grid'
?
'// '
:
''
)
?>
"<?php
\n
"
.
(
$generator
->
indexWidgetType
===
'grid'
?
'// '
:
''
)
?>
<?php
if
(
$generator
->
searchModelClass
!==
''
)
:
?>
echo $this->render('_search', ['model' =>$searchModel]);
<?php
endif
;
?>
...
...
@@ -95,8 +93,8 @@ echo '?>';
<?=
"<?php \yii\widgets\Pjax::begin(['id'=>'pjax-main', 'enableReplaceState'=> false, 'linkSelector'=>'#pjax-main ul.pagination a, th a', 'clientOptions' => ['pjax:success'=>'function()
{
alert(\"yo\")
}
']]) ?>
\n
"
;
?>
<h1>
<?=
"<?= Yii::t('
{
$generator
->
modelMessageCategory
}
', '
{
$modelName
}
') ?>
"
?>
<small>
<?=
"<?= Yii::t('
{
$generator
->
modelMessageCategory
}
', '
{
$modelName
}
') ?>
\n
"
?>
<small>
List
</small>
</h1>
...
...
@@ -152,6 +150,7 @@ echo "?>\n"
'url' => ['{$route}'],
'label' => '<i class="glyphicon glyphicon-arrow-right"> ' . Yii::t('$generator->modelMessageCategory', '$label') . '</i>',
],
PHP;
?>
<?php
endforeach
;
?>
...
...
@@ -169,15 +168,15 @@ PHP;
'class' => 'dropdown-menu-right'
],
'encodeLabels' => false,
'items' => [
<?=
$items
?>
]
],
'items' => [
<?=
"
\n
"
.
$items
.
"
\n
"
?>
]
],
'options' => [
'class' => 'btn-default'
]
]
);
<?=
'?>'
?>
</div>
<?=
"?>
\n
"
?>
</div>
</div>
<hr
/>
...
...
@@ -188,16 +187,15 @@ PHP;
'pager' => [
'class' => yii\widgets\LinkPager::className(),
'firstPageLabel' =>
<?=
$generator
->
generateString
(
'First'
)
?>
,
'lastPageLabel' =>
<?=
$generator
->
generateString
(
'Last'
)
?>
],
'lastPageLabel' =>
<?=
$generator
->
generateString
(
'Last'
)
.
",
\n
"
?>
],
<?php
if
(
$generator
->
searchModelClass
!==
''
)
:
?>
'filterModel' => $searchModel,
<?php
endif
;
?>
'tableOptions' => ['class' => 'table table-striped table-bordered table-hover'],
'headerRowOptions' => ['class'=>'x'],
'columns' => [
<?php
'columns' => [
<?php
$actionButtonColumn
=
<<<PHP
[
'class' => '{$generator->actionButtonClass}',
...
...
src/generators/crud/default/views/update.php
View file @
d94cc56c
...
...
@@ -24,7 +24,7 @@ use yii\helpers\Html;
* @var
<?=
ltrim
(
$generator
->
modelClass
,
'\\'
)
?>
$model
*/
$this->title = Yii::t('
<?=
$generator
->
modelMessageCategory
?>
', '
<?=
$modelName
?>
') . $model->
<?=
$generator
->
getNameAttribute
(
$this->title = Yii::t('
<?=
$generator
->
modelMessageCategory
?>
', '
<?=
$modelName
?>
') .
" " .
$model->
<?=
$generator
->
getNameAttribute
(
)
?>
. ', ' .
<?=
$generator
->
generateString
(
'Edit'
)
?>
;
$this->params['breadcrumbs'][] = ['label' => Yii::t('
<?=
$generator
->
modelMessageCategory
?>
', '
<?=
$modelName
?>
'), 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => (string)$model->
<?=
$generator
->
getNameAttribute
(
...
...
@@ -38,7 +38,7 @@ $this->params['breadcrumbs'][] = <?= $generator->generateString('Edit') ?>;
<small>
<?php
$label
=
StringHelper
::
basename
(
$generator
->
modelClass
);
?>
<?=
'<?= $model->'
.
$generator
->
getModelNameAttribute
(
$generator
->
modelClass
)
.
' ?>'
?>
<?=
'<?= $model->'
.
$generator
->
getModelNameAttribute
(
$generator
->
modelClass
)
.
" ?>
\n
"
?>
</small>
</h1>
...
...
src/generators/crud/default/views/view.php
View file @
d94cc56c
...
...
@@ -10,16 +10,17 @@ use yii\helpers\StringHelper;
/** @var \yii\db\ActiveRecord $model */
/** @var $generator \schmunk42\giiant\generators\crud\Generator */
## TODO: move to generator (?); cleanup
$model
=
new
$generator
->
modelClass
();
$model
=
new
$generator
->
modelClass
();
$model
->
setScenario
(
'crud'
);
$safeAttributes
=
$model
->
safeAttributes
();
if
(
empty
(
$safeAttributes
))
{
if
(
empty
(
$safeAttributes
))
{
$model
->
setScenario
(
'default'
);
$safeAttributes
=
$model
->
safeAttributes
();
}
if
(
empty
(
$safeAttributes
))
{
if
(
empty
(
$safeAttributes
))
{
$safeAttributes
=
$model
->
getTableSchema
()
->
columnNames
;
}
...
...
@@ -44,7 +45,7 @@ use dmstr\bootstrap\Tabs;
$copyParams = $model->attributes;
$this->title = Yii::t('
<?=
$generator
->
modelMessageCategory
?>
', '
<?=
$modelName
?>
');
$this->params['breadcrumbs'][] = ['label' => Yii::t('
<?=
$generator
->
modelMessageCategory
?>
', '
<?=
Inflector
::
pluralize
(
$modelName
)
?>
'), 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => Yii::t('
<?=
$generator
->
modelMessageCategory
?>
', '
<?=
Inflector
::
pluralize
(
$modelName
)
?>
'), 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => (string)$model->
<?=
$generator
->
getNameAttribute
()
?>
, 'url' => ['view',
<?=
$urlParams
?>
]];
$this->params['breadcrumbs'][] =
<?=
$generator
->
generateString
(
'View'
)
?>
;
?>
...
...
@@ -61,9 +62,9 @@ $this->params['breadcrumbs'][] = <?= $generator->generateString('View') ?>;
<h1>
<?=
"<?= Yii::t('
{
$generator
->
modelMessageCategory
}
', '
{
$modelName
}
') ?>"
?>
<?=
"<?= Yii::t('
{
$generator
->
modelMessageCategory
}
', '
{
$modelName
}
') ?>
\n
"
?>
<small>
<?=
'<?= $model->'
.
$generator
->
getModelNameAttribute
(
$generator
->
modelClass
)
.
' ?>'
?>
<?=
'<?= $model->'
.
$generator
->
getModelNameAttribute
(
$generator
->
modelClass
)
.
" ?>
\n
"
?>
</small>
</h1>
...
...
@@ -72,24 +73,24 @@ $this->params['breadcrumbs'][] = <?= $generator->generateString('View') ?>;
<!-- menu buttons -->
<div
class=
'pull-left'
>
<?=
'<?= '
?>
Html::a(
<?=
'<?= '
?>
Html::a(
'
<span
class=
"glyphicon glyphicon-pencil"
></span>
' .
<?=
$generator
->
generateString
(
'Edit'
)
?>
,
[ 'update',
<?=
$urlParams
?>
],
['class' => 'btn btn-info']) ?>
<?=
'<?= '
?>
Html::a(
<?=
'<?= '
?>
Html::a(
'
<span
class=
"glyphicon glyphicon-copy"
></span>
' .
<?=
$generator
->
generateString
(
'Copy'
)
?>
,
['create',
<?=
$urlParams
?>
, '
<?=
StringHelper
::
basename
(
$generator
->
modelClass
)
?>
'=>$copyParams],
['class' => 'btn btn-success']) ?>
<?=
'<?= '
?>
Html::a(
<?=
'<?= '
?>
Html::a(
'
<span
class=
"glyphicon glyphicon-plus"
></span>
' .
<?=
$generator
->
generateString
(
'New'
)
?>
,
['create'],
['class' => 'btn btn-success']) ?>
</div>
<div
class=
"pull-right"
>
<?=
"<?= "
?>
Html::a('
<span
class=
"glyphicon glyphicon-list"
></span>
'
<?=
"<?= "
?>
Html::a('
<span
class=
"glyphicon glyphicon-list"
></span>
'
.
<?=
$generator
->
generateString
(
'Full list'
)
?>
, ['index'], ['class'=>'btn btn-default']) ?>
</div>
...
...
@@ -98,20 +99,24 @@ $this->params['breadcrumbs'][] = <?= $generator->generateString('View') ?>;
<hr
/>
<?php
echo
"<?php
\$
this->beginBlock('
{
$generator
->
modelClass
}
'); ?>
\n
"
;
echo
"<?php
\$
this->beginBlock('
"
.
substr
(
strrchr
(
$model
::
className
(),
'\\'
),
1
)
.
"
'); ?>
\n
"
;
?>
<?=
$generator
->
partialView
(
'detail_prepend'
,
$model
);
?>
<?=
'<?= '
?>
DetailView::widget([
<?=
'<?= '
?>
DetailView::widget([
'model' => $model,
'attributes' => [
<?php
foreach
(
$safeAttributes
as
$attribute
)
{
foreach
(
$safeAttributes
as
$attribute
)
{
$format
=
$generator
->
attributeFormat
(
$attribute
);
if
(
!
$format
)
{
if
(
!
$format
)
{
continue
;
}
else
{
}
else
{
echo
$format
.
",
\n
"
;
}
}
...
...
@@ -123,9 +128,11 @@ $this->params['breadcrumbs'][] = <?= $generator->generateString('View') ?>;
<hr/>
<?=
'<?= '
?>
Html::a('
<span
class=
"glyphicon glyphicon-trash"
></span>
' .
<?=
$generator
->
generateString
(
<?=
'<?= '
?>
Html::a('
<span
class=
"glyphicon glyphicon-trash"
></span>
' .
<?=
$generator
->
generateString
(
'Delete'
)
?>
, ['delete',
<?=
$urlParams
?>
],
)
?>
, ['delete',
<?=
$urlParams
?>
],
[
'class' => 'btn btn-danger',
'data-confirm' => '' .
<?=
$generator
->
generateString
(
'Are you sure to delete this item?'
)
?>
. '',
...
...
@@ -134,27 +141,29 @@ $this->params['breadcrumbs'][] = <?= $generator->generateString('View') ?>;
<?=
"<?php
\$
this->endBlock(); ?>
\n\n
"
;
?>
<?php
// get relation info $ prepare add button
$model
=
new
$generator
->
modelClass
();
$items
=
<<<EOS
$label
=
substr
(
strrchr
(
$model
::
className
(),
'\\'
),
1
);
$items
=
<<<EOS
[
'label' => '<b class=""># '.\$model->{$model->primaryKey()[0]}.'</b>',
'content' => \$this->blocks['{$
generator->modelClass
}'],
'content' => \$this->blocks['{$
label
}'],
'active' => true,
],
EOS;
foreach
(
$generator
->
getModelRelations
(
$generator
->
modelClass
,
[
'has_many'
])
as
$name
=>
$relation
)
{
foreach
(
$generator
->
getModelRelations
(
$generator
->
modelClass
,
[
'has_many'
])
as
$name
=>
$relation
)
{
echo
"
\n
<?php
\$
this->beginBlock('
$name
'); ?>
\n
"
;
$showAllRecords
=
false
;
if
(
$relation
->
via
!==
null
)
{
$pivotName
=
Inflector
::
pluralize
(
$generator
->
getModelByTableName
(
$relation
->
via
->
from
[
0
]));
if
(
$relation
->
via
!==
null
)
{
$pivotName
=
Inflector
::
pluralize
(
$generator
->
getModelByTableName
(
$relation
->
via
->
from
[
0
]));
$pivotRelation
=
$model
->
{
'get'
.
$pivotName
}();
$pivotPk
=
key
(
$pivotRelation
->
link
);
$pivotPk
=
key
(
$pivotRelation
->
link
);
$addButton
=
" <?= Html::a(
'<span class=
\"
glyphicon glyphicon-link
\"
></span> ' . "
.
$generator
->
generateString
(
'Attach'
)
.
" . ' "
.
...
...
@@ -165,40 +174,44 @@ EOS;
)
.
"'=>
\$
model->
{
$model
->
primaryKey
()[
0
]
}
]],
['class'=>'btn btn-info btn-xs']
) ?>
\n
"
;
}
else
{
}
else
{
$addButton
=
''
;
}
// relation list, add, create buttons
echo
"<div style='position: relative'><div style='position:absolute; right: 0px; top: 0px;'>
\n
"
;
echo
"<div style='position: relative'>
\n
<div style='position:absolute; right: 0px; top: 0px;'>
\n
"
;
echo
" <?= Html::a(
'<span class=
\"
glyphicon glyphicon-list
\"
></span> ' . "
.
$generator
->
generateString
(
'List All'
)
.
" . ' "
.
Inflector
::
camel2words
(
$name
)
.
"',
Inflector
::
camel2words
(
$name
)
.
"',
['"
.
$generator
->
createRelationRoute
(
$relation
,
'index'
)
.
"'],
['class'=>'btn text-muted btn-xs']
) ?>
\n
"
;
// TODO: support multiple PKs
echo
" <?= Html::a(
'<span class=
\"
glyphicon glyphicon-plus
\"
></span> ' . "
.
$generator
->
generateString
(
'New'
)
.
" . ' "
.
Inflector
::
singularize
(
Inflector
::
camel2words
(
$name
))
.
"',
Inflector
::
singularize
(
Inflector
::
camel2words
(
$name
))
.
"',
['"
.
$generator
->
createRelationRoute
(
$relation
,
'create'
)
.
"', '"
.
Inflector
::
id2camel
(
$generator
->
generateRelationTo
(
$relation
),
'-'
,
true
)
.
"' => ['"
.
key
(
$relation
->
link
)
.
"' =>
\$
model->"
.
$model
->
primaryKey
()[
0
]
.
"]],
Inflector
::
id2camel
(
$generator
->
generateRelationTo
(
$relation
),
'-'
,
true
)
.
"' => ['"
.
key
(
$relation
->
link
)
.
"' =>
\$
model->"
.
$model
->
primaryKey
()[
0
]
.
"]],
['class'=>'btn btn-success btn-xs']
); ?>
\n
"
;
echo
$addButton
;
echo
'</div></div>'
;
#<div class='clearfix'></div>\n";
echo
"</div>
\n
</div>
\n
"
;
#<div class='clearfix'></div>\n";
// render pivot grid
if
(
$relation
->
via
!==
null
)
{
$pjaxId
=
"pjax-
{
$pivotName
}
"
;
if
(
$relation
->
via
!==
null
)
{
$pjaxId
=
"pjax-
{
$pivotName
}
"
;
$gridRelation
=
$pivotRelation
;
$gridName
=
$pivotName
;
}
else
{
$pjaxId
=
"pjax-
{
$name
}
"
;
$gridName
=
$pivotName
;
}
else
{
$pjaxId
=
"pjax-
{
$name
}
"
;
$gridRelation
=
$relation
;
$gridName
=
$name
;
$gridName
=
$name
;
}
$output
=
$generator
->
relationGrid
(
$gridName
,
$gridRelation
,
$showAllRecords
);
...
...
@@ -206,8 +219,8 @@ EOS;
// render relation grid
if
(
!
empty
(
$output
))
:
echo
"<?php Pjax::begin(['id'=>'pjax-
{
$name
}
', 'enableReplaceState'=> false, 'linkSelector'=>'#pjax-
{
$name
}
ul.pagination a, th a', 'clientOptions' => ['pjax:success'=>'function()
{
alert(\"yo\")
}
']]) ?>
\n
"
;
echo
'<?= '
.
$output
.
"
?>
\n
"
;
echo
"<?php Pjax::end() ?>
\n
"
;
echo
"<?=
\n
"
.
$output
.
"
\n
?>
\n
"
;
echo
"<?php Pjax::end() ?>
\n
"
;
endif
;
echo
"<?php
\$
this->endBlock() ?>
\n\n
"
;
...
...
@@ -219,21 +232,21 @@ EOS;
'content' => \$this->blocks['$name'],
'label' => '<small>$label <span class="badge badge-default">'.count(\$model->get{$name}()->asArray()->all()).'</span></small>',
'active' => false,
],
],
\n
EOS;
}
?>
<?=
// render tabs
<?=
// render tabs
"<?= Tabs::widget(
[
'id' => 'relation-tabs',
'encodeLabels' => false,
'items' => [
$items
]
'items' => [
\n
$items
]
]
);
?>"
;
?>
?>
</div>
src/generators/crud/providers/core/RelationProvider.php
View file @
d94cc56c
...
...
@@ -324,20 +324,26 @@ EOS;
$pageParam
=
Inflector
::
slug
(
"page-
{
$name
}
"
);
$firstPageLabel
=
$this
->
generator
->
generateString
(
'First'
);
$lastPageLabel
=
$this
->
generator
->
generateString
(
'Last'
);
$code
=
'\'<div class="table-responsive">\' . '
;
$code
=
"'<div class=
\"
table-responsive
\"
>'
\n
. "
;
$code
.=
<<<EOS
\\yii\\grid\\GridView::widget([
'layout' => '{summary}{pager}<br/>{items}{pager}',
'dataProvider' => new \\yii\\data\\ActiveDataProvider([{$query}, 'pagination' => ['pageSize' => 20, 'pageParam'=>'{$pageParam}']]),
'dataProvider' => new \\yii\\data\\ActiveDataProvider([
{$query},
'pagination' => [
'pageSize' => 20,
'pageParam'=>'{$pageParam}',
]
]),
'pager' => [
'class' => yii\widgets\LinkPager::className(),
'firstPageLabel' => {$firstPageLabel},
'lastPageLabel' => {$lastPageLabel}
],
'columns' => [$columns]
'columns' => [
\n
$columns]
])
EOS;
$code
.=
' . \'</div>\' '
;
$code
.=
"
\n
. '</div>' "
;
return
$code
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment