| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428 |
- <div class="table-responsive">
- <div class="table-buttons py-2 bg-primary rounded-start d-flex flex-column ">
- <button type="button" class="btn btn-sm text-white" data-bs-toggle="modal"
- data-bs-target="#table_{{ $id }}_modal_search">
- <i class="bi bi-search-heart @if(request()->has('s')) text-danger @endif"></i>
- </button>
- <button type="button" class="btn btn-sm text-white " data-bs-toggle="modal"
- data-bs-target="#table_{{ $id }}_modal_filters">
- <i class="bi bi-funnel-fill @if(request()->has('filters')) text-danger @endif"></i>
- </button>
- <button type="button" class="btn btn-sm text-white " data-bs-toggle="modal"
- data-bs-target="#table_{{ $id }}_modal_settings">
- <i class="bi bi-gear-fill"></i>
- </button>
- </div>
- <table class="table" id="tbl" data-table-name="{{ $id }}" style="display: none; min-height: 380px;">
- <thead>
- <tr>
- @foreach($header as $headerName => $headerTitle)
- <th scope="col" class="bg-primary-subtle column_{{ $headerName }}">
- <div class="d-flex align-items-center justify-content-between">
- <div class="cursor-pointer sort-by-column" data-name="{{ $headerName }}">
- {{ $headerTitle }}
- </div>
- <div class="text-center mx-1 cursor-pointer" data-name="{{ $headerName }}">
- @if(($headerName== $sortBy))
- @if($orderBy === 'asc')
- <i class="bi bi-arrow-down-square-fill text-primary"></i>
- @else
- <i class="bi bi-arrow-up-square-fill text-primary"></i>
- @endif
- @endif
- </div>
- @if($headerName !== 'image')
- {{-- @if(isset((array_merge($filters, $ranges, $dates))[$headerName]) || ($headerName == $sortBy))--}}
- <div class="text-end cursor-pointer dropdown" data-bs-auto-close="outside" aria-expanded="false">
- <i
- data-bs-auto-close="outside"
- aria-expanded="false"
- data-bs-toggle="dropdown"
- class="dropdown-toggle bi
- @if(isset(request()->filters[$headerName]) ||
- isset(request()->filters[str_replace('_txt', '', $headerName) . '_from']) ||
- isset(request()->filters[str_replace('_txt', '', $headerName) . '_to'])
- )
- bi-funnel-fill text-danger
- @else
- bi-funnel
- @endif
- " id="{{$headerName}}"></i>
- @php
- $mergedData = array_merge($filters, $ranges, $dates);
- $type = null;
- $data = (array_merge($filters, $ranges, $dates))[$headerName] ?? null;
- if (isset($filters[$headerName])) {
- $type = 'filters';
- } elseif (isset($ranges[$headerName])) {
- $type = 'ranges';
- } elseif (isset($dates[$headerName])) {
- $type = 'dates';
- }
- @endphp
- @include('partials.newFilterElement', ['id' => $headerName, 'data' => $data, 'type' => $type, 'table' => $id, 'isSort' => $headerName == $sortBy, '$orderBy' => $orderBy])
- </div>
- @endif
- </div>
- </th>
- @endforeach
- </tr>
- </thead>
- <tbody>
- @foreach($strings as $string)
- <tr>
- @foreach($header as $headerName => $headerTitle)
- <td class="column_{{$headerName}}"
- @if(isset($routeName) && !str_contains($headerName, 'image') && !str_contains($headerName, 'order_status_name')) onclick="location.href='{{ route($routeName, $string->id) }}'" @endif>
- @if(str_contains($headerName, '-'))
- @php
- list($rel, $field) = explode('-', $headerName);
- @endphp
- @if(isset($string->$rel->$field))
- @if(str_ends_with($field, '_id'))
- @php
- $relation = \Illuminate\Support\Str::camel(str_replace('_id', '', $field));
- @endphp
- {!! $string->$rel->$relation?->name; !!}
- @else
- @if(str_contains($field, 'image') && $string->$rel->$field)
- <a href="{{ $string->$rel->$field }}" data-toggle="lightbox"
- data-gallery="photos" data-size="fullscreen">
- <img src="{{ $string->$rel->$field }}" alt="" class="img-thumbnail maf-img">
- </a>
- @else
- {!! $string->$rel->$field !!}
- @endif
- @endif
- @else
- <ul class="small mb-0 list-group list-group-flush bg-secondary">
- @foreach($string->$rel ?? [] as $item)
- <li class="list-group-item py-0 bg-body-secondary">
- {!! $item->$field !!}
- </li>
- @endforeach
- </ul>
- @endif
- @elseif(str_ends_with($headerName, '_id'))
- @php
- $relation = \Illuminate\Support\Str::camel(str_replace('_id', '', $headerName));
- @endphp
- @if($headerName == 'order_status_id')
- <div class="badge fs-5 text-bg-{{ App\Models\Order::STATUS_COLOR[$string->order_status_id] }}">{{ $string->$relation?->name }}</div>
- @else
- {!! $string->$relation?->name; !!}
- @endif
- @elseif(str_ends_with($headerName, '_date') && ($string->$headerName))
- {{ \App\Helpers\DateHelper::getHumanDate($string->$headerName, true) }}
- @elseif(str_contains($headerName, 'image') && $string->$headerName)
- <a href="{{ $string->$headerName }}" data-toggle="lightbox" data-gallery="photos"
- data-size="fullscreen">
- <img src="{{ $string->$headerName }}" alt="" class="img-thumbnail maf-img">
- </a>
- @elseif(str_contains($headerName, 'order_status_name'))
- <select name="order_status_name" data-order-id="{{ $string->id }}" @disabled(!hasRole('admin,manager')) class="change-order-status form-control form-control-sm" >
- @foreach($statuses as $statusId => $statusName)
- <option value="{{ $statusId }}" @selected($statusName == $string->$headerName)>{{ $statusName }}</option>
- @endforeach
- </select>
- @else
- <p title="{!! $string->$headerName !!}">
- {!! \Illuminate\Support\Str::words($string->$headerName, config('app.words_in_table_cell_limit'), ' ...') !!}
- </p>
- @endif
- </td>
- @endforeach
- </tr>
- @endforeach
- </tbody>
- </table>
- </div>
- <!-- Модальное окно настроек таблицы -->
- <div class="modal fade" id="table_{{ $id }}_modal_settings" tabindex="-1" aria-labelledby="exampleModalLabel"
- aria-hidden="true">
- <div class="modal-dialog modal-fullscreen-sm-down">
- <div class="modal-content">
- <div class="modal-header">
- <h1 class="modal-title fs-5" id="exampleModalLabel">Выбор отображаемых колонок</h1>
- <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
- </div>
- <div class="modal-body">
- @foreach($header as $headerName => $headerTitle)
- <div>
- <label class="me-3"><input type="checkbox" checked="checked" data-name="{{ $headerName }}"
- class="toggle-column checkbox-{{ $headerName }}"> {{ $headerTitle }}
- </label>
- </div>
- @endforeach
- </div>
- <div class="modal-footer">
- <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Закрыть</button>
- </div>
- </div>
- </div>
- </div>
- <!-- Модальное окно фильтров -->
- <div class="modal fade" id="table_{{ $id }}_modal_filters" tabindex="-1" aria-labelledby="exampleModalLabel"
- aria-hidden="true">
- <div class="modal-dialog modal-fullscreen-sm-down modal-lg">
- <div class="modal-content">
- <div class="modal-header">
- <h1 class="modal-title fs-5" id="exampleModalLabel">Фильтры по колонкам таблицы</h1>
- <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
- </div>
- <div class="modal-body">
- <form class="filters">
- @if(isset($filters) && is_array($filters))
- @foreach($filters as $filterName => $filter)
- @php $filter['values'] = ['' => ''] + $filter['values'] @endphp
- @include('partials.select', [
- 'name' => 'filters[' . $filterName . ']',
- 'title' => $filter['title'],
- 'options' => $filter['values'],
- 'value' => request()->filters[$filterName] ?? '',
- ])
- @endforeach
- @endif
- @if(isset($ranges) && is_array($ranges))
- @foreach($ranges as $rangeName => $range)
- @include('partials.input', [
- 'name' => 'filters[' . $rangeName . '_from]',
- 'type' => 'number',
- 'title' => $range['title'] . ' с:',
- 'min' => $range['min'],
- 'max' => $range['max'],
- 'value' => request()->filters[$rangeName . '_from'] ?? '', // $range['min']
- ])
- @include('partials.input', [
- 'name' => 'filters[' . $rangeName . '_to]',
- 'type' => 'number',
- 'title' => ' по:',
- 'min' => $range['min'],
- 'max' => $range['max'],
- 'value' => request()->filters[$rangeName . '_to'] ?? '', // $range['max']
- ])
- @endforeach
- @endif
- @if(isset($dates) && is_array($dates))
- @foreach($dates as $rangeName => $range)
- @include('partials.input', [
- 'name' => 'filters[' . $rangeName . '_from]',
- 'type' => 'date',
- 'title' => $range['title'] . ' с:',
- 'min' => $range['min'],
- 'max' => $range['max'],
- 'value' => request()->filters[$rangeName . '_from'] ?? '',
- ])
- @include('partials.input', [
- 'name' => 'filters[' . $rangeName . '_to]',
- 'type' => 'date',
- 'title' => $range['title'] . ' по:',
- 'min' => $range['min'],
- 'max' => $range['max'],
- 'value' => request()->filters[$rangeName . '_to'] ?? '',
- ])
- @endforeach
- @endif
- </form>
- </div>
- <div class="modal-footer">
- <button type="button" class="btn btn-primary accept-filters" data-bs-dismiss="modal">Применить</button>
- <button type="button" class="btn btn-outline-secondary reset-filters" data-bs-dismiss="modal">Сбросить
- </button>
- </div>
- </div>
- </div>
- </div>
- <!-- Модальное окно поиска -->
- <div class="modal fade" id="table_{{ $id }}_modal_search" tabindex="-1" aria-labelledby="exampleModalLabel"
- aria-hidden="true">
- <div class="modal-dialog modal-fullscreen-sm-down modal-lg">
- <div class="modal-content">
- <div class="modal-header">
- <h1 class="modal-title fs-5" id="exampleModalLabel">Поиск</h1>
- <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
- </div>
- <div class="modal-body">
- <div>
- Поиск ведётся по следующим колонкам:
- <span class="fst-italic">
- @foreach($searchFields as $searchField)
- {{ $header[$searchField] }}
- @if(!$loop->last)
- ,
- @endif
- @endforeach
- </span>
- </div>
- <form class="search-form">
- @include('partials.input', [
- 'name' => 's',
- 'title' => 'Поиск',
- 'placeholder' => 'что ищем?',
- 'value' => request()->s ?? '',
- ])
- </form>
- </div>
- <div class="modal-footer">
- <button type="button" class="btn btn-primary accept-search" data-bs-dismiss="modal">Найти</button>
- <button type="button" class="btn btn-outline-secondary reset-search" data-bs-dismiss="modal">Сбросить
- </button>
- </div>
- </div>
- </div>
- </div>
- @push('scripts')
- <script type="module">
- // on page load set column visible
- let tbl = $('#tbl');
- let tableName = tbl.attr('data-table-name');
- let tables = JSON.parse(localStorage.getItem('table_' + tableName));
- // on first load create tables object
- if (!tables) {
- tables = {};
- }
- // hide disabled columns
- $.each(tables, function (colName, colStatus) {
- if (!colStatus) {
- $('.checkbox-' + colName).attr('checked', false);
- $('.column_' + colName).hide();
- }
- });
- // highlight search text
- let searchText = $('.search-form input').val();
- if (searchText !== '') {
- let innerHTML = tbl.html();
- let index = innerHTML.indexOf(searchText);
- if (index >= 0) {
- innerHTML = innerHTML.substring(0, index) + "<span class='highlight'>" + innerHTML.substring(index, index + searchText.length) + "</span>" + innerHTML.substring(index + searchText.length);
- tbl.html(innerHTML);
- }
- }
- $('.table').fadeIn();
- $('.toggle-column').on('change', function () {
- let columnName = $(this).attr('data-name');
- let columnStatus = $(this).is(':checked');
- // save column status
- tables[columnName] = columnStatus;
- localStorage.setItem('table_' + tableName, JSON.stringify(tables));
- // show or hide column
- if (columnStatus) {
- $('.column_' + columnName).show('fast');
- } else {
- $('.column_' + columnName).hide('fast');
- }
- });
- $('.sort-by-column').on('click', function () {
- let columnName = $(this).attr('data-name');
- let currentUrl = new URL(document.location.href);
- let currentColumnName = currentUrl.searchParams.get('sortBy');
- currentUrl.searchParams.set('sortBy', columnName);
- if ((currentColumnName !== columnName) || (currentUrl.searchParams.has('order'))) {
- currentUrl.searchParams.delete('order');
- } else {
- currentUrl.searchParams.set('order', 'desc');
- }
- document.location.href = currentUrl.href;
- });
- $('.accept-filters').on('click', function () {
- let filters = $('.filters').serializeArray();
- let currentUrl = new URL(document.location.href);
- $.each(filters, function (id, filter) {
- if (filter.value !== '') {
- currentUrl.searchParams.set(filter.name, filter.value);
- } else {
- currentUrl.searchParams.delete(filter.name);
- }
- });
- currentUrl.searchParams.delete('page');
- document.location.href = currentUrl.href;
- });
- $('.reset-filters').on('click', function () {
- let filters = $('.filters').serializeArray();
- let currentUrl = new URL(document.location.href);
- $.each(filters, function (id, filter) {
- currentUrl.searchParams.delete(filter.name);
- });
- currentUrl.searchParams.delete('page');
- document.location.href = currentUrl.href;
- });
- $('.accept-search').on('click', function () {
- let s = $('.search-form input').val();
- let currentUrl = new URL(document.location.href);
- if (s !== '') {
- currentUrl.searchParams.set('s', s);
- } else {
- currentUrl.searchParams.delete('s');
- }
- currentUrl.searchParams.delete('page');
- document.location.href = currentUrl.href;
- });
- $('.reset-search').on('click', function () {
- let currentUrl = new URL(document.location.href);
- currentUrl.searchParams.delete('s');
- currentUrl.searchParams.delete('page');
- document.location.href = currentUrl.href;
- });
- $('.change-order-status').on('change', function () {
- let orderStatusId = $(this).val();
- let orderId = $(this).attr('data-order-id');
- $.post(
- '{{ route('order.update') }}',
- {
- '_token' : '{{ csrf_token() }}',
- id: orderId,
- order_status_id: orderStatusId
- },
- function () {
- $('.alerts').append(
- '<div class="main-alert alert alert-success" role="alert">Обновлён статус площадки!</div>'
- );
- setTimeout(function () {
- $('.main-alert').fadeTo(2000, 500).slideUp(500, function () {
- $(".main-alert").slideUp(500);
- })
- }, 3000);
- }
- );
- });
- $(document).ready(async function () {
- let height1 = $('.das').innerHeight();
- let height2 = $('.catalog').innerHeight();
- let totalHeight = (Number(height1) || 0) + (Number(height2) || 0);
- $(".table-responsive").css('maxHeight', $(window).height() - totalHeight - 50);
- });
- </script>
- @endpush
|