Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prettify model preview page #781

Merged
merged 1 commit into from
Sep 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/PanelTraits/AutoSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ trait AutoSet
*/
public function setFromDb()
{
$this->setDoctrineTypesMapping();
$this->getDbColumnTypes();

array_map(function ($field) {
Expand Down Expand Up @@ -102,6 +103,9 @@ public function getFieldTypeFromDbColumnType($field)
break;

case 'text':
return 'textarea';
break;

case 'mediumtext':
case 'longtext':
return 'textarea';
Expand All @@ -125,6 +129,18 @@ public function getFieldTypeFromDbColumnType($field)
}
}

// Fix for DBAL not supporting enum
public function setDoctrineTypesMapping()
{
$types = ['enum' => 'string'];
$platform = \DB::getDoctrineConnection()->getDatabasePlatform();
foreach ($types as $type_key => $type_value) {
if (!$platform->hasDoctrineTypeMappingFor($type_key)) {
$platform->registerDoctrineTypeMapping($type_key, $type_value);
}
}
}

/**
* Turn a database column name or PHP variable into a pretty label to be shown to the user.
*
Expand Down
19 changes: 19 additions & 0 deletions src/app/Http/Controllers/CrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,30 @@ public function show($id)
{
$this->crud->hasAccessOrFail('show');

// set columns from db
$this->crud->setFromDb();

// cycle through old columns for removal
foreach($this->crud->columns as $old_id => $column) {
// replace any relationship columns
if(array_key_exists('model', $column)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space after if!!!

Why exists vs isset?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed! Thanks.

$this->crud->columns[$column['name']] = $this->crud->columns[$old_id];
}
// remove old numbered columns
if(is_integer($old_id)) {
unset($this->crud->columns[$old_id]);
}

}

// get the info for that entry
$this->data['entry'] = $this->crud->getEntry($id);
$this->data['crud'] = $this->crud;
$this->data['title'] = trans('backpack::crud.preview').' '.$this->crud->entity_name;

// remove preview button from stack:line
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? I forget why...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because you're already on the "preview" page :-)

$this->crud->removeButton('preview');

// load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package
return view($this->crud->getShowView(), $this->data);
}
Expand Down
2 changes: 2 additions & 0 deletions src/resources/views/columns/textarea.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{-- regular object attribute --}}
<td>{!! $entry->{$column['name']} !!}</td>
43 changes: 36 additions & 7 deletions src/resources/views/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@section('content-header')
<section class="content-header">
<h1>
{{ trans('backpack::crud.preview') }} <span>{{ $crud->entity_name }}</span>
{{ trans('backpack::crud.preview') }} <span class="text-lowercase">{{ $crud->entity_name }}</span>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have text-lowercase in that span? German, for one, has rules about capitalising nouns for example?

</h1>
<ol class="breadcrumb">
<li><a href="{{ url(config('backpack.base.route_prefix'), 'dashboard') }}">{{ trans('backpack::crud.admin') }}</a></li>
Expand All @@ -15,19 +15,50 @@

@section('content')
@if ($crud->hasAccess('list'))
<a href="{{ url($crud->route) }}"><i class="fa fa-angle-double-left"></i> {{ trans('backpack::crud.back_to_all') }} <span>{{ $crud->entity_name_plural }}</span></a><br><br>
<a href="{{ url($crud->route) }}"><i class="fa fa-angle-double-left"></i> {{ trans('backpack::crud.back_to_all') }} <span class="text-lowercase">{{ $crud->entity_name_plural }}</span></a><br><br>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

text-lowercase?

@endif

<!-- Default box -->
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">
{{ trans('backpack::crud.preview') }}
<span>{{ $crud->entity_name }}</span>
<span class="text-lowercase">{{ $crud->entity_name }}</span>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

text-lowercase?

</h3>
</div>
<div class="box-body">
{{ dump($entry) }}
<table class="table table-striped table-bordered">
<tbody>
@foreach ($crud->columns as $column)
<tr>
<td>
<strong>{{ $column['label'] }}</strong>
</td>
@if (!isset($column['type']))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indenting below is odd.

@include('crud::columns.text')
@else
@if(view()->exists('vendor.backpack.crud.columns.'.$column['type']))
@include('vendor.backpack.crud.columns.'.$column['type'])
@else
@if(view()->exists('crud::columns.'.$column['type']))
@include('crud::columns.'.$column['type'])
@else
@include('crud::columns.text')
@endif
@endif
@endif
</tr>
@endforeach
@if ($crud->buttons->where('stack', 'line')->count())
<tr>
<td><strong>Actions</td>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You sure that doesn't have a translation key?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed! Thank you.

<td>
@include('crud::inc.button_stack', ['stack' => 'line'])
</td>
</tr>
@endif
</tbody>
</table>
</div><!-- /.box-body -->
</div><!-- /.box -->

Expand All @@ -36,10 +67,8 @@

@section('after_styles')
<link rel="stylesheet" href="{{ asset('vendor/backpack/crud/css/crud.css') }}">
<link rel="stylesheet" href="{{ asset('vendor/backpack/crud/css/show.css') }}">
@endsection

@section('after_scripts')
<script src="{{ asset('vendor/backpack/crud/js/crud.js') }}"></script>
<script src="{{ asset('vendor/backpack/crud/js/show.js') }}"></script>
@endsection
@endsection