Created
October 3, 2019 12:03
-
-
Save Atmden/70d9072e500b0f766a498eb6c05dce85 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<table {!! $attributes !!}> | |
<colgroup> | |
@foreach ($columns as $column) | |
<col width="{!! $column->getWidth() !!}"/> | |
@endforeach | |
</colgroup> | |
<thead> | |
<tr> | |
@foreach ($columns as $column) | |
<th {!! $column->getHeader()->htmlAttributesToString() !!}> | |
{!! $column->getHeader()->render() !!} | |
</th> | |
@endforeach | |
</tr> | |
</thead> | |
@yield('table.header') | |
<tbody> | |
@forelse($collection->pluck('floor')->unique() as $floor) | |
<tr> | |
<td colspan="{{ $columns->count() / 2 }}" class="warning text-left"> | |
<span style="font-size: 18px">{{ $floor }} этаж</span> | |
</td> | |
<td colspan="{{ $columns->count() / 2 }}" class="text-right warning"> | |
<form action="{{ route('admin.floor.copy') }}" | |
method="POST" | |
style="display:inline-block;" | |
> | |
@csrf | |
<input type="hidden" name="entrance_id" value="{{ request('entrance_id') }}"> | |
<input type="hidden" name="home_id" value="{{ request('parent_id') }}"> | |
<input type="hidden" name="floor" value="{{ $floor }}"> | |
<button class="btn btn-warning btn-sm"> | |
<i class="fa fa-copy"></i> | |
Копировать этаж | |
</button> | |
</form> | |
<form action="#" | |
method="POST" | |
style="display:inline-block;" | |
> | |
@csrf | |
@method('delete') | |
<input type="hidden" name="entrance_id" value="{{ request('entrance_id') }}"> | |
<input type="hidden" name="home_id" value="{{ request('parent_id') }}"> | |
<input type="hidden" name="floor" value="{{ $floor }}"> | |
<button class="btn btn-danger btn-sm"> | |
<i class="fa fa-trash"></i> | |
Удалить этаж | |
</button> | |
</form> | |
</td> | |
</tr> | |
@foreach ($collection->where('floor', $floor) as $model) | |
<tr> | |
@foreach ($columns as $column) | |
<?php | |
$column->setModel($model); | |
if ($column instanceof \SleepingOwl\Admin\Display\Column\Control) { | |
$column->initialize(); | |
} | |
if($column instanceof \SleepingOwl\Admin\Contracts\Display\ColumnEditableInterface) { | |
?> | |
<td> | |
{!! $column->render() !!} | |
</td> | |
<?php } else { ?> | |
<td {!! $column->htmlAttributesToString() !!}> | |
{!! $column->render() !!} | |
</td> | |
<?php | |
} | |
?> | |
@endforeach | |
</tr> | |
@endforeach | |
@empty | |
<tr> | |
<td colspan="{{ $columns->count() }}" class="text-center" style="padding: 20px 0"> | |
<b>К выбраннуму подъезду квартиры ещё не добавлены</b> | |
</td> | |
</tr> | |
@endforelse | |
</tbody> | |
@yield('table.footer') | |
</table> | |
@if(!is_null($pagination)) | |
<div class="panel-footer"> | |
{!! $pagination !!} | |
</div> | |
@endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Sections; | |
use AdminColumn; | |
use AdminColumnEditable; | |
use AdminDisplay; | |
use AdminForm; | |
use AdminFormElement; | |
use App\Extensions\Entrances; | |
use App\Models\Bathroom; | |
use App\Models\WindowView; | |
use App\Models\Apartment; | |
use App\Models\Complex; | |
use App\Models\Entrance; | |
use App\Models\Home; | |
use App\Models\Status; | |
use App\Services\EntranceService; | |
use Carbon\Carbon; | |
use Illuminate\Database\Eloquent\Builder; | |
use SleepingOwl\Admin\Display\Column\Editable\Text; | |
class ApartmentSection extends BaseSection | |
{ | |
protected $title = 'Квартиры'; | |
protected $titles = ['create' => 'Создание новой квартиры', 'edit' => 'Редактирование квартиры']; | |
protected $redirectWithParent = true; | |
public function getTitle() | |
{ | |
if (request()->has(['parent_id', 'entrance_id'])) { | |
$home = Home::findOrFail(request('parent_id')); | |
return sprintf( | |
'%s → %s → %s → %s', | |
$home->complex->name, | |
$home->name, | |
$home->entrances->where('id', request('entrance_id'))->first()->name, | |
$this->title | |
); | |
} | |
return parent::getTitle(); | |
} | |
protected function breadcrumbs() | |
{ | |
$home = Home::findOrFail(request('parent_id')); | |
$this->addBreadCrumb([ | |
'id' => 'objects', | |
'parent' => 'home', | |
'title' => 'Мои объекты', | |
'url' => route('admin.model', ['complexes']), | |
]); | |
$this->addBreadCrumb([ | |
'id' => 'object', | |
'parent' => 'objects', | |
'title' => $home->complex->name, | |
'url' => null, | |
]); | |
$this->addBreadCrumb([ | |
'id' => 'homes', | |
'parent' => 'object', | |
'title' => 'Список домов', | |
'url' => route('admin.model', ['homes']), | |
]); | |
$this->addBreadCrumb([ | |
'id' => 'currentHome', | |
'parent' => 'homes', | |
'title' => $home->name, | |
'url' => null, | |
]); | |
$this->addBreadCrumb([ | |
'id' => 'apartments', | |
'parent' => 'currentHome', | |
'title' => 'Квартиры', | |
'url' => route('admin.model', ['apartments']), | |
]); | |
} | |
public function redirectInWithParent(array $requiredParams = ['parent_id'], array $queryParams = []) | |
{ | |
if (!request()->has('entrance_id') && request()->has('parent_id')) { | |
$entrance = Entrance::byHome(request('parent_id'))->orderBy('id')->first(); | |
$queryParams['entrance_id'] = $entrance->id; | |
} | |
return parent::redirectInWithParent(['parent_id', 'entrance_id'], $queryParams); | |
} | |
protected function modifyDisplay(callable $cb) | |
{ | |
// 404 Если ссылка на не существующий подъезд | |
if (request()->has('entrance_id')) { | |
$entrance = Entrance::find(request('entrance_id')); | |
if (!$entrance) { | |
request()->query->remove('entrance_id'); | |
} | |
} | |
// Если есть Дом но подъезд для этого не один не создан то создать подъезд | |
if (request()->has('parent_id')) { | |
$homeId = request('parent_id'); | |
if (Entrance::byHome($homeId)->count() == 0) { | |
$service = new EntranceService; | |
$service->create($homeId); | |
} | |
} | |
return parent::modifyDisplay($cb); | |
} | |
public function onDisplay() | |
{ | |
$table = AdminDisplay::table() | |
->with(['home']) | |
->setApply(function (Builder $query) { | |
return $query->where('home_id', request('parent_id'))->orderFull('desc', 'desc'); | |
}) | |
->setColumns([ | |
$this->columnID(), | |
AdminColumnEditable::text('number', 'Номер квартиры') | |
->setWidth(50), | |
AdminColumnEditable::text('order', 'Сортировка') | |
->setWidth(50), | |
AdminColumnEditable::text('count_rooms', 'Комнат') | |
->setWidth(50), | |
AdminColumnEditable::text('area_total', 'Общ. площадь') | |
->setWidth(50), | |
AdminColumnEditable::text('area_calculated', 'Расч. площадь') | |
->setWidth(50), | |
AdminColumnEditable::datetime('updated_at', 'Created At') | |
->setWidth(50), | |
AdminColumnEditable::text('price', 'Цена') | |
->setText(function (Text $element) { | |
return number_format($element->getModelValue(), 0, '.', ' ') . ' ₽'; | |
}) | |
->setWidth(50), | |
AdminColumnEditable::text('price_area', 'Цена за м2') | |
->setText(function (Text $element) { | |
return number_format($element->getModelValue(), 0, '.', ' ') . ' ₽'; | |
}) | |
->setWidth(50), | |
AdminColumnEditable::select('status_id', 'Статус', Status::class) | |
->setWidth(50) | |
->setDisplay('name'), | |
]) | |
->setNewEntryButtonText('Новая квартира') | |
->paginate(config('admin.pagination.count')); | |
$table->extend('entrances', new Entrances); | |
$table->getColumns() | |
->setView('display.extensions.apartment_columns') | |
->getControlColumn() | |
->addButton( | |
$this->button(function (Apartment $apartment) { | |
return route('admin.apartment.copy', $apartment->id); | |
}, 'Копировать квартиру') | |
->setMethod('post') | |
->hideText() | |
->setIcon('fa fa-copy') | |
->setHtmlAttribute('class', 'btn-warning') | |
); | |
return $table; | |
} | |
public function onEdit($id) | |
{ | |
$home = Home::find(request('parent_id')) ?: optional(); | |
return AdminForm::panel()->addBody([ | |
$this->formColumns([ | |
[ | |
AdminFormElement::select('complex_id', 'Жилой комплекс', Complex::class) | |
->setDefaultValue(optional($home->complex)->id) | |
->setDisplay('name') | |
->required(), | |
], | |
[ | |
AdminFormElement::dependentselect('home_id', 'Дом', ['complex_id']) | |
->setModelForOptions(Home::class, 'name') | |
->setLoadOptionsQueryPreparer(function ($item, Builder $query) { | |
return $query->where('complex_id', $item->getDependValue('complex_id')); | |
}) | |
->setAjaxParameters(request()->all()) | |
->setDefaultValue($home->id) | |
->required(), | |
], | |
[ | |
AdminFormElement::dependentselect('entrance_id', 'Подъезд', ['complex_id', 'home_id']) | |
->setModelForOptions(Entrance::class, 'name') | |
->setLoadOptionsQueryPreparer(function ($item, Builder $query) { | |
return $query->where('home_id', $item->getDependValue('home_id')); | |
}) | |
->setAjaxParameters(request()->all()) | |
->setDefaultValue(request('entrance_id')) | |
->setDisplay('name') | |
->required(), | |
], | |
]), | |
$this->formColumns([ | |
[ | |
AdminFormElement::select('status_id', 'Статус', Status::class) | |
->setDisplay('name') | |
->required(), | |
], | |
[ | |
AdminFormElement::checkbox('is_studio', 'Студия?'), | |
], | |
[ | |
AdminFormElement::number('order', 'Сортировка'), | |
], | |
]), | |
$this->formColumns([ | |
[ | |
AdminFormElement::number('number', 'Номер квартиры')->required(), | |
], | |
[ | |
AdminFormElement::number('floor', 'Этаж')->required(), | |
], | |
[ | |
AdminFormElement::number('count_rooms', 'Количество комнат'), | |
], | |
]), | |
$this->formColumns([ | |
[ | |
AdminFormElement::text('area_total', 'Общая площадь') | |
->addValidationRule('nullable') | |
->addValidationRule('numeric') | |
->required(), | |
], | |
[ | |
AdminFormElement::text('area_calculated', 'Расчётная площадь') | |
->addValidationRule('nullable') | |
->addValidationRule('numeric'), | |
], | |
[ | |
AdminFormElement::text('area_without_balconies', 'Площадь по БТИ') | |
->addValidationRule('nullable') | |
->addValidationRule('numeric'), | |
], | |
]), | |
$this->formColumns([ | |
[ | |
AdminFormElement::text('area_living', 'Жилая площадь') | |
->addValidationRule('nullable') | |
->addValidationRule('numeric'), | |
], | |
[ | |
AdminFormElement::text('area_kitchen', 'Площадь кухни') | |
->addValidationRule('nullable') | |
->addValidationRule('numeric'), | |
], | |
]), | |
$this->formColumns([ | |
[ | |
AdminFormElement::text('price', 'Стоимость') | |
->addValidationRule('integer') | |
->addValidationRule('nullable') | |
->addValidationRule('required_without:price_area', 'Одна из цен должна быть заполнена'), | |
], | |
[ | |
AdminFormElement::text('price_area', 'Стоимость за квадратный метр') | |
->addValidationRule('integer') | |
->addValidationRule('nullable') | |
->addValidationRule('required_without:price', 'Одна из цен должна быть заполнена') | |
->setHelpText('Если указана то общая стоимость будет расчитываться из расчёта за м2'), | |
], | |
]), | |
$this->formColumns([ | |
[ | |
AdminFormElement::number('count_loggias', 'Количество лоджий'), | |
], | |
[ | |
AdminFormElement::text('area_loggias', 'Площадь лоджий') | |
->addValidationRule('nullable') | |
->addValidationRule('numeric'), | |
], | |
[ | |
AdminFormElement::number('count_balconies', 'Количество балконов'), | |
], | |
[ | |
AdminFormElement::text('area_balconies', 'Площадь балконов') | |
->addValidationRule('nullable') | |
->addValidationRule('numeric'), | |
], | |
]), | |
$this->formColumns([ | |
[ | |
AdminFormElement::select('bathroom_id', 'Санузел', Bathroom::class) | |
->setDisplay('name'), | |
], | |
[ | |
AdminFormElement::select('window_view_id', 'Вид из окон', WindowView::class) | |
->setDisplay('name'), | |
], | |
]), | |
]); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="b-apartment-entrances" style="padding: 15px; background: #ecf0f5;"> | |
@foreach($entrances as $entrance) | |
<div class="btn-group"> | |
<div class="input-group-btn"> | |
<a href="{{ request()->fullUrlWithQuery(['entrance_id' => $entrance->id]) }}" | |
class="btn {{ request('entrance_id') == $entrance->id ? 'btn-success' : 'btn-primary' }}" | |
> | |
{{ $entrance->name }} | |
</a> | |
</div> | |
<form action="{{ route('admin.entrance.copy', $entrance->id) }}" method="post" class="input-group-btn"> | |
@csrf | |
<button class="btn btn-warning" title="Копировать"> | |
<i class="fa fa-copy"></i> | |
</button> | |
</form> | |
<form action="{{ route('admin.entrance.delete', $entrance->id) }}" method="post" class="input-group-btn"> | |
@csrf | |
@method('delete') | |
<button class="btn btn-danger" title="Удалить"> | |
<i class="fa fa-remove"></i> | |
</button> | |
</form> | |
</div> | |
@endforeach | |
<form action="{{ route('admin.entrance.store') }}" method="post" style="display:inline-block;"> | |
@csrf | |
<input type="hidden" name="home_id" value="{{ request('parent_id') }}"> | |
<button type="submit" class="btn btn-primary"> | |
<i class="fa fa-plus"></i> | |
Новый подъезд | |
</button> | |
</form> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace App\Extensions; | |
use App\Admin\Http\Sections\ApartmentSection; | |
use App\Admin\Permissions\DeveloperCabinetNames; | |
use App\Models\Complex; | |
use App\Models\Entrance; | |
use App\Models\Home; | |
use App\Models\User; | |
use SleepingOwl\Admin\Contracts\Display\Placable; | |
use SleepingOwl\Admin\Display\Extension\Extension; | |
use SleepingOwl\Admin\Traits\ElementPlacementTrait; | |
use SleepingOwl\Admin\Traits\ElementViewTrait; | |
use Illuminate\Database\Eloquent\Builder; | |
class Entrances extends Extension implements Placable | |
{ | |
use ElementPlacementTrait, ElementViewTrait; | |
protected $view = '_extensions.entrances'; | |
protected $placement = 'panel.heading'; | |
public function getView() | |
{ | |
return view($this->view); | |
} | |
public function toArray() | |
{ | |
$entrances = Entrance::byHome(request('parent_id'))->get(); | |
return [ | |
'entrances' => $entrances | |
]; | |
} | |
public function modifyQuery(Builder $query) | |
{ | |
return $query->when(request()->has('entrance_id'), function (Builder $query) { | |
return $query->where('entrance_id', request('entrance_id')); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment