Skip to content

Commit

Permalink
Modifying bake templates for a fresher look.
Browse files Browse the repository at this point in the history
Some of the highlights:

* It uses a couple foundation css classes, I plan to remove this later
* Index tables are limited to 7 fields
* TEXT type fields are removed for the index table
* Reordered the pagination elements for a better look
  • Loading branch information
lorenzo committed Sep 5, 2014
1 parent edf9187 commit 205f3e9
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 63 deletions.
45 changes: 23 additions & 22 deletions src/Template/Bake/default/views/form.ctp
Expand Up @@ -13,8 +13,30 @@
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
use Cake\Utility\Inflector;

?>
<div class="<?= $pluralVar ?> form">
<div class="actions columns large-2 medium-3">
<h3><?= "<?= __('Actions') ?>" ?></h3>
<ul class="side-nav">
<?php if (strpos($action, 'add') === false): ?>
<li><?= "<?= \$this->Form->postLink(__('Delete'), ['action' => 'delete', \${$singularVar}->{$primaryKey[0]}], ['confirm' => __('Are you sure you want to delete # %s?', \${$singularVar}->{$primaryKey[0]})]) ?>" ?></li>
<?php endif; ?>
<li><?= "<?= \$this->Html->link(__('List " . $pluralHumanName . "'), ['action' => 'index']) ?>" ?></li>
<?php
$done = [];
foreach ($associations as $type => $data) {
foreach ($data as $alias => $details) {
if ($details['controller'] != $this->name && !in_array($details['controller'], $done)) {
echo "\t\t<li><?= \$this->Html->link(__('List " . Inflector::humanize($details['controller']) . "'), ['controller' => '{$details['controller']}', 'action' => 'index']) ?> </li>\n";
echo "\t\t<li><?= \$this->Html->link(__('New " . Inflector::humanize(Inflector::singularize(Inflector::underscore($alias))) . "'), ['controller' => '{$details['controller']}', 'action' => 'add']) ?> </li>\n";
$done[] = $details['controller'];
}
}
}
?>
</ul>
</div>
<div class="<?= $pluralVar ?> form large-10 medium-9 columns">
<?= "<?= \$this->Form->create(\${$singularVar}) ?>\n" ?>
<fieldset>
<legend><?= sprintf("<?= __('%s %s'); ?>", Inflector::humanize($action), $singularHumanName) ?></legend>
Expand Down Expand Up @@ -45,24 +67,3 @@ use Cake\Utility\Inflector;
echo "<?= \$this->Form->end() ?>\n";
?>
</div>
<div class="actions">
<h3><?= "<?= __('Actions') ?>" ?></h3>
<ul>
<?php if (strpos($action, 'add') === false): ?>
<li><?= "<?= \$this->Form->postLink(__('Delete'), ['action' => 'delete', \${$singularVar}->{$primaryKey[0]}], ['confirm' => __('Are you sure you want to delete # %s?', \${$singularVar}->{$primaryKey[0]})]) ?>" ?></li>
<?php endif; ?>
<li><?= "<?= \$this->Html->link(__('List " . $pluralHumanName . "'), ['action' => 'index']) ?>" ?></li>
<?php
$done = [];
foreach ($associations as $type => $data) {
foreach ($data as $alias => $details) {
if ($details['controller'] != $this->name && !in_array($details['controller'], $done)) {
echo "\t\t<li><?= \$this->Html->link(__('List " . Inflector::humanize($details['controller']) . "'), ['controller' => '{$details['controller']}', 'action' => 'index']) ?> </li>\n";
echo "\t\t<li><?= \$this->Html->link(__('New " . Inflector::humanize(Inflector::singularize(Inflector::underscore($alias))) . "'), ['controller' => '{$details['controller']}', 'action' => 'add']) ?> </li>\n";
$done[] = $details['controller'];
}
}
}
?>
</ul>
</div>
93 changes: 52 additions & 41 deletions src/Template/Bake/default/views/index.ctp
Expand Up @@ -13,73 +13,84 @@
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
use Cake\Utility\Inflector;

$fields = collection($fields)
->filter(function($field) use ($schema) {
return !in_array($schema->columnType($field), ['binary', 'text']);
})
->take(7);
?>
<div class="actions columns large-2 medium-3">
<h3><?= "<?= __('Actions') ?>"; ?></h3>
<ul class="side-nav">
<li><?= "<?= \$this->Html->link(__('New " . $singularHumanName . "'), ['action' => 'add']) ?>"; ?></li>
<?php
$done = [];
foreach ($associations as $type => $data) {
foreach ($data as $alias => $details) {
if ($details['controller'] != $this->name && !in_array($details['controller'], $done)) {
echo "\t\t<li><?= \$this->Html->link(__('List " . Inflector::humanize($details['controller']) . "'), ['controller' => '{$details['controller']}', 'action' => 'index']) ?> </li>\n";
echo "\t\t<li><?= \$this->Html->link(__('New " . Inflector::humanize(Inflector::singularize(Inflector::underscore($alias))) . "'), ['controller' => '{$details['controller']}', 'action' => 'add']) ?> </li>\n";
$done[] = $details['controller'];
}
}
}
?>
<div class="<?= $pluralVar ?> index">
<h2><?= "<?= __('{$pluralHumanName}') ?>"; ?></h2>
</ul>
</div>
<div class="<?= $pluralVar ?> index large-10 medium-9 columns">
<table cellpadding="0" cellspacing="0">
<thead>
<tr>
<?php foreach ($fields as $field): ?>
<th><?= "<?= \$this->Paginator->sort('{$field}') ?>"; ?></th>
<th><?= "<?= \$this->Paginator->sort('{$field}') ?>"; ?></th>
<?php endforeach; ?>
<th class="actions"><?= "<?= __('Actions') ?>"; ?></th>
<th class="actions"><?= "<?= __('Actions') ?>"; ?></th>
</tr>
</thead>
<tbody>
<?php
echo "<?php foreach (\${$pluralVar} as \${$singularVar}): ?>\n";
echo "\t<tr>\n";
echo "\t\t<tr>\n";
foreach ($fields as $field) {
$isKey = false;
if (!empty($associations['BelongsTo'])) {
foreach ($associations['BelongsTo'] as $alias => $details) {
if ($field === $details['foreignKey']) {
$isKey = true;
echo "\t\t<td>\n\t\t\t<?= \${$singularVar}->has('{$details['property']}') ? \$this->Html->link(\${$singularVar}->{$details['property']}->{$details['displayField']}, ['controller' => '{$details['controller']}', 'action' => 'view', \${$singularVar}->{$details['property']}->{$details['primaryKey'][0]}]) : '' ?>\n\t\t</td>\n";
echo "\t\t\t<td>\n\t\t\t\t<?= \${$singularVar}->has('{$details['property']}') ? \$this->Html->link(\${$singularVar}->{$details['property']}->{$details['displayField']}, ['controller' => '{$details['controller']}', 'action' => 'view', \${$singularVar}->{$details['property']}->{$details['primaryKey'][0]}]) : '' ?>\n\t\t\t</td>\n";
break;
}
}
}
if ($isKey !== true) {
echo "\t\t<td><?= h(\${$singularVar}->{$field}) ?>&nbsp;</td>\n";
echo "\t\t\t<td><?= h(\${$singularVar}->{$field}) ?>&nbsp;</td>\n";
}
}

$pk = "\${$singularVar}->{$primaryKey[0]}";

echo "\t\t<td class=\"actions\">\n";
echo "\t\t\t<?= \$this->Html->link(__('View'), ['action' => 'view', {$pk}]) ?>\n";
echo "\t\t\t<?= \$this->Html->link(__('Edit'), ['action' => 'edit', {$pk}]) ?>\n";
echo "\t\t\t<?= \$this->Form->postLink(__('Delete'), ['action' => 'delete', {$pk}], ['confirm' => __('Are you sure you want to delete # {0}?', {$pk})]) ?>\n";
echo "\t\t</td>\n";
echo "\t</tr>\n";
echo "\t\t\t<td class=\"actions\">\n";
echo "\t\t\t\t<?= \$this->Html->link(__('View'), ['action' => 'view', {$pk}]) ?>\n";
echo "\t\t\t\t<?= \$this->Html->link(__('Edit'), ['action' => 'edit', {$pk}]) ?>\n";
echo "\t\t\t\t<?= \$this->Form->postLink(__('Delete'), ['action' => 'delete', {$pk}], ['confirm' => __('Are you sure you want to delete # {0}?', {$pk})]) ?>\n";
echo "\t\t\t</td>\n";
echo "\t\t</tr>\n";

echo "\t<?php endforeach; ?>\n";
?>
</thead>
</table>
<p><?= "<?= \$this->Paginator->counter() ?>"; ?></p>
<ul class="pagination">
<?php
echo "<?php\n";
echo "\t\techo \$this->Paginator->prev('< ' . __('previous'));\n";
echo "\t\techo \$this->Paginator->numbers();\n";
echo "\t\techo \$this->Paginator->next(__('next') . ' >');\n";
echo "\t?>\n";
?>
</ul>
</div>
<div class="actions">
<h3><?= "<?= __('Actions') ?>"; ?></h3>
<ul>
<li><?= "<?= \$this->Html->link(__('New " . $singularHumanName . "'), ['action' => 'add']) ?>"; ?></li>
<?php
$done = [];
foreach ($associations as $type => $data) {
foreach ($data as $alias => $details) {
if ($details['controller'] != $this->name && !in_array($details['controller'], $done)) {
echo "\t\t<li><?= \$this->Html->link(__('List " . Inflector::humanize($details['controller']) . "'), ['controller' => '{$details['controller']}', 'action' => 'index']) ?> </li>\n";
echo "\t\t<li><?= \$this->Html->link(__('New " . Inflector::humanize(Inflector::singularize(Inflector::underscore($alias))) . "'), ['controller' => '{$details['controller']}', 'action' => 'add']) ?> </li>\n";
$done[] = $details['controller'];
}
}
}
?>
</ul>
<div class="paginator">
<ul class="pagination">
<?php
echo "<?php\n";
echo "\t\t\techo \$this->Paginator->prev('< ' . __('previous'));\n";
echo "\t\t\techo \$this->Paginator->numbers();\n";
echo "\t\t\techo \$this->Paginator->next(__('next') . ' >');\n";
echo "\t\t?>\n";
?>
</ul>
<p><?= "<?= \$this->Paginator->counter() ?>"; ?></p>
</div>
</div>

0 comments on commit 205f3e9

Please sign in to comment.