Skip to content

Commit 8e74df4

Browse files
committed
Implement bake view close #13
1 parent 73193b5 commit 8e74df4

2 files changed

Lines changed: 147 additions & 59 deletions

File tree

src/Template/Bake/Template/index.ctp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ if (!in_array($field, ['created', 'modified', 'updated'])) :%>
7777
$pk = '$' . $singularVar . '->' . $primaryKey[0];
7878
%>
7979
<td class="actions" style="white-space:nowrap">
80-
<?= $this->Html->link(__('Edit'), ['action' => 'edit', <%= $pk %>], ['class'=>'btn btn-primary btn-xs']) ?>
80+
<?= $this->Html->link(__('View'), ['action' => 'view', <%= $pk %>], ['class'=>'btn btn-info btn-xs']) ?>
81+
<?= $this->Html->link(__('Edit'), ['action' => 'edit', <%= $pk %>], ['class'=>'btn btn-warning btn-xs']) ?>
8182
<?= $this->Form->postLink(__('Delete'), ['action' => 'delete', <%= $pk %>], ['confirm' => __('Confirm to delete this entry?'), 'class'=>'btn btn-danger btn-xs']) ?>
8283
</td>
8384
</tr>

src/Template/Bake/Template/view.ctp

Lines changed: 145 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -51,71 +51,158 @@ $pk = "\$$singularVar->{$primaryKey[0]}";
5151

5252
<!-- Main content -->
5353
<section class="content">
54+
<div class="row">
55+
<div class="col-md-12">
56+
<div class="box box-solid">
57+
<div class="box-header with-border">
58+
<i class="fa fa-info"></i>
59+
<h3 class="box-title"><?php echo __('Information'); ?></h3>
60+
</div>
61+
<!-- /.box-header -->
62+
<div class="box-body">
63+
<dl class="dl-horizontal">
64+
<% if ($groupedFields['string']) : %>
65+
<% foreach ($groupedFields['string'] as $field) : %>
66+
<% if (isset($associationFields[$field])) :
67+
$details = $associationFields[$field];
68+
%>
69+
<dt><?= __('<%= Inflector::humanize($details['property']) %>') ?></dt>
70+
<dd>
71+
<?= $<%= $singularVar %>->has('<%= $details['property'] %>') ? $<%= $singularVar %>-><%= $details['property'] %>-><%= $details['displayField'] %> : '' ?>
72+
</dd>
73+
<% else :
74+
if ($field != 'password') :%>
75+
<dt><?= __('<%= Inflector::humanize($field) %>') ?></dt>
76+
<dd>
77+
<?= h($<%= $singularVar %>-><%= $field %>) ?>
78+
</dd>
79+
<% endif; %>
80+
<% endif; %>
81+
<% endforeach; %>
82+
<% endif; %>
83+
84+
<% if ($associations['HasOne']) : %>
85+
<% foreach ($associations['HasOne'] as $alias => $details) : %>
86+
<dt><?= __('<%= Inflector::humanize(Inflector::singularize(Inflector::underscore($alias))) %>') ?></dt>
87+
<dd>
88+
<?= $<%= $singularVar %>->has('<%= $details['property'] %>') ? $this->Html->link($<%= $singularVar %>-><%= $details['property'] %>-><%= $details['displayField'] %>, ['controller' => '<%= $details['controller'] %>', 'action' => 'view', $<%= $singularVar %>-><%= $details['property'] %>-><%= $details['primaryKey'][0] %>]) : '' ?>
89+
</dd>
90+
<% endforeach; %>
91+
<% endif; %>
92+
93+
<% if ($groupedFields['number']) : %>
94+
<% foreach ($groupedFields['number'] as $field) : %>
95+
<% if ($field != $primaryKey[0]) :%>
96+
<dt><?= __('<%= Inflector::humanize($field) %>') ?></dt>
97+
<dd>
98+
<?= $this->Number->format($<%= $singularVar %>-><%= $field %>) ?>
99+
</dd>
100+
<% endif; %>
101+
<% endforeach; %>
102+
<% endif; %>
103+
104+
<% if ($groupedFields['date']) : %>
105+
<% foreach ($groupedFields['date'] as $field) : %>
106+
<% if (!in_array($field, ['created', 'modified', 'updated'])) : %>
107+
<dt><%= "<%= __('" . Inflector::humanize($field) . "') %>" %></dt>
108+
<dd>
109+
<?= h($<%= $singularVar %>-><%= $field %>) ?>
110+
</dd>
111+
<% endif; %>
112+
<% endforeach; %>
113+
<% endif; %>
114+
115+
<% if ($groupedFields['boolean']) : %>
116+
<% foreach ($groupedFields['boolean'] as $field) : %>
117+
<dt><?= __('<%= Inflector::humanize($field) %>') ?></dt>
118+
<dd>
119+
<?= $<%= $singularVar %>-><%= $field %> ? __('Yes') : __('No'); ?>
120+
</dd>
121+
<% endforeach; %>
122+
<% endif; %>
123+
124+
<% if ($groupedFields['text']) : %>
125+
<% foreach ($groupedFields['text'] as $field) : %>
126+
<dt><?= __('<%= Inflector::humanize($field) %>') ?></dt>
127+
<dd>
128+
<?= $this->Text->autoParagraph(h($<%= $singularVar %>-><%= $field %>)); ?>
129+
</dd>
130+
<% endforeach; %>
131+
<% endif; %>
132+
</dl>
133+
</div>
134+
<!-- /.box-body -->
135+
</div>
136+
<!-- /.box -->
137+
</div>
138+
<!-- ./col -->
139+
</div>
140+
<!-- div -->
141+
142+
<%
143+
$relations = $associations['HasMany'] + $associations['BelongsToMany'];
144+
foreach ($relations as $alias => $details):
145+
$otherSingularVar = Inflector::variable($alias);
146+
$otherPluralHumanName = Inflector::humanize(Inflector::underscore($details['controller']));
147+
%>
54148
<div class="row">
55-
<div class="col-md-12">
56-
<div class="box box-solid">
57-
<div class="box-header with-border">
58-
<i class="fa fa-text-width"></i>
59-
<h3 class="box-title"><?php echo __('Information'); ?></h3>
149+
<div class="col-xs-12">
150+
<div class="box">
151+
<div class="box-header">
152+
<i class="fa fa-share-alt"></i>
153+
<h3 class="box-title"><?= __('Related {0}', ['<%= $otherPluralHumanName %>']) ?></h3>
60154
</div>
61155
<!-- /.box-header -->
62-
<div class="box-body">
63-
<dl class="dl-horizontal">
64-
<% if ($groupedFields['string']) : %>
65-
<% foreach ($groupedFields['string'] as $field) : %>
66-
<% if (isset($associationFields[$field])) :
67-
$details = $associationFields[$field];
68-
%>
69-
<dt><?= __('<%= Inflector::humanize($details['property']) %>') ?></dt>
70-
<dd><?= $<%= $singularVar %>->has('<%= $details['property'] %>') ? $<%= $singularVar %>-><%= $details['property'] %>-><%= $details['displayField'] %> : '' ?></dd>
71-
<% else :
72-
if ($field != 'password') :%>
73-
<dt><?= __('<%= Inflector::humanize($field) %>') ?></dt>
74-
<dd><?= h($<%= $singularVar %>-><%= $field %>) ?></dd>
75-
<% endif; %>
76-
<% endif; %>
77-
<% endforeach; %>
78-
<% endif; %>
79-
<% if ($associations['HasOne']) : %>
80-
<% foreach ($associations['HasOne'] as $alias => $details) : %>
81-
<dt><?= __('<%= Inflector::humanize(Inflector::singularize(Inflector::underscore($alias))) %>') ?></dt>
82-
<dd><?= $<%= $singularVar %>->has('<%= $details['property'] %>') ? $this->Html->link($<%= $singularVar %>-><%= $details['property'] %>-><%= $details['displayField'] %>, ['controller' => '<%= $details['controller'] %>', 'action' => 'view', $<%= $singularVar %>-><%= $details['property'] %>-><%= $details['primaryKey'][0] %>]) : '' ?></dd>
83-
<% endforeach; %>
84-
<% endif; %>
85-
<% if ($groupedFields['number']) : %>
86-
<% foreach ($groupedFields['number'] as $field) : %>
87-
<% if ($field != $primaryKey[0]) :%>
88-
<dt><?= __('<%= Inflector::humanize($field) %>') ?></dt>
89-
<dd><?= $this->Number->format($<%= $singularVar %>-><%= $field %>) ?></dd>
90-
<% endif; %>
91-
<% endforeach; %>
92-
<% endif; %>
93-
<% if ($groupedFields['date']) : %>
94-
<% foreach ($groupedFields['date'] as $field) : %>
95-
<% if (!in_array($field, ['created', 'modified', 'updated'])) : %>
96-
<dt><%= "<%= __('" . Inflector::humanize($field) . "') %>" %></dt>
97-
<dd><?= h($<%= $singularVar %>-><%= $field %>) ?></dd>
98-
<% endif; %>
99-
<% endforeach; %>
100-
<% endif; %>
101-
<% if ($groupedFields['boolean']) : %>
102-
<% foreach ($groupedFields['boolean'] as $field) : %>
103-
<dt><?= __('<%= Inflector::humanize($field) %>') ?></dt>
104-
<dd><?= $<%= $singularVar %>-><%= $field %> ? __('Yes') : __('No'); ?></dd>
105-
<% endforeach; %>
106-
<% endif; %>
107-
<% if ($groupedFields['text']) : %>
108-
<% foreach ($groupedFields['text'] as $field) : %>
109-
<dt><?= __('<%= Inflector::humanize($field) %>') ?></dt>
110-
<dd><?= $this->Text->autoParagraph(h($<%= $singularVar %>-><%= $field %>)); ?></dd>
111-
<% endforeach; %>
112-
<% endif; %>
113-
</dl>
156+
<div class="box-body table-responsive no-padding">
157+
158+
<?php if (!empty($<%= $singularVar %>-><%= $details['property'] %>)): ?>
159+
160+
<table class="table table-hover">
161+
<tbody>
162+
<tr>
163+
<% foreach ($details['fields'] as $field): %>
164+
<% if (in_array($field, ['created', 'modified'])) { continue; } %>
165+
166+
<th>
167+
<%= Inflector::humanize($field) %>
168+
</th>
169+
170+
<% endforeach; %>
171+
172+
<th>
173+
<?php echo __('Actions'); ?>
174+
</th>
175+
</tr>
176+
177+
<?php foreach ($<%= $singularVar %>-><%= $details['property'] %> as $<%= $otherSingularVar %>): ?>
178+
<tr>
179+
<% foreach ($details['fields'] as $field): %>
180+
<% if (in_array($field, ['created', 'modified'])) { continue; } %>
181+
182+
<td>
183+
<?= h($<%= $otherSingularVar %>-><%= $field %>) ?>
184+
</td>
185+
<% endforeach; %>
186+
187+
<% $otherPk = "\${$otherSingularVar}->{$details['primaryKey'][0]}"; %>
188+
<td class="actions">
189+
<?= $this->Html->link(__('View'), ['controller' => '<%= $details['controller'] %>', 'action' => 'view', <%= $otherPk %>], ['class'=>'btn btn-info btn-xs']) %>
190+
<?= $this->Html->link(__('Edit'), ['controller' => '<%= $details['controller'] %>', 'action' => 'edit', <%= $otherPk %>], ['class'=>'btn btn-warning btn-xs']) %>
191+
<?= $this->Form->postLink(__('Delete'), ['controller' => '<%= $details['controller'] %>', 'action' => 'delete', <%= $otherPk %>], ['confirm' => __('Are you sure you want to delete # {0}?', <%= $otherPk %>), 'class'=>'btn btn-danger btn-xs']) %>
192+
</td>
193+
</tr>
194+
<?php endforeach; ?>
195+
196+
</tbody>
197+
</table>
198+
199+
<?php endif; ?>
200+
114201
</div>
115202
<!-- /.box-body -->
116203
</div>
117204
<!-- /.box -->
118205
</div>
119-
<!-- ./col -->
120206
</div>
207+
<% endforeach; %>
121208
</section>

0 commit comments

Comments
 (0)